From 73af405400d08c0055a2fa503b3343e7db7beba0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Stuczy=C5=84ski?= Date: Fri, 23 Apr 2021 15:34:35 +0100 Subject: [PATCH] Checking for tx success when sending coins (#586) * Checking for tx success when sending coins * Changed send return type to BroadcastTxSuccess --- clients/validator/src/index.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/clients/validator/src/index.ts b/clients/validator/src/index.ts index 3986cb1d3a..47744d4976 100644 --- a/clients/validator/src/index.ts +++ b/clients/validator/src/index.ts @@ -4,7 +4,6 @@ import { Bip39, Random } from "@cosmjs/crypto"; import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing"; import MixnodesCache from "./caches/mixnodes"; import { coin, Coin, coins } from "@cosmjs/launchpad"; -import { BroadcastTxResponse } from "@cosmjs/stargate" import { ExecuteResult, InstantiateOptions, @@ -24,6 +23,7 @@ import { } from "./currency"; import GatewaysCache from "./caches/gateways"; import QueryClient, { IQueryClient } from "./query-client"; +import { BroadcastTxSuccess, isBroadcastTxFailure } from "@cosmjs/stargate"; export { coins, coin }; export { Coin }; @@ -271,9 +271,13 @@ export default class ValidatorClient { /** * Send funds from one address to another. */ - async send(senderAddress: string, recipientAddress: string, coins: readonly Coin[], memo?: string): Promise { + async send(senderAddress: string, recipientAddress: string, coins: readonly Coin[], memo?: string): Promise { if (this.client instanceof NetClient) { - return this.client.sendTokens(senderAddress, recipientAddress, coins, memo); + const result = await this.client.sendTokens(senderAddress, recipientAddress, coins, memo); + if (isBroadcastTxFailure(result)) { + throw new Error(`Error when broadcasting tx ${result.transactionHash} at height ${result.height}. Code: ${result.code}; Raw log: ${result.rawLog}`) + } + return result } else { throw new Error("Tried to use send with a query client"); }