Add has{DryRun, PaymentInfo} to submittables (#5331)

This commit is contained in:
Jaco
2022-11-12 08:03:31 +02:00
committed by GitHub
parent b2f67ffae1
commit b90a1e388f
3 changed files with 16 additions and 2 deletions
+1
View File
@@ -9,6 +9,7 @@ Contributed:
Changes:
- Cater for `TransactionPaymentApi/2` runtime calls
- Add getters for `has{DryRun, PaymentInfo}` on submittables (feature detection)
## 9.7.1 Nov 6, 2022
@@ -50,6 +50,11 @@ export interface SubmittableResultValue {
}
export interface SubmittableExtrinsic<ApiType extends ApiTypes, R extends ISubmittableResult = ISubmittableResult> extends Extrinsic {
/** true if api.rpc.system.dryRun is available, enabling dryRun(...) */
hasDryRun: boolean;
/** true if api.call.transactionPaymentApi.queryInfo is available, enabling paymentInfo(...) */
hasPaymentInfo: boolean;
dryRun (account: AddressOrPair, options?: Partial<SignerOptions>): SubmittableDryRunResult<ApiType>;
paymentInfo (account: AddressOrPair, options?: Partial<SignerOptions>): SubmittablePaymentResult<ApiType>;
+10 -2
View File
@@ -100,9 +100,17 @@ export function createClass <ApiType extends ApiTypes> ({ api, apiType, blockHas
this.#ignoreStatusCb = apiType === 'rxjs';
}
public get hasDryRun (): boolean {
return isFunction(api.rpc.system?.dryRun);
}
public get hasPaymentInfo (): boolean {
return isFunction(api.call.transactionPaymentApi?.queryInfo);
}
// dry run an extrinsic
public dryRun (account: AddressOrPair, optionsOrHash?: Partial<SignerOptions> | Uint8Array | string): SubmittableDryRunResult<ApiType> {
if (!api.rpc.system?.dryRun) {
if (!this.hasDryRun) {
throw new Error('The system.dryRun RPC call is not available in your environment');
}
@@ -124,7 +132,7 @@ export function createClass <ApiType extends ApiTypes> ({ api, apiType, blockHas
// calculate the payment info for this transaction (if signed and submitted)
public paymentInfo (account: AddressOrPair, optionsOrHash?: Partial<SignerOptions> | Uint8Array | string): SubmittablePaymentResult<ApiType> {
if (!api.call.transactionPaymentApi?.queryInfo) {
if (!this.hasPaymentInfo) {
throw new Error('The transactionPaymentApi.queryInfo runtime call is not available in your environment');
}