Create api-contract (baseline for useful interactions) (#1007)
* Create api-contract (baseline for useful interactions) * Add CHANGELOG entry (breaking)
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 { 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);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user