mirror of
https://github.com/cosmos/cosmjs.git
synced 2025-03-10 21:49:15 +00:00
Move marshalTx/unmarshalTx to BCP
This commit is contained in:
parent
57d0686ac6
commit
f704194836
@ -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[];
|
||||
|
@ -69,7 +69,6 @@ export function main(originalArgs: readonly string[]): void {
|
||||
"logs",
|
||||
"makeCosmoshubPath",
|
||||
"makeSignBytes",
|
||||
"marshalTx",
|
||||
"IndexedTx",
|
||||
"Coin",
|
||||
"Msg",
|
||||
|
@ -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;
|
||||
}
|
@ -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;
|
||||
|
@ -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,
|
||||
|
2
packages/sdk38/types/decoding.d.ts
vendored
2
packages/sdk38/types/decoding.d.ts
vendored
@ -1,2 +0,0 @@
|
||||
import { StdTx } from "./types";
|
||||
export declare function unmarshalTx(data: Uint8Array): StdTx;
|
3
packages/sdk38/types/encoding.d.ts
vendored
3
packages/sdk38/types/encoding.d.ts
vendored
@ -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,
|
||||
|
3
packages/sdk38/types/index.d.ts
vendored
3
packages/sdk38/types/index.d.ts
vendored
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user