Skip to content

Commit

Permalink
Add transaction-payment runtime API V3 (#5430)
Browse files Browse the repository at this point in the history
* Add transaction-payment runtime API V3

* Apply suggestions from code review

* Update packages/types/src/interfaces/payment/runtime.ts

* Update packages/types/src/interfaces/payment/runtime.ts

* Apply suggestions from code review

* Handle query_info vs query_call_info correctly

Co-authored-by: Jaco <jacogr@gmail.com>
  • Loading branch information
notlesh and jacogr authored Jan 27, 2023
1 parent 932efb6 commit cc4e4b2
Showing 1 changed file with 94 additions and 36 deletions.
130 changes: 94 additions & 36 deletions packages/types/src/interfaces/payment/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { DefinitionCall, DefinitionsCall } from '../../types';

import { objectSpread } from '@polkadot/util';

const V1_V2_SHARED_PAY: Record<string, DefinitionCall> = {
const V1_V2_V3_SHARED_PAY: Record<string, DefinitionCall> = {
query_fee_details: {
description: 'The transaction fee details',
params: [
Expand All @@ -22,7 +22,7 @@ const V1_V2_SHARED_PAY: Record<string, DefinitionCall> = {
}
};

const V1_V2_SHARED_CALL: Record<string, DefinitionCall> = {
const V1_V2_V3_SHARED_CALL: Record<string, DefinitionCall> = {
query_call_fee_details: {
description: 'The call fee details',
params: [
Expand All @@ -39,25 +39,84 @@ const V1_V2_SHARED_CALL: Record<string, DefinitionCall> = {
}
};

const V2_V3_SHARED_QUERY_INFO: Record<string, DefinitionCall> = {
query_info: {
description: 'The call info',
params: [
{
name: 'call',
type: 'Call'
},
{
name: 'len',
type: 'u32'
}
],
type: 'RuntimeDispatchInfo'
}
};

const V2_V3_SHARED_QUERY_CALL_INFO: Record<string, DefinitionCall> = {
query_call_info: {
description: 'The call info',
params: [
{
name: 'call',
type: 'Call'
},
{
name: 'len',
type: 'u32'
}
],
type: 'RuntimeDispatchInfo'
}
};

const V3_QUERY_WEIGHT_TO_FEE: Record<string, DefinitionCall> = {
query_weight_to_fee: {
description: 'Query the output of the current WeightToFee given some input',
params: [
{
name: 'weight',
type: 'Weight'
}
],
type: 'Balance'
}
};

const V3_QUERY_LENGTH_TO_FEE: 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'
}
};

export const runtime: DefinitionsCall = {
TransactionPaymentApi: [
{
methods: objectSpread({
query_info: {
description: 'The transaction info',
params: [
{
name: 'uxt',
type: 'Extrinsic'
},
{
name: 'len',
type: 'u32'
}
],
type: 'RuntimeDispatchInfo'
}
}, V1_V2_SHARED_PAY),
methods: objectSpread(
{},
V3_QUERY_WEIGHT_TO_FEE,
V3_QUERY_LENGTH_TO_FEE,
V2_V3_SHARED_QUERY_INFO,
V1_V2_V3_SHARED_PAY
),
version: 3
},
{
methods: objectSpread(
{},
V2_V3_SHARED_QUERY_INFO,
V1_V2_V3_SHARED_PAY
),
version: 2
},
{
Expand All @@ -80,28 +139,27 @@ export const runtime: DefinitionsCall = {
// type: 'RuntimeDispatchInfoV1'
type: 'RuntimeDispatchInfo'
}
}, V1_V2_SHARED_PAY),
}, V1_V2_V3_SHARED_PAY),
version: 1
}
],
TransactionPaymentCallApi: [
{
methods: objectSpread({
query_call_info: {
description: 'The call info',
params: [
{
name: 'call',
type: 'Call'
},
{
name: 'len',
type: 'u32'
}
],
type: 'RuntimeDispatchInfo'
}
}, V1_V2_SHARED_CALL),
methods: objectSpread(
{},
V3_QUERY_WEIGHT_TO_FEE,
V3_QUERY_LENGTH_TO_FEE,
V2_V3_SHARED_QUERY_CALL_INFO,
V1_V2_V3_SHARED_CALL
),
version: 3
},
{
methods: objectSpread(
{},
V2_V3_SHARED_QUERY_CALL_INFO,
V1_V2_V3_SHARED_CALL
),
version: 2
},
{
Expand All @@ -122,7 +180,7 @@ export const runtime: DefinitionsCall = {
// _may_ yield fallback decoding on some versions of the runtime
type: 'RuntimeDispatchInfo'
}
}, V1_V2_SHARED_CALL),
}, V1_V2_V3_SHARED_CALL),
version: 1
}
]
Expand Down

0 comments on commit cc4e4b2

Please sign in to comment.