diff --git a/packages/bcp/src/decode.spec.ts b/packages/bcp/src/decode.spec.ts index ce5d6fbd..1a5a3840 100644 --- a/packages/bcp/src/decode.spec.ts +++ b/packages/bcp/src/decode.spec.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/camelcase */ import { types } from "@cosmwasm/sdk"; -import { Address, Algorithm, TokenTicker } from "@iov/bcp"; +import { Address, Algorithm, SendTransaction, TokenTicker } from "@iov/bcp"; import { Encoding } from "@iov/encoding"; import { @@ -37,12 +37,14 @@ describe("decode", () => { quantity: "11657995", tokenTicker: "ATOM" as TokenTicker, }; - const defaultSendTransaction = { - kind: "bcp/send" as const, + const defaultMemo = "Best greetings"; + const defaultSendTransaction: SendTransaction = { + kind: "bcp/send", chainId: testdata.chainId, sender: "cosmos1h806c7khnvmjlywdrkdgk2vrayy2mmvf9rxk2r" as Address, recipient: "cosmos1z7g5w84ynmjyg0kqpahdjqpj7yq34v3suckp0e" as Address, amount: defaultAmount, + memo: defaultMemo, }; const defaultFee = { tokens: { @@ -136,7 +138,7 @@ describe("decode", () => { ], }, }; - expect(parseMsg(msg, testdata.chainId, defaultTokens)).toEqual(defaultSendTransaction); + expect(parseMsg(msg, defaultMemo, testdata.chainId, defaultTokens)).toEqual(defaultSendTransaction); }); }); @@ -155,7 +157,6 @@ describe("decode", () => { }); }); - describe("parseSignedTx", () => { it("works", () => { expect(parseSignedTx(cosmoshub.tx.value, testdata.chainId, testdata.nonce, defaultTokens)).toEqual( diff --git a/packages/bcp/src/decode.ts b/packages/bcp/src/decode.ts index 956f3996..5b84e914 100644 --- a/packages/bcp/src/decode.ts +++ b/packages/bcp/src/decode.ts @@ -70,7 +70,12 @@ export function decodeAmount(tokens: BankTokens, coin: types.Coin): Amount { }; } -export function parseMsg(msg: types.Msg, chainId: ChainId, tokens: BankTokens): UnsignedTransaction { +export function parseMsg( + msg: types.Msg, + memo: string | undefined, + chainId: ChainId, + tokens: BankTokens, +): UnsignedTransaction { if (types.isMsgSend(msg)) { if (msg.value.amount.length !== 1) { throw new Error("Only MsgSend with one amount is supported"); @@ -81,6 +86,7 @@ export function parseMsg(msg: types.Msg, chainId: ChainId, tokens: BankTokens): sender: msg.value.from_address as Address, recipient: msg.value.to_address as Address, amount: decodeAmount(tokens, msg.value.amount[0]), + memo: memo, }; return send; } else { @@ -117,13 +123,12 @@ export function parseSignedTx( } const [primarySignature] = txValue.signatures.map(signature => decodeFullSignature(signature, nonce)); - const msg = parseMsg(txValue.msg[0], chainId, tokens); + const msg = parseMsg(txValue.msg[0], txValue.memo, chainId, tokens); const fee = parseFee(txValue.fee, tokens); - const transaction = { + const transaction: UnsignedTransaction = { ...msg, chainId: chainId, - memo: txValue.memo, fee: fee, }; diff --git a/packages/bcp/types/decode.d.ts b/packages/bcp/types/decode.d.ts index cb68994d..7908393f 100644 --- a/packages/bcp/types/decode.d.ts +++ b/packages/bcp/types/decode.d.ts @@ -18,7 +18,12 @@ export declare function decodeSignature(signature: string): SignatureBytes; export declare function decodeFullSignature(signature: types.StdSignature, nonce: number): FullSignature; export declare function coinToDecimal(tokens: BankTokens, coin: types.Coin): readonly [Decimal, string]; export declare function decodeAmount(tokens: BankTokens, coin: types.Coin): Amount; -export declare function parseMsg(msg: types.Msg, chainId: ChainId, tokens: BankTokens): UnsignedTransaction; +export declare function parseMsg( + msg: types.Msg, + memo: string | undefined, + chainId: ChainId, + tokens: BankTokens, +): UnsignedTransaction; export declare function parseFee(fee: types.StdFee, tokens: BankTokens): Fee; export declare function parseSignedTx( txValue: types.StdTx,