Restore naive implementation for getting sequence

This commit is contained in:
Simon Warta 2020-02-14 15:55:54 +01:00
parent e4f1252331
commit 964965ca82
2 changed files with 21 additions and 6 deletions

View File

@ -306,7 +306,7 @@ describe("CosmWasmConnection", () => {
expect(transaction).toEqual(unsigned);
expect(signatures.length).toEqual(1);
expect(signatures[0]).toEqual({
nonce: -1, // Unfortunately this information is unavailable as previous implementation attempt is broken. See https://github.com/iov-one/iov-core/pull/1390
nonce: signed.signatures[0].nonce,
pubkey: {
algo: signed.signatures[0].pubkey.algo,
data: Secp256k1.compressPubkey(signed.signatures[0].pubkey.data),

View File

@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/camelcase */
import { CosmosAddressBech32Prefix, CosmWasmClient, RestClient, TxsResponse } from "@cosmwasm/sdk";
import { CosmosAddressBech32Prefix, CosmWasmClient, RestClient, TxsResponse, types } from "@cosmwasm/sdk";
import {
Account,
AccountQuery,
@ -359,10 +359,25 @@ export class CosmWasmConnection implements BlockchainConnection {
private async parseAndPopulateTxResponseSigned(
response: TxsResponse,
): Promise<ConfirmedAndSignedTransaction<UnsignedTransaction> | FailedTransaction> {
// There is no known way to get the nonce that was used for signing a transaction.
// This information is nesessary for signature validation.
// TODO: fix
const nonce = -1 as Nonce;
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) ||
types.isMsgInstantiateContract(firstMsg) ||
types.isMsgExecuteContract(firstMsg)
) {
senderAddress = firstMsg.value.sender;
} else {
throw new Error(`Got unsupported type of message: ${firstMsg.type}`);
}
const { accountNumber, sequence: currentSequence } = await this.cosmWasmClient.getNonce(senderAddress);
const nonce = accountToNonce(accountNumber, currentSequence - 1);
return parseTxsResponseSigned(
this.chainId,