mirror of
https://github.com/cosmos/cosmjs.git
synced 2025-03-10 21:49:15 +00:00
Add support for parsing MsgStoreCode in BCP
This commit is contained in:
parent
f3a413f62a
commit
8f0509e11e
@ -1,5 +1,5 @@
|
||||
/* eslint-disable @typescript-eslint/camelcase */
|
||||
import { RestClient, TxsResponse, unmarshalTx } from "@cosmwasm/sdk";
|
||||
import { RestClient, TxsResponse, types, unmarshalTx } from "@cosmwasm/sdk";
|
||||
import {
|
||||
Account,
|
||||
AccountQuery,
|
||||
@ -305,8 +305,19 @@ export class CosmWasmConnection implements BlockchainConnection {
|
||||
response: TxsResponse,
|
||||
chainId: ChainId,
|
||||
): Promise<ConfirmedAndSignedTransaction<UnsignedTransaction> | FailedTransaction> {
|
||||
const sender = (response.tx.value as any).msg[0].value.from_address;
|
||||
const accountForHeight = await this.restClient.authAccounts(sender, response.height);
|
||||
const firstMsg = response.tx.value.msg.find(() => true);
|
||||
if (!firstMsg) throw new Error("Got transaction without a first message. What is going on here?");
|
||||
|
||||
let senderAddress: string;
|
||||
if (types.isMsgSend(firstMsg)) {
|
||||
senderAddress = firstMsg.value.from_address;
|
||||
} else if (types.isMsgStoreCode(firstMsg)) {
|
||||
senderAddress = firstMsg.value.sender;
|
||||
} else {
|
||||
throw new Error(`Got unsupported type of message: ${firstMsg.type}`);
|
||||
}
|
||||
|
||||
const accountForHeight = await this.restClient.authAccounts(senderAddress, response.height);
|
||||
// this is technically not the proper nonce. maybe this causes issues for sig validation?
|
||||
// leaving for now unless it causes issues
|
||||
const sequence = (accountForHeight.result.value.sequence - 1) as Nonce;
|
||||
|
@ -72,21 +72,27 @@ export function decodeAmount(tokens: TokenInfos, coin: types.Coin): Amount {
|
||||
};
|
||||
}
|
||||
|
||||
export function parseMsg(msg: types.Msg, chainId: ChainId, tokens: TokenInfos): SendTransaction {
|
||||
if (!types.isMsgSend(msg)) {
|
||||
throw new Error("Unknown message type in transaction");
|
||||
export function parseMsg(msg: types.Msg, chainId: ChainId, tokens: TokenInfos): UnsignedTransaction {
|
||||
if (types.isMsgSend(msg)) {
|
||||
if (msg.value.amount.length !== 1) {
|
||||
throw new Error("Only MsgSend with one amount is supported");
|
||||
}
|
||||
const send: SendTransaction = {
|
||||
kind: "bcp/send",
|
||||
chainId: chainId,
|
||||
sender: msg.value.from_address as Address,
|
||||
recipient: msg.value.to_address as Address,
|
||||
amount: decodeAmount(tokens, msg.value.amount[0]),
|
||||
};
|
||||
return send;
|
||||
} else {
|
||||
// Unknown transaction type
|
||||
const unknown = {
|
||||
chainId: chainId,
|
||||
kind: "bcp/unknown",
|
||||
};
|
||||
return unknown;
|
||||
}
|
||||
const msgValue = msg.value;
|
||||
if (msgValue.amount.length !== 1) {
|
||||
throw new Error("Only MsgSend with one amount is supported");
|
||||
}
|
||||
return {
|
||||
kind: "bcp/send",
|
||||
chainId: chainId,
|
||||
sender: msgValue.from_address as Address,
|
||||
recipient: msgValue.to_address as Address,
|
||||
amount: decodeAmount(tokens, msgValue.amount[0]),
|
||||
};
|
||||
}
|
||||
|
||||
export function parseFee(fee: types.StdFee, tokens: TokenInfos): Fee {
|
||||
|
3
packages/bcp/types/decode.d.ts
vendored
3
packages/bcp/types/decode.d.ts
vendored
@ -7,7 +7,6 @@ import {
|
||||
FullSignature,
|
||||
Nonce,
|
||||
PubkeyBundle,
|
||||
SendTransaction,
|
||||
SignatureBytes,
|
||||
SignedTransaction,
|
||||
UnsignedTransaction,
|
||||
@ -19,7 +18,7 @@ export declare function decodeSignature(signature: string): SignatureBytes;
|
||||
export declare function decodeFullSignature(signature: types.StdSignature, nonce: number): FullSignature;
|
||||
export declare function coinToDecimal(tokens: TokenInfos, coin: types.Coin): readonly [Decimal, string];
|
||||
export declare function decodeAmount(tokens: TokenInfos, coin: types.Coin): Amount;
|
||||
export declare function parseMsg(msg: types.Msg, chainId: ChainId, tokens: TokenInfos): SendTransaction;
|
||||
export declare function parseMsg(msg: types.Msg, chainId: ChainId, tokens: TokenInfos): UnsignedTransaction;
|
||||
export declare function parseFee(fee: types.StdFee, tokens: TokenInfos): Fee;
|
||||
export declare function parseTx(
|
||||
txValue: types.StdTx,
|
||||
|
Loading…
x
Reference in New Issue
Block a user