Create api-contract (baseline for useful interactions) (#1007)

* Create api-contract (baseline for useful interactions)

* Add CHANGELOG entry (breaking)
This commit is contained in:
Jaco Greeff
2019-06-14 13:48:53 +02:00
committed by GitHub
parent 6e7a126f4d
commit 4cba24c134
25 changed files with 614 additions and 312 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 { ContractABI, ContractABIFn } from './types';
import { stringCamelCase } from '@polkadot/util';
import { createMethod } from './method';
import { validateAbi } from './validation';
export default class ContractAbi {
readonly abi: ContractABI;
readonly deploy: ContractABIFn;
readonly messages: { [index: string]: ContractABIFn } = {};
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);
});
}
}