Skip to content

Commit

Permalink
Rename BroadcastTx{Success,Failure} to DeliverTx{Success,Failure}
Browse files Browse the repository at this point in the history
  • Loading branch information
webmaster128 committed Nov 23, 2021
1 parent b4de1c1 commit 5baf978
Show file tree
Hide file tree
Showing 22 changed files with 139 additions and 151 deletions.
14 changes: 7 additions & 7 deletions packages/cli/examples/simulate.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { coins, makeCosmoshubPath } from "@cosmjs/amino";
import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
import {
assertIsBroadcastTxSuccess,
assertIsDeliverTxSuccess,
calculateFee,
GasPrice,
MsgSendEncodeObject,
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand Down
4 changes: 2 additions & 2 deletions packages/cli/examples/stargate.ts
Original file line number Diff line number Diff line change
@@ -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 =
Expand Down Expand Up @@ -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();
12 changes: 6 additions & 6 deletions packages/cosmwasm-stargate/src/cosmwasmclient.searchtx.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions packages/cosmwasm-stargate/src/cosmwasmclient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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}$/);
Expand Down
8 changes: 4 additions & 4 deletions packages/cosmwasm-stargate/src/cosmwasmclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {
AuthExtension,
BankExtension,
Block,
BroadcastTxResponse,
Coin,
DeliverTxResponse,
IndexedTx,
isSearchByHeightQuery,
isSearchBySentFromOrToQuery,
Expand Down Expand Up @@ -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.
Expand All @@ -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.`,
Expand Down
24 changes: 12 additions & 12 deletions packages/cosmwasm-stargate/src/queries/wasm.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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")
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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");
Expand Down
Loading

0 comments on commit 5baf978

Please sign in to comment.