Skip to content

Commit

Permalink
Merge pull request #50 from bandprotocol/feat/fix-MsgSubmitProposal
Browse files Browse the repository at this point in the history
fix bug MsgSubmitProposal content
  • Loading branch information
babybunn authored Sep 1, 2023
2 parents d816a15 + 1a068ab commit 6a54a07
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 17 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bandprotocol/bandchain.js",
"version": "2.2.0",
"version": "2.2.1",
"description": "Library for interacting with BandChain in browser and Node.js environments",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ export { Obi } from './obi'
export { Coin } from '../proto/cosmos/base/v1beta1/coin_pb'
export { Fee } from '../proto/cosmos/tx/v1beta1/tx_pb'
export * as Proposal from './proposal'
export { Plan } from '../proto/cosmos/upgrade/v1beta1/upgrade_pb'
export { ParamChange } from '../proto/cosmos/params/v1beta1/params_pb'
22 changes: 12 additions & 10 deletions src/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ export class MsgSubmitProposal
constructor(
initialDepositList: Coin[],
proposer: string,
content?: Proposal.Content,
public content?: Proposal.Content,
) {
super()
this.setInitialDepositList(initialDepositList)
Expand All @@ -724,14 +724,15 @@ export class MsgSubmitProposal
}

toJSON(): object {
const { content } = this
return {
type: 'cosmos-sdk/MsgSubmitProposal',
value: {
proposer: this.getProposer(),
proposer: this.getProposer().toString(),
initial_deposit: this.getInitialDepositList().map((coin) =>
coin.toObject(),
),
content: this.getContent()?.toObject(),
content: content.toJSON(),
},
}
}
Expand Down Expand Up @@ -762,7 +763,7 @@ export class MsgSubmitCouncilProposal
title: string,
council: CouncilTypeMap[keyof CouncilTypeMap],
proposer: string,
messagesList: Array<BaseMsg>,
public messagesList: Array<BaseMsg>,
metadata: string,
) {
super()
Expand All @@ -787,13 +788,14 @@ export class MsgSubmitCouncilProposal
}

toJSON(): object {
const { messagesList } = this
return {
type: 'council/MsgSubmitProposal',
value: {
title: this.getTitle(),
council: this.getCouncil(),
messages: this.getMessagesList().map((msg) => msg.toObject()),
metadata: this.getMetadata(),
title: this.getTitle().toString(),
council: this.getCouncil().toString(),
messages: messagesList.map((msg: BaseMsg) => msg.toJSON()),
metadata: this.getMetadata().toString(),
},
}
}
Expand Down Expand Up @@ -843,8 +845,8 @@ export class MsgVoteCouncil extends MsgVoteCouncilProto implements BaseMsg {
type: 'council/MsgVote',
value: {
proposal_id: this.getProposalId().toString(),
voter: this.getVoter(),
option: this.getOption(),
voter: this.getVoter().toString(),
option: this.getOption().toString(),
},
}
}
Expand Down
78 changes: 72 additions & 6 deletions src/proposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ import {
} from '../proto/cosmos/upgrade/v1beta1/upgrade_pb'
import { VetoProposal as VetoProposalPb } from '../proto/council/v1beta1/types_pb'
import { Coin } from '../proto/cosmos/base/v1beta1/coin_pb'
import { Message as JSPBMesage } from 'google-protobuf'

export interface BaseMsg extends JSPBMesage {
toAny(): Any
}
import { BaseMsg } from 'message'

export class TextProposal extends TextProposalPb implements BaseMsg {
constructor(title: string, description: string) {
Expand All @@ -30,6 +26,16 @@ export class TextProposal extends TextProposalPb implements BaseMsg {
any.pack(this.serializeBinary(), 'cosmos.gov.v1beta1.TextProposal', '/')
return any
}

toJSON(): object {
return {
type: 'cosmos-sdk/TextProposal',
value: {
title: this.getTitle().toString(),
description: this.getDescription().toString(),
},
}
}
}

export class CommunityPoolSpendProposal
Expand Down Expand Up @@ -58,6 +64,18 @@ export class CommunityPoolSpendProposal
)
return any
}

toJSON(): object {
return {
type: 'cosmos-sdk/CommunityPoolSpend',
value: {
title: this.getTitle().toString(),
description: this.getDescription().toString(),
recipient: this.getRecipient().toString(),
amount: this.getAmountList().map((coin) => coin.toObject()),
},
}
}
}

export class ParameterChangeProposal
Expand All @@ -80,13 +98,24 @@ export class ParameterChangeProposal
)
return any
}

toJSON(): object {
return {
type: 'cosmos-sdk/ParameterChangeProposal',
value: {
title: this.getTitle().toString(),
description: this.getDescription().toString(),
changes: this.getChangesList().map((change) => change.toObject()),
},
}
}
}

export class SoftwareUpgradeProposal
extends SoftwareUpgradeProposalPb
implements BaseMsg
{
constructor(title: string, description: string, plan: Plan) {
constructor(title: string, description: string, public plan: Plan) {
super()
this.setTitle(title)
this.setDescription(description)
Expand All @@ -102,6 +131,23 @@ export class SoftwareUpgradeProposal
)
return any
}

toJSON(): object {
const plan = this.getPlan()

return {
type: 'cosmos-sdk/SoftwareUpgradeProposal',
value: {
title: this.getTitle().toString(),
description: this.getDescription(),
plan: {
info: plan.getInfo().toString(),
name: plan.getName().toString(),
height: plan.getHeight().toString(),
},
},
}
}
}

export class CancelSoftwareUpgradeProposal
Expand All @@ -123,6 +169,16 @@ export class CancelSoftwareUpgradeProposal
)
return any
}

toJSON(): object {
return {
type: 'cosmos-sdk/CancelSoftwareUpgradeProposal',
value: {
title: this.getTitle().toString(),
description: this.getDescription().toString(),
},
}
}
}

export class VetoProposal extends VetoProposalPb implements BaseMsg {
Expand All @@ -137,6 +193,16 @@ export class VetoProposal extends VetoProposalPb implements BaseMsg {
any.pack(this.serializeBinary(), 'council.v1beta1.VetoProposal', '/')
return any
}

toJSON(): object {
return {
type: 'council/VetoProposal',
value: {
proposal_id: this.getProposalId().toString(),
description: this.getDescription().toString(),
},
}
}
}

export namespace Proposal {
Expand Down

0 comments on commit 6a54a07

Please sign in to comment.