diff --git a/packages/bcp/src/cosmwasmconnection.spec.ts b/packages/bcp/src/cosmwasmconnection.spec.ts index d3f3ae56..74c4f977 100644 --- a/packages/bcp/src/cosmwasmconnection.spec.ts +++ b/packages/bcp/src/cosmwasmconnection.spec.ts @@ -18,7 +18,7 @@ import { assert } from "@iov/utils"; import { CosmWasmCodec } from "./cosmwasmcodec"; import { CosmWasmConnection, TokenConfiguration } from "./cosmwasmconnection"; -import { signedTxJson, txId } from "./testdata.spec"; +import * as testdata from "./testdata.spec"; const { fromBase64, toHex } = Encoding; @@ -197,12 +197,10 @@ describe("CosmWasmConnection", () => { describe("identifier", () => { it("calculates tx hash from PostableBytes", async () => { pendingWithoutCosmos(); - const codec = new CosmWasmCodec(defaultPrefix, atomConfig.bankTokens); const connection = await CosmWasmConnection.establish(httpUrl, defaultPrefix, atomConfig); - const postable = codec.bytesToPost(signedTxJson); - const id = await connection.identifier(postable); + const id = await connection.identifier(testdata.signedTxJson); expect(id).toMatch(/^[0-9A-F]{64}$/); - expect(id).toEqual(txId); + expect(id).toEqual(testdata.txId); }); }); diff --git a/packages/bcp/src/cosmwasmconnection.ts b/packages/bcp/src/cosmwasmconnection.ts index 801ec313..a44be650 100644 --- a/packages/bcp/src/cosmwasmconnection.ts +++ b/packages/bcp/src/cosmwasmconnection.ts @@ -1,12 +1,5 @@ /* eslint-disable @typescript-eslint/camelcase */ -import { - CosmosAddressBech32Prefix, - CosmWasmClient, - RestClient, - TxsResponse, - types, - unmarshalTx, -} from "@cosmwasm/sdk"; +import { CosmosAddressBech32Prefix, CosmWasmClient, RestClient, TxsResponse, types } from "@cosmwasm/sdk"; import { Account, AccountQuery, @@ -28,6 +21,7 @@ import { PostableBytes, PostTxResponse, PubkeyQuery, + SignedTransaction, Token, TokenTicker, TransactionId, @@ -46,6 +40,7 @@ import { Stream } from "xstream"; import { decodeCosmosPubkey, pubkeyToAddress } from "./address"; import { Caip5 } from "./caip5"; import { decodeAmount, parseTxsResponse } from "./decode"; +import { buildSignedTx } from "./encode"; import { accountToNonce, BankToken, Erc20Token } from "./types"; const { fromAscii, toHex } = Encoding; @@ -162,8 +157,12 @@ export class CosmWasmConnection implements BlockchainConnection { return this.supportedTokens; } - public async identifier(signed: PostableBytes): Promise { - const tx = unmarshalTx(signed); + /** + * This is a replacement for the unimplemented CosmWasmCodec.identifier. Here we have more + * context and network available, which we might use to implement the API in an async way. + */ + public async identifier(signed: SignedTransaction): Promise { + const tx = buildSignedTx(signed, this.bankTokens, this.erc20Tokens); // tslint:disable-next-line: deprecation const bytes = await this.restClient.encodeTx(tx); const hash = new Sha256(bytes).digest(); diff --git a/packages/bcp/types/cosmwasmconnection.d.ts b/packages/bcp/types/cosmwasmconnection.d.ts index 6d15edea..66305e8c 100644 --- a/packages/bcp/types/cosmwasmconnection.d.ts +++ b/packages/bcp/types/cosmwasmconnection.d.ts @@ -14,6 +14,7 @@ import { PostableBytes, PostTxResponse, PubkeyQuery, + SignedTransaction, Token, TokenTicker, TransactionId, @@ -58,7 +59,11 @@ export declare class CosmWasmConnection implements BlockchainConnection { height(): Promise; getToken(searchTicker: TokenTicker): Promise; getAllTokens(): Promise; - identifier(signed: PostableBytes): Promise; + /** + * This is a replacement for the unimplemented CosmWasmCodec.identifier. Here we have more + * context and network available, which we might use to implement the API in an async way. + */ + identifier(signed: SignedTransaction): Promise; getAccount(query: AccountQuery): Promise; watchAccount(_account: AccountQuery): Stream; getNonce(query: AddressQuery | PubkeyQuery): Promise; diff --git a/packages/sdk/src/restclient.spec.ts b/packages/sdk/src/restclient.spec.ts index 9862d178..276de57b 100644 --- a/packages/sdk/src/restclient.spec.ts +++ b/packages/sdk/src/restclient.spec.ts @@ -221,9 +221,8 @@ describe("RestClient", () => { describe("encodeTx", () => { it("works for cosmoshub example", async () => { pendingWithoutCosmos(); - const tx = cosmoshub.tx.value; const client = new RestClient(httpUrl); - expect(await client.encodeTx(tx)).toEqual(fromBase64(cosmoshub.tx_data)); + expect(await client.encodeTx(cosmoshub.tx)).toEqual(fromBase64(cosmoshub.tx_data)); }); }); diff --git a/packages/sdk/src/restclient.ts b/packages/sdk/src/restclient.ts index b6ee7e05..8815981d 100644 --- a/packages/sdk/src/restclient.ts +++ b/packages/sdk/src/restclient.ts @@ -9,7 +9,6 @@ import { isStdTx, Model, parseWasmData, - StdTx, WasmData, } from "./types"; @@ -221,8 +220,7 @@ export class RestClient { } /** returns the amino-encoding of the transaction performed by the server */ - public async encodeTx(stdTx: StdTx): Promise { - const tx = { type: "cosmos-sdk/StdTx", value: stdTx }; + public async encodeTx(tx: CosmosSdkTx): Promise { const responseData = await this.post("/txs/encode", tx); if (!(responseData as any).tx) { throw new Error("Unexpected response data format"); diff --git a/packages/sdk/types/restclient.d.ts b/packages/sdk/types/restclient.d.ts index 8f41d03a..a7e87e27 100644 --- a/packages/sdk/types/restclient.d.ts +++ b/packages/sdk/types/restclient.d.ts @@ -1,4 +1,4 @@ -import { CodeInfo, ContractInfo, CosmosSdkAccount, CosmosSdkTx, Model, StdTx } from "./types"; +import { CodeInfo, ContractInfo, CosmosSdkAccount, CosmosSdkTx, Model } from "./types"; interface NodeInfo { readonly network: string; } @@ -92,7 +92,7 @@ export declare class RestClient { blocksLatest(): Promise; blocks(height: number): Promise; /** returns the amino-encoding of the transaction performed by the server */ - encodeTx(stdTx: StdTx): Promise; + encodeTx(tx: CosmosSdkTx): Promise; authAccounts(address: string, height?: string): Promise; txs(query: string): Promise; txsById(id: string): Promise;