RestClient posts with JSON-encoded StdTx

This commit is contained in:
Ethan Frey 2020-02-03 19:44:38 +01:00
parent 9299b73aa6
commit e50733eb71

View File

@ -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<PostTxsResponse> {
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);