From e50733eb71b13d5923c451865f228d3da89ba226 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Mon, 3 Feb 2020 19:44:38 +0100 Subject: [PATCH] RestClient posts with JSON-encoded StdTx --- packages/sdk/src/restclient.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/sdk/src/restclient.ts b/packages/sdk/src/restclient.ts index bd9e4eed..f715393e 100644 --- a/packages/sdk/src/restclient.ts +++ b/packages/sdk/src/restclient.ts @@ -1,7 +1,9 @@ -import { unmarshalTx } from "@tendermint/amino-js"; +import { Encoding } from "@iov/encoding"; import axios, { AxiosInstance } from "axios"; -import { AminoTx, BaseAccount } from "./types"; +import { AminoTx, BaseAccount, isAminoStdTx } from "./types"; + +const { fromUtf8 } = Encoding; interface NodeInfo { readonly network: string; @@ -157,10 +159,15 @@ export class RestClient { return responseData as TxsResponse; } + // tx must be JSON encoded StdTx (no wrapper) public async postTx(tx: Uint8Array): Promise { - const unmarshalled = unmarshalTx(tx, true); + // TODO: check this is StdTx + const decoded = JSON.parse(fromUtf8(tx)); + if (!isAminoStdTx(decoded)) { + throw new Error("Must be json encoded StdTx"); + } const params = { - tx: unmarshalled.value, + tx: decoded, mode: this.mode, }; const responseData = await this.post("/txs", params);