Create parseTxsResponseUnsigned

This commit is contained in:
Simon Warta 2020-02-12 14:55:33 +01:00
parent 11710d5849
commit 580ce6bfaa
4 changed files with 54 additions and 7 deletions

View File

@ -38,7 +38,7 @@ import { Stream } from "xstream";
import { decodeCosmosPubkey, pubkeyToAddress } from "./address";
import { Caip5 } from "./caip5";
import { decodeAmount, parseTxsResponse } from "./decode";
import { decodeAmount, parseTxsResponseSigned } from "./decode";
import { buildSignedTx } from "./encode";
import { accountToNonce, BankToken, Erc20Token } from "./types";
@ -385,6 +385,6 @@ export class CosmWasmConnection implements BlockchainConnection {
const sequence = accountForHeight.result.value.sequence - 1;
const nonce = accountToNonce(accountNumber, sequence);
return parseTxsResponse(chainId, parseInt(response.height, 10), nonce, response, this.bankTokens);
return parseTxsResponseSigned(chainId, parseInt(response.height, 10), nonce, response, this.bankTokens);
}
}

View File

@ -11,7 +11,8 @@ import {
parseFee,
parseMsg,
parseSignedTx,
parseTxsResponse,
parseTxsResponseSigned,
parseTxsResponseUnsigned,
parseUnsignedTx,
} from "./decode";
import * as testdata from "./testdata.spec";
@ -174,7 +175,29 @@ describe("decode", () => {
});
});
describe("parseTxsResponse", () => {
describe("parseTxsResponseUnsigned", () => {
it("works", () => {
const currentHeight = 2923;
const txsResponse = {
height: "2823",
txhash: testdata.txId,
raw_log: '[{"msg_index":0,"success":true,"log":""}]',
tx: cosmoshub.tx,
};
const expected = {
transaction: testdata.sendTxJson,
height: 2823,
confirmations: 101,
transactionId: testdata.txId,
log: '[{"msg_index":0,"success":true,"log":""}]',
};
expect(parseTxsResponseUnsigned(testdata.chainId, currentHeight, txsResponse, defaultTokens)).toEqual(
expected,
);
});
});
describe("parseTxsResponseSigned", () => {
it("works", () => {
const currentHeight = 2923;
const txsResponse = {
@ -191,7 +214,7 @@ describe("decode", () => {
log: '[{"msg_index":0,"success":true,"log":""}]',
};
expect(
parseTxsResponse(testdata.chainId, currentHeight, testdata.nonce, txsResponse, defaultTokens),
parseTxsResponseSigned(testdata.chainId, currentHeight, testdata.nonce, txsResponse, defaultTokens),
).toEqual(expected);
});
});

View File

@ -5,6 +5,7 @@ import {
Amount,
ChainId,
ConfirmedAndSignedTransaction,
ConfirmedTransaction,
Fee,
FullSignature,
Nonce,
@ -144,7 +145,23 @@ export function parseSignedTx(
};
}
export function parseTxsResponse(
export function parseTxsResponseUnsigned(
chainId: ChainId,
currentHeight: number,
response: TxsResponse,
tokens: BankTokens,
): ConfirmedTransaction<UnsignedTransaction> {
const height = parseInt(response.height, 10);
return {
transaction: parseUnsignedTx(response.tx.value, chainId, tokens),
height: height,
confirmations: currentHeight - height + 1,
transactionId: response.txhash as TransactionId,
log: response.raw_log,
};
}
export function parseTxsResponseSigned(
chainId: ChainId,
currentHeight: number,
nonce: Nonce,

View File

@ -3,6 +3,7 @@ import {
Amount,
ChainId,
ConfirmedAndSignedTransaction,
ConfirmedTransaction,
Fee,
FullSignature,
Nonce,
@ -36,7 +37,13 @@ export declare function parseSignedTx(
nonce: Nonce,
tokens: BankTokens,
): SignedTransaction;
export declare function parseTxsResponse(
export declare function parseTxsResponseUnsigned(
chainId: ChainId,
currentHeight: number,
response: TxsResponse,
tokens: BankTokens,
): ConfirmedTransaction<UnsignedTransaction>;
export declare function parseTxsResponseSigned(
chainId: ChainId,
currentHeight: number,
nonce: Nonce,