From d699bfda1f4fbb85da446f670f7f19980e895014 Mon Sep 17 00:00:00 2001 From: Gregory Hill Date: Tue, 15 Aug 2023 12:12:08 +0100 Subject: [PATCH] fix: query payment info Signed-off-by: Gregory Hill --- docker-compose.yml | 2 +- package.json | 4 +- src/factory.ts | 90 ++++++++++++++++++- src/interfaces/definitions.ts | 25 ------ .../parachain/staging/system.test.ts | 9 ++ 5 files changed, 100 insertions(+), 30 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 35dcc2da1..e7489b83a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ version: "3.8" services: interbtc: - image: "interlayhq/interbtc:1.25.0-rc5" + image: "interlayhq/interbtc:1.25.0" command: - --rpc-external - --ws-external diff --git a/package.json b/package.json index d5cde4213..9bd650b89 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@interlay/interbtc-api", - "version": "2.4.2", + "version": "2.4.3", "description": "JavaScript library to interact with interBTC", "main": "build/src/index.js", "typings": "build/src/index.d.ts", @@ -122,4 +122,4 @@ ], "recursive": true } -} +} \ No newline at end of file diff --git a/src/factory.ts b/src/factory.ts index 588b267f5..83f42f9fc 100644 --- a/src/factory.ts +++ b/src/factory.ts @@ -5,10 +5,11 @@ import { ProviderInterface } from "@polkadot/rpc-provider/types"; import { TypeRegistry } from "@polkadot/types"; import { RegistryTypes } from "@polkadot/types/types"; import { DefinitionRpc, DefinitionRpcSub } from "@polkadot/types/types"; - import * as definitions from "./interfaces/definitions"; import { InterBtcApi, DefaultInterBtcApi } from "./interbtc-api"; import { BitcoinNetwork } from "./types"; +import { objectSpread } from "@polkadot/util"; +import { DefinitionCall, DefinitionsCall } from "@polkadot/types/types"; export function createProvider(endpoint: string, autoConnect?: number | false | undefined): ProviderInterface { if (/https?:\/\//.exec(endpoint)) { @@ -34,7 +35,9 @@ export function createSubstrateAPI( types, rpc, noInitWarn: noInitWarn || true, - runtime: definitions.default.runtime + // manual definition for transactionPaymentApi.queryInfo until polkadot-js/api can be upgraded + // TODO: revert when this work is merged: https://github.com/interlay/interbtc-api/pull/672 + runtime: getRuntimeDefs(), }); } @@ -61,3 +64,86 @@ export function createAPIRegistry(): TypeRegistry { registry.register(getAPITypes()); return registry; } + +const V1_TO_V4_SHARED_PAY: Record = { + query_fee_details: { + description: "The transaction fee details", + params: [ + { + name: "uxt", + type: "Extrinsic" + }, + { + name: "len", + type: "u32" + } + ], + type: "FeeDetails" + } +}; + +const V2_TO_V4_SHARED_PAY: Record = { + query_info: { + description: "The transaction info", + params: [ + { + name: "uxt", + type: "Extrinsic" + }, + { + name: "len", + type: "u32" + } + ], + type: "RuntimeDispatchInfo" + } +}; + +const V3_SHARED_PAY_CALL: Record = { + query_length_to_fee: { + description: "Query the output of the current LengthToFee given some input", + params: [ + { + name: "length", + type: "u32" + } + ], + type: "Balance" + }, + query_weight_to_fee: { + description: "Query the output of the current WeightToFee given some input", + params: [ + { + name: "weight", + type: "Weight" + } + ], + type: "Balance" + } +}; + +export function getRuntimeDefs(): DefinitionsCall { + return { + TransactionPaymentApi: [ + { + // V4 is equivalent to V3 (V4 just dropped all V1 references) + methods: objectSpread( + {}, + V3_SHARED_PAY_CALL, + V2_TO_V4_SHARED_PAY, + V1_TO_V4_SHARED_PAY + ), + version: 4 + }, + { + methods: objectSpread( + {}, + V3_SHARED_PAY_CALL, + V2_TO_V4_SHARED_PAY, + V1_TO_V4_SHARED_PAY + ), + version: 3 + }, + ] + }; +} diff --git a/src/interfaces/definitions.ts b/src/interfaces/definitions.ts index f14f7b124..33a3b92aa 100644 --- a/src/interfaces/definitions.ts +++ b/src/interfaces/definitions.ts @@ -3,31 +3,6 @@ export default { types: definitions.types[0].types, rpc: parseProviderRpcDefinitions(definitions.rpc), providerRpc: definitions.rpc, - // manual definition for transactionPaymentApi.queryInfo until polkadot-js/api can be upgraded - // TODO: revert when this work is merged: https://github.com/interlay/interbtc-api/pull/672 - runtime: { - TransactionPaymentApi: [ - { - methods: { - queryInfo: { - description: 'Retrieves the fee information for an encoded extrinsic', - params: [ - { - name: 'uxt', - type: 'Extrinsic' - }, - { - name: 'len', - type: 'u32' - } - ], - type: 'RuntimeDispatchInfo' - } - }, - version: 4 - } - ] - } }; function parseProviderRpcDefinitions( diff --git a/test/integration/parachain/staging/system.test.ts b/test/integration/parachain/staging/system.test.ts index 2e85b3c37..bb3994382 100644 --- a/test/integration/parachain/staging/system.test.ts +++ b/test/integration/parachain/staging/system.test.ts @@ -38,4 +38,13 @@ describe("systemAPI", () => { assert.isAtLeast(futureBlockNumber, currentBlockNumber + 9); assert.isAtMost(futureBlockNumber, currentBlockNumber + 11); }); + + it("should get paymentInfo", async () => { + const tx = api.tx.system.remark(""); + assert.isTrue(tx.hasPaymentInfo); + await assert.isFulfilled( + tx.paymentInfo(sudoAccount), + "Expected payment info for extrinsic" + ); + }); });