* Create api-contract (baseline for useful interactions) * Add CHANGELOG entry (breaking)
30 lines
858 B
TypeScript
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);
|
|
});
|
|
}
|
|
}
|