Remove broken height argument from RestClient.authAccounts

This commit is contained in:
Simon Warta 2020-02-13 12:30:24 +01:00
parent d24d6255e1
commit 7d610348c6
4 changed files with 9 additions and 30 deletions

View File

@ -322,7 +322,7 @@ describe("CosmWasmConnection", () => {
expect(transaction).toEqual(unsigned);
expect(signatures.length).toEqual(1);
expect(signatures[0]).toEqual({
nonce: signed.signatures[0].nonce, // This equality check works by pure luck. The implementation is broken. See https://github.com/iov-one/iov-core/pull/1390
nonce: -1, // Unfortunately this information is unavailable as previous implementation attempt is broken. See https://github.com/iov-one/iov-core/pull/1390
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, types } from "@cosmwasm/sdk";
import { CosmosAddressBech32Prefix, CosmWasmClient, RestClient, TxsResponse } from "@cosmwasm/sdk";
import {
Account,
AccountQuery,
@ -364,30 +364,10 @@ export class CosmWasmConnection implements BlockchainConnection {
private async parseAndPopulateTxResponseSigned(
response: TxsResponse,
): Promise<ConfirmedAndSignedTransaction<UnsignedTransaction> | FailedTransaction> {
const firstMsg = response.tx.value.msg.find(() => true);
if (!firstMsg) throw new Error("Got transaction without a first message. What is going on here?");
// needed to get the (account_number, sequence) for the primary signature
let primarySignerAddress: string;
if (types.isMsgSend(firstMsg)) {
primarySignerAddress = firstMsg.value.from_address;
} else if (
types.isMsgStoreCode(firstMsg) ||
types.isMsgInstantiateContract(firstMsg) ||
types.isMsgExecuteContract(firstMsg)
) {
primarySignerAddress = firstMsg.value.sender;
} else {
throw new Error(`Got unsupported type of message: ${firstMsg.type}`);
}
// tslint:disable-next-line: deprecation
const accountForHeight = await this.restClient.authAccounts(primarySignerAddress, response.height);
const accountNumber = accountForHeight.result.value.account_number;
// this is technically not the proper sequence. maybe this causes issues for sig validation?
// leaving for now unless it causes issues
const sequence = accountForHeight.result.value.sequence - 1;
const nonce = accountToNonce(accountNumber, sequence);
// 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 chainId = this.chainId();
return parseTxsResponseSigned(chainId, parseInt(response.height, 10), nonce, response, this.bankTokens);

View File

@ -228,9 +228,8 @@ export class RestClient {
return Encoding.fromBase64((responseData as EncodeTxResponse).tx);
}
public async authAccounts(address: string, height?: string): Promise<AuthAccountsResponse> {
const path =
height === undefined ? `/auth/accounts/${address}` : `/auth/accounts/${address}?tx.height=${height}`;
public async authAccounts(address: string): Promise<AuthAccountsResponse> {
const path = `/auth/accounts/${address}`;
const responseData = await this.get(path);
if ((responseData as any).result.type !== "cosmos-sdk/Account") {
throw new Error("Unexpected response data format");

View File

@ -93,7 +93,7 @@ export declare class RestClient {
blocks(height: number): Promise<BlocksResponse>;
/** returns the amino-encoding of the transaction performed by the server */
encodeTx(tx: CosmosSdkTx): Promise<Uint8Array>;
authAccounts(address: string, height?: string): Promise<AuthAccountsResponse>;
authAccounts(address: string): Promise<AuthAccountsResponse>;
txs(query: string): Promise<SearchTxsResponse>;
txsById(id: string): Promise<TxsResponse>;
postTx(tx: Uint8Array): Promise<PostTxsResponse>;