Skip to content

Commit

Permalink
feat: msgSubmitGenericProposal
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasRalee committed Aug 21, 2024
1 parent d1de9a5 commit d9de27b
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/sdk-ts/src/core/accounts/PrivateKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export class PrivateKey {
* @returns {PublicKey} a Public key that can be used to verify the signatures made with this PrivateKey
**/
toPublicKey(): PublicKey {
return PublicKey.fromHex(this.wallet.privateKey)
return PublicKey.fromPrivateKeyHex(this.wallet.privateKey)
}

/**
Expand Down
21 changes: 12 additions & 9 deletions packages/sdk-ts/src/core/modules/gov/index.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
import MsgVote from './msgs/MsgVote'
import MsgGovDeposit from './msgs/MsgDeposit'
import MsgSubmitProposalExpiryFuturesMarketLaunch from './msgs/MsgSubmitProposalExpiryFuturesMarketLaunch'
import MsgSubmitProposalPerpetualMarketLaunch from './msgs/MsgSubmitProposalPerpetualMarketLaunch'
import MsgSubmitTextProposal from './msgs/MsgSubmitTextProposal'
import MsgSubmitGenericProposal from './msgs/MsgSubmitGenericProposal'
import MsgSubmitProposalSpotMarketLaunch from './msgs/MsgSubmitProposalSpotMarketLaunch'
import MsgSubmitProposalPerpetualMarketLaunch from './msgs/MsgSubmitProposalPerpetualMarketLaunch'
import MsgSubmitProposalSpotMarketParamUpdate from './msgs/MsgSubmitProposalSpotMarketParamUpdate'
import MsgSubmitTextProposal from './msgs/MsgSubmitTextProposal'
import MsgSubmitProposalExpiryFuturesMarketLaunch from './msgs/MsgSubmitProposalExpiryFuturesMarketLaunch'

export type MsgSubmitProposal =
| MsgSubmitProposalExpiryFuturesMarketLaunch
| MsgSubmitProposalPerpetualMarketLaunch
| MsgSubmitTextProposal
| MsgSubmitGenericProposal
| MsgSubmitProposalSpotMarketLaunch
| MsgSubmitProposalPerpetualMarketLaunch
| MsgSubmitProposalSpotMarketParamUpdate
| MsgSubmitTextProposal
| MsgSubmitProposalExpiryFuturesMarketLaunch

export {
MsgSubmitProposalExpiryFuturesMarketLaunch,
MsgSubmitProposalPerpetualMarketLaunch,
MsgSubmitTextProposal,
MsgSubmitGenericProposal,
MsgSubmitProposalSpotMarketLaunch,
MsgSubmitProposalPerpetualMarketLaunch,
MsgSubmitProposalSpotMarketParamUpdate,
MsgSubmitTextProposal,
MsgSubmitProposalExpiryFuturesMarketLaunch,
}

export * from './ProposalContentDecomposer'
Expand Down
137 changes: 137 additions & 0 deletions packages/sdk-ts/src/core/modules/gov/msgs/MsgSubmitGenericProposal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
import snakecaseKeys from 'snakecase-keys'
import {
CosmosGovV1Tx,
GoogleProtobufAny,
CosmosBaseV1Beta1Coin,
} from '@injectivelabs/core-proto-ts'
import { MsgBase } from '../../MsgBase'
import { Msgs } from '../../../../core/modules/msgs'

export declare namespace MsgSubmitGenericProposal {
export interface Params {
title: string
summary: string
expedited?: boolean
proposer: string
metadata?: string
messages: Msgs[]
deposit: {
amount: string
denom: string
}
}

export type Proto = CosmosGovV1Tx.MsgSubmitProposal
}

/**
* @category Messages
*/
export default class MsgSubmitGenericProposal extends MsgBase<
MsgSubmitGenericProposal.Params,
MsgSubmitGenericProposal.Proto
> {
static fromJSON(
params: MsgSubmitGenericProposal.Params,
): MsgSubmitGenericProposal {
return new MsgSubmitGenericProposal(params)
}

public toProto() {
const { params } = this

const depositParams = CosmosBaseV1Beta1Coin.Coin.create()

depositParams.denom = params.deposit.denom
depositParams.amount = params.deposit.amount

const message = CosmosGovV1Tx.MsgSubmitProposal.create()

message.messages = params.messages.map((msg) => {
const contentAny = GoogleProtobufAny.Any.create()

contentAny.typeUrl = msg.toDirectSign().type
contentAny.value = msg.toBinary()

return contentAny
})
message.initialDeposit = [depositParams]
message.proposer = params.proposer
message.metadata = params.metadata || ''
message.title = params.title
message.summary = params.summary
message.expedited = params.expedited || false

return CosmosGovV1Tx.MsgSubmitProposal.fromPartial(message)
}

public toData() {
const proto = this.toProto()

return {
'@type': '/cosmos.gov.v1.MsgSubmitProposal',
...proto,
}
}

public toAmino() {
const { params } = this

const messageWithProposalType: any = snakecaseKeys({
messages: params.messages.map((msg) => msg.toAmino()),
initialDeposit: [
{
denom: params.deposit.denom,
amount: params.deposit.amount,
},
],
proposer: params.proposer,
metadata: params.metadata || '',
title: params.title,
summary: params.summary,
expedited: params.expedited || false,
})

return {
type: 'cosmos-sdk/MsgSubmitProposal',
value: messageWithProposalType,
}
}

public toWeb3() {
const { params } = this

const messageWithProposalType: any = {
messages: params.messages.map((msg) => msg.toWeb3()),
initialDeposit: [
{
denom: params.deposit.denom,
amount: params.deposit.amount,
},
],
proposer: params.proposer,
metadata: params.metadata || '',
title: params.title,
summary: params.summary,
expedited: params.expedited || false,
}

return {
'@type': '/cosmos.gov.v1.MsgSubmitProposal',
...messageWithProposalType,
}
}

public toDirectSign() {
const proto = this.toProto()

return {
type: '/cosmos.gov.v1.MsgSubmitProposal',
message: proto,
}
}

public toBinary(): Uint8Array {
return CosmosGovV1Tx.MsgSubmitProposal.encode(this.toProto()).finish()
}
}

0 comments on commit d9de27b

Please sign in to comment.