Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: query payment info #676

Merged
merged 1 commit into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
);
});
});