From 6b52d376b58be9248fb9919c9af36a434f153370 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Sat, 20 Jun 2020 10:37:14 +0200 Subject: [PATCH 1/8] Create new msgs module --- .../sdk38/src/cosmosclient.searchtx.spec.ts | 3 ++- packages/sdk38/src/cosmosclient.spec.ts | 3 ++- packages/sdk38/src/encoding.ts | 3 ++- packages/sdk38/src/index.ts | 14 ++---------- packages/sdk38/src/msgs.ts | 22 +++++++++++++++++++ packages/sdk38/src/restclient.spec.ts | 3 ++- packages/sdk38/src/signingcosmosclient.ts | 3 ++- packages/sdk38/src/types.ts | 22 +------------------ packages/sdk38/types/encoding.d.ts | 3 ++- packages/sdk38/types/index.d.ts | 14 ++---------- packages/sdk38/types/msgs.d.ts | 17 ++++++++++++++ packages/sdk38/types/types.d.ts | 17 +------------- 12 files changed, 57 insertions(+), 67 deletions(-) create mode 100644 packages/sdk38/src/msgs.ts create mode 100644 packages/sdk38/types/msgs.d.ts diff --git a/packages/sdk38/src/cosmosclient.searchtx.spec.ts b/packages/sdk38/src/cosmosclient.searchtx.spec.ts index b1c75d60..3bf1210f 100644 --- a/packages/sdk38/src/cosmosclient.searchtx.spec.ts +++ b/packages/sdk38/src/cosmosclient.searchtx.spec.ts @@ -4,6 +4,7 @@ import { assert, sleep } from "@cosmjs/utils"; import { Coin } from "./coins"; import { CosmosClient, isPostTxFailure } from "./cosmosclient"; import { makeSignBytes } from "./encoding"; +import { isMsgSend, MsgSend } from "./msgs"; import { Secp256k1Pen } from "./pen"; import { RestClient } from "./restclient"; import { SigningCosmosClient } from "./signingcosmosclient"; @@ -15,7 +16,7 @@ import { wasmd, wasmdEnabled, } from "./testutils.spec"; -import { CosmosSdkTx, isMsgSend, MsgSend } from "./types"; +import { CosmosSdkTx } from "./types"; describe("CosmosClient.searchTx", () => { let sendSuccessful: diff --git a/packages/sdk38/src/cosmosclient.spec.ts b/packages/sdk38/src/cosmosclient.spec.ts index 8cf1c1e4..cdea2316 100644 --- a/packages/sdk38/src/cosmosclient.spec.ts +++ b/packages/sdk38/src/cosmosclient.spec.ts @@ -5,6 +5,7 @@ import { ReadonlyDate } from "readonly-date"; import { CosmosClient, isPostTxFailure, PrivateCosmWasmClient } from "./cosmosclient"; import { makeSignBytes } from "./encoding"; import { findAttribute } from "./logs"; +import { MsgSend } from "./msgs"; import { Secp256k1Pen } from "./pen"; import cosmoshub from "./testdata/cosmoshub.json"; import { @@ -15,7 +16,7 @@ import { unused, wasmd, } from "./testutils.spec"; -import { MsgSend, StdFee } from "./types"; +import { StdFee } from "./types"; const blockTime = 1_000; // ms diff --git a/packages/sdk38/src/encoding.ts b/packages/sdk38/src/encoding.ts index 30a3193e..b4275fe9 100644 --- a/packages/sdk38/src/encoding.ts +++ b/packages/sdk38/src/encoding.ts @@ -1,6 +1,7 @@ import { toUtf8 } from "@cosmjs/encoding"; -import { Msg, StdFee } from "./types"; +import { Msg } from "./msgs"; +import { StdFee } from "./types"; function sortJson(json: any): any { if (typeof json !== "object" || json === null) { diff --git a/packages/sdk38/src/index.ts b/packages/sdk38/src/index.ts index 50ca53e3..c8fafcad 100644 --- a/packages/sdk38/src/index.ts +++ b/packages/sdk38/src/index.ts @@ -30,20 +30,10 @@ export { SearchTxsResponse, TxsResponse, } from "./restclient"; +export { isMsgSend, Msg, MsgSend } from "./msgs"; export { Pen, Secp256k1Pen, makeCosmoshubPath } from "./pen"; export { decodeBech32Pubkey, encodeBech32Pubkey, encodeSecp256k1Pubkey } from "./pubkey"; export { findSequenceForSignedTx } from "./sequence"; export { encodeSecp256k1Signature, decodeSignature } from "./signature"; export { FeeTable, SigningCallback, SigningCosmosClient } from "./signingcosmosclient"; -export { - isMsgSend, - isStdTx, - pubkeyType, - CosmosSdkTx, - PubKey, - Msg, - MsgSend, - StdFee, - StdSignature, - StdTx, -} from "./types"; +export { isStdTx, pubkeyType, CosmosSdkTx, PubKey, StdFee, StdSignature, StdTx } from "./types"; diff --git a/packages/sdk38/src/msgs.ts b/packages/sdk38/src/msgs.ts new file mode 100644 index 00000000..f503515d --- /dev/null +++ b/packages/sdk38/src/msgs.ts @@ -0,0 +1,22 @@ +import { Coin } from "./coins"; + +export interface Msg { + readonly type: string; + readonly value: any; +} + +/** A Cosmos SDK token transfer message */ +export interface MsgSend extends Msg { + readonly type: "cosmos-sdk/MsgSend"; + readonly value: { + /** Bech32 account address */ + readonly from_address: string; + /** Bech32 account address */ + readonly to_address: string; + readonly amount: ReadonlyArray; + }; +} + +export function isMsgSend(msg: Msg): msg is MsgSend { + return (msg as MsgSend).type === "cosmos-sdk/MsgSend"; +} diff --git a/packages/sdk38/src/restclient.spec.ts b/packages/sdk38/src/restclient.spec.ts index bdaea11a..33a184bc 100644 --- a/packages/sdk38/src/restclient.spec.ts +++ b/packages/sdk38/src/restclient.spec.ts @@ -7,6 +7,7 @@ import { rawSecp256k1PubkeyToAddress } from "./address"; import { isPostTxFailure } from "./cosmosclient"; import { makeSignBytes } from "./encoding"; import { parseLogs } from "./logs"; +import { Msg, MsgSend } from "./msgs"; import { makeCosmoshubPath, Secp256k1Pen } from "./pen"; import { encodeBech32Pubkey } from "./pubkey"; import { RestClient, TxsResponse } from "./restclient"; @@ -26,7 +27,7 @@ import { wasmd, wasmdEnabled, } from "./testutils.spec"; -import { Msg, MsgSend, StdFee, StdSignature, StdTx } from "./types"; +import { StdFee, StdSignature, StdTx } from "./types"; const emptyAddress = "cosmos1ltkhnmdcqemmd2tkhnx7qx66tq7e0wykw2j85k"; diff --git a/packages/sdk38/src/signingcosmosclient.ts b/packages/sdk38/src/signingcosmosclient.ts index c144955e..5d758071 100644 --- a/packages/sdk38/src/signingcosmosclient.ts +++ b/packages/sdk38/src/signingcosmosclient.ts @@ -1,8 +1,9 @@ import { Coin, coins } from "./coins"; import { Account, CosmosClient, GetNonceResult, PostTxResult } from "./cosmosclient"; import { makeSignBytes } from "./encoding"; +import { MsgSend } from "./msgs"; import { BroadcastMode } from "./restclient"; -import { MsgSend, StdFee, StdSignature } from "./types"; +import { StdFee, StdSignature } from "./types"; export interface SigningCallback { (signBytes: Uint8Array): Promise; diff --git a/packages/sdk38/src/types.ts b/packages/sdk38/src/types.ts index 814c393c..49346bf7 100644 --- a/packages/sdk38/src/types.ts +++ b/packages/sdk38/src/types.ts @@ -1,4 +1,5 @@ import { Coin } from "./coins"; +import { Msg } from "./msgs"; /** An Amino/Cosmos SDK StdTx */ export interface StdTx { @@ -20,27 +21,6 @@ export interface CosmosSdkTx { readonly value: StdTx; } -export interface Msg { - readonly type: string; - readonly value: any; -} - -/** A Cosmos SDK token transfer message */ -export interface MsgSend extends Msg { - readonly type: "cosmos-sdk/MsgSend"; - readonly value: { - /** Bech32 account address */ - readonly from_address: string; - /** Bech32 account address */ - readonly to_address: string; - readonly amount: ReadonlyArray; - }; -} - -export function isMsgSend(msg: Msg): msg is MsgSend { - return (msg as MsgSend).type === "cosmos-sdk/MsgSend"; -} - export interface StdFee { readonly amount: ReadonlyArray; readonly gas: string; diff --git a/packages/sdk38/types/encoding.d.ts b/packages/sdk38/types/encoding.d.ts index e51c7168..6eece8ca 100644 --- a/packages/sdk38/types/encoding.d.ts +++ b/packages/sdk38/types/encoding.d.ts @@ -1,4 +1,5 @@ -import { Msg, StdFee } from "./types"; +import { Msg } from "./msgs"; +import { StdFee } from "./types"; export declare function makeSignBytes( msgs: readonly Msg[], fee: StdFee, diff --git a/packages/sdk38/types/index.d.ts b/packages/sdk38/types/index.d.ts index 7a9de872..9b84fb42 100644 --- a/packages/sdk38/types/index.d.ts +++ b/packages/sdk38/types/index.d.ts @@ -28,20 +28,10 @@ export { SearchTxsResponse, TxsResponse, } from "./restclient"; +export { isMsgSend, Msg, MsgSend } from "./msgs"; export { Pen, Secp256k1Pen, makeCosmoshubPath } from "./pen"; export { decodeBech32Pubkey, encodeBech32Pubkey, encodeSecp256k1Pubkey } from "./pubkey"; export { findSequenceForSignedTx } from "./sequence"; export { encodeSecp256k1Signature, decodeSignature } from "./signature"; export { FeeTable, SigningCallback, SigningCosmosClient } from "./signingcosmosclient"; -export { - isMsgSend, - isStdTx, - pubkeyType, - CosmosSdkTx, - PubKey, - Msg, - MsgSend, - StdFee, - StdSignature, - StdTx, -} from "./types"; +export { isStdTx, pubkeyType, CosmosSdkTx, PubKey, StdFee, StdSignature, StdTx } from "./types"; diff --git a/packages/sdk38/types/msgs.d.ts b/packages/sdk38/types/msgs.d.ts new file mode 100644 index 00000000..a0ed1280 --- /dev/null +++ b/packages/sdk38/types/msgs.d.ts @@ -0,0 +1,17 @@ +import { Coin } from "./coins"; +export interface Msg { + readonly type: string; + readonly value: any; +} +/** A Cosmos SDK token transfer message */ +export interface MsgSend extends Msg { + readonly type: "cosmos-sdk/MsgSend"; + readonly value: { + /** Bech32 account address */ + readonly from_address: string; + /** Bech32 account address */ + readonly to_address: string; + readonly amount: ReadonlyArray; + }; +} +export declare function isMsgSend(msg: Msg): msg is MsgSend; diff --git a/packages/sdk38/types/types.d.ts b/packages/sdk38/types/types.d.ts index bb8390ed..2eb30fc9 100644 --- a/packages/sdk38/types/types.d.ts +++ b/packages/sdk38/types/types.d.ts @@ -1,4 +1,5 @@ import { Coin } from "./coins"; +import { Msg } from "./msgs"; /** An Amino/Cosmos SDK StdTx */ export interface StdTx { readonly msg: ReadonlyArray; @@ -11,22 +12,6 @@ export interface CosmosSdkTx { readonly type: string; readonly value: StdTx; } -export interface Msg { - readonly type: string; - readonly value: any; -} -/** A Cosmos SDK token transfer message */ -export interface MsgSend extends Msg { - readonly type: "cosmos-sdk/MsgSend"; - readonly value: { - /** Bech32 account address */ - readonly from_address: string; - /** Bech32 account address */ - readonly to_address: string; - readonly amount: ReadonlyArray; - }; -} -export declare function isMsgSend(msg: Msg): msg is MsgSend; export interface StdFee { readonly amount: ReadonlyArray; readonly gas: string; From 33d55e69238e78eebef07485c92dcc0739814f99 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Sat, 20 Jun 2020 10:48:39 +0200 Subject: [PATCH 2/8] Add MsgDelegate --- packages/cli/src/cli.ts | 1 + packages/sdk38/src/index.ts | 2 +- packages/sdk38/src/msgs.ts | 20 ++++++++++++++++++++ packages/sdk38/types/index.d.ts | 2 +- packages/sdk38/types/msgs.d.ts | 16 ++++++++++++++++ 5 files changed, 39 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/cli.ts b/packages/cli/src/cli.ts index 1e612b3d..f36c1b07 100644 --- a/packages/cli/src/cli.ts +++ b/packages/cli/src/cli.ts @@ -93,6 +93,7 @@ export function main(originalArgs: readonly string[]): void { "IndexedTx", "Coin", "Msg", + "MsgDelegate", "MsgSend", "Pen", "PubKey", diff --git a/packages/sdk38/src/index.ts b/packages/sdk38/src/index.ts index c8fafcad..30e02d4b 100644 --- a/packages/sdk38/src/index.ts +++ b/packages/sdk38/src/index.ts @@ -30,7 +30,7 @@ export { SearchTxsResponse, TxsResponse, } from "./restclient"; -export { isMsgSend, Msg, MsgSend } from "./msgs"; +export { isMsgDelegate, isMsgSend, Msg, MsgDelegate, MsgSend } from "./msgs"; export { Pen, Secp256k1Pen, makeCosmoshubPath } from "./pen"; export { decodeBech32Pubkey, encodeBech32Pubkey, encodeSecp256k1Pubkey } from "./pubkey"; export { findSequenceForSignedTx } from "./sequence"; diff --git a/packages/sdk38/src/msgs.ts b/packages/sdk38/src/msgs.ts index f503515d..83937893 100644 --- a/packages/sdk38/src/msgs.ts +++ b/packages/sdk38/src/msgs.ts @@ -20,3 +20,23 @@ export interface MsgSend extends Msg { export function isMsgSend(msg: Msg): msg is MsgSend { return (msg as MsgSend).type === "cosmos-sdk/MsgSend"; } + +/** + * A Cosmos SDK MsgDelegate + * + * @see https://docs.cosmos.network/master/modules/staking/03_messages.html#msgdelegate + */ +export interface MsgDelegate extends Msg { + readonly type: "cosmos-sdk/MsgDelegate"; + readonly value: { + /** Bech32 encoded delegator address */ + readonly delegator_address: string; + /** Bech32 encoded validator address */ + readonly validator_address: string; + readonly amount: Coin; + }; +} + +export function isMsgDelegate(msg: Msg): msg is MsgDelegate { + return (msg as MsgDelegate).type === "cosmos-sdk/MsgDelegate"; +} diff --git a/packages/sdk38/types/index.d.ts b/packages/sdk38/types/index.d.ts index 9b84fb42..a6b777b9 100644 --- a/packages/sdk38/types/index.d.ts +++ b/packages/sdk38/types/index.d.ts @@ -28,7 +28,7 @@ export { SearchTxsResponse, TxsResponse, } from "./restclient"; -export { isMsgSend, Msg, MsgSend } from "./msgs"; +export { isMsgDelegate, isMsgSend, Msg, MsgDelegate, MsgSend } from "./msgs"; export { Pen, Secp256k1Pen, makeCosmoshubPath } from "./pen"; export { decodeBech32Pubkey, encodeBech32Pubkey, encodeSecp256k1Pubkey } from "./pubkey"; export { findSequenceForSignedTx } from "./sequence"; diff --git a/packages/sdk38/types/msgs.d.ts b/packages/sdk38/types/msgs.d.ts index a0ed1280..eabba375 100644 --- a/packages/sdk38/types/msgs.d.ts +++ b/packages/sdk38/types/msgs.d.ts @@ -15,3 +15,19 @@ export interface MsgSend extends Msg { }; } export declare function isMsgSend(msg: Msg): msg is MsgSend; +/** + * A Cosmos SDK MsgDelegate + * + * @see https://docs.cosmos.network/master/modules/staking/03_messages.html#msgdelegate + */ +export interface MsgDelegate extends Msg { + readonly type: "cosmos-sdk/MsgDelegate"; + readonly value: { + /** Bech32 encoded delegator address */ + readonly delegator_address: string; + /** Bech32 encoded validator address */ + readonly validator_address: string; + readonly amount: Coin; + }; +} +export declare function isMsgDelegate(msg: Msg): msg is MsgDelegate; From 3e7ab8ac5287b86c8e1cad081e585320ed5333f0 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Sat, 20 Jun 2020 14:17:57 +0200 Subject: [PATCH 3/8] Rename to StdSignDoc --- packages/sdk38/src/encoding.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/sdk38/src/encoding.ts b/packages/sdk38/src/encoding.ts index b4275fe9..c5cefc8d 100644 --- a/packages/sdk38/src/encoding.ts +++ b/packages/sdk38/src/encoding.ts @@ -21,7 +21,12 @@ function sortJson(json: any): any { return result; } -interface SignJson { +/** + * The document to be signed + * + * @see https://docs.cosmos.network/master/modules/auth/03_types.html#stdsigndoc + */ +interface StdSignDoc { readonly account_number: string; readonly chain_id: string; readonly fee: StdFee; @@ -38,7 +43,7 @@ export function makeSignBytes( accountNumber: number, sequence: number, ): Uint8Array { - const signJson: SignJson = { + const signDoc: StdSignDoc = { // eslint-disable-next-line @typescript-eslint/camelcase account_number: accountNumber.toString(), // eslint-disable-next-line @typescript-eslint/camelcase @@ -48,6 +53,6 @@ export function makeSignBytes( msgs: msgs, sequence: sequence.toString(), }; - const signMsg = sortJson(signJson); - return toUtf8(JSON.stringify(signMsg)); + const sortedSignDoc = sortJson(signDoc); + return toUtf8(JSON.stringify(sortedSignDoc)); } From d5f874e608dcc38a598cbbbbe7ee4c8d714234c9 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Sat, 20 Jun 2020 14:39:26 +0200 Subject: [PATCH 4/8] Improve StdTx docs --- packages/sdk38/src/types.ts | 10 +++++++--- packages/sdk38/types/types.d.ts | 10 +++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/packages/sdk38/src/types.ts b/packages/sdk38/src/types.ts index 49346bf7..e0c085a8 100644 --- a/packages/sdk38/src/types.ts +++ b/packages/sdk38/src/types.ts @@ -1,11 +1,15 @@ import { Coin } from "./coins"; import { Msg } from "./msgs"; -/** An Amino/Cosmos SDK StdTx */ +/** + * A Cosmos SDK StdTx + * + * @see https://docs.cosmos.network/master/modules/auth/03_types.html#stdtx + */ export interface StdTx { - readonly msg: ReadonlyArray; + readonly msg: readonly Msg[]; readonly fee: StdFee; - readonly signatures: ReadonlyArray; + readonly signatures: readonly StdSignature[]; readonly memo: string | undefined; } diff --git a/packages/sdk38/types/types.d.ts b/packages/sdk38/types/types.d.ts index 2eb30fc9..2f3d218d 100644 --- a/packages/sdk38/types/types.d.ts +++ b/packages/sdk38/types/types.d.ts @@ -1,10 +1,14 @@ import { Coin } from "./coins"; import { Msg } from "./msgs"; -/** An Amino/Cosmos SDK StdTx */ +/** + * A Cosmos SDK StdTx + * + * @see https://docs.cosmos.network/master/modules/auth/03_types.html#stdtx + */ export interface StdTx { - readonly msg: ReadonlyArray; + readonly msg: readonly Msg[]; readonly fee: StdFee; - readonly signatures: ReadonlyArray; + readonly signatures: readonly StdSignature[]; readonly memo: string | undefined; } export declare function isStdTx(txValue: unknown): txValue is StdTx; From b36d324e6c7c6a456a74166bec4aa84f6fcfd028 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Mon, 22 Jun 2020 10:34:37 +0200 Subject: [PATCH 5/8] Harden signedTx --- .../cosmwasm/src/signingcosmwasmclient.ts | 19 ++++++++++++++----- packages/sdk38/src/signingcosmosclient.ts | 4 ++-- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/packages/cosmwasm/src/signingcosmwasmclient.ts b/packages/cosmwasm/src/signingcosmwasmclient.ts index 3e52b236..5f2480dc 100644 --- a/packages/cosmwasm/src/signingcosmwasmclient.ts +++ b/packages/cosmwasm/src/signingcosmwasmclient.ts @@ -1,6 +1,15 @@ import { Sha256 } from "@cosmjs/crypto"; import { toBase64, toHex } from "@cosmjs/encoding"; -import { BroadcastMode, Coin, coins, makeSignBytes, MsgSend, StdFee, StdSignature } from "@cosmjs/sdk38"; +import { + BroadcastMode, + Coin, + coins, + makeSignBytes, + MsgSend, + StdFee, + StdSignature, + StdTx, +} from "@cosmjs/sdk38"; import pako from "pako"; import { isValidBuilder } from "./builder"; @@ -157,7 +166,7 @@ export class SigningCosmWasmClient extends CosmWasmClient { const chainId = await this.getChainId(); const signBytes = makeSignBytes([storeCodeMsg], fee, chainId, memo, accountNumber, sequence); const signature = await this.signCallback(signBytes); - const signedTx = { + const signedTx: StdTx = { msg: [storeCodeMsg], fee: fee, memo: memo, @@ -206,7 +215,7 @@ export class SigningCosmWasmClient extends CosmWasmClient { const signBytes = makeSignBytes([instantiateMsg], fee, chainId, memo, accountNumber, sequence); const signature = await this.signCallback(signBytes); - const signedTx = { + const signedTx: StdTx = { msg: [instantiateMsg], fee: fee, memo: memo, @@ -246,7 +255,7 @@ export class SigningCosmWasmClient extends CosmWasmClient { const chainId = await this.getChainId(); const signBytes = makeSignBytes([executeMsg], fee, chainId, memo, accountNumber, sequence); const signature = await this.signCallback(signBytes); - const signedTx = { + const signedTx: StdTx = { msg: [executeMsg], fee: fee, memo: memo, @@ -283,7 +292,7 @@ export class SigningCosmWasmClient extends CosmWasmClient { const chainId = await this.getChainId(); const signBytes = makeSignBytes([sendMsg], fee, chainId, memo, accountNumber, sequence); const signature = await this.signCallback(signBytes); - const signedTx = { + const signedTx: StdTx = { msg: [sendMsg], fee: fee, memo: memo, diff --git a/packages/sdk38/src/signingcosmosclient.ts b/packages/sdk38/src/signingcosmosclient.ts index 5d758071..4768bf60 100644 --- a/packages/sdk38/src/signingcosmosclient.ts +++ b/packages/sdk38/src/signingcosmosclient.ts @@ -3,7 +3,7 @@ import { Account, CosmosClient, GetNonceResult, PostTxResult } from "./cosmoscli import { makeSignBytes } from "./encoding"; import { MsgSend } from "./msgs"; import { BroadcastMode } from "./restclient"; -import { StdFee, StdSignature } from "./types"; +import { StdFee, StdSignature, StdTx } from "./types"; export interface SigningCallback { (signBytes: Uint8Array): Promise; @@ -96,7 +96,7 @@ export class SigningCosmosClient extends CosmosClient { const chainId = await this.getChainId(); const signBytes = makeSignBytes([sendMsg], fee, chainId, memo, accountNumber, sequence); const signature = await this.signCallback(signBytes); - const signedTx = { + const signedTx: StdTx = { msg: [sendMsg], fee: fee, memo: memo, From e157c35104b2aa12f5df4f7399f6cc90073557bc Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Mon, 22 Jun 2020 10:35:17 +0200 Subject: [PATCH 6/8] Avoid shell globbing in jq query --- scripts/wasmd/deploy_staking.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/wasmd/deploy_staking.js b/scripts/wasmd/deploy_staking.js index 24d86d06..3248a9a3 100755 --- a/scripts/wasmd/deploy_staking.js +++ b/scripts/wasmd/deploy_staking.js @@ -17,7 +17,7 @@ const codeMeta = { }; // To get the proper validator address, run the demo chain (./scripts/wasmd/start.sh), then run: -// curl http://localhost:1317/staking/validators | jq .result[0].operator_address +// curl http://localhost:1317/staking/validators | jq '.result[0].operator_address' const bounty = { label: "Bounty", initMsg: { From ccd9a5db11292a02c2081306700060e04091c98e Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Mon, 22 Jun 2020 10:35:29 +0200 Subject: [PATCH 7/8] Import missing types to CLI --- packages/cli/src/cli.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/cli/src/cli.ts b/packages/cli/src/cli.ts index f36c1b07..3ac27c5c 100644 --- a/packages/cli/src/cli.ts +++ b/packages/cli/src/cli.ts @@ -92,6 +92,7 @@ export function main(originalArgs: readonly string[]): void { "makeSignBytes", "IndexedTx", "Coin", + "CosmosClient", "Msg", "MsgDelegate", "MsgSend", @@ -100,6 +101,7 @@ export function main(originalArgs: readonly string[]): void { "pubkeyToAddress", "RestClient", "Secp256k1Pen", + "SigningCosmosClient", "StdFee", "StdTx", ], From 8b535aa01a69e59217e7e680ea8691219a5c3dc1 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Mon, 22 Jun 2020 10:35:37 +0200 Subject: [PATCH 8/8] Add delegation demo --- packages/cli/examples/delegate.ts | 38 +++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 packages/cli/examples/delegate.ts diff --git a/packages/cli/examples/delegate.ts b/packages/cli/examples/delegate.ts new file mode 100644 index 00000000..9d6fc327 --- /dev/null +++ b/packages/cli/examples/delegate.ts @@ -0,0 +1,38 @@ +const pen = await Secp256k1Pen.fromMnemonic("enlist hip relief stomach skate base shallow young switch frequent cry park"); +const senderAddress = pen.address("cosmos"); + +const client = new CosmosClient("http://localhost:1317"); + +const msg: MsgDelegate = { + type: "cosmos-sdk/MsgDelegate", + value: { + delegator_address: senderAddress, + // To get the proper validator address, start the demo chain (./scripts/wasmd/start.sh), then run: + // curl http://localhost:1317/staking/validators | jq '.result[0].operator_address' + validator_address: "cosmosvaloper1gjvanqxc774u6ed9thj4gpn9gj5zus5u32enqn", + amount: coin(300000, "ustake"), + } +} +const fee = { + amount: coins(2000, "ucosm"), + gas: "120000", // 120k +}; +const memo = "Use your power wisely"; + +const chainId = await client.getChainId(); +console.log("Connected to chain:", chainId); + +const { accountNumber, sequence } = await client.getNonce(senderAddress); +console.log("Account/sequence:", accountNumber, sequence); + +const signBytes = makeSignBytes([msg], fee, chainId, memo, accountNumber, sequence); +const signature = await pen.sign(signBytes); +const signedTx: StdTx = { + msg: [msg], + fee: fee, + memo: memo, + signatures: [signature], +}; + +const result = await client.postTx(signedTx); +console.log("Post result:", result);