@decent-bet/solido
Version:
Code first contract entity mapper for Solidity based blockchains like Ethereum, Vechain, Tron
38 lines (37 loc) • 1.79 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const TopicSignature_1 = require("./TopicSignature");
const decorators_1 = require("../decorators");
class SolidoProvider {
buildDynamicStubs() {
if (this.abi.length > 0) {
const contract = this;
this.methods = {};
this.events = {};
this.abi.forEach(definition => {
if (definition.type === 'function' && (definition.stateMutability === 'view' ||
definition.constant)) {
this.methods = Object.assign({}, this.methods, { [definition.name]: (...req) => decorators_1._Read(definition.name, contract, req, {}) });
}
if (definition.type === 'function' && (definition.stateMutability === 'nonpayable' ||
!definition.constant)) {
this.methods = Object.assign({}, this.methods, { [definition.name]: (...req) => decorators_1._Write(definition.name, contract, req, {}) });
}
if (definition.type === 'event') {
this.events = Object.assign({}, this.events, { [definition.name]: () => decorators_1._GetEvent(definition.name, contract) });
}
});
}
}
setContractImport(contractImport) {
this.abi = contractImport.raw.abi;
this.contractImport = contractImport;
this.abi.forEach(definition => {
if (definition.type === 'event' && definition.signature) {
const topic = new TopicSignature_1.TopicSignature(definition.signature);
this.topics = Object.assign({}, this.topics, { [definition.name]: topic });
}
});
}
}
exports.SolidoProvider = SolidoProvider;