More ergonomic contracts interfaces (RxJs only initial) (#1015)
* More ergnomic contracts interfaces
* extend SubmittableResult
* Allow creation of contract from blueprint
* "decorate" Contract (just playing with interfaces)
* Make actual messages calls
* Rename to Rx{Blueprint, Cond, Contract}
* Add exports
* Support contract & contracts endpoints
* Remove unneeded ApiType generics (may return)
* Comment 2.x/1.x detection
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
// Copyright 2017-2019 @polkadot/api-contract authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { SubmittableModuleExtrinsics } from '@polkadot/api/types';
|
||||
import { ApiObject, ContractABI, IContractBase } from './types';
|
||||
|
||||
import { assert } from '@polkadot/util';
|
||||
|
||||
import Abi from './Abi';
|
||||
|
||||
// NOTE Experimental, POC, bound to change
|
||||
export default abstract class RxBase implements IContractBase<'rxjs'> {
|
||||
readonly abi: Abi;
|
||||
readonly api: ApiObject<'rxjs'>;
|
||||
readonly apiContracts: SubmittableModuleExtrinsics<'rxjs'>;
|
||||
|
||||
constructor (api: ApiObject<'rxjs'>, abi: ContractABI | Abi) {
|
||||
this.abi = abi instanceof Abi
|
||||
? abi
|
||||
: new Abi(abi);
|
||||
this.api = api;
|
||||
|
||||
// cater for substrate 2.x & 1.x (in order)
|
||||
this.apiContracts = api.tx.contracts || api.tx.contract;
|
||||
|
||||
assert(this.apiContracts && this.apiContracts.putCode, `You need to connect to a node with the contracts module, the metadata does not enable api.tx.contracts on this instance`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user