Pull out parseUnsignedTx
This commit is contained in:
parent
8ad5524b09
commit
11710d5849
@ -12,6 +12,7 @@ import {
|
||||
parseMsg,
|
||||
parseSignedTx,
|
||||
parseTxsResponse,
|
||||
parseUnsignedTx,
|
||||
} from "./decode";
|
||||
import * as testdata from "./testdata.spec";
|
||||
import cosmoshub from "./testdata/cosmoshub.json";
|
||||
@ -157,6 +158,14 @@ describe("decode", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("parseUnsignedTx", () => {
|
||||
it("works", () => {
|
||||
expect(parseUnsignedTx(cosmoshub.tx.value, testdata.chainId, defaultTokens)).toEqual(
|
||||
testdata.sendTxJson,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("parseSignedTx", () => {
|
||||
it("works", () => {
|
||||
expect(parseSignedTx(cosmoshub.tx.value, testdata.chainId, testdata.nonce, defaultTokens)).toEqual(
|
||||
|
||||
@ -109,12 +109,11 @@ export function parseFee(fee: types.StdFee, tokens: BankTokens): Fee {
|
||||
};
|
||||
}
|
||||
|
||||
export function parseSignedTx(
|
||||
export function parseUnsignedTx(
|
||||
txValue: types.StdTx,
|
||||
chainId: ChainId,
|
||||
nonce: Nonce,
|
||||
tokens: BankTokens,
|
||||
): SignedTransaction {
|
||||
): UnsignedTransaction {
|
||||
if (!types.isStdTx(txValue)) {
|
||||
throw new Error("Only StdTx is supported");
|
||||
}
|
||||
@ -122,18 +121,25 @@ export function parseSignedTx(
|
||||
throw new Error("Only single-message transactions currently supported");
|
||||
}
|
||||
|
||||
const [primarySignature] = txValue.signatures.map(signature => decodeFullSignature(signature, nonce));
|
||||
const msg = parseMsg(txValue.msg[0], txValue.memo, chainId, tokens);
|
||||
const fee = parseFee(txValue.fee, tokens);
|
||||
|
||||
const transaction: UnsignedTransaction = {
|
||||
return {
|
||||
...msg,
|
||||
chainId: chainId,
|
||||
fee: fee,
|
||||
};
|
||||
}
|
||||
|
||||
export function parseSignedTx(
|
||||
txValue: types.StdTx,
|
||||
chainId: ChainId,
|
||||
nonce: Nonce,
|
||||
tokens: BankTokens,
|
||||
): SignedTransaction {
|
||||
const [primarySignature] = txValue.signatures.map(signature => decodeFullSignature(signature, nonce));
|
||||
return {
|
||||
transaction: transaction,
|
||||
transaction: parseUnsignedTx(txValue, chainId, tokens),
|
||||
signatures: [primarySignature],
|
||||
};
|
||||
}
|
||||
|
||||
5
packages/bcp/types/decode.d.ts
vendored
5
packages/bcp/types/decode.d.ts
vendored
@ -25,6 +25,11 @@ export declare function parseMsg(
|
||||
tokens: BankTokens,
|
||||
): UnsignedTransaction;
|
||||
export declare function parseFee(fee: types.StdFee, tokens: BankTokens): Fee;
|
||||
export declare function parseUnsignedTx(
|
||||
txValue: types.StdTx,
|
||||
chainId: ChainId,
|
||||
tokens: BankTokens,
|
||||
): UnsignedTransaction;
|
||||
export declare function parseSignedTx(
|
||||
txValue: types.StdTx,
|
||||
chainId: ChainId,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user