Files
api/packages/api-contract/src/Abi.ts
T
Jaco Greeff 4cba24c134 Create api-contract (baseline for useful interactions) (#1007)
* Create api-contract (baseline for useful interactions)

* Add CHANGELOG entry (breaking)
2019-06-14 13:48:53 +02:00

30 lines
858 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 } 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);
});
}
}