Move sortJson into @cosmwasm/sdk

This commit is contained in:
Simon Warta 2020-02-04 01:16:28 +01:00
parent ee2c621fba
commit 8034ae7bc6
5 changed files with 22 additions and 21 deletions

View File

@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/camelcase */
import { marshalTx, unmarshalTx } from "@cosmwasm/sdk";
import { marshalTx, sortJson, unmarshalTx } from "@cosmwasm/sdk";
import {
Address,
ChainId,
@ -24,24 +24,6 @@ import { nonceToAccountNumber, nonceToSequence, TokenInfos } from "./types";
const { toUtf8 } = Encoding;
function sortJson(json: any): any {
if (typeof json !== "object" || json === null) {
return json;
}
if (Array.isArray(json)) {
return json.map(sortJson);
}
const sortedKeys = Object.keys(json).sort();
const result = sortedKeys.reduce(
(accumulator, key) => ({
...accumulator,
[key]: sortJson(json[key]),
}),
{},
);
return result;
}
export class CosmWasmCodec implements TxCodec {
private readonly prefix: CosmosBech32Prefix;
private readonly tokens: TokenInfos;

View File

@ -2,6 +2,24 @@ import { Encoding } from "@iov/encoding";
import { StdTx } from "./types";
export function sortJson(json: any): any {
if (typeof json !== "object" || json === null) {
return json;
}
if (Array.isArray(json)) {
return json.map(sortJson);
}
const sortedKeys = Object.keys(json).sort();
const result = sortedKeys.reduce(
(accumulator, key) => ({
...accumulator,
[key]: sortJson(json[key]),
}),
{},
);
return result;
}
export function marshalTx(tx: StdTx): Uint8Array {
const json = JSON.stringify(tx);
return Encoding.toUtf8(json);

View File

@ -1,6 +1,6 @@
import * as types from "./types";
export { unmarshalTx } from "./decoding";
export { marshalTx } from "./encoding";
export { marshalTx, sortJson } from "./encoding";
export { RestClient, TxsResponse } from "./restclient";
export { types };

View File

@ -1,2 +1,3 @@
import { StdTx } from "./types";
export declare function sortJson(json: any): any;
export declare function marshalTx(tx: StdTx): Uint8Array;

View File

@ -1,5 +1,5 @@
import * as types from "./types";
export { unmarshalTx } from "./decoding";
export { marshalTx } from "./encoding";
export { marshalTx, sortJson } from "./encoding";
export { RestClient, TxsResponse } from "./restclient";
export { types };