Skip to content

Commit

Permalink
Merge pull request #676 from interlay/fix/payment-info
Browse files Browse the repository at this point in the history
fix: query payment info
  • Loading branch information
gregdhill authored Aug 15, 2023
2 parents 3a85386 + d699bfd commit 6262ea7
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 30 deletions.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -122,4 +122,4 @@
],
"recursive": true
}
}
}
90 changes: 88 additions & 2 deletions src/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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(),
});
}

Expand All @@ -61,3 +64,86 @@ export function createAPIRegistry(): TypeRegistry {
registry.register(getAPITypes());
return registry;
}

const V1_TO_V4_SHARED_PAY: Record<string, DefinitionCall> = {
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<string, DefinitionCall> = {
query_info: {
description: "The transaction info",
params: [
{
name: "uxt",
type: "Extrinsic"
},
{
name: "len",
type: "u32"
}
],
type: "RuntimeDispatchInfo"
}
};

const V3_SHARED_PAY_CALL: Record<string, DefinitionCall> = {
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
},
]
};
}
25 changes: 0 additions & 25 deletions src/interfaces/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
9 changes: 9 additions & 0 deletions test/integration/parachain/staging/system.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
);
});
});

0 comments on commit 6262ea7

Please sign in to comment.