Merge pull request #946 from cosmos/rename-BroadcastTxResponse
Rename BroadcastTx{Success,Failure} to DeliverTx{Success,Failure}
This commit is contained in:
commit
baa4e5e049
@ -1,7 +1,7 @@
|
||||
import { coins, makeCosmoshubPath } from "@cosmjs/amino";
|
||||
import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
|
||||
import {
|
||||
assertIsBroadcastTxSuccess,
|
||||
assertIsDeliverTxSuccess,
|
||||
calculateFee,
|
||||
GasPrice,
|
||||
MsgSendEncodeObject,
|
||||
@ -30,7 +30,7 @@ const client = await SigningStargateClient.connectWithSigner(rpcEndpoint, wallet
|
||||
const amount = coins(1234567, "ucosm");
|
||||
const memo = "With simulate";
|
||||
const result = await client.sendTokens(account.address, recipient, amount, "auto", memo);
|
||||
assertIsBroadcastTxSuccess(result);
|
||||
assertIsDeliverTxSuccess(result);
|
||||
console.log("Successfully broadcasted:", result);
|
||||
}
|
||||
|
||||
@ -40,7 +40,7 @@ const client = await SigningStargateClient.connectWithSigner(rpcEndpoint, wallet
|
||||
const amount = coins(1234567, "ucosm");
|
||||
const memo = "With simulate";
|
||||
const result = await client.sendTokens(account.address, recipient, amount, 1.2, memo);
|
||||
assertIsBroadcastTxSuccess(result);
|
||||
assertIsDeliverTxSuccess(result);
|
||||
console.log("Successfully broadcasted:", result);
|
||||
}
|
||||
|
||||
@ -60,7 +60,7 @@ const client = await SigningStargateClient.connectWithSigner(rpcEndpoint, wallet
|
||||
const gasEstimation = await client.simulate(account.address, [sendMsg], memo);
|
||||
const fee = calculateFee(Math.round(gasEstimation * 1.3), gasPrice);
|
||||
const result = await client.sendTokens(account.address, recipient, amount, fee, memo);
|
||||
assertIsBroadcastTxSuccess(result);
|
||||
assertIsDeliverTxSuccess(result);
|
||||
console.log("Successfully broadcasted:", result);
|
||||
}
|
||||
|
||||
@ -78,7 +78,7 @@ const client = await SigningStargateClient.connectWithSigner(rpcEndpoint, wallet
|
||||
};
|
||||
const memo = "With simulate";
|
||||
const result = await client.signAndBroadcast(account.address, [sendMsg], "auto", memo);
|
||||
assertIsBroadcastTxSuccess(result);
|
||||
assertIsDeliverTxSuccess(result);
|
||||
console.log("Successfully broadcasted:", result);
|
||||
}
|
||||
|
||||
@ -96,7 +96,7 @@ const client = await SigningStargateClient.connectWithSigner(rpcEndpoint, wallet
|
||||
};
|
||||
const memo = "With simulate";
|
||||
const result = await client.signAndBroadcast(account.address, [sendMsg], 1.4, memo);
|
||||
assertIsBroadcastTxSuccess(result);
|
||||
assertIsDeliverTxSuccess(result);
|
||||
console.log("Successfully broadcasted:", result);
|
||||
}
|
||||
|
||||
@ -116,7 +116,7 @@ const client = await SigningStargateClient.connectWithSigner(rpcEndpoint, wallet
|
||||
const gasEstimation = await client.simulate(account.address, [sendMsg], memo);
|
||||
const fee = calculateFee(Math.round(gasEstimation * 1.3), gasPrice);
|
||||
const result = await client.signAndBroadcast(account.address, [sendMsg], fee, memo);
|
||||
assertIsBroadcastTxSuccess(result);
|
||||
assertIsDeliverTxSuccess(result);
|
||||
console.log("Successfully broadcasted:", result);
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { coins, makeCosmoshubPath } from "@cosmjs/amino";
|
||||
import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
|
||||
import { assertIsBroadcastTxSuccess, calculateFee, GasPrice, SigningStargateClient } from "@cosmjs/stargate";
|
||||
import { assertIsDeliverTxSuccess, calculateFee, GasPrice, SigningStargateClient } from "@cosmjs/stargate";
|
||||
|
||||
// Wallet
|
||||
const mnemonic =
|
||||
@ -29,7 +29,7 @@ const result = await client.sendTokens(
|
||||
fee,
|
||||
"Have fun with your star coins",
|
||||
);
|
||||
assertIsBroadcastTxSuccess(result);
|
||||
assertIsDeliverTxSuccess(result);
|
||||
console.log("Successfully broadcasted:", result);
|
||||
|
||||
client.disconnect();
|
||||
|
||||
@ -10,11 +10,11 @@ import {
|
||||
TxBodyEncodeObject,
|
||||
} from "@cosmjs/proto-signing";
|
||||
import {
|
||||
BroadcastTxResponse,
|
||||
Coin,
|
||||
coins,
|
||||
isBroadcastTxFailure,
|
||||
isBroadcastTxSuccess,
|
||||
DeliverTxResponse,
|
||||
isDeliverTxFailure,
|
||||
isDeliverTxSuccess,
|
||||
isMsgSendEncodeObject,
|
||||
} from "@cosmjs/stargate";
|
||||
import { assert, sleep } from "@cosmjs/utils";
|
||||
@ -46,7 +46,7 @@ async function sendTokens(
|
||||
amount: readonly Coin[],
|
||||
memo: string,
|
||||
): Promise<{
|
||||
readonly broadcastResponse: BroadcastTxResponse;
|
||||
readonly broadcastResponse: DeliverTxResponse;
|
||||
readonly tx: Uint8Array;
|
||||
}> {
|
||||
const [{ address: walletAddress, pubkey: pubkeyBytes }] = await wallet.getAccounts();
|
||||
@ -118,7 +118,7 @@ describe("CosmWasmClient.getTx and .searchTx", () => {
|
||||
coins(123456700000000, "ucosm"),
|
||||
"Sending more than I can afford",
|
||||
);
|
||||
if (isBroadcastTxFailure(unsuccessfulResult.broadcastResponse)) {
|
||||
if (isDeliverTxFailure(unsuccessfulResult.broadcastResponse)) {
|
||||
sendUnsuccessful = {
|
||||
sender: alice.address0,
|
||||
recipient: unsuccessfulRecipient,
|
||||
@ -135,7 +135,7 @@ describe("CosmWasmClient.getTx and .searchTx", () => {
|
||||
coins(1234567, "ucosm"),
|
||||
"Something I can afford",
|
||||
);
|
||||
if (isBroadcastTxSuccess(successfulResult.broadcastResponse)) {
|
||||
if (isDeliverTxSuccess(successfulResult.broadcastResponse)) {
|
||||
sendSuccessful = {
|
||||
sender: alice.address0,
|
||||
recipient: successfulRecipient,
|
||||
|
||||
@ -10,7 +10,7 @@ import {
|
||||
Registry,
|
||||
TxBodyEncodeObject,
|
||||
} from "@cosmjs/proto-signing";
|
||||
import { assertIsBroadcastTxSuccess, coins, logs, MsgSendEncodeObject, StdFee } from "@cosmjs/stargate";
|
||||
import { assertIsDeliverTxSuccess, coins, logs, MsgSendEncodeObject, StdFee } from "@cosmjs/stargate";
|
||||
import { assert, sleep } from "@cosmjs/utils";
|
||||
import { TxRaw } from "cosmjs-types/cosmos/tx/v1beta1/tx";
|
||||
import { ReadonlyDate } from "readonly-date";
|
||||
@ -213,7 +213,7 @@ describe("CosmWasmClient", () => {
|
||||
});
|
||||
const signedTx = Uint8Array.from(TxRaw.encode(txRaw).finish());
|
||||
const result = await client.broadcastTx(signedTx);
|
||||
assertIsBroadcastTxSuccess(result);
|
||||
assertIsDeliverTxSuccess(result);
|
||||
const amountAttr = logs.findAttribute(logs.parseRawLog(result.rawLog), "transfer", "amount");
|
||||
expect(amountAttr.value).toEqual("1234567ucosm");
|
||||
expect(result.transactionHash).toMatch(/^[0-9A-F]{64}$/);
|
||||
|
||||
@ -7,8 +7,8 @@ import {
|
||||
AuthExtension,
|
||||
BankExtension,
|
||||
Block,
|
||||
BroadcastTxResponse,
|
||||
Coin,
|
||||
DeliverTxResponse,
|
||||
IndexedTx,
|
||||
isSearchByHeightQuery,
|
||||
isSearchBySentFromOrToQuery,
|
||||
@ -251,7 +251,7 @@ export class CosmWasmClient {
|
||||
*
|
||||
* If the transaction is not included in a block before the provided timeout, this errors with a `TimeoutError`.
|
||||
*
|
||||
* If the transaction is included in a block, a `BroadcastTxResponse` is returned. The caller then
|
||||
* If the transaction is included in a block, a `DeliverTxResponse` is returned. The caller then
|
||||
* usually needs to check for execution success or failure.
|
||||
*/
|
||||
// NOTE: This method is tested against slow chains and timeouts in the @cosmjs/stargate package.
|
||||
@ -260,13 +260,13 @@ export class CosmWasmClient {
|
||||
tx: Uint8Array,
|
||||
timeoutMs = 60_000,
|
||||
pollIntervalMs = 3_000,
|
||||
): Promise<BroadcastTxResponse> {
|
||||
): Promise<DeliverTxResponse> {
|
||||
let timedOut = false;
|
||||
const txPollTimeout = setTimeout(() => {
|
||||
timedOut = true;
|
||||
}, timeoutMs);
|
||||
|
||||
const pollForTx = async (txId: string): Promise<BroadcastTxResponse> => {
|
||||
const pollForTx = async (txId: string): Promise<DeliverTxResponse> => {
|
||||
if (timedOut) {
|
||||
throw new TimeoutError(
|
||||
`Transaction with ID ${txId} was submitted but was not yet found on the chain. You might want to check later.`,
|
||||
|
||||
@ -2,11 +2,11 @@ import { sha256 } from "@cosmjs/crypto";
|
||||
import { fromAscii, fromHex, toAscii, toHex } from "@cosmjs/encoding";
|
||||
import { DirectSecp256k1HdWallet, OfflineDirectSigner, Registry } from "@cosmjs/proto-signing";
|
||||
import {
|
||||
assertIsBroadcastTxSuccess,
|
||||
BroadcastTxResponse,
|
||||
assertIsDeliverTxSuccess,
|
||||
Coin,
|
||||
coin,
|
||||
coins,
|
||||
DeliverTxResponse,
|
||||
logs,
|
||||
SigningStargateClient,
|
||||
StdFee,
|
||||
@ -44,7 +44,7 @@ const registry = new Registry([
|
||||
async function uploadContract(
|
||||
signer: OfflineDirectSigner,
|
||||
contract: ContractUploadInstructions,
|
||||
): Promise<BroadcastTxResponse> {
|
||||
): Promise<DeliverTxResponse> {
|
||||
const memo = "My first contract on chain";
|
||||
const theMsg: MsgStoreCodeEncodeObject = {
|
||||
typeUrl: "/cosmwasm.wasm.v1.MsgStoreCode",
|
||||
@ -70,7 +70,7 @@ async function instantiateContract(
|
||||
codeId: number,
|
||||
beneficiaryAddress: string,
|
||||
funds?: readonly Coin[],
|
||||
): Promise<BroadcastTxResponse> {
|
||||
): Promise<DeliverTxResponse> {
|
||||
const memo = "Create an escrow instance";
|
||||
const theMsg: MsgInstantiateContractEncodeObject = {
|
||||
typeUrl: "/cosmwasm.wasm.v1.MsgInstantiateContract",
|
||||
@ -104,7 +104,7 @@ async function executeContract(
|
||||
signer: OfflineDirectSigner,
|
||||
contractAddress: string,
|
||||
msg: Record<string, unknown>,
|
||||
): Promise<BroadcastTxResponse> {
|
||||
): Promise<DeliverTxResponse> {
|
||||
const memo = "Time for action";
|
||||
const theMsg: MsgExecuteContractEncodeObject = {
|
||||
typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
|
||||
@ -138,7 +138,7 @@ describe("WasmExtension", () => {
|
||||
if (wasmdEnabled()) {
|
||||
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(alice.mnemonic, { prefix: wasmd.prefix });
|
||||
const result = await uploadContract(wallet, hackatom);
|
||||
assertIsBroadcastTxSuccess(result);
|
||||
assertIsDeliverTxSuccess(result);
|
||||
hackatomCodeId = Number.parseInt(
|
||||
JSON.parse(result.rawLog!)[0]
|
||||
.events.find((event: any) => event.type === "store_code")
|
||||
@ -147,7 +147,7 @@ describe("WasmExtension", () => {
|
||||
);
|
||||
|
||||
const instantiateResult = await instantiateContract(wallet, hackatomCodeId, makeRandomAddress());
|
||||
assertIsBroadcastTxSuccess(instantiateResult);
|
||||
assertIsDeliverTxSuccess(instantiateResult);
|
||||
hackatomContractAddress = JSON.parse(instantiateResult.rawLog!)[0]
|
||||
.events.find((event: any) => event.type === "instantiate")
|
||||
.attributes.find((attribute: any) => attribute.key === "_contract_address").value;
|
||||
@ -200,7 +200,7 @@ describe("WasmExtension", () => {
|
||||
const beneficiaryAddress = makeRandomAddress();
|
||||
const funds = coins(707707, "ucosm");
|
||||
const result = await instantiateContract(wallet, hackatomCodeId, beneficiaryAddress, funds);
|
||||
assertIsBroadcastTxSuccess(result);
|
||||
assertIsDeliverTxSuccess(result);
|
||||
const myAddress = JSON.parse(result.rawLog!)[0]
|
||||
.events.find((event: any) => event.type === "instantiate")
|
||||
.attributes!.find((attribute: any) => attribute.key === "_contract_address").value;
|
||||
@ -243,7 +243,7 @@ describe("WasmExtension", () => {
|
||||
const beneficiaryAddress = makeRandomAddress();
|
||||
const funds = coins(707707, "ucosm");
|
||||
const result = await instantiateContract(wallet, hackatomCodeId, beneficiaryAddress, funds);
|
||||
assertIsBroadcastTxSuccess(result);
|
||||
assertIsDeliverTxSuccess(result);
|
||||
|
||||
const myAddress = JSON.parse(result.rawLog!)[0]
|
||||
.events.find((event: any) => event.type === "instantiate")
|
||||
@ -375,7 +375,7 @@ describe("WasmExtension", () => {
|
||||
// upload
|
||||
{
|
||||
const result = await uploadContract(wallet, getHackatom());
|
||||
assertIsBroadcastTxSuccess(result);
|
||||
assertIsDeliverTxSuccess(result);
|
||||
const parsedLogs = logs.parseLogs(logs.parseRawLog(result.rawLog));
|
||||
const codeIdAttr = logs.findAttribute(parsedLogs, "store_code", "code_id");
|
||||
codeId = Number.parseInt(codeIdAttr.value, 10);
|
||||
@ -390,7 +390,7 @@ describe("WasmExtension", () => {
|
||||
// instantiate
|
||||
{
|
||||
const result = await instantiateContract(wallet, codeId, beneficiaryAddress, funds);
|
||||
assertIsBroadcastTxSuccess(result);
|
||||
assertIsDeliverTxSuccess(result);
|
||||
const parsedLogs = logs.parseLogs(logs.parseRawLog(result.rawLog));
|
||||
const contractAddressAttr = logs.findAttribute(parsedLogs, "instantiate", "_contract_address");
|
||||
contractAddress = contractAddressAttr.value;
|
||||
@ -408,7 +408,7 @@ describe("WasmExtension", () => {
|
||||
// execute
|
||||
{
|
||||
const result = await executeContract(wallet, contractAddress, { release: {} });
|
||||
assertIsBroadcastTxSuccess(result);
|
||||
assertIsDeliverTxSuccess(result);
|
||||
const parsedLogs = logs.parseLogs(logs.parseRawLog(result.rawLog));
|
||||
const wasmEvent = parsedLogs.find(() => true)?.events.find((e) => e.type === "wasm");
|
||||
assert(wasmEvent, "Event of type wasm expected");
|
||||
|
||||
@ -6,7 +6,7 @@ import { decodeTxRaw, DirectSecp256k1HdWallet, Registry } from "@cosmjs/proto-si
|
||||
import {
|
||||
AminoMsgDelegate,
|
||||
AminoTypes,
|
||||
assertIsBroadcastTxSuccess,
|
||||
assertIsDeliverTxSuccess,
|
||||
coin,
|
||||
coins,
|
||||
MsgDelegateEncodeObject,
|
||||
@ -522,7 +522,7 @@ describe("SigningCosmWasmClient", () => {
|
||||
defaultSendFee,
|
||||
memo,
|
||||
);
|
||||
assertIsBroadcastTxSuccess(result);
|
||||
assertIsDeliverTxSuccess(result);
|
||||
expect(result.rawLog).toBeTruthy();
|
||||
|
||||
// got tokens
|
||||
@ -558,7 +558,7 @@ describe("SigningCosmWasmClient", () => {
|
||||
defaultSendFee,
|
||||
memo,
|
||||
);
|
||||
assertIsBroadcastTxSuccess(result);
|
||||
assertIsDeliverTxSuccess(result);
|
||||
expect(result.rawLog).toBeTruthy();
|
||||
|
||||
// got tokens
|
||||
@ -596,7 +596,7 @@ describe("SigningCosmWasmClient", () => {
|
||||
};
|
||||
const memo = "Use your power wisely";
|
||||
const result = await client.signAndBroadcast(alice.address0, [msgAny], fee, memo);
|
||||
assertIsBroadcastTxSuccess(result);
|
||||
assertIsDeliverTxSuccess(result);
|
||||
|
||||
client.disconnect();
|
||||
});
|
||||
@ -622,7 +622,7 @@ describe("SigningCosmWasmClient", () => {
|
||||
};
|
||||
const memo = "Use your power wisely";
|
||||
const result = await client.signAndBroadcast(alice.address0, [msgAny], "auto", memo);
|
||||
assertIsBroadcastTxSuccess(result);
|
||||
assertIsDeliverTxSuccess(result);
|
||||
|
||||
client.disconnect();
|
||||
});
|
||||
@ -653,7 +653,7 @@ describe("SigningCosmWasmClient", () => {
|
||||
};
|
||||
const memo = "Use your power wisely";
|
||||
const result = await client.signAndBroadcast(alice.address0, [msgAny], fee, memo);
|
||||
assertIsBroadcastTxSuccess(result);
|
||||
assertIsDeliverTxSuccess(result);
|
||||
|
||||
await sleep(500);
|
||||
|
||||
@ -693,7 +693,7 @@ describe("SigningCosmWasmClient", () => {
|
||||
};
|
||||
const memo = "Use your tokens wisely";
|
||||
const result = await client.signAndBroadcast(alice.address0, [msgAny], fee, memo);
|
||||
assertIsBroadcastTxSuccess(result);
|
||||
assertIsDeliverTxSuccess(result);
|
||||
|
||||
client.disconnect();
|
||||
});
|
||||
@ -721,7 +721,7 @@ describe("SigningCosmWasmClient", () => {
|
||||
};
|
||||
const memo = "Use your tokens wisely";
|
||||
const result = await client.signAndBroadcast(alice.address0, [msgAny], fee, memo);
|
||||
assertIsBroadcastTxSuccess(result);
|
||||
assertIsDeliverTxSuccess(result);
|
||||
|
||||
client.disconnect();
|
||||
});
|
||||
@ -750,7 +750,7 @@ describe("SigningCosmWasmClient", () => {
|
||||
};
|
||||
const memo = "Use your tokens wisely";
|
||||
const result = await client.signAndBroadcast(alice.address0, [msgAny], fee, memo);
|
||||
assertIsBroadcastTxSuccess(result);
|
||||
assertIsDeliverTxSuccess(result);
|
||||
|
||||
client.disconnect();
|
||||
});
|
||||
@ -875,7 +875,7 @@ describe("SigningCosmWasmClient", () => {
|
||||
};
|
||||
const memo = "Use your power wisely";
|
||||
const result = await client.signAndBroadcast(alice.address0, [msgAny], fee, memo);
|
||||
assertIsBroadcastTxSuccess(result);
|
||||
assertIsDeliverTxSuccess(result);
|
||||
|
||||
client.disconnect();
|
||||
});
|
||||
@ -905,7 +905,7 @@ describe("SigningCosmWasmClient", () => {
|
||||
};
|
||||
const memo = "Use your power wisely";
|
||||
const result = await client.signAndBroadcast(alice.address0, [msgAny], fee, memo);
|
||||
assertIsBroadcastTxSuccess(result);
|
||||
assertIsDeliverTxSuccess(result);
|
||||
|
||||
await sleep(500);
|
||||
|
||||
@ -950,7 +950,7 @@ describe("SigningCosmWasmClient", () => {
|
||||
|
||||
// ensure signature is valid
|
||||
const result = await client.broadcastTx(Uint8Array.from(TxRaw.encode(signed).finish()));
|
||||
assertIsBroadcastTxSuccess(result);
|
||||
assertIsDeliverTxSuccess(result);
|
||||
|
||||
client.disconnect();
|
||||
});
|
||||
@ -990,7 +990,7 @@ describe("SigningCosmWasmClient", () => {
|
||||
|
||||
// ensure signature is valid
|
||||
const result = await client.broadcastTx(Uint8Array.from(TxRaw.encode(signed).finish()));
|
||||
assertIsBroadcastTxSuccess(result);
|
||||
assertIsDeliverTxSuccess(result);
|
||||
|
||||
client.disconnect();
|
||||
});
|
||||
@ -1023,7 +1023,7 @@ describe("SigningCosmWasmClient", () => {
|
||||
|
||||
// ensure signature is valid
|
||||
const result = await client.broadcastTx(Uint8Array.from(TxRaw.encode(signed).finish()));
|
||||
assertIsBroadcastTxSuccess(result);
|
||||
assertIsDeliverTxSuccess(result);
|
||||
|
||||
client.disconnect();
|
||||
});
|
||||
@ -1054,7 +1054,7 @@ describe("SigningCosmWasmClient", () => {
|
||||
|
||||
// ensure signature is valid
|
||||
const result = await client.broadcastTx(Uint8Array.from(TxRaw.encode(signed).finish()));
|
||||
assertIsBroadcastTxSuccess(result);
|
||||
assertIsDeliverTxSuccess(result);
|
||||
|
||||
client.disconnect();
|
||||
});
|
||||
@ -1179,7 +1179,7 @@ describe("SigningCosmWasmClient", () => {
|
||||
|
||||
// ensure signature is valid
|
||||
const result = await client.broadcastTx(Uint8Array.from(TxRaw.encode(signed).finish()));
|
||||
assertIsBroadcastTxSuccess(result);
|
||||
assertIsDeliverTxSuccess(result);
|
||||
|
||||
client.disconnect();
|
||||
});
|
||||
@ -1219,7 +1219,7 @@ describe("SigningCosmWasmClient", () => {
|
||||
|
||||
// ensure signature is valid
|
||||
const result = await client.broadcastTx(Uint8Array.from(TxRaw.encode(signed).finish()));
|
||||
assertIsBroadcastTxSuccess(result);
|
||||
assertIsDeliverTxSuccess(result);
|
||||
|
||||
client.disconnect();
|
||||
});
|
||||
|
||||
@ -15,13 +15,13 @@ import {
|
||||
} from "@cosmjs/proto-signing";
|
||||
import {
|
||||
AminoTypes,
|
||||
BroadcastTxFailure,
|
||||
BroadcastTxResponse,
|
||||
calculateFee,
|
||||
Coin,
|
||||
defaultRegistryTypes,
|
||||
DeliverTxFailure,
|
||||
DeliverTxResponse,
|
||||
GasPrice,
|
||||
isBroadcastTxFailure,
|
||||
isDeliverTxFailure,
|
||||
logs,
|
||||
MsgDelegateEncodeObject,
|
||||
MsgSendEncodeObject,
|
||||
@ -124,7 +124,7 @@ export interface ExecuteResult {
|
||||
readonly transactionHash: string;
|
||||
}
|
||||
|
||||
function createBroadcastTxErrorMessage(result: BroadcastTxFailure): string {
|
||||
function createBroadcastTxErrorMessage(result: DeliverTxFailure): string {
|
||||
return `Error when broadcasting tx ${result.transactionHash} at height ${result.height}. Code: ${result.code}; Raw log: ${result.rawLog}`;
|
||||
}
|
||||
|
||||
@ -237,7 +237,7 @@ export class SigningCosmWasmClient extends CosmWasmClient {
|
||||
};
|
||||
|
||||
const result = await this.signAndBroadcast(senderAddress, [storeCodeMsg], fee, memo);
|
||||
if (isBroadcastTxFailure(result)) {
|
||||
if (isDeliverTxFailure(result)) {
|
||||
throw new Error(createBroadcastTxErrorMessage(result));
|
||||
}
|
||||
const parsedLogs = logs.parseRawLog(result.rawLog);
|
||||
@ -273,7 +273,7 @@ export class SigningCosmWasmClient extends CosmWasmClient {
|
||||
}),
|
||||
};
|
||||
const result = await this.signAndBroadcast(senderAddress, [instantiateContractMsg], fee, options.memo);
|
||||
if (isBroadcastTxFailure(result)) {
|
||||
if (isDeliverTxFailure(result)) {
|
||||
throw new Error(createBroadcastTxErrorMessage(result));
|
||||
}
|
||||
const parsedLogs = logs.parseRawLog(result.rawLog);
|
||||
@ -301,7 +301,7 @@ export class SigningCosmWasmClient extends CosmWasmClient {
|
||||
}),
|
||||
};
|
||||
const result = await this.signAndBroadcast(senderAddress, [updateAdminMsg], fee, memo);
|
||||
if (isBroadcastTxFailure(result)) {
|
||||
if (isDeliverTxFailure(result)) {
|
||||
throw new Error(createBroadcastTxErrorMessage(result));
|
||||
}
|
||||
return {
|
||||
@ -324,7 +324,7 @@ export class SigningCosmWasmClient extends CosmWasmClient {
|
||||
}),
|
||||
};
|
||||
const result = await this.signAndBroadcast(senderAddress, [clearAdminMsg], fee, memo);
|
||||
if (isBroadcastTxFailure(result)) {
|
||||
if (isDeliverTxFailure(result)) {
|
||||
throw new Error(createBroadcastTxErrorMessage(result));
|
||||
}
|
||||
return {
|
||||
@ -351,7 +351,7 @@ export class SigningCosmWasmClient extends CosmWasmClient {
|
||||
}),
|
||||
};
|
||||
const result = await this.signAndBroadcast(senderAddress, [migrateContractMsg], fee, memo);
|
||||
if (isBroadcastTxFailure(result)) {
|
||||
if (isDeliverTxFailure(result)) {
|
||||
throw new Error(createBroadcastTxErrorMessage(result));
|
||||
}
|
||||
return {
|
||||
@ -378,7 +378,7 @@ export class SigningCosmWasmClient extends CosmWasmClient {
|
||||
}),
|
||||
};
|
||||
const result = await this.signAndBroadcast(senderAddress, [executeContractMsg], fee, memo);
|
||||
if (isBroadcastTxFailure(result)) {
|
||||
if (isDeliverTxFailure(result)) {
|
||||
throw new Error(createBroadcastTxErrorMessage(result));
|
||||
}
|
||||
return {
|
||||
@ -393,7 +393,7 @@ export class SigningCosmWasmClient extends CosmWasmClient {
|
||||
amount: readonly Coin[],
|
||||
fee: StdFee | "auto" | number,
|
||||
memo = "",
|
||||
): Promise<BroadcastTxResponse> {
|
||||
): Promise<DeliverTxResponse> {
|
||||
const sendMsg: MsgSendEncodeObject = {
|
||||
typeUrl: "/cosmos.bank.v1beta1.MsgSend",
|
||||
value: {
|
||||
@ -411,7 +411,7 @@ export class SigningCosmWasmClient extends CosmWasmClient {
|
||||
amount: Coin,
|
||||
fee: StdFee | "auto" | number,
|
||||
memo = "",
|
||||
): Promise<BroadcastTxResponse> {
|
||||
): Promise<DeliverTxResponse> {
|
||||
const delegateMsg: MsgDelegateEncodeObject = {
|
||||
typeUrl: "/cosmos.staking.v1beta1.MsgDelegate",
|
||||
value: MsgDelegate.fromPartial({ delegatorAddress: delegatorAddress, validatorAddress, amount }),
|
||||
@ -425,7 +425,7 @@ export class SigningCosmWasmClient extends CosmWasmClient {
|
||||
amount: Coin,
|
||||
fee: StdFee | "auto" | number,
|
||||
memo = "",
|
||||
): Promise<BroadcastTxResponse> {
|
||||
): Promise<DeliverTxResponse> {
|
||||
const undelegateMsg: MsgUndelegateEncodeObject = {
|
||||
typeUrl: "/cosmos.staking.v1beta1.MsgUndelegate",
|
||||
value: MsgUndelegate.fromPartial({ delegatorAddress: delegatorAddress, validatorAddress, amount }),
|
||||
@ -438,7 +438,7 @@ export class SigningCosmWasmClient extends CosmWasmClient {
|
||||
validatorAddress: string,
|
||||
fee: StdFee | "auto" | number,
|
||||
memo = "",
|
||||
): Promise<BroadcastTxResponse> {
|
||||
): Promise<DeliverTxResponse> {
|
||||
const withdrawDelegatorRewardMsg: MsgWithdrawDelegatorRewardEncodeObject = {
|
||||
typeUrl: "/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward",
|
||||
value: MsgWithdrawDelegatorReward.fromPartial({ delegatorAddress: delegatorAddress, validatorAddress }),
|
||||
@ -459,7 +459,7 @@ export class SigningCosmWasmClient extends CosmWasmClient {
|
||||
messages: readonly EncodeObject[],
|
||||
fee: StdFee | "auto" | number,
|
||||
memo = "",
|
||||
): Promise<BroadcastTxResponse> {
|
||||
): Promise<DeliverTxResponse> {
|
||||
let usedFee: StdFee;
|
||||
if (fee == "auto" || typeof fee === "number") {
|
||||
assertDefined(this.gasPrice, "Gas price must be set in the client options when auto gas is used.");
|
||||
|
||||
@ -4,7 +4,7 @@ import {
|
||||
SigningCosmosClient,
|
||||
} from "@cosmjs/launchpad";
|
||||
import {
|
||||
assertIsBroadcastTxSuccess as assertIsBroadcastTxSuccessStargate,
|
||||
assertIsDeliverTxSuccess as assertIsDeliverTxSuccessStargate,
|
||||
calculateFee,
|
||||
SigningStargateClient,
|
||||
StargateClient,
|
||||
@ -100,7 +100,7 @@ export class Faucet {
|
||||
}
|
||||
const fee = calculateFee(constants.gasLimits.send, constants.gasPrice);
|
||||
const result = await client.sendTokens(job.sender, job.recipient, [job.amount], fee, constants.memo);
|
||||
assertIsBroadcastTxSuccessStargate(result);
|
||||
assertIsDeliverTxSuccessStargate(result);
|
||||
}
|
||||
|
||||
/** Use one of the distributor accounts to send tokens to user */
|
||||
|
||||
@ -14,7 +14,7 @@ import {
|
||||
SigningCosmosClient,
|
||||
} from "@cosmjs/launchpad";
|
||||
import {
|
||||
assertIsBroadcastTxSuccess as assertIsBroadcastTxSuccessStargate,
|
||||
assertIsDeliverTxSuccess as assertIsDeliverTxSuccessStargate,
|
||||
calculateFee,
|
||||
SigningStargateClient,
|
||||
} from "@cosmjs/stargate";
|
||||
@ -73,7 +73,7 @@ describe("LedgerSigner", () => {
|
||||
defaultFee,
|
||||
memo,
|
||||
);
|
||||
assertIsBroadcastTxSuccessStargate(sendResult);
|
||||
assertIsDeliverTxSuccessStargate(sendResult);
|
||||
}
|
||||
});
|
||||
|
||||
@ -202,7 +202,7 @@ describe("LedgerSigner", () => {
|
||||
coins(1234, "ucosm"),
|
||||
defaultFee,
|
||||
);
|
||||
assertIsBroadcastTxSuccessStargate(result);
|
||||
assertIsDeliverTxSuccessStargate(result);
|
||||
},
|
||||
interactiveTimeout,
|
||||
);
|
||||
|
||||
@ -93,15 +93,15 @@ export {
|
||||
isSearchByTagsQuery,
|
||||
} from "./search";
|
||||
export {
|
||||
assertIsBroadcastTxSuccess,
|
||||
assertIsDeliverTxSuccess,
|
||||
Block,
|
||||
BlockHeader,
|
||||
BroadcastTxFailure,
|
||||
BroadcastTxResponse,
|
||||
BroadcastTxSuccess,
|
||||
DeliverTxFailure,
|
||||
DeliverTxResponse,
|
||||
DeliverTxSuccess,
|
||||
IndexedTx,
|
||||
isBroadcastTxFailure,
|
||||
isBroadcastTxSuccess,
|
||||
isDeliverTxFailure,
|
||||
isDeliverTxSuccess,
|
||||
SequenceResponse,
|
||||
StargateClient,
|
||||
TimeoutError,
|
||||
|
||||
@ -13,7 +13,7 @@ import { TxRaw } from "cosmjs-types/cosmos/tx/v1beta1/tx";
|
||||
import { MsgSendEncodeObject } from "./encodeobjects";
|
||||
import { makeCompactBitArray, makeMultisignedTx } from "./multisignature";
|
||||
import { SignerData, SigningStargateClient } from "./signingstargateclient";
|
||||
import { assertIsBroadcastTxSuccess, StargateClient } from "./stargateclient";
|
||||
import { assertIsDeliverTxSuccess, StargateClient } from "./stargateclient";
|
||||
import { faucet, pendingWithoutSimapp, simapp } from "./testutils.spec";
|
||||
|
||||
describe("multisignature", () => {
|
||||
@ -268,7 +268,7 @@ describe("multisignature", () => {
|
||||
);
|
||||
// ensure signature is valid
|
||||
const result = await broadcaster.broadcastTx(Uint8Array.from(TxRaw.encode(signedTx).finish()));
|
||||
assertIsBroadcastTxSuccess(result);
|
||||
assertIsDeliverTxSuccess(result);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@ -6,7 +6,7 @@ import { MsgDelegate } from "cosmjs-types/cosmos/staking/v1beta1/tx";
|
||||
|
||||
import { MsgDelegateEncodeObject } from "../encodeobjects";
|
||||
import { SigningStargateClient } from "../signingstargateclient";
|
||||
import { assertIsBroadcastTxSuccess } from "../stargateclient";
|
||||
import { assertIsDeliverTxSuccess } from "../stargateclient";
|
||||
import {
|
||||
defaultSigningClientOptions,
|
||||
faucet,
|
||||
@ -51,7 +51,7 @@ describe("DistributionExtension", () => {
|
||||
};
|
||||
const memo = "Test delegation for Stargate";
|
||||
const result = await client.signAndBroadcast(faucet.address0, [msgAny], defaultFee, memo);
|
||||
assertIsBroadcastTxSuccess(result);
|
||||
assertIsDeliverTxSuccess(result);
|
||||
|
||||
await sleep(75); // wait until transactions are indexed
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@ import {
|
||||
MsgVoteEncodeObject,
|
||||
} from "../encodeobjects";
|
||||
import { SigningStargateClient } from "../signingstargateclient";
|
||||
import { assertIsBroadcastTxSuccess } from "../stargateclient";
|
||||
import { assertIsDeliverTxSuccess } from "../stargateclient";
|
||||
import {
|
||||
defaultSigningClientOptions,
|
||||
faucet,
|
||||
@ -85,7 +85,7 @@ describe("GovExtension", () => {
|
||||
defaultFee,
|
||||
"Test proposal for simd",
|
||||
);
|
||||
assertIsBroadcastTxSuccess(proposalResult);
|
||||
assertIsDeliverTxSuccess(proposalResult);
|
||||
const logs = JSON.parse(proposalResult.rawLog || "");
|
||||
proposalId = logs[0].events
|
||||
.find(({ type }: any) => type === "submit_proposal")
|
||||
@ -106,7 +106,7 @@ describe("GovExtension", () => {
|
||||
},
|
||||
};
|
||||
const result = await client.signAndBroadcast(voter1Address, [msgDelegate], defaultFee);
|
||||
assertIsBroadcastTxSuccess(result);
|
||||
assertIsDeliverTxSuccess(result);
|
||||
}
|
||||
|
||||
const voteMsg: MsgVoteEncodeObject = {
|
||||
@ -118,7 +118,7 @@ describe("GovExtension", () => {
|
||||
},
|
||||
};
|
||||
const voteResult = await client.signAndBroadcast(voter1Address, [voteMsg], defaultFee);
|
||||
assertIsBroadcastTxSuccess(voteResult);
|
||||
assertIsDeliverTxSuccess(voteResult);
|
||||
}
|
||||
|
||||
// Voter 2
|
||||
@ -134,7 +134,7 @@ describe("GovExtension", () => {
|
||||
},
|
||||
};
|
||||
const result = await client.signAndBroadcast(voter2Address, [msgDelegate], defaultFee);
|
||||
assertIsBroadcastTxSuccess(result);
|
||||
assertIsDeliverTxSuccess(result);
|
||||
}
|
||||
|
||||
const voteMsg: MsgVoteEncodeObject = {
|
||||
@ -146,7 +146,7 @@ describe("GovExtension", () => {
|
||||
},
|
||||
};
|
||||
const voteResult = await client.signAndBroadcast(voter2Address, [voteMsg], defaultFee);
|
||||
assertIsBroadcastTxSuccess(voteResult);
|
||||
assertIsDeliverTxSuccess(voteResult);
|
||||
}
|
||||
|
||||
await sleep(75); // wait until transactions are indexed
|
||||
|
||||
@ -6,7 +6,7 @@ import { MsgDelegate, MsgUndelegate } from "cosmjs-types/cosmos/staking/v1beta1/
|
||||
|
||||
import { MsgDelegateEncodeObject, MsgUndelegateEncodeObject } from "../encodeobjects";
|
||||
import { SigningStargateClient } from "../signingstargateclient";
|
||||
import { assertIsBroadcastTxSuccess } from "../stargateclient";
|
||||
import { assertIsDeliverTxSuccess } from "../stargateclient";
|
||||
import {
|
||||
defaultSigningClientOptions,
|
||||
faucet,
|
||||
@ -52,7 +52,7 @@ describe("StakingExtension", () => {
|
||||
};
|
||||
const memo = "Test delegation for Stargate";
|
||||
const result = await client.signAndBroadcast(faucet.address0, [msgAny], defaultFee, memo);
|
||||
assertIsBroadcastTxSuccess(result);
|
||||
assertIsDeliverTxSuccess(result);
|
||||
}
|
||||
{
|
||||
const msg: MsgUndelegate = {
|
||||
@ -66,7 +66,7 @@ describe("StakingExtension", () => {
|
||||
};
|
||||
const memo = "Test undelegation for Stargate";
|
||||
const result = await client.signAndBroadcast(faucet.address0, [msgAny], defaultFee, memo);
|
||||
assertIsBroadcastTxSuccess(result);
|
||||
assertIsDeliverTxSuccess(result);
|
||||
}
|
||||
|
||||
await sleep(75); // wait until transactions are indexed
|
||||
|
||||
@ -5,7 +5,7 @@ import { MsgDelegate } from "cosmjs-types/cosmos/staking/v1beta1/tx";
|
||||
import Long from "long";
|
||||
|
||||
import { defaultRegistryTypes, SigningStargateClient } from "../signingstargateclient";
|
||||
import { assertIsBroadcastTxSuccess, StargateClient } from "../stargateclient";
|
||||
import { assertIsDeliverTxSuccess, StargateClient } from "../stargateclient";
|
||||
import {
|
||||
defaultSigningClientOptions,
|
||||
faucet,
|
||||
@ -51,7 +51,7 @@ describe("TxExtension", () => {
|
||||
defaultFee,
|
||||
memo,
|
||||
);
|
||||
assertIsBroadcastTxSuccess(result);
|
||||
assertIsDeliverTxSuccess(result);
|
||||
txHash = result.transactionHash;
|
||||
}
|
||||
|
||||
|
||||
@ -14,7 +14,7 @@ import { AminoMsgDelegate } from "./aminomsgs";
|
||||
import { AminoTypes } from "./aminotypes";
|
||||
import { MsgDelegateEncodeObject, MsgSendEncodeObject } from "./encodeobjects";
|
||||
import { PrivateSigningStargateClient, SigningStargateClient } from "./signingstargateclient";
|
||||
import { assertIsBroadcastTxSuccess, isBroadcastTxFailure } from "./stargateclient";
|
||||
import { assertIsDeliverTxSuccess, isDeliverTxFailure } from "./stargateclient";
|
||||
import {
|
||||
defaultGasPrice,
|
||||
defaultSendFee,
|
||||
@ -100,7 +100,7 @@ describe("SigningStargateClient", () => {
|
||||
defaultSendFee,
|
||||
memo,
|
||||
);
|
||||
assertIsBroadcastTxSuccess(result);
|
||||
assertIsDeliverTxSuccess(result);
|
||||
expect(result.rawLog).toBeTruthy();
|
||||
|
||||
// got tokens
|
||||
@ -136,7 +136,7 @@ describe("SigningStargateClient", () => {
|
||||
defaultSendFee,
|
||||
memo,
|
||||
);
|
||||
assertIsBroadcastTxSuccess(result);
|
||||
assertIsDeliverTxSuccess(result);
|
||||
expect(result.rawLog).toBeTruthy();
|
||||
|
||||
// got tokens
|
||||
@ -174,7 +174,7 @@ describe("SigningStargateClient", () => {
|
||||
memo,
|
||||
);
|
||||
// CheckTx must pass but the execution must fail in DeliverTx due to invalid channel/port
|
||||
expect(isBroadcastTxFailure(result)).toEqual(true);
|
||||
expect(isDeliverTxFailure(result)).toEqual(true);
|
||||
}
|
||||
|
||||
// no height timeout
|
||||
@ -191,7 +191,7 @@ describe("SigningStargateClient", () => {
|
||||
memo,
|
||||
);
|
||||
// CheckTx must pass but the execution must fail in DeliverTx due to invalid channel/port
|
||||
expect(isBroadcastTxFailure(result)).toEqual(true);
|
||||
expect(isDeliverTxFailure(result)).toEqual(true);
|
||||
}
|
||||
});
|
||||
|
||||
@ -223,7 +223,7 @@ describe("SigningStargateClient", () => {
|
||||
memo,
|
||||
);
|
||||
// CheckTx must pass but the execution must fail in DeliverTx due to invalid channel/port
|
||||
expect(isBroadcastTxFailure(result)).toEqual(true);
|
||||
expect(isDeliverTxFailure(result)).toEqual(true);
|
||||
}
|
||||
|
||||
// no height timeout
|
||||
@ -240,7 +240,7 @@ describe("SigningStargateClient", () => {
|
||||
memo,
|
||||
);
|
||||
// CheckTx must pass but the execution must fail in DeliverTx due to invalid channel/port
|
||||
expect(isBroadcastTxFailure(result)).toEqual(true);
|
||||
expect(isDeliverTxFailure(result)).toEqual(true);
|
||||
}
|
||||
});
|
||||
});
|
||||
@ -271,7 +271,7 @@ describe("SigningStargateClient", () => {
|
||||
};
|
||||
const memo = "Use your power wisely";
|
||||
const result = await client.signAndBroadcast(faucet.address0, [msgAny], fee, memo);
|
||||
assertIsBroadcastTxSuccess(result);
|
||||
assertIsDeliverTxSuccess(result);
|
||||
});
|
||||
|
||||
it("works with auto gas", async () => {
|
||||
@ -292,7 +292,7 @@ describe("SigningStargateClient", () => {
|
||||
value: msg,
|
||||
};
|
||||
const result = await client.signAndBroadcast(faucet.address0, [msgAny], "auto");
|
||||
assertIsBroadcastTxSuccess(result);
|
||||
assertIsDeliverTxSuccess(result);
|
||||
});
|
||||
|
||||
it("works with a modifying signer", async () => {
|
||||
@ -319,7 +319,7 @@ describe("SigningStargateClient", () => {
|
||||
};
|
||||
const memo = "Use your power wisely";
|
||||
const result = await client.signAndBroadcast(faucet.address0, [msgAny], fee, memo);
|
||||
assertIsBroadcastTxSuccess(result);
|
||||
assertIsDeliverTxSuccess(result);
|
||||
|
||||
await sleep(1000);
|
||||
|
||||
@ -358,7 +358,7 @@ describe("SigningStargateClient", () => {
|
||||
};
|
||||
const memo = "Use your tokens wisely";
|
||||
const result = await client.signAndBroadcast(faucet.address0, [msgAny], fee, memo);
|
||||
assertIsBroadcastTxSuccess(result);
|
||||
assertIsDeliverTxSuccess(result);
|
||||
});
|
||||
|
||||
it("works with staking MsgDelegate", async () => {
|
||||
@ -385,7 +385,7 @@ describe("SigningStargateClient", () => {
|
||||
};
|
||||
const memo = "Use your tokens wisely";
|
||||
const result = await client.signAndBroadcast(faucet.address0, [msgAny], fee, memo);
|
||||
assertIsBroadcastTxSuccess(result);
|
||||
assertIsDeliverTxSuccess(result);
|
||||
});
|
||||
|
||||
it("works with a custom registry and custom message", async () => {
|
||||
@ -505,7 +505,7 @@ describe("SigningStargateClient", () => {
|
||||
};
|
||||
const memo = "Use your power wisely";
|
||||
const result = await client.signAndBroadcast(faucet.address0, [msgAny], fee, memo);
|
||||
assertIsBroadcastTxSuccess(result);
|
||||
assertIsDeliverTxSuccess(result);
|
||||
});
|
||||
|
||||
it("works with a modifying signer", async () => {
|
||||
@ -532,7 +532,7 @@ describe("SigningStargateClient", () => {
|
||||
};
|
||||
const memo = "Use your power wisely";
|
||||
const result = await client.signAndBroadcast(faucet.address0, [msgAny], fee, memo);
|
||||
assertIsBroadcastTxSuccess(result);
|
||||
assertIsDeliverTxSuccess(result);
|
||||
|
||||
await sleep(1000);
|
||||
|
||||
@ -576,7 +576,7 @@ describe("SigningStargateClient", () => {
|
||||
|
||||
// ensure signature is valid
|
||||
const result = await client.broadcastTx(Uint8Array.from(TxRaw.encode(signed).finish()));
|
||||
assertIsBroadcastTxSuccess(result);
|
||||
assertIsDeliverTxSuccess(result);
|
||||
});
|
||||
|
||||
it("works with a modifying signer", async () => {
|
||||
@ -613,7 +613,7 @@ describe("SigningStargateClient", () => {
|
||||
|
||||
// ensure signature is valid
|
||||
const result = await client.broadcastTx(Uint8Array.from(TxRaw.encode(signed).finish()));
|
||||
assertIsBroadcastTxSuccess(result);
|
||||
assertIsDeliverTxSuccess(result);
|
||||
});
|
||||
});
|
||||
|
||||
@ -645,7 +645,7 @@ describe("SigningStargateClient", () => {
|
||||
|
||||
// ensure signature is valid
|
||||
const result = await client.broadcastTx(Uint8Array.from(TxRaw.encode(signed).finish()));
|
||||
assertIsBroadcastTxSuccess(result);
|
||||
assertIsDeliverTxSuccess(result);
|
||||
});
|
||||
|
||||
it("works with staking MsgDelegate", async () => {
|
||||
@ -675,7 +675,7 @@ describe("SigningStargateClient", () => {
|
||||
|
||||
// ensure signature is valid
|
||||
const result = await client.broadcastTx(Uint8Array.from(TxRaw.encode(signed).finish()));
|
||||
assertIsBroadcastTxSuccess(result);
|
||||
assertIsDeliverTxSuccess(result);
|
||||
});
|
||||
|
||||
it("works with a custom registry and custom message", async () => {
|
||||
@ -798,7 +798,7 @@ describe("SigningStargateClient", () => {
|
||||
|
||||
// ensure signature is valid
|
||||
const result = await client.broadcastTx(Uint8Array.from(TxRaw.encode(signed).finish()));
|
||||
assertIsBroadcastTxSuccess(result);
|
||||
assertIsDeliverTxSuccess(result);
|
||||
});
|
||||
|
||||
it("works with a modifying signer", async () => {
|
||||
@ -835,7 +835,7 @@ describe("SigningStargateClient", () => {
|
||||
|
||||
// ensure signature is valid
|
||||
const result = await client.broadcastTx(Uint8Array.from(TxRaw.encode(signed).finish()));
|
||||
assertIsBroadcastTxSuccess(result);
|
||||
assertIsDeliverTxSuccess(result);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -69,7 +69,7 @@ import {
|
||||
MsgWithdrawDelegatorRewardEncodeObject,
|
||||
} from "./encodeobjects";
|
||||
import { calculateFee, GasPrice } from "./fee";
|
||||
import { BroadcastTxResponse, StargateClient } from "./stargateclient";
|
||||
import { DeliverTxResponse, StargateClient } from "./stargateclient";
|
||||
|
||||
export const defaultRegistryTypes: ReadonlyArray<[string, GeneratedType]> = [
|
||||
["/cosmos.bank.v1beta1.MsgMultiSend", MsgMultiSend],
|
||||
@ -210,7 +210,7 @@ export class SigningStargateClient extends StargateClient {
|
||||
amount: readonly Coin[],
|
||||
fee: StdFee | "auto" | number,
|
||||
memo = "",
|
||||
): Promise<BroadcastTxResponse> {
|
||||
): Promise<DeliverTxResponse> {
|
||||
const sendMsg: MsgSendEncodeObject = {
|
||||
typeUrl: "/cosmos.bank.v1beta1.MsgSend",
|
||||
value: {
|
||||
@ -228,7 +228,7 @@ export class SigningStargateClient extends StargateClient {
|
||||
amount: Coin,
|
||||
fee: StdFee | "auto" | number,
|
||||
memo = "",
|
||||
): Promise<BroadcastTxResponse> {
|
||||
): Promise<DeliverTxResponse> {
|
||||
const delegateMsg: MsgDelegateEncodeObject = {
|
||||
typeUrl: "/cosmos.staking.v1beta1.MsgDelegate",
|
||||
value: MsgDelegate.fromPartial({
|
||||
@ -246,7 +246,7 @@ export class SigningStargateClient extends StargateClient {
|
||||
amount: Coin,
|
||||
fee: StdFee | "auto" | number,
|
||||
memo = "",
|
||||
): Promise<BroadcastTxResponse> {
|
||||
): Promise<DeliverTxResponse> {
|
||||
const undelegateMsg: MsgUndelegateEncodeObject = {
|
||||
typeUrl: "/cosmos.staking.v1beta1.MsgUndelegate",
|
||||
value: MsgUndelegate.fromPartial({
|
||||
@ -263,7 +263,7 @@ export class SigningStargateClient extends StargateClient {
|
||||
validatorAddress: string,
|
||||
fee: StdFee | "auto" | number,
|
||||
memo = "",
|
||||
): Promise<BroadcastTxResponse> {
|
||||
): Promise<DeliverTxResponse> {
|
||||
const withdrawMsg: MsgWithdrawDelegatorRewardEncodeObject = {
|
||||
typeUrl: "/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward",
|
||||
value: MsgWithdrawDelegatorReward.fromPartial({
|
||||
@ -285,7 +285,7 @@ export class SigningStargateClient extends StargateClient {
|
||||
timeoutTimestamp: number | undefined,
|
||||
fee: StdFee | "auto" | number,
|
||||
memo = "",
|
||||
): Promise<BroadcastTxResponse> {
|
||||
): Promise<DeliverTxResponse> {
|
||||
const timeoutTimestampNanoseconds = timeoutTimestamp
|
||||
? Long.fromNumber(timeoutTimestamp).multiply(1_000_000_000)
|
||||
: undefined;
|
||||
@ -309,7 +309,7 @@ export class SigningStargateClient extends StargateClient {
|
||||
messages: readonly EncodeObject[],
|
||||
fee: StdFee | "auto" | number,
|
||||
memo = "",
|
||||
): Promise<BroadcastTxResponse> {
|
||||
): Promise<DeliverTxResponse> {
|
||||
let usedFee: StdFee;
|
||||
if (fee == "auto" || typeof fee === "number") {
|
||||
assertDefined(this.gasPrice, "Gas price must be set in the client options when auto gas is used.");
|
||||
|
||||
@ -14,12 +14,7 @@ import { Coin } from "cosmjs-types/cosmos/base/v1beta1/coin";
|
||||
import { TxRaw } from "cosmjs-types/cosmos/tx/v1beta1/tx";
|
||||
|
||||
import { isMsgSendEncodeObject } from "./encodeobjects";
|
||||
import {
|
||||
BroadcastTxResponse,
|
||||
isBroadcastTxFailure,
|
||||
isBroadcastTxSuccess,
|
||||
StargateClient,
|
||||
} from "./stargateclient";
|
||||
import { DeliverTxResponse, isDeliverTxFailure, isDeliverTxSuccess, StargateClient } from "./stargateclient";
|
||||
import {
|
||||
defaultSigningClientOptions,
|
||||
faucet,
|
||||
@ -46,7 +41,7 @@ async function sendTokens(
|
||||
amount: readonly Coin[],
|
||||
memo: string,
|
||||
): Promise<{
|
||||
readonly broadcastResponse: BroadcastTxResponse;
|
||||
readonly broadcastResponse: DeliverTxResponse;
|
||||
readonly tx: Uint8Array;
|
||||
}> {
|
||||
const [{ address: walletAddress, pubkey: pubkeyBytes }] = await wallet.getAccounts();
|
||||
@ -122,7 +117,7 @@ describe("StargateClient.getTx and .searchTx", () => {
|
||||
coins(123456700000000, "ucosm"),
|
||||
"Sending more than I can afford",
|
||||
);
|
||||
if (isBroadcastTxFailure(unsuccessfulResult.broadcastResponse)) {
|
||||
if (isDeliverTxFailure(unsuccessfulResult.broadcastResponse)) {
|
||||
sendUnsuccessful = {
|
||||
sender: faucet.address0,
|
||||
recipient: unsuccessfulRecipient,
|
||||
@ -139,7 +134,7 @@ describe("StargateClient.getTx and .searchTx", () => {
|
||||
coins(1234567, "ucosm"),
|
||||
"Something I can afford",
|
||||
);
|
||||
if (isBroadcastTxSuccess(successfulResult.broadcastResponse)) {
|
||||
if (isDeliverTxSuccess(successfulResult.broadcastResponse)) {
|
||||
sendSuccessful = {
|
||||
sender: faucet.address0,
|
||||
recipient: successfulRecipient,
|
||||
|
||||
@ -14,7 +14,7 @@ import { TxRaw } from "cosmjs-types/cosmos/tx/v1beta1/tx";
|
||||
import { ReadonlyDate } from "readonly-date";
|
||||
|
||||
import {
|
||||
assertIsBroadcastTxSuccess,
|
||||
assertIsDeliverTxSuccess,
|
||||
PrivateStargateClient,
|
||||
StargateClient,
|
||||
TimeoutError,
|
||||
@ -327,7 +327,7 @@ describe("StargateClient", () => {
|
||||
});
|
||||
const txRawBytes = Uint8Array.from(TxRaw.encode(txRaw).finish());
|
||||
const txResult = await client.broadcastTx(txRawBytes);
|
||||
assertIsBroadcastTxSuccess(txResult);
|
||||
assertIsDeliverTxSuccess(txResult);
|
||||
|
||||
const { gasUsed, rawLog, transactionHash } = txResult;
|
||||
expect(gasUsed).toBeGreaterThan(0);
|
||||
@ -436,7 +436,7 @@ describe("StargateClient", () => {
|
||||
const txRawBytes1 = Uint8Array.from(TxRaw.encode(txRaw1).finish());
|
||||
const largeTimeoutMs = 30_000;
|
||||
const txResult = await client.broadcastTx(txRawBytes1, largeTimeoutMs);
|
||||
assertIsBroadcastTxSuccess(txResult);
|
||||
assertIsDeliverTxSuccess(txResult);
|
||||
|
||||
const { accountNumber: accountNumber2, sequence: sequence2 } = (await client.getSequence(address))!;
|
||||
const authInfoBytes2 = makeAuthInfoBytes([{ pubkey, sequence: sequence2 }], feeAmount, gasLimit);
|
||||
|
||||
@ -92,7 +92,7 @@ export interface SequenceResponse {
|
||||
readonly sequence: number;
|
||||
}
|
||||
|
||||
export interface BroadcastTxFailure {
|
||||
export interface DeliverTxFailure {
|
||||
readonly height: number;
|
||||
readonly code: number;
|
||||
readonly transactionHash: string;
|
||||
@ -100,7 +100,7 @@ export interface BroadcastTxFailure {
|
||||
readonly data?: readonly MsgData[];
|
||||
}
|
||||
|
||||
export interface BroadcastTxSuccess {
|
||||
export interface DeliverTxSuccess {
|
||||
readonly height: number;
|
||||
readonly transactionHash: string;
|
||||
readonly rawLog?: string;
|
||||
@ -112,29 +112,22 @@ export interface BroadcastTxSuccess {
|
||||
/**
|
||||
* The response after successfully broadcasting a transaction.
|
||||
* Success or failure refer to the execution result.
|
||||
*
|
||||
* The name is a bit misleading as this contains the result of the execution
|
||||
* in a block. Both `BroadcastTxSuccess` and `BroadcastTxFailure` contain a height
|
||||
* field, which is the height of the block that contains the transaction. This means
|
||||
* transactions that were never included in a block cannot be expressed with this type.
|
||||
*/
|
||||
export type BroadcastTxResponse = BroadcastTxSuccess | BroadcastTxFailure;
|
||||
export type DeliverTxResponse = DeliverTxSuccess | DeliverTxFailure;
|
||||
|
||||
export function isBroadcastTxFailure(result: BroadcastTxResponse): result is BroadcastTxFailure {
|
||||
return !!(result as BroadcastTxFailure).code;
|
||||
export function isDeliverTxFailure(result: DeliverTxResponse): result is DeliverTxFailure {
|
||||
return !!(result as DeliverTxFailure).code;
|
||||
}
|
||||
|
||||
export function isBroadcastTxSuccess(result: BroadcastTxResponse): result is BroadcastTxSuccess {
|
||||
return !isBroadcastTxFailure(result);
|
||||
export function isDeliverTxSuccess(result: DeliverTxResponse): result is DeliverTxSuccess {
|
||||
return !isDeliverTxFailure(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures the given result is a success. Throws a detailed error message otherwise.
|
||||
*/
|
||||
export function assertIsBroadcastTxSuccess(
|
||||
result: BroadcastTxResponse,
|
||||
): asserts result is BroadcastTxSuccess {
|
||||
if (isBroadcastTxFailure(result)) {
|
||||
export function assertIsDeliverTxSuccess(result: DeliverTxResponse): asserts result is DeliverTxSuccess {
|
||||
if (isDeliverTxFailure(result)) {
|
||||
throw new Error(
|
||||
`Error when broadcasting tx ${result.transactionHash} at height ${result.height}. Code: ${result.code}; Raw log: ${result.rawLog}`,
|
||||
);
|
||||
@ -344,20 +337,20 @@ export class StargateClient {
|
||||
*
|
||||
* If the transaction is not included in a block before the provided timeout, this errors with a `TimeoutError`.
|
||||
*
|
||||
* If the transaction is included in a block, a `BroadcastTxResponse` is returned. The caller then
|
||||
* If the transaction is included in a block, a `DeliverTxResponse` is returned. The caller then
|
||||
* usually needs to check for execution success or failure.
|
||||
*/
|
||||
public async broadcastTx(
|
||||
tx: Uint8Array,
|
||||
timeoutMs = 60_000,
|
||||
pollIntervalMs = 3_000,
|
||||
): Promise<BroadcastTxResponse> {
|
||||
): Promise<DeliverTxResponse> {
|
||||
let timedOut = false;
|
||||
const txPollTimeout = setTimeout(() => {
|
||||
timedOut = true;
|
||||
}, timeoutMs);
|
||||
|
||||
const pollForTx = async (txId: string): Promise<BroadcastTxResponse> => {
|
||||
const pollForTx = async (txId: string): Promise<DeliverTxResponse> => {
|
||||
if (timedOut) {
|
||||
throw new TimeoutError(
|
||||
`Transaction with ID ${txId} was submitted but was not yet found on the chain. You might want to check later.`,
|
||||
|
||||
@ -6,7 +6,7 @@ const { Random } = require("@cosmjs/crypto");
|
||||
const { Bech32 } = require("@cosmjs/encoding");
|
||||
const { DirectSecp256k1HdWallet } = require("@cosmjs/proto-signing");
|
||||
const {
|
||||
assertIsBroadcastTxSuccess,
|
||||
assertIsDeliverTxSuccess,
|
||||
SigningStargateClient,
|
||||
calculateFee,
|
||||
GasPrice,
|
||||
@ -28,7 +28,7 @@ async function main() {
|
||||
const fee = calculateFee(80_000, "0.025ucosm");
|
||||
const memo = "Ensure chain has my pubkey";
|
||||
const sendResult = await client.sendTokens(faucet.address0, recipient, amount, fee, memo);
|
||||
assertIsBroadcastTxSuccess(sendResult);
|
||||
assertIsDeliverTxSuccess(sendResult);
|
||||
}
|
||||
|
||||
main().then(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user