Move marshalTx/unmarshalTx to BCP

This commit is contained in:
Simon Warta 2020-06-04 21:10:11 +02:00
parent 57d0686ac6
commit f704194836
8 changed files with 19 additions and 28 deletions

View File

@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/camelcase */
import { makeSignBytes, marshalTx, unmarshalTx } from "@cosmjs/sdk38";
import { isStdTx, makeSignBytes, StdTx } from "@cosmjs/sdk38";
import {
Address,
ChainId,
@ -14,7 +14,7 @@ import {
TxCodec,
UnsignedTransaction,
} from "@iov/bcp";
import { Bech32 } from "@iov/encoding";
import { Bech32, fromUtf8, toUtf8 } from "@iov/encoding";
import { pubkeyToAddress } from "./address";
import { Caip5 } from "./caip5";
@ -22,6 +22,19 @@ import { parseSignedTx } from "./decode";
import { buildSignedTx, buildUnsignedTx } from "./encode";
import { BankToken, nonceToAccountNumber, nonceToSequence } from "./types";
function marshalTx(tx: StdTx): Uint8Array {
const json = JSON.stringify(tx);
return toUtf8(json);
}
function unmarshalTx(data: Uint8Array): StdTx {
const decoded = JSON.parse(fromUtf8(data));
if (!isStdTx(decoded)) {
throw new Error("Must be json encoded StdTx");
}
return decoded;
}
export class CosmosCodec implements TxCodec {
private readonly addressPrefix: string;
private readonly bankTokens: readonly BankToken[];

View File

@ -69,7 +69,6 @@ export function main(originalArgs: readonly string[]): void {
"logs",
"makeCosmoshubPath",
"makeSignBytes",
"marshalTx",
"IndexedTx",
"Coin",
"Msg",

View File

@ -1,11 +0,0 @@
import { fromUtf8 } from "@iov/encoding";
import { isStdTx, StdTx } from "./types";
export function unmarshalTx(data: Uint8Array): StdTx {
const decoded = JSON.parse(fromUtf8(data));
if (!isStdTx(decoded)) {
throw new Error("Must be json encoded StdTx");
}
return decoded;
}

View File

@ -1,6 +1,6 @@
import { toUtf8 } from "@iov/encoding";
import { Msg, StdFee, StdTx } from "./types";
import { Msg, StdFee } from "./types";
function sortJson(json: any): any {
if (typeof json !== "object" || json === null) {
@ -20,11 +20,6 @@ function sortJson(json: any): any {
return result;
}
export function marshalTx(tx: StdTx): Uint8Array {
const json = JSON.stringify(tx);
return toUtf8(json);
}
interface SignJson {
readonly account_number: string;
readonly chain_id: string;

View File

@ -19,8 +19,7 @@ export {
SearchTxQuery,
SearchTxFilter,
} from "./cosmosclient";
export { unmarshalTx } from "./decoding";
export { makeSignBytes, marshalTx } from "./encoding";
export { makeSignBytes } from "./encoding";
export {
AuthAccountsResponse,
BlockResponse,

View File

@ -1,2 +0,0 @@
import { StdTx } from "./types";
export declare function unmarshalTx(data: Uint8Array): StdTx;

View File

@ -1,5 +1,4 @@
import { Msg, StdFee, StdTx } from "./types";
export declare function marshalTx(tx: StdTx): Uint8Array;
import { Msg, StdFee } from "./types";
export declare function makeSignBytes(
msgs: readonly Msg[],
fee: StdFee,

View File

@ -17,8 +17,7 @@ export {
SearchTxQuery,
SearchTxFilter,
} from "./cosmosclient";
export { unmarshalTx } from "./decoding";
export { makeSignBytes, marshalTx } from "./encoding";
export { makeSignBytes } from "./encoding";
export {
AuthAccountsResponse,
BlockResponse,