Files
api/packages/api-contract/src/Abi.ts
T
Jaco Greeff f30c516099 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
2019-06-21 16:48:00 +02:00

30 lines
874 B
TypeScript

// 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 { ContractABI, ContractABIFn, IAbi, IAbi$Messages } from './types';
import { stringCamelCase } from '@polkadot/util';
import { createMethod } from './method';
import { validateAbi } from './validation';
export default class ContractAbi implements IAbi {
readonly abi: ContractABI;
readonly deploy: ContractABIFn;
readonly messages: IAbi$Messages = {};
constructor (abi: ContractABI) {
validateAbi(abi);
this.abi = abi;
this.deploy = createMethod('deploy', abi.deploy);
abi.messages.forEach((method) => {
const name = stringCamelCase(method.name);
this.messages[name] = createMethod(`messages.${name}`, method);
});
}
}