Adjust exec with SubmittableExtrinsic (#2701)
* Adjust exec with SubmittableExtrinsic * inputData
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
// Copyright 2017-2020 @polkadot/api authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { ApiTypes, DecorateMethod, SubmittableModuleExtrinsics } from '@polkadot/api/types';
|
||||
import { ApiTypes, DecorateMethod } from '@polkadot/api/types';
|
||||
import { AnyJson, Registry } from '@polkadot/types/types';
|
||||
import { ApiObject } from '../types';
|
||||
|
||||
@@ -27,8 +27,4 @@ export default abstract class Base<ApiType extends ApiTypes> {
|
||||
|
||||
assert(this.api.rx.tx.contracts && this.api.rx.tx.contracts.putCode, 'You need to connect to a node with the contracts module, the metadata does not enable api.tx.contracts on this instance');
|
||||
}
|
||||
|
||||
protected get _apiContracts (): SubmittableModuleExtrinsics<'rxjs'> {
|
||||
return this.api.rx.tx.contracts;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { ApiTypes, DecorateMethod } from '@polkadot/api/types';
|
||||
import { ApiTypes, DecorateMethod, SignerOptions } from '@polkadot/api/types';
|
||||
import { AccountId, EventRecord, Hash } from '@polkadot/types/interfaces';
|
||||
import { AnyJson, IKeyringPair, ISubmittableResult } from '@polkadot/types/types';
|
||||
import { ApiObject } from '../types';
|
||||
@@ -21,7 +21,7 @@ import { applyOnEvent } from './util';
|
||||
type BlueprintCreateResultSubscription<ApiType extends ApiTypes> = Observable<BlueprintCreateResult<ApiType>>;
|
||||
|
||||
export interface BlueprintCreate<ApiType extends ApiTypes> {
|
||||
signAndSend (account: IKeyringPair | string | AccountId): BlueprintCreateResultSubscription<ApiType>;
|
||||
signAndSend (account: IKeyringPair | string | AccountId, options?: SignerOptions): BlueprintCreateResultSubscription<ApiType>;
|
||||
}
|
||||
|
||||
class BlueprintCreateResult<ApiType extends ApiTypes> extends SubmittableResult {
|
||||
@@ -50,10 +50,10 @@ export default class Blueprint<ApiType extends ApiTypes> extends Base<ApiType> {
|
||||
return {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
signAndSend: this._decorateMethod(
|
||||
(account: IKeyringPair | string | AccountId): BlueprintCreateResultSubscription<ApiType> =>
|
||||
this._apiContracts
|
||||
(account: IKeyringPair | string | AccountId, options?: SignerOptions): BlueprintCreateResultSubscription<ApiType> =>
|
||||
this.api.rx.tx.contracts
|
||||
.create(endowment, maxGas, this.codeHash, this.abi.constructors[constructorIndex](...params))
|
||||
.signAndSend(account)
|
||||
.signAndSend(account, options)
|
||||
.pipe(
|
||||
map((result) =>
|
||||
new BlueprintCreateResult(result, applyOnEvent(result, 'Instantiated', (record: EventRecord) =>
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { ApiTypes, DecorateMethod } from '@polkadot/api/types';
|
||||
import { ApiTypes, DecorateMethod, SignerOptions } from '@polkadot/api/types';
|
||||
import { AccountId, Address, EventRecord, Hash } from '@polkadot/types/interfaces';
|
||||
import { AnyJson, IKeyringPair, ISubmittableResult } from '@polkadot/types/types';
|
||||
import { ApiObject } from '../types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { SubmittableResult } from '@polkadot/api';
|
||||
@@ -21,7 +20,7 @@ import { applyOnEvent } from './util';
|
||||
type CodePutCodeResultSubscription<ApiType extends ApiTypes> = Observable<CodePutCodeResult<ApiType>>;
|
||||
|
||||
export interface CodePutCode<ApiType extends ApiTypes> {
|
||||
signAndSend (account: IKeyringPair | string | AccountId | Address): CodePutCodeResultSubscription<ApiType>;
|
||||
signAndSend (account: IKeyringPair | string | AccountId | Address, options?: SignerOptions): CodePutCodeResultSubscription<ApiType>;
|
||||
}
|
||||
|
||||
class CodePutCodeResult<ApiType extends ApiTypes> extends SubmittableResult {
|
||||
@@ -44,14 +43,14 @@ export default class Code<ApiType extends ApiTypes> extends Base<ApiType> {
|
||||
this.code = u8aToU8a(wasm);
|
||||
}
|
||||
|
||||
public createBlueprint = (maxGas: number | BN): CodePutCode<ApiType> => {
|
||||
public createBlueprint = (): CodePutCode<ApiType> => {
|
||||
return {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
signAndSend: this._decorateMethod(
|
||||
(account: IKeyringPair | string | AccountId): CodePutCodeResultSubscription<ApiType> =>
|
||||
this._apiContracts
|
||||
.putCode(maxGas, compactAddLength(this.code))
|
||||
.signAndSend(account)
|
||||
(account: IKeyringPair | string | AccountId, options?: SignerOptions): CodePutCodeResultSubscription<ApiType> =>
|
||||
this.api.rx.tx.contracts
|
||||
.putCode(compactAddLength(this.code))
|
||||
.signAndSend(account, options)
|
||||
.pipe(
|
||||
map((result) =>
|
||||
new CodePutCodeResult(result, applyOnEvent(result, 'CodeStored', (record: EventRecord) =>
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { ApiTypes, DecorateMethod, ObsInnerType } from '@polkadot/api/types';
|
||||
import { SubmittableExtrinsic } from '@polkadot/api/submittable/types';
|
||||
|
||||
import { AccountId, ContractExecResult } from '@polkadot/types/interfaces';
|
||||
import { AnyJson, Codec, CodecArg, IKeyringPair } from '@polkadot/types/types';
|
||||
import { ApiObject, AbiMessage, ContractCallOutcome } from '../types';
|
||||
@@ -15,7 +17,6 @@ import { assert, isFunction, isNumber } from '@polkadot/util';
|
||||
import Abi from '../Abi';
|
||||
import { formatData } from '../util';
|
||||
import Base from './Base';
|
||||
import { SignerOptions } from '@polkadot/api/submittable/types';
|
||||
|
||||
type ContractCallTypes = 'tx' | 'rpc';
|
||||
|
||||
@@ -25,10 +26,6 @@ type ContractCallResultSubscription<ApiType extends ApiTypes, CallType extends C
|
||||
// eslint-disable-next-line no-use-before-define
|
||||
: Promise<ObsInnerType<ContractCallResult<CallType>>>;
|
||||
|
||||
export interface ContractExec<ApiType extends ApiTypes> {
|
||||
signAndSend (account: IKeyringPair | string | AccountId, options?: Partial<SignerOptions>): ContractCallResultSubscription<ApiType, 'tx'>;
|
||||
}
|
||||
|
||||
export interface ContractRead<ApiType extends ApiTypes> {
|
||||
send (account: IKeyringPair | string | AccountId): ContractCallResultSubscription<ApiType, 'rpc'>;
|
||||
}
|
||||
@@ -60,17 +57,12 @@ export default class Contract<ApiType extends ApiTypes> extends Base<ApiType> {
|
||||
return [fn(...params), fn];
|
||||
}
|
||||
|
||||
public exec = (message: AbiMessage | number, value: BN | string | number, gasLimit: BN | string | number, ...params: CodecArg[]): ContractExec<ApiType> => {
|
||||
public exec = (message: AbiMessage | number, value: BN | string | number, gasLimit: BN | string | number, ...params: CodecArg[]): SubmittableExtrinsic<ApiType> => {
|
||||
const [inputData] = this._createInput(message, params);
|
||||
|
||||
return {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
signAndSend: this._decorateMethod((account: IKeyringPair | string | AccountId, options?: Partial<SignerOptions>): ContractCallResult<'tx'> =>
|
||||
this._apiContracts
|
||||
.call(this.address, value, gasLimit, inputData)
|
||||
.signAndSend(account, options)
|
||||
)
|
||||
};
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore I give up
|
||||
return this.api.tx.contracts.call(this.address, value, gasLimit, inputData);
|
||||
}
|
||||
|
||||
public read = (message: AbiMessage | number, value: BN | string | number, gasLimit: BN | string | number, ...params: CodecArg[]): ContractRead<ApiType> => {
|
||||
|
||||
Reference in New Issue
Block a user