From cc4e4b236d9ab79972f2ee8e45416148c1fe37d0 Mon Sep 17 00:00:00 2001 From: Stephen Shelton Date: Thu, 26 Jan 2023 21:43:02 -0700 Subject: [PATCH] Add transaction-payment runtime API V3 (#5430) * 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 --- .../types/src/interfaces/payment/runtime.ts | 130 +++++++++++++----- 1 file changed, 94 insertions(+), 36 deletions(-) diff --git a/packages/types/src/interfaces/payment/runtime.ts b/packages/types/src/interfaces/payment/runtime.ts index d1331f8dd2..e3afc296ec 100644 --- a/packages/types/src/interfaces/payment/runtime.ts +++ b/packages/types/src/interfaces/payment/runtime.ts @@ -5,7 +5,7 @@ import type { DefinitionCall, DefinitionsCall } from '../../types'; import { objectSpread } from '@polkadot/util'; -const V1_V2_SHARED_PAY: Record = { +const V1_V2_V3_SHARED_PAY: Record = { query_fee_details: { description: 'The transaction fee details', params: [ @@ -22,7 +22,7 @@ const V1_V2_SHARED_PAY: Record = { } }; -const V1_V2_SHARED_CALL: Record = { +const V1_V2_V3_SHARED_CALL: Record = { query_call_fee_details: { description: 'The call fee details', params: [ @@ -39,25 +39,84 @@ const V1_V2_SHARED_CALL: Record = { } }; +const V2_V3_SHARED_QUERY_INFO: Record = { + 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 = { + 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 = { + 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 = { + 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 }, { @@ -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 }, { @@ -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 } ]