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:
Jaco Greeff
2019-06-21 16:48:00 +02:00
committed by GitHub
parent 5e5bb9984b
commit f30c516099
10 changed files with 288 additions and 45 deletions
+29
View File
@@ -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`);
}
}