From 5dcaf706dde998ac49d16dc3d4a6a49c5f4480a8 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Mon, 3 Aug 2020 17:23:05 +0200 Subject: [PATCH 1/2] Rename postTx -> broadcastTx in launchpad/cosmwasm etc --- packages/cli/README.md | 2 +- packages/cli/examples/delegate.ts | 4 +- packages/cli/src/cli.ts | 2 +- .../src/cosmwasmclient.searchtx.spec.ts | 6 +- packages/cosmwasm/src/cosmwasmclient.spec.ts | 14 ++- packages/cosmwasm/src/cosmwasmclient.ts | 8 +- packages/cosmwasm/src/lcdapi/wasm.spec.ts | 32 +++---- .../src/signingcosmwasmclient.spec.ts | 10 +- .../cosmwasm/src/signingcosmwasmclient.ts | 56 +++++------ packages/cosmwasm/types/cosmwasmclient.d.ts | 6 +- .../cosmwasm/types/signingcosmwasmclient.d.ts | 12 ++- packages/faucet/src/faucet.ts | 2 +- .../src/cosmosclient.searchtx.spec.ts | 6 +- packages/launchpad/src/cosmosclient.spec.ts | 8 +- packages/launchpad/src/cosmosclient.ts | 26 +++--- packages/launchpad/src/index.ts | 14 +-- packages/launchpad/src/lcdapi/base.ts | 2 +- .../launchpad/src/lcdapi/distribution.spec.ts | 6 +- packages/launchpad/src/lcdapi/gov.spec.ts | 8 +- packages/launchpad/src/lcdapi/index.ts | 2 +- .../launchpad/src/lcdapi/lcdclient.spec.ts | 92 +++++++++---------- packages/launchpad/src/lcdapi/lcdclient.ts | 8 +- packages/launchpad/src/lcdapi/staking.spec.ts | 10 +- .../launchpad/src/signingcosmosclient.spec.ts | 10 +- packages/launchpad/src/signingcosmosclient.ts | 14 +-- packages/launchpad/types/cosmosclient.d.ts | 18 ++-- packages/launchpad/types/index.d.ts | 14 +-- packages/launchpad/types/lcdapi/base.d.ts | 2 +- packages/launchpad/types/lcdapi/index.d.ts | 2 +- .../launchpad/types/lcdapi/lcdclient.d.ts | 6 +- .../launchpad/types/signingcosmosclient.d.ts | 14 ++- packages/tendermint-rpc/src/client.spec.ts | 2 +- scripts/wasmd/send_first.js | 9 +- 33 files changed, 224 insertions(+), 203 deletions(-) diff --git a/packages/cli/README.md b/packages/cli/README.md index 98c086c2..e406fd12 100644 --- a/packages/cli/README.md +++ b/packages/cli/README.md @@ -81,7 +81,7 @@ const signedTx: StdTx = { memo: memo, signatures: [signature], }; -const postResult = await client.postTx(signedTx); +const broadcastResult = await client.broadcastTx(signedTx); ``` ## Extended helpers diff --git a/packages/cli/examples/delegate.ts b/packages/cli/examples/delegate.ts index c9e4830c..7055050f 100644 --- a/packages/cli/examples/delegate.ts +++ b/packages/cli/examples/delegate.ts @@ -36,5 +36,5 @@ const signedTx: StdTx = { signatures: [signature], }; -const result = await client.postTx(signedTx); -console.log("Post result:", result); +const result = await client.broadcastTx(signedTx); +console.log("Broadcast result:", result); diff --git a/packages/cli/src/cli.ts b/packages/cli/src/cli.ts index b256d2f4..a9754714 100644 --- a/packages/cli/src/cli.ts +++ b/packages/cli/src/cli.ts @@ -95,6 +95,7 @@ export async function main(originalArgs: readonly string[]): Promise { "makeCosmoshubPath", "makeSignBytes", "IndexedTx", + "BroadcastTxResult", "Coin", "CosmosClient", "Msg", @@ -102,7 +103,6 @@ export async function main(originalArgs: readonly string[]): Promise { "MsgSend", "LcdClient", "OfflineSigner", - "PostTxResult", "PubKey", "pubkeyToAddress", "Secp256k1Wallet", diff --git a/packages/cosmwasm/src/cosmwasmclient.searchtx.spec.ts b/packages/cosmwasm/src/cosmwasmclient.searchtx.spec.ts index 8c0747ef..b9d6d359 100644 --- a/packages/cosmwasm/src/cosmwasmclient.searchtx.spec.ts +++ b/packages/cosmwasm/src/cosmwasmclient.searchtx.spec.ts @@ -3,8 +3,8 @@ import { Coin, coins, CosmosSdkTx, + isBroadcastTxFailure, isMsgSend, - isPostTxFailure, LcdClient, makeSignBytes, MsgSend, @@ -115,8 +115,8 @@ describe("CosmWasmClient.searchTx", () => { }, }; const transactionId = await client.getIdentifier(tx); - const result = await client.postTx(tx.value); - if (isPostTxFailure(result)) { + const result = await client.broadcastTx(tx.value); + if (isBroadcastTxFailure(result)) { sendUnsuccessful = { sender: alice.address0, recipient: recipient, diff --git a/packages/cosmwasm/src/cosmwasmclient.spec.ts b/packages/cosmwasm/src/cosmwasmclient.spec.ts index 6b917752..868aa02a 100644 --- a/packages/cosmwasm/src/cosmwasmclient.spec.ts +++ b/packages/cosmwasm/src/cosmwasmclient.spec.ts @@ -1,7 +1,13 @@ /* eslint-disable @typescript-eslint/naming-convention */ import { Sha256 } from "@cosmjs/crypto"; import { Bech32, fromHex, fromUtf8, toAscii, toBase64 } from "@cosmjs/encoding"; -import { assertIsPostTxSuccess, makeSignBytes, MsgSend, Secp256k1Wallet, StdFee } from "@cosmjs/launchpad"; +import { + assertIsBroadcastTxSuccess, + makeSignBytes, + MsgSend, + Secp256k1Wallet, + StdFee, +} from "@cosmjs/launchpad"; import { assert, sleep } from "@cosmjs/utils"; import { ReadonlyDate } from "readonly-date"; @@ -197,7 +203,7 @@ describe("CosmWasmClient", () => { }); }); - describe("postTx", () => { + describe("broadcastTx", () => { it("works", async () => { pendingWithoutWasmd(); const wallet = await Secp256k1Wallet.fromMnemonic(alice.mnemonic); @@ -238,8 +244,8 @@ describe("CosmWasmClient", () => { memo: memo, signatures: [signature], }; - const result = await client.postTx(signedTx); - assertIsPostTxSuccess(result); + const result = await client.broadcastTx(signedTx); + assertIsBroadcastTxSuccess(result); const { logs, transactionHash } = result; const amountAttr = findAttribute(logs, "transfer", "amount"); expect(amountAttr.value).toEqual("1234567ucosm"); diff --git a/packages/cosmwasm/src/cosmwasmclient.ts b/packages/cosmwasm/src/cosmwasmclient.ts index 358c0fda..cd2bf88d 100644 --- a/packages/cosmwasm/src/cosmwasmclient.ts +++ b/packages/cosmwasm/src/cosmwasmclient.ts @@ -3,12 +3,12 @@ import { fromBase64, fromHex, toHex } from "@cosmjs/encoding"; import { AuthExtension, BroadcastMode, + BroadcastTxResult, Coin, CosmosSdkTx, IndexedTx, LcdClient, normalizePubkey, - PostTxResult, PubKey, setupAuthExtension, StdTx, @@ -163,7 +163,7 @@ export class CosmWasmClient { * for the lifetime of your application. When switching backends, a new instance must be created. * * @param apiUrl The URL of a Cosmos SDK light client daemon API (sometimes called REST server or REST API) - * @param broadcastMode Defines at which point of the transaction processing the postTx method (i.e. transaction broadcasting) returns + * @param broadcastMode Defines at which point of the transaction processing the broadcastTx method returns */ public constructor(apiUrl: string, broadcastMode = BroadcastMode.Block) { this.lcdClient = LcdClient.withExtensions( @@ -321,8 +321,8 @@ export class CosmWasmClient { return filtered; } - public async postTx(tx: StdTx): Promise { - const result = await this.lcdClient.postTx(tx); + public async broadcastTx(tx: StdTx): Promise { + const result = await this.lcdClient.broadcastTx(tx); if (!result.txhash.match(/^([0-9A-F][0-9A-F])+$/)) { throw new Error("Received ill-formatted txhash. Must be non-empty upper-case hex"); } diff --git a/packages/cosmwasm/src/lcdapi/wasm.spec.ts b/packages/cosmwasm/src/lcdapi/wasm.spec.ts index 0e0b7204..7f087172 100644 --- a/packages/cosmwasm/src/lcdapi/wasm.spec.ts +++ b/packages/cosmwasm/src/lcdapi/wasm.spec.ts @@ -2,16 +2,16 @@ import { Sha256 } from "@cosmjs/crypto"; import { Bech32, fromAscii, fromHex, fromUtf8, toAscii, toBase64, toHex } from "@cosmjs/encoding"; import { - assertIsPostTxSuccess, + assertIsBroadcastTxSuccess, AuthExtension, + BroadcastTxResult, + BroadcastTxsResponse, Coin, coin, coins, LcdClient, makeSignBytes, OfflineSigner, - PostTxResult, - PostTxsResponse, Secp256k1Wallet, setupAuthExtension, SigningCosmosClient, @@ -52,7 +52,7 @@ function makeWasmClient(apiUrl: string): WasmClient { async function uploadContract( signer: OfflineSigner, contract: ContractUploadInstructions, -): Promise { +): Promise { const memo = "My first contract on chain"; const theMsg: MsgStoreCode = { type: "wasm/MsgStoreCode", @@ -70,7 +70,7 @@ async function uploadContract( const firstAddress = (await signer.getAccounts())[0].address; const client = new SigningCosmosClient(wasmd.endpoint, firstAddress, signer); - return client.signAndPost([theMsg], fee, memo); + return client.signAndBroadcast([theMsg], fee, memo); } async function instantiateContract( @@ -78,7 +78,7 @@ async function instantiateContract( codeId: number, beneficiaryAddress: string, transferAmount?: readonly Coin[], -): Promise { +): Promise { const memo = "Create an escrow instance"; const theMsg: MsgInstantiateContract = { type: "wasm/MsgInstantiateContract", @@ -100,7 +100,7 @@ async function instantiateContract( const firstAddress = (await signer.getAccounts())[0].address; const client = new SigningCosmosClient(wasmd.endpoint, firstAddress, signer); - return client.signAndPost([theMsg], fee, memo); + return client.signAndBroadcast([theMsg], fee, memo); } async function executeContract( @@ -108,7 +108,7 @@ async function executeContract( signer: OfflineSigner, contractAddress: string, msg: object, -): Promise { +): Promise { const memo = "Time for action"; const theMsg: MsgExecuteContract = { type: "wasm/MsgExecuteContract", @@ -128,7 +128,7 @@ async function executeContract( const signBytes = makeSignBytes([theMsg], fee, wasmd.chainId, memo, account_number, sequence); const signature = await signer.sign(alice.address0, signBytes); const signedTx = makeSignedTx(theMsg, fee, memo, signature); - return client.postTx(signedTx); + return client.broadcastTx(signedTx); } describe("WasmExtension", () => { @@ -141,13 +141,13 @@ describe("WasmExtension", () => { if (wasmdEnabled()) { const wallet = await Secp256k1Wallet.fromMnemonic(alice.mnemonic); const result = await uploadContract(wallet, hackatom); - assertIsPostTxSuccess(result); + assertIsBroadcastTxSuccess(result); const logs = parseLogs(result.logs); const codeIdAttr = findAttribute(logs, "message", "code_id"); hackatomCodeId = Number.parseInt(codeIdAttr.value, 10); const instantiateResult = await instantiateContract(wallet, hackatomCodeId, makeRandomAddress()); - assertIsPostTxSuccess(instantiateResult); + assertIsBroadcastTxSuccess(instantiateResult); const instantiateLogs = parseLogs(instantiateResult.logs); const contractAddressAttr = findAttribute(instantiateLogs, "message", "contract_address"); hackatomContractAddress = contractAddressAttr.value; @@ -204,7 +204,7 @@ describe("WasmExtension", () => { } const result = await instantiateContract(wallet, hackatomCodeId, beneficiaryAddress, transferAmount); - assertIsPostTxSuccess(result); + assertIsBroadcastTxSuccess(result); const logs = parseLogs(result.logs); const contractAddressAttr = findAttribute(logs, "message", "contract_address"); const myAddress = contractAddressAttr.value; @@ -253,7 +253,7 @@ describe("WasmExtension", () => { // create new instance and compare before and after const result = await instantiateContract(wallet, hackatomCodeId, beneficiaryAddress, transferAmount); - assertIsPostTxSuccess(result); + assertIsBroadcastTxSuccess(result); const logs = parseLogs(result.logs); const contractAddressAttr = findAttribute(logs, "message", "contract_address"); const myAddress = contractAddressAttr.value; @@ -468,7 +468,7 @@ describe("WasmExtension", () => { }); }); - describe("postTx", () => { + describe("broadcastTx", () => { it("can upload, instantiate and execute wasm", async () => { pendingWithoutWasmd(); const wallet = await Secp256k1Wallet.fromMnemonic(alice.mnemonic); @@ -483,7 +483,7 @@ describe("WasmExtension", () => { { // console.log("Raw log:", result.raw_log); const result = await uploadContract(wallet, getHackatom()); - assertIsPostTxSuccess(result); + assertIsBroadcastTxSuccess(result); const logs = parseLogs(result.logs); const codeIdAttr = findAttribute(logs, "message", "code_id"); codeId = Number.parseInt(codeIdAttr.value, 10); @@ -497,7 +497,7 @@ describe("WasmExtension", () => { // instantiate { const result = await instantiateContract(wallet, codeId, beneficiaryAddress, transferAmount); - assertIsPostTxSuccess(result); + assertIsBroadcastTxSuccess(result); // console.log("Raw log:", result.raw_log); const logs = parseLogs(result.logs); const contractAddressAttr = findAttribute(logs, "message", "contract_address"); diff --git a/packages/cosmwasm/src/signingcosmwasmclient.spec.ts b/packages/cosmwasm/src/signingcosmwasmclient.spec.ts index 5d34bae4..2adc6ebb 100644 --- a/packages/cosmwasm/src/signingcosmwasmclient.spec.ts +++ b/packages/cosmwasm/src/signingcosmwasmclient.spec.ts @@ -2,7 +2,7 @@ import { Sha256 } from "@cosmjs/crypto"; import { toHex } from "@cosmjs/encoding"; import { - assertIsPostTxSuccess, + assertIsBroadcastTxSuccess, AuthExtension, coin, coins, @@ -333,7 +333,7 @@ describe("SigningCosmWasmClient", () => { // send const result = await client.sendTokens(beneficiaryAddress, transferAmount, "for dinner"); - assertIsPostTxSuccess(result); + assertIsBroadcastTxSuccess(result); const [firstLog] = result.logs; expect(firstLog).toBeTruthy(); @@ -344,7 +344,7 @@ describe("SigningCosmWasmClient", () => { }); }); - describe("signAndPost", () => { + describe("signAndBroadcast", () => { it("works", async () => { pendingWithoutWasmd(); const wallet = await Secp256k1Wallet.fromMnemonic(alice.mnemonic); @@ -362,8 +362,8 @@ describe("SigningCosmWasmClient", () => { amount: coins(2000, "ucosm"), gas: "180000", // 180k }; - const result = await client.signAndPost([msg], fee, "Use your power wisely"); - assertIsPostTxSuccess(result); + const result = await client.signAndBroadcast([msg], fee, "Use your power wisely"); + assertIsBroadcastTxSuccess(result); }); }); }); diff --git a/packages/cosmwasm/src/signingcosmwasmclient.ts b/packages/cosmwasm/src/signingcosmwasmclient.ts index febecbba..2553e43e 100644 --- a/packages/cosmwasm/src/signingcosmwasmclient.ts +++ b/packages/cosmwasm/src/signingcosmwasmclient.ts @@ -3,15 +3,15 @@ import { Sha256 } from "@cosmjs/crypto"; import { toBase64, toHex } from "@cosmjs/encoding"; import { BroadcastMode, + BroadcastTxFailure, + BroadcastTxResult, Coin, coins, - isPostTxFailure, + isBroadcastTxFailure, makeSignBytes, Msg, MsgSend, OfflineSigner, - PostTxFailure, - PostTxResult, StdFee, StdTx, } from "@cosmjs/launchpad"; @@ -154,8 +154,8 @@ export interface ExecuteResult { readonly transactionHash: string; } -function createPostTxErrorMessage(result: PostTxFailure): string { - return `Error when posting tx ${result.transactionHash} at height ${result.height}. Code: ${result.code}; Raw log: ${result.rawLog}`; +function createBroadcastTxErrorMessage(result: BroadcastTxFailure): string { + return `Error when broadcasting tx ${result.transactionHash} at height ${result.height}. Code: ${result.code}; Raw log: ${result.rawLog}`; } export class SigningCosmWasmClient extends CosmWasmClient { @@ -174,7 +174,7 @@ export class SigningCosmWasmClient extends CosmWasmClient { * @param senderAddress The address that will sign and send transactions using this instance * @param signer An implementation of OfflineSigner which can provide signatures for transactions, potentially requiring user input. * @param customFees The fees that are paid for transactions - * @param broadcastMode Defines at which point of the transaction processing the postTx method (i.e. transaction broadcasting) returns + * @param broadcastMode Defines at which point of the transaction processing the broadcastTx method returns */ public constructor( apiUrl: string, @@ -214,9 +214,9 @@ export class SigningCosmWasmClient extends CosmWasmClient { builder: builder, }, }; - const result = await this.signAndPost([storeCodeMsg], this.fees.upload, memo); - if (isPostTxFailure(result)) { - throw new Error(createPostTxErrorMessage(result)); + const result = await this.signAndBroadcast([storeCodeMsg], this.fees.upload, memo); + if (isBroadcastTxFailure(result)) { + throw new Error(createBroadcastTxErrorMessage(result)); } const codeIdAttr = findAttribute(result.logs, "message", "code_id"); return { @@ -247,9 +247,9 @@ export class SigningCosmWasmClient extends CosmWasmClient { admin: options.admin, }, }; - const result = await this.signAndPost([instantiateMsg], this.fees.init, options.memo); - if (isPostTxFailure(result)) { - throw new Error(createPostTxErrorMessage(result)); + const result = await this.signAndBroadcast([instantiateMsg], this.fees.init, options.memo); + if (isBroadcastTxFailure(result)) { + throw new Error(createBroadcastTxErrorMessage(result)); } const contractAddressAttr = findAttribute(result.logs, "message", "contract_address"); return { @@ -268,9 +268,9 @@ export class SigningCosmWasmClient extends CosmWasmClient { new_admin: newAdmin, }, }; - const result = await this.signAndPost([updateAdminMsg], this.fees.changeAdmin, memo); - if (isPostTxFailure(result)) { - throw new Error(createPostTxErrorMessage(result)); + const result = await this.signAndBroadcast([updateAdminMsg], this.fees.changeAdmin, memo); + if (isBroadcastTxFailure(result)) { + throw new Error(createBroadcastTxErrorMessage(result)); } return { logs: result.logs, @@ -286,9 +286,9 @@ export class SigningCosmWasmClient extends CosmWasmClient { contract: contractAddress, }, }; - const result = await this.signAndPost([clearAdminMsg], this.fees.changeAdmin, memo); - if (isPostTxFailure(result)) { - throw new Error(createPostTxErrorMessage(result)); + const result = await this.signAndBroadcast([clearAdminMsg], this.fees.changeAdmin, memo); + if (isBroadcastTxFailure(result)) { + throw new Error(createBroadcastTxErrorMessage(result)); } return { logs: result.logs, @@ -311,9 +311,9 @@ export class SigningCosmWasmClient extends CosmWasmClient { msg: migrateMsg, }, }; - const result = await this.signAndPost([msg], this.fees.migrate, memo); - if (isPostTxFailure(result)) { - throw new Error(createPostTxErrorMessage(result)); + const result = await this.signAndBroadcast([msg], this.fees.migrate, memo); + if (isBroadcastTxFailure(result)) { + throw new Error(createBroadcastTxErrorMessage(result)); } return { logs: result.logs, @@ -336,9 +336,9 @@ export class SigningCosmWasmClient extends CosmWasmClient { sent_funds: transferAmount || [], }, }; - const result = await this.signAndPost([executeMsg], this.fees.exec, memo); - if (isPostTxFailure(result)) { - throw new Error(createPostTxErrorMessage(result)); + const result = await this.signAndBroadcast([executeMsg], this.fees.exec, memo); + if (isBroadcastTxFailure(result)) { + throw new Error(createBroadcastTxErrorMessage(result)); } return { logs: result.logs, @@ -350,7 +350,7 @@ export class SigningCosmWasmClient extends CosmWasmClient { recipientAddress: string, transferAmount: readonly Coin[], memo = "", - ): Promise { + ): Promise { const sendMsg: MsgSend = { type: "cosmos-sdk/MsgSend", value: { @@ -359,14 +359,14 @@ export class SigningCosmWasmClient extends CosmWasmClient { amount: transferAmount, }, }; - return this.signAndPost([sendMsg], this.fees.send, memo); + return this.signAndBroadcast([sendMsg], this.fees.send, memo); } /** * Gets account number and sequence from the API, creates a sign doc, * creates a single signature, assembles the signed transaction and broadcasts it. */ - public async signAndPost(msgs: readonly Msg[], fee: StdFee, memo = ""): Promise { + public async signAndBroadcast(msgs: readonly Msg[], fee: StdFee, memo = ""): Promise { const { accountNumber, sequence } = await this.getSequence(); const chainId = await this.getChainId(); const signBytes = makeSignBytes(msgs, fee, chainId, memo, accountNumber, sequence); @@ -377,6 +377,6 @@ export class SigningCosmWasmClient extends CosmWasmClient { memo: memo, signatures: [signature], }; - return this.postTx(signedTx); + return this.broadcastTx(signedTx); } } diff --git a/packages/cosmwasm/types/cosmwasmclient.d.ts b/packages/cosmwasm/types/cosmwasmclient.d.ts index a45dd0a5..ba126d81 100644 --- a/packages/cosmwasm/types/cosmwasmclient.d.ts +++ b/packages/cosmwasm/types/cosmwasmclient.d.ts @@ -1,11 +1,11 @@ import { AuthExtension, BroadcastMode, + BroadcastTxResult, Coin, CosmosSdkTx, IndexedTx, LcdClient, - PostTxResult, PubKey, StdTx, } from "@cosmjs/launchpad"; @@ -124,7 +124,7 @@ export declare class CosmWasmClient { * for the lifetime of your application. When switching backends, a new instance must be created. * * @param apiUrl The URL of a Cosmos SDK light client daemon API (sometimes called REST server or REST API) - * @param broadcastMode Defines at which point of the transaction processing the postTx method (i.e. transaction broadcasting) returns + * @param broadcastMode Defines at which point of the transaction processing the broadcastTx method returns */ constructor(apiUrl: string, broadcastMode?: BroadcastMode); getChainId(): Promise; @@ -149,7 +149,7 @@ export declare class CosmWasmClient { */ getBlock(height?: number): Promise; searchTx(query: SearchTxQuery, filter?: SearchTxFilter): Promise; - postTx(tx: StdTx): Promise; + broadcastTx(tx: StdTx): Promise; getCodes(): Promise; getCodeDetails(codeId: number): Promise; getContracts(codeId: number): Promise; diff --git a/packages/cosmwasm/types/signingcosmwasmclient.d.ts b/packages/cosmwasm/types/signingcosmwasmclient.d.ts index c42c7ff4..67f290b1 100644 --- a/packages/cosmwasm/types/signingcosmwasmclient.d.ts +++ b/packages/cosmwasm/types/signingcosmwasmclient.d.ts @@ -1,4 +1,4 @@ -import { BroadcastMode, Coin, Msg, OfflineSigner, PostTxResult, StdFee } from "@cosmjs/launchpad"; +import { BroadcastMode, BroadcastTxResult, Coin, Msg, OfflineSigner, StdFee } from "@cosmjs/launchpad"; import { Account, CosmWasmClient, GetSequenceResult } from "./cosmwasmclient"; import { Log } from "./logs"; /** @@ -95,7 +95,7 @@ export declare class SigningCosmWasmClient extends CosmWasmClient { * @param senderAddress The address that will sign and send transactions using this instance * @param signer An implementation of OfflineSigner which can provide signatures for transactions, potentially requiring user input. * @param customFees The fees that are paid for transactions - * @param broadcastMode Defines at which point of the transaction processing the postTx method (i.e. transaction broadcasting) returns + * @param broadcastMode Defines at which point of the transaction processing the broadcastTx method returns */ constructor( apiUrl: string, @@ -123,10 +123,14 @@ export declare class SigningCosmWasmClient extends CosmWasmClient { memo?: string, transferAmount?: readonly Coin[], ): Promise; - sendTokens(recipientAddress: string, transferAmount: readonly Coin[], memo?: string): Promise; + sendTokens( + recipientAddress: string, + transferAmount: readonly Coin[], + memo?: string, + ): Promise; /** * Gets account number and sequence from the API, creates a sign doc, * creates a single signature, assembles the signed transaction and broadcasts it. */ - signAndPost(msgs: readonly Msg[], fee: StdFee, memo?: string): Promise; + signAndBroadcast(msgs: readonly Msg[], fee: StdFee, memo?: string): Promise; } diff --git a/packages/faucet/src/faucet.ts b/packages/faucet/src/faucet.ts index 4f7289e7..ab170d89 100644 --- a/packages/faucet/src/faucet.ts +++ b/packages/faucet/src/faucet.ts @@ -74,7 +74,7 @@ export class Faucet { } /** - * Creates and posts a send transaction. Then waits until the transaction is in a block. + * Creates and broadcasts a send transaction. Then waits until the transaction is in a block. */ public async send(job: SendJob): Promise { await this.clients[job.sender].sendTokens(job.recipient, [job.amount], "Make love, not war"); diff --git a/packages/launchpad/src/cosmosclient.searchtx.spec.ts b/packages/launchpad/src/cosmosclient.searchtx.spec.ts index e86b8534..f3bbda31 100644 --- a/packages/launchpad/src/cosmosclient.searchtx.spec.ts +++ b/packages/launchpad/src/cosmosclient.searchtx.spec.ts @@ -2,7 +2,7 @@ import { assert, sleep } from "@cosmjs/utils"; import { coins } from "./coins"; -import { CosmosClient, isPostTxFailure } from "./cosmosclient"; +import { CosmosClient, isBroadcastTxFailure } from "./cosmosclient"; import { makeSignBytes } from "./encoding"; import { LcdClient } from "./lcdapi"; import { isMsgSend, MsgSend } from "./msgs"; @@ -67,8 +67,8 @@ describe("CosmosClient.searchTx", () => { }, }; const transactionId = await client.getIdentifier(tx); - const result = await client.postTx(tx.value); - if (isPostTxFailure(result)) { + const result = await client.broadcastTx(tx.value); + if (isBroadcastTxFailure(result)) { sendUnsuccessful = { sender: faucet.address, recipient: recipient, diff --git a/packages/launchpad/src/cosmosclient.spec.ts b/packages/launchpad/src/cosmosclient.spec.ts index 34124d71..032e3f30 100644 --- a/packages/launchpad/src/cosmosclient.spec.ts +++ b/packages/launchpad/src/cosmosclient.spec.ts @@ -2,7 +2,7 @@ import { sleep } from "@cosmjs/utils"; import { ReadonlyDate } from "readonly-date"; -import { assertIsPostTxSuccess, CosmosClient, PrivateCosmWasmClient } from "./cosmosclient"; +import { assertIsBroadcastTxSuccess, CosmosClient, PrivateCosmWasmClient } from "./cosmosclient"; import { makeSignBytes } from "./encoding"; import { findAttribute } from "./logs"; import { MsgSend } from "./msgs"; @@ -190,7 +190,7 @@ describe("CosmosClient", () => { }); }); - describe("postTx", () => { + describe("broadcastTx", () => { it("works", async () => { pendingWithoutWasmd(); const wallet = await Secp256k1Wallet.fromMnemonic(faucet.mnemonic); @@ -233,8 +233,8 @@ describe("CosmosClient", () => { memo: memo, signatures: [signature], }; - const txResult = await client.postTx(signedTx); - assertIsPostTxSuccess(txResult); + const txResult = await client.broadcastTx(signedTx); + assertIsBroadcastTxSuccess(txResult); const { logs, transactionHash } = txResult; const amountAttr = findAttribute(logs, "transfer", "amount"); expect(amountAttr.value).toEqual("1234567ucosm"); diff --git a/packages/launchpad/src/cosmosclient.ts b/packages/launchpad/src/cosmosclient.ts index 555afd43..a369f8b5 100644 --- a/packages/launchpad/src/cosmosclient.ts +++ b/packages/launchpad/src/cosmosclient.ts @@ -28,7 +28,7 @@ export interface Account { readonly sequence: number; } -export interface PostTxFailure { +export interface BroadcastTxFailure { /** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */ readonly transactionHash: string; readonly height: number; @@ -36,7 +36,7 @@ export interface PostTxFailure { readonly rawLog: string; } -export interface PostTxSuccess { +export interface BroadcastTxSuccess { readonly logs: readonly Log[]; readonly rawLog: string; /** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */ @@ -44,23 +44,23 @@ export interface PostTxSuccess { readonly data?: Uint8Array; } -export type PostTxResult = PostTxSuccess | PostTxFailure; +export type BroadcastTxResult = BroadcastTxSuccess | BroadcastTxFailure; -export function isPostTxFailure(result: PostTxResult): result is PostTxFailure { - return !!(result as PostTxFailure).code; +export function isBroadcastTxFailure(result: BroadcastTxResult): result is BroadcastTxFailure { + return !!(result as BroadcastTxFailure).code; } -export function isPostTxSuccess(result: PostTxResult): result is PostTxSuccess { - return !isPostTxFailure(result); +export function isBroadcastTxSuccess(result: BroadcastTxResult): result is BroadcastTxSuccess { + return !isBroadcastTxFailure(result); } /** * Ensures the given result is a success. Throws a detailed error message otherwise. */ -export function assertIsPostTxSuccess(result: PostTxResult): asserts result is PostTxSuccess { - if (isPostTxFailure(result)) { +export function assertIsBroadcastTxSuccess(result: BroadcastTxResult): asserts result is BroadcastTxSuccess { + if (isBroadcastTxFailure(result)) { throw new Error( - `Error when posting tx ${result.transactionHash} at height ${result.height}. Code: ${result.code}; Raw log: ${result.rawLog}`, + `Error when broadcasting tx ${result.transactionHash} at height ${result.height}. Code: ${result.code}; Raw log: ${result.rawLog}`, ); } } @@ -168,7 +168,7 @@ export class CosmosClient { * for the lifetime of your application. When switching backends, a new instance must be created. * * @param apiUrl The URL of a Cosmos SDK light client daemon API (sometimes called REST server or REST API) - * @param broadcastMode Defines at which point of the transaction processing the postTx method (i.e. transaction broadcasting) returns + * @param broadcastMode Defines at which point of the transaction processing the broadcastTx method returns */ public constructor(apiUrl: string, broadcastMode = BroadcastMode.Block) { this.lcdClient = LcdClient.withExtensions( @@ -310,8 +310,8 @@ export class CosmosClient { return filtered; } - public async postTx(tx: StdTx): Promise { - const result = await this.lcdClient.postTx(tx); + public async broadcastTx(tx: StdTx): Promise { + const result = await this.lcdClient.broadcastTx(tx); if (!result.txhash.match(/^([0-9A-F][0-9A-F])+$/)) { throw new Error("Received ill-formatted txhash. Must be non-empty upper-case hex"); } diff --git a/packages/launchpad/src/index.ts b/packages/launchpad/src/index.ts index 0149c07f..71cd826e 100644 --- a/packages/launchpad/src/index.ts +++ b/packages/launchpad/src/index.ts @@ -6,17 +6,17 @@ export { Coin, coin, coins } from "./coins"; export { Account, - assertIsPostTxSuccess, + assertIsBroadcastTxSuccess, Block, BlockHeader, CosmosClient, GetSequenceResult, IndexedTx, - isPostTxFailure, - isPostTxSuccess, - PostTxFailure, - PostTxResult, - PostTxSuccess, + isBroadcastTxFailure, + isBroadcastTxSuccess, + BroadcastTxFailure, + BroadcastTxResult, + BroadcastTxSuccess, SearchByHeightQuery, SearchByIdQuery, SearchBySentFromOrToQuery, @@ -62,7 +62,7 @@ export { NodeInfoResponse, normalizeLcdApiArray, normalizePubkey, - PostTxsResponse, + BroadcastTxsResponse, SearchTxsResponse, setupAuthExtension, setupBankExtension, diff --git a/packages/launchpad/src/lcdapi/base.ts b/packages/launchpad/src/lcdapi/base.ts index 2e31b20a..ad1ae0fe 100644 --- a/packages/launchpad/src/lcdapi/base.ts +++ b/packages/launchpad/src/lcdapi/base.ts @@ -126,7 +126,7 @@ export interface SearchTxsResponse { readonly txs: readonly TxsResponse[]; } -export interface PostTxsResponse { +export interface BroadcastTxsResponse { readonly height: string; readonly txhash: string; readonly code?: number; diff --git a/packages/launchpad/src/lcdapi/distribution.spec.ts b/packages/launchpad/src/lcdapi/distribution.spec.ts index 4d2dd774..38562109 100644 --- a/packages/launchpad/src/lcdapi/distribution.spec.ts +++ b/packages/launchpad/src/lcdapi/distribution.spec.ts @@ -3,7 +3,7 @@ import { Bech32 } from "@cosmjs/encoding"; import { sleep } from "@cosmjs/utils"; import { coin, coins } from "../coins"; -import { assertIsPostTxSuccess } from "../cosmosclient"; +import { assertIsBroadcastTxSuccess } from "../cosmosclient"; import { makeSignBytes } from "../encoding"; import { MsgDelegate } from "../msgs"; import { Secp256k1Wallet } from "../secp256k1wallet"; @@ -55,8 +55,8 @@ describe("DistributionExtension", () => { signatures: [signature], }; - const result = await client.postTx(tx); - assertIsPostTxSuccess(result); + const result = await client.broadcastTx(tx); + assertIsBroadcastTxSuccess(result); await sleep(75); // wait until transactions are indexed } diff --git a/packages/launchpad/src/lcdapi/gov.spec.ts b/packages/launchpad/src/lcdapi/gov.spec.ts index 17dc66d1..44f79889 100644 --- a/packages/launchpad/src/lcdapi/gov.spec.ts +++ b/packages/launchpad/src/lcdapi/gov.spec.ts @@ -2,7 +2,7 @@ import { sleep } from "@cosmjs/utils"; import { coins } from "../coins"; -import { assertIsPostTxSuccess } from "../cosmosclient"; +import { assertIsBroadcastTxSuccess } from "../cosmosclient"; import { makeSignBytes } from "../encoding"; import { Secp256k1Wallet } from "../secp256k1wallet"; import { SigningCosmosClient } from "../signingcosmosclient"; @@ -66,8 +66,8 @@ describe("GovExtension", () => { signatures: [proposalSignature], }; - const proposalResult = await client.postTx(proposalTx); - assertIsPostTxSuccess(proposalResult); + const proposalResult = await client.broadcastTx(proposalTx); + assertIsBroadcastTxSuccess(proposalResult); proposalId = proposalResult.logs[0].events .find(({ type }) => type === "submit_proposal")! .attributes.find(({ key }) => key === "proposal_id")!.value; @@ -97,7 +97,7 @@ describe("GovExtension", () => { memo: voteMemo, signatures: [voteSignature], }; - await client.postTx(voteTx); + await client.broadcastTx(voteTx); await sleep(75); // wait until transactions are indexed } diff --git a/packages/launchpad/src/lcdapi/index.ts b/packages/launchpad/src/lcdapi/index.ts index db3bdb73..a401d6c3 100644 --- a/packages/launchpad/src/lcdapi/index.ts +++ b/packages/launchpad/src/lcdapi/index.ts @@ -71,7 +71,7 @@ export { BlockResponse, BroadcastMode, EncodeTxResponse, - PostTxsResponse, + BroadcastTxsResponse, NodeInfoResponse, SearchTxsResponse, TxsResponse, diff --git a/packages/launchpad/src/lcdapi/lcdclient.spec.ts b/packages/launchpad/src/lcdapi/lcdclient.spec.ts index 1edaeb7f..42418e18 100644 --- a/packages/launchpad/src/lcdapi/lcdclient.spec.ts +++ b/packages/launchpad/src/lcdapi/lcdclient.spec.ts @@ -2,7 +2,7 @@ import { assert, sleep } from "@cosmjs/utils"; import { Coin } from "../coins"; -import { isPostTxFailure } from "../cosmosclient"; +import { isBroadcastTxFailure } from "../cosmosclient"; import { makeSignBytes } from "../encoding"; import { parseLogs } from "../logs"; import { MsgSend } from "../msgs"; @@ -248,8 +248,8 @@ describe("LcdClient", () => { signatures: [signature], }; const transactionId = await client.getIdentifier({ type: "cosmos-sdk/StdTx", value: signedTx }); - const result = await client.postTx(signedTx); - assert(isPostTxFailure(result)); + const result = await client.broadcastTx(signedTx); + assert(isBroadcastTxFailure(result)); unsuccessful = { sender: faucet.address, recipient: recipient, @@ -312,7 +312,7 @@ describe("LcdClient", () => { }); describe("txsQuery", () => { - let posted: + let broadcasted: | { readonly sender: string; readonly recipient: string; @@ -338,7 +338,7 @@ describe("LcdClient", () => { await sleep(75); // wait until tx is indexed const txDetails = await new LcdClient(wasmd.endpoint).txById(result.transactionHash); - posted = { + broadcasted = { sender: faucet.address, recipient: recipient, hash: result.transactionHash, @@ -350,68 +350,68 @@ describe("LcdClient", () => { it("can query transactions by height", async () => { pendingWithoutWasmd(); - assert(posted); + assert(broadcasted); const client = new LcdClient(wasmd.endpoint); - const result = await client.txsQuery(`tx.height=${posted.height}&limit=26`); + const result = await client.txsQuery(`tx.height=${broadcasted.height}&limit=26`); expect(result).toEqual({ count: jasmine.stringMatching(/^(1|2|3|4|5)$/), // 1-5 transactions as string limit: "26", page_number: "1", page_total: "1", total_count: jasmine.stringMatching(/^(1|2|3|4|5)$/), // 1-5 transactions as string - txs: jasmine.arrayContaining([posted.tx]), + txs: jasmine.arrayContaining([broadcasted.tx]), }); }); it("can query transactions by ID", async () => { pendingWithoutWasmd(); - assert(posted); + assert(broadcasted); const client = new LcdClient(wasmd.endpoint); - const result = await client.txsQuery(`tx.hash=${posted.hash}&limit=26`); + const result = await client.txsQuery(`tx.hash=${broadcasted.hash}&limit=26`); expect(result).toEqual({ count: "1", limit: "26", page_number: "1", page_total: "1", total_count: "1", - txs: [posted.tx], + txs: [broadcasted.tx], }); }); it("can query transactions by sender", async () => { pendingWithoutWasmd(); - assert(posted); + assert(broadcasted); const client = new LcdClient(wasmd.endpoint); - const result = await client.txsQuery(`message.sender=${posted.sender}&limit=200`); + const result = await client.txsQuery(`message.sender=${broadcasted.sender}&limit=200`); expect(parseInt(result.count, 10)).toBeGreaterThanOrEqual(1); expect(parseInt(result.limit, 10)).toEqual(200); expect(parseInt(result.page_number, 10)).toEqual(1); expect(parseInt(result.page_total, 10)).toEqual(1); expect(parseInt(result.total_count, 10)).toBeGreaterThanOrEqual(1); expect(result.txs.length).toBeGreaterThanOrEqual(1); - expect(result.txs[result.txs.length - 1]).toEqual(posted.tx); + expect(result.txs[result.txs.length - 1]).toEqual(broadcasted.tx); }); it("can query transactions by recipient", async () => { pendingWithoutWasmd(); - assert(posted); + assert(broadcasted); const client = new LcdClient(wasmd.endpoint); - const result = await client.txsQuery(`transfer.recipient=${posted.recipient}&limit=200`); + const result = await client.txsQuery(`transfer.recipient=${broadcasted.recipient}&limit=200`); expect(parseInt(result.count, 10)).toEqual(1); expect(parseInt(result.limit, 10)).toEqual(200); expect(parseInt(result.page_number, 10)).toEqual(1); expect(parseInt(result.page_total, 10)).toEqual(1); expect(parseInt(result.total_count, 10)).toEqual(1); expect(result.txs.length).toBeGreaterThanOrEqual(1); - expect(result.txs[result.txs.length - 1]).toEqual(posted.tx); + expect(result.txs[result.txs.length - 1]).toEqual(broadcasted.tx); }); it("can filter by tx.hash and tx.minheight", async () => { pending("This combination is broken 🤷‍♂️. Handle client-side at higher level."); pendingWithoutWasmd(); - assert(posted); + assert(broadcasted); const client = new LcdClient(wasmd.endpoint); - const hashQuery = `tx.hash=${posted.hash}`; + const hashQuery = `tx.hash=${broadcasted.hash}`; { const { count } = await client.txsQuery(`${hashQuery}&tx.minheight=0`); @@ -419,26 +419,26 @@ describe("LcdClient", () => { } { - const { count } = await client.txsQuery(`${hashQuery}&tx.minheight=${posted.height - 1}`); + const { count } = await client.txsQuery(`${hashQuery}&tx.minheight=${broadcasted.height - 1}`); expect(count).toEqual("1"); } { - const { count } = await client.txsQuery(`${hashQuery}&tx.minheight=${posted.height}`); + const { count } = await client.txsQuery(`${hashQuery}&tx.minheight=${broadcasted.height}`); expect(count).toEqual("1"); } { - const { count } = await client.txsQuery(`${hashQuery}&tx.minheight=${posted.height + 1}`); + const { count } = await client.txsQuery(`${hashQuery}&tx.minheight=${broadcasted.height + 1}`); expect(count).toEqual("0"); } }); it("can filter by recipient and tx.minheight", async () => { pendingWithoutWasmd(); - assert(posted); + assert(broadcasted); const client = new LcdClient(wasmd.endpoint); - const recipientQuery = `transfer.recipient=${posted.recipient}`; + const recipientQuery = `transfer.recipient=${broadcasted.recipient}`; { const { count } = await client.txsQuery(`${recipientQuery}&tx.minheight=0`); @@ -446,26 +446,26 @@ describe("LcdClient", () => { } { - const { count } = await client.txsQuery(`${recipientQuery}&tx.minheight=${posted.height - 1}`); + const { count } = await client.txsQuery(`${recipientQuery}&tx.minheight=${broadcasted.height - 1}`); expect(count).toEqual("1"); } { - const { count } = await client.txsQuery(`${recipientQuery}&tx.minheight=${posted.height}`); + const { count } = await client.txsQuery(`${recipientQuery}&tx.minheight=${broadcasted.height}`); expect(count).toEqual("1"); } { - const { count } = await client.txsQuery(`${recipientQuery}&tx.minheight=${posted.height + 1}`); + const { count } = await client.txsQuery(`${recipientQuery}&tx.minheight=${broadcasted.height + 1}`); expect(count).toEqual("0"); } }); it("can filter by recipient and tx.maxheight", async () => { pendingWithoutWasmd(); - assert(posted); + assert(broadcasted); const client = new LcdClient(wasmd.endpoint); - const recipientQuery = `transfer.recipient=${posted.recipient}`; + const recipientQuery = `transfer.recipient=${broadcasted.recipient}`; { const { count } = await client.txsQuery(`${recipientQuery}&tx.maxheight=9999999999999`); @@ -473,17 +473,17 @@ describe("LcdClient", () => { } { - const { count } = await client.txsQuery(`${recipientQuery}&tx.maxheight=${posted.height + 1}`); + const { count } = await client.txsQuery(`${recipientQuery}&tx.maxheight=${broadcasted.height + 1}`); expect(count).toEqual("1"); } { - const { count } = await client.txsQuery(`${recipientQuery}&tx.maxheight=${posted.height}`); + const { count } = await client.txsQuery(`${recipientQuery}&tx.maxheight=${broadcasted.height}`); expect(count).toEqual("1"); } { - const { count } = await client.txsQuery(`${recipientQuery}&tx.maxheight=${posted.height - 1}`); + const { count } = await client.txsQuery(`${recipientQuery}&tx.maxheight=${broadcasted.height - 1}`); expect(count).toEqual("0"); } }); @@ -502,7 +502,7 @@ describe("LcdClient", () => { }); }); - describe("postTx", () => { + describe("broadcastTx", () => { it("can send tokens", async () => { pendingWithoutWasmd(); const wallet = await Secp256k1Wallet.fromMnemonic(faucet.mnemonic); @@ -540,7 +540,7 @@ describe("LcdClient", () => { const signBytes = makeSignBytes([theMsg], fee, wasmd.chainId, memo, account_number, sequence); const signature = await wallet.sign(walletAddress, signBytes); const signedTx = makeSignedTx(theMsg, fee, memo, signature); - const result = await client.postTx(signedTx); + const result = await client.broadcastTx(signedTx); expect(result.code).toBeUndefined(); expect(result).toEqual({ height: jasmine.stringMatching(nonNegativeIntegerMatcher), @@ -606,9 +606,9 @@ describe("LcdClient", () => { memo: memo, signatures: [signature1, signature2, signature3], }; - const postResult = await client.postTx(signedTx); - expect(postResult.code).toEqual(4); - expect(postResult.raw_log).toContain("wrong number of signers"); + const broadcastResult = await client.broadcastTx(signedTx); + expect(broadcastResult.code).toEqual(4); + expect(broadcastResult.raw_log).toContain("wrong number of signers"); }); it("can send multiple messages with one signature", async () => { @@ -666,8 +666,8 @@ describe("LcdClient", () => { memo: memo, signatures: [signature1], }; - const postResult = await client.postTx(signedTx); - expect(postResult.code).toBeUndefined(); + const broadcastResult = await client.broadcastTx(signedTx); + expect(broadcastResult.code).toBeUndefined(); }); it("can send multiple messages with multiple signatures", async () => { @@ -732,11 +732,11 @@ describe("LcdClient", () => { memo: memo, signatures: [signature2, signature1], }; - const postResult = await client.postTx(signedTx); - expect(postResult.code).toBeUndefined(); + const broadcastResult = await client.broadcastTx(signedTx); + expect(broadcastResult.code).toBeUndefined(); await sleep(500); - const searched = await client.txsQuery(`tx.hash=${postResult.txhash}`); + const searched = await client.txsQuery(`tx.hash=${broadcastResult.txhash}`); expect(searched.txs.length).toEqual(1); expect(searched.txs[0].tx.value.signatures).toEqual([signature2, signature1]); }); @@ -803,8 +803,8 @@ describe("LcdClient", () => { memo: memo, signatures: [signature2, signature1], }; - const postResult = await client.postTx(signedTx); - expect(postResult.code).toEqual(8); + const broadcastResult = await client.broadcastTx(signedTx); + expect(broadcastResult.code).toEqual(8); }); it("can't send transaction with wrong signature order (2)", async () => { @@ -869,8 +869,8 @@ describe("LcdClient", () => { memo: memo, signatures: [signature1, signature2], }; - const postResult = await client.postTx(signedTx); - expect(postResult.code).toEqual(8); + const broadcastResult = await client.broadcastTx(signedTx); + expect(broadcastResult.code).toEqual(8); }); }); }); diff --git a/packages/launchpad/src/lcdapi/lcdclient.ts b/packages/launchpad/src/lcdapi/lcdclient.ts index f62b14a1..a3e34d36 100644 --- a/packages/launchpad/src/lcdapi/lcdclient.ts +++ b/packages/launchpad/src/lcdapi/lcdclient.ts @@ -6,9 +6,9 @@ import { CosmosSdkTx, StdTx } from "../types"; import { BlockResponse, BroadcastMode, + BroadcastTxsResponse, EncodeTxResponse, NodeInfoResponse, - PostTxsResponse, SearchTxsResponse, TxsResponse, } from "./base"; @@ -206,7 +206,7 @@ export class LcdClient { * in higher level components. Feel free to raise an issue in this case. * * @param apiUrl The URL of a Cosmos SDK light client daemon API (sometimes called REST server or REST API) - * @param broadcastMode Defines at which point of the transaction processing the postTx method (i.e. transaction broadcasting) returns + * @param broadcastMode Defines at which point of the transaction processing the broadcastTx method returns */ public constructor(apiUrl: string, broadcastMode = BroadcastMode.Block) { const headers = { @@ -298,7 +298,7 @@ export class LcdClient { * * @param tx a signed transaction as StdTx (i.e. not wrapped in type/value container) */ - public async postTx(tx: StdTx): Promise { + public async broadcastTx(tx: StdTx): Promise { const params = { tx: tx, mode: this.broadcastMode, @@ -307,6 +307,6 @@ export class LcdClient { if (!responseData.txhash) { throw new Error("Unexpected response data format"); } - return responseData as PostTxsResponse; + return responseData as BroadcastTxsResponse; } } diff --git a/packages/launchpad/src/lcdapi/staking.spec.ts b/packages/launchpad/src/lcdapi/staking.spec.ts index 624728e5..4580bf17 100644 --- a/packages/launchpad/src/lcdapi/staking.spec.ts +++ b/packages/launchpad/src/lcdapi/staking.spec.ts @@ -2,7 +2,7 @@ import { assert, sleep } from "@cosmjs/utils"; import { coin, coins } from "../coins"; -import { assertIsPostTxSuccess } from "../cosmosclient"; +import { assertIsBroadcastTxSuccess } from "../cosmosclient"; import { makeSignBytes } from "../encoding"; import { MsgDelegate, MsgUndelegate } from "../msgs"; import { Secp256k1Wallet } from "../secp256k1wallet"; @@ -57,8 +57,8 @@ describe("StakingExtension", () => { signatures: [signature], }; - const result = await client.postTx(tx); - assertIsPostTxSuccess(result); + const result = await client.broadcastTx(tx); + assertIsBroadcastTxSuccess(result); } { const msg: MsgUndelegate = { @@ -80,8 +80,8 @@ describe("StakingExtension", () => { signatures: [signature], }; - const result = await client.postTx(tx); - assertIsPostTxSuccess(result); + const result = await client.broadcastTx(tx); + assertIsBroadcastTxSuccess(result); } await sleep(75); // wait until transactions are indexed diff --git a/packages/launchpad/src/signingcosmosclient.spec.ts b/packages/launchpad/src/signingcosmosclient.spec.ts index 425458df..f6dd9326 100644 --- a/packages/launchpad/src/signingcosmosclient.spec.ts +++ b/packages/launchpad/src/signingcosmosclient.spec.ts @@ -2,7 +2,7 @@ import { assert } from "@cosmjs/utils"; import { Coin, coin, coins } from "./coins"; -import { assertIsPostTxSuccess, PrivateCosmWasmClient } from "./cosmosclient"; +import { assertIsBroadcastTxSuccess, PrivateCosmWasmClient } from "./cosmosclient"; import { MsgDelegate } from "./msgs"; import { Secp256k1Wallet } from "./secp256k1wallet"; import { SigningCosmosClient } from "./signingcosmosclient"; @@ -68,7 +68,7 @@ describe("SigningCosmosClient", () => { // send const result = await client.sendTokens(beneficiaryAddress, transferAmount, "for dinner"); - assertIsPostTxSuccess(result); + assertIsBroadcastTxSuccess(result); const [firstLog] = result.logs; expect(firstLog).toBeTruthy(); @@ -79,7 +79,7 @@ describe("SigningCosmosClient", () => { }); }); - describe("signAndPost", () => { + describe("signAndBroadcast", () => { it("works", async () => { pendingWithoutWasmd(); const wallet = await Secp256k1Wallet.fromMnemonic(faucet.mnemonic); @@ -97,8 +97,8 @@ describe("SigningCosmosClient", () => { amount: coins(2000, "ucosm"), gas: "180000", // 180k }; - const result = await client.signAndPost([msg], fee, "Use your power wisely"); - assertIsPostTxSuccess(result); + const result = await client.signAndBroadcast([msg], fee, "Use your power wisely"); + assertIsBroadcastTxSuccess(result); }); }); }); diff --git a/packages/launchpad/src/signingcosmosclient.ts b/packages/launchpad/src/signingcosmosclient.ts index cd9eb6d8..ea9a79e6 100644 --- a/packages/launchpad/src/signingcosmosclient.ts +++ b/packages/launchpad/src/signingcosmosclient.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/naming-convention */ import { Coin, coins } from "./coins"; -import { Account, CosmosClient, GetSequenceResult, PostTxResult } from "./cosmosclient"; +import { Account, BroadcastTxResult, CosmosClient, GetSequenceResult } from "./cosmosclient"; import { makeSignBytes } from "./encoding"; import { BroadcastMode } from "./lcdapi"; import { Msg, MsgSend } from "./msgs"; @@ -28,7 +28,7 @@ export class SigningCosmosClient extends CosmosClient { private readonly fees: FeeTable; /** - * Creates a new client with signing capability to interact with a CosmWasm blockchain. This is the bigger brother of CosmWasmClient. + * Creates a new client with signing capability to interact with a Cosmos SDK blockchain. This is the bigger brother of CosmosClient. * * This instance does a lot of caching. In order to benefit from that you should try to use one instance * for the lifetime of your application. When switching backends, a new instance must be created. @@ -37,7 +37,7 @@ export class SigningCosmosClient extends CosmosClient { * @param senderAddress The address that will sign and send transactions using this instance * @param signer An implementation of OfflineSigner which can provide signatures for transactions, potentially requiring user input. * @param customFees The fees that are paid for transactions - * @param broadcastMode Defines at which point of the transaction processing the postTx method (i.e. transaction broadcasting) returns + * @param broadcastMode Defines at which point of the transaction processing the broadcastTx method returns */ public constructor( apiUrl: string, @@ -66,7 +66,7 @@ export class SigningCosmosClient extends CosmosClient { recipientAddress: string, transferAmount: readonly Coin[], memo = "", - ): Promise { + ): Promise { const sendMsg: MsgSend = { type: "cosmos-sdk/MsgSend", value: { @@ -75,14 +75,14 @@ export class SigningCosmosClient extends CosmosClient { amount: transferAmount, }, }; - return this.signAndPost([sendMsg], this.fees.send, memo); + return this.signAndBroadcast([sendMsg], this.fees.send, memo); } /** * Gets account number and sequence from the API, creates a sign doc, * creates a single signature, assembles the signed transaction and broadcasts it. */ - public async signAndPost(msgs: readonly Msg[], fee: StdFee, memo = ""): Promise { + public async signAndBroadcast(msgs: readonly Msg[], fee: StdFee, memo = ""): Promise { const { accountNumber, sequence } = await this.getSequence(); const chainId = await this.getChainId(); const signBytes = makeSignBytes(msgs, fee, chainId, memo, accountNumber, sequence); @@ -93,6 +93,6 @@ export class SigningCosmosClient extends CosmosClient { memo: memo, signatures: [signature], }; - return this.postTx(signedTx); + return this.broadcastTx(signedTx); } } diff --git a/packages/launchpad/types/cosmosclient.d.ts b/packages/launchpad/types/cosmosclient.d.ts index f6a28054..02577e85 100644 --- a/packages/launchpad/types/cosmosclient.d.ts +++ b/packages/launchpad/types/cosmosclient.d.ts @@ -14,27 +14,29 @@ export interface Account { readonly accountNumber: number; readonly sequence: number; } -export interface PostTxFailure { +export interface BroadcastTxFailure { /** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */ readonly transactionHash: string; readonly height: number; readonly code: number; readonly rawLog: string; } -export interface PostTxSuccess { +export interface BroadcastTxSuccess { readonly logs: readonly Log[]; readonly rawLog: string; /** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */ readonly transactionHash: string; readonly data?: Uint8Array; } -export declare type PostTxResult = PostTxSuccess | PostTxFailure; -export declare function isPostTxFailure(result: PostTxResult): result is PostTxFailure; -export declare function isPostTxSuccess(result: PostTxResult): result is PostTxSuccess; +export declare type BroadcastTxResult = BroadcastTxSuccess | BroadcastTxFailure; +export declare function isBroadcastTxFailure(result: BroadcastTxResult): result is BroadcastTxFailure; +export declare function isBroadcastTxSuccess(result: BroadcastTxResult): result is BroadcastTxSuccess; /** * Ensures the given result is a success. Throws a detailed error message otherwise. */ -export declare function assertIsPostTxSuccess(result: PostTxResult): asserts result is PostTxSuccess; +export declare function assertIsBroadcastTxSuccess( + result: BroadcastTxResult, +): asserts result is BroadcastTxSuccess; export interface SearchByIdQuery { readonly id: string; } @@ -113,7 +115,7 @@ export declare class CosmosClient { * for the lifetime of your application. When switching backends, a new instance must be created. * * @param apiUrl The URL of a Cosmos SDK light client daemon API (sometimes called REST server or REST API) - * @param broadcastMode Defines at which point of the transaction processing the postTx method (i.e. transaction broadcasting) returns + * @param broadcastMode Defines at which point of the transaction processing the broadcastTx method returns */ constructor(apiUrl: string, broadcastMode?: BroadcastMode); getChainId(): Promise; @@ -138,6 +140,6 @@ export declare class CosmosClient { */ getBlock(height?: number): Promise; searchTx(query: SearchTxQuery, filter?: SearchTxFilter): Promise; - postTx(tx: StdTx): Promise; + broadcastTx(tx: StdTx): Promise; private txsQuery; } diff --git a/packages/launchpad/types/index.d.ts b/packages/launchpad/types/index.d.ts index d8dfe32e..a4dce608 100644 --- a/packages/launchpad/types/index.d.ts +++ b/packages/launchpad/types/index.d.ts @@ -4,17 +4,17 @@ export { pubkeyToAddress, rawSecp256k1PubkeyToAddress } from "./address"; export { Coin, coin, coins } from "./coins"; export { Account, - assertIsPostTxSuccess, + assertIsBroadcastTxSuccess, Block, BlockHeader, CosmosClient, GetSequenceResult, IndexedTx, - isPostTxFailure, - isPostTxSuccess, - PostTxFailure, - PostTxResult, - PostTxSuccess, + isBroadcastTxFailure, + isBroadcastTxSuccess, + BroadcastTxFailure, + BroadcastTxResult, + BroadcastTxSuccess, SearchByHeightQuery, SearchByIdQuery, SearchBySentFromOrToQuery, @@ -60,7 +60,7 @@ export { NodeInfoResponse, normalizeLcdApiArray, normalizePubkey, - PostTxsResponse, + BroadcastTxsResponse, SearchTxsResponse, setupAuthExtension, setupBankExtension, diff --git a/packages/launchpad/types/lcdapi/base.d.ts b/packages/launchpad/types/lcdapi/base.d.ts index 437d252f..83f3f7df 100644 --- a/packages/launchpad/types/lcdapi/base.d.ts +++ b/packages/launchpad/types/lcdapi/base.d.ts @@ -108,7 +108,7 @@ export interface SearchTxsResponse { readonly limit: string; readonly txs: readonly TxsResponse[]; } -export interface PostTxsResponse { +export interface BroadcastTxsResponse { readonly height: string; readonly txhash: string; readonly code?: number; diff --git a/packages/launchpad/types/lcdapi/index.d.ts b/packages/launchpad/types/lcdapi/index.d.ts index 07b83300..ea39c092 100644 --- a/packages/launchpad/types/lcdapi/index.d.ts +++ b/packages/launchpad/types/lcdapi/index.d.ts @@ -62,7 +62,7 @@ export { BlockResponse, BroadcastMode, EncodeTxResponse, - PostTxsResponse, + BroadcastTxsResponse, NodeInfoResponse, SearchTxsResponse, TxsResponse, diff --git a/packages/launchpad/types/lcdapi/lcdclient.d.ts b/packages/launchpad/types/lcdapi/lcdclient.d.ts index 7b275b02..b5cfd8ba 100644 --- a/packages/launchpad/types/lcdapi/lcdclient.d.ts +++ b/packages/launchpad/types/lcdapi/lcdclient.d.ts @@ -2,9 +2,9 @@ import { CosmosSdkTx, StdTx } from "../types"; import { BlockResponse, BroadcastMode, + BroadcastTxsResponse, EncodeTxResponse, NodeInfoResponse, - PostTxsResponse, SearchTxsResponse, TxsResponse, } from "./base"; @@ -140,7 +140,7 @@ export declare class LcdClient { * in higher level components. Feel free to raise an issue in this case. * * @param apiUrl The URL of a Cosmos SDK light client daemon API (sometimes called REST server or REST API) - * @param broadcastMode Defines at which point of the transaction processing the postTx method (i.e. transaction broadcasting) returns + * @param broadcastMode Defines at which point of the transaction processing the broadcastTx method returns */ constructor(apiUrl: string, broadcastMode?: BroadcastMode); get(path: string, params?: Record): Promise; @@ -159,6 +159,6 @@ export declare class LcdClient { * * @param tx a signed transaction as StdTx (i.e. not wrapped in type/value container) */ - postTx(tx: StdTx): Promise; + broadcastTx(tx: StdTx): Promise; } export {}; diff --git a/packages/launchpad/types/signingcosmosclient.d.ts b/packages/launchpad/types/signingcosmosclient.d.ts index 7add9e98..9e6062a2 100644 --- a/packages/launchpad/types/signingcosmosclient.d.ts +++ b/packages/launchpad/types/signingcosmosclient.d.ts @@ -1,5 +1,5 @@ import { Coin } from "./coins"; -import { Account, CosmosClient, GetSequenceResult, PostTxResult } from "./cosmosclient"; +import { Account, BroadcastTxResult, CosmosClient, GetSequenceResult } from "./cosmosclient"; import { BroadcastMode } from "./lcdapi"; import { Msg } from "./msgs"; import { StdFee } from "./types"; @@ -15,7 +15,7 @@ export declare class SigningCosmosClient extends CosmosClient { private readonly signer; private readonly fees; /** - * Creates a new client with signing capability to interact with a CosmWasm blockchain. This is the bigger brother of CosmWasmClient. + * Creates a new client with signing capability to interact with a Cosmos SDK blockchain. This is the bigger brother of CosmosClient. * * This instance does a lot of caching. In order to benefit from that you should try to use one instance * for the lifetime of your application. When switching backends, a new instance must be created. @@ -24,7 +24,7 @@ export declare class SigningCosmosClient extends CosmosClient { * @param senderAddress The address that will sign and send transactions using this instance * @param signer An implementation of OfflineSigner which can provide signatures for transactions, potentially requiring user input. * @param customFees The fees that are paid for transactions - * @param broadcastMode Defines at which point of the transaction processing the postTx method (i.e. transaction broadcasting) returns + * @param broadcastMode Defines at which point of the transaction processing the broadcastTx method returns */ constructor( apiUrl: string, @@ -35,10 +35,14 @@ export declare class SigningCosmosClient extends CosmosClient { ); getSequence(address?: string): Promise; getAccount(address?: string): Promise; - sendTokens(recipientAddress: string, transferAmount: readonly Coin[], memo?: string): Promise; + sendTokens( + recipientAddress: string, + transferAmount: readonly Coin[], + memo?: string, + ): Promise; /** * Gets account number and sequence from the API, creates a sign doc, * creates a single signature, assembles the signed transaction and broadcasts it. */ - signAndPost(msgs: readonly Msg[], fee: StdFee, memo?: string): Promise; + signAndBroadcast(msgs: readonly Msg[], fee: StdFee, memo?: string): Promise; } diff --git a/packages/tendermint-rpc/src/client.spec.ts b/packages/tendermint-rpc/src/client.spec.ts index ac8ee019..c7466c95 100644 --- a/packages/tendermint-rpc/src/client.spec.ts +++ b/packages/tendermint-rpc/src/client.spec.ts @@ -60,7 +60,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, adaptor: Adaptor): void { client.disconnect(); }); - it("can post a transaction", async () => { + it("can broadcast a transaction", async () => { pendingWithoutTendermint(); const client = new Client(rpcFactory(), adaptor); const tx = buildKvTx(randomString(), randomString()); diff --git a/scripts/wasmd/send_first.js b/scripts/wasmd/send_first.js index f0b14850..c12332b1 100755 --- a/scripts/wasmd/send_first.js +++ b/scripts/wasmd/send_first.js @@ -3,7 +3,12 @@ /* eslint-disable @typescript-eslint/naming-convention */ const { Random } = require("@cosmjs/crypto"); const { Bech32 } = require("@cosmjs/encoding"); -const { coins, Secp256k1Wallet, SigningCosmosClient, assertIsPostTxSuccess } = require("@cosmjs/launchpad"); +const { + coins, + Secp256k1Wallet, + SigningCosmosClient, + assertIsBroadcastTxSuccess, +} = require("@cosmjs/launchpad"); const httpUrl = "http://localhost:1317"; const faucet = { @@ -19,7 +24,7 @@ async function main() { const amount = coins(226644, "ucosm"); const memo = "Ensure chain has my pubkey"; const sendResult = await client.sendTokens(recipient, amount, memo); - assertIsPostTxSuccess(sendResult); + assertIsBroadcastTxSuccess(sendResult); } main().then( From 877bd68b4a195f78d505f82e51709ba3885c23b9 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Mon, 3 Aug 2020 17:24:14 +0200 Subject: [PATCH 2/2] Update CHANGELOG for postTx -> broadcastTx change --- CHANGELOG.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cb2c464f..728ff249 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,18 @@ # CHANGELOG +## 0.23.0 (unreleased) + +- @cosmjs/cosmwasm: Rename `CosmWasmClient.postTx` method to `.broadcastTx`. +- @cosmjs/cosmwasm: Rename `SigningCosmWasmClient.signAndPost` method to + `.signAndBroadcast`. +- @cosmjs/launchpad: Rename `CosmosClient.postTx` method to `.broadcastTx`. +- @cosmjs/launchpad: Rename `SigningCosmosClient.signAndPost` method to + `.signAndBroadcast`. +- @cosmjs/launchpad: Rename `PostTx`-related types to `BroadcastTxResult`, + `BroadcastTxSuccess` and `BroadcastTxFailure` respectively, as well as helper + functions `isBroadcastTxFailure`, `isBroadcastTxSuccess` and + `assertIsBroadcastTxSuccess`. + ## 0.22.0 (2020-08-03) - @cosmjs/cli: Now supports HTTPs URLs for `--init` code sources.