Adjust API for new ethers v5 API

see issue for details: https://github.com/ethers-io/ethers.js/issues/920#issuecomment-650836642
This commit is contained in:
2020-06-29 17:23:08 +02:00
parent bc38dcb136
commit 23d3dd3a80
18 changed files with 209 additions and 36 deletions

View File

@@ -5,7 +5,7 @@ class Acl extends Base {
hasPermission (fromAddress, contractAddress, roleID, params = null) {
let roleHash = EthersUtils.keccak256(EthersUtils.toUtf8Bytes(roleID));
return this.functions.hasPermission(
return this.hasPermission(
fromAddress,
contractAddress,
roleHash,

View File

@@ -1,10 +1,13 @@
const deprecate = require('../utils/deprecate');
class Base {
constructor (contract) {
this.contract = contract;
}
get functions () {
return this.contract.functions;
deprecate('The property `functions` is deprecated. contract functions are now directly defined on the ethers contract object. https://github.com/ethers-io/ethers.js/issues/920#issuecomment-650836642');
return this.contract;
}
get address () {

View File

@@ -4,33 +4,33 @@ const deprecate = require('../utils/deprecate');
class Contribution extends Record {
get count () {
return this.functions.contributionsCount();
return this.contract.contributionsCount();
}
getById (id) {
return this.functions.getContribution(id)
return this.contract.getContribution(id)
.then(data => {
return this.ipfs.catAndMerge(data, ContributionSerializer.deserialize);
});
}
getData (id) {
return this.functions.getContribution(id);
return this.contract.getContribution(id);
}
getByContributorId (contributorId) {
return this.functions.getContributorAddressById(contributorId)
return this.contract.getContributorAddressById(contributorId)
.then(address => this.getByContributorAddress(address));
}
getByContributorAddress (address) {
return this.functions.balanceOf(address)
return this.contract.balanceOf(address)
.then(async (balance) => {
const count = balance.toNumber();
const contributions = [];
for (let index = 0; index < count; index++) {
const id = await this.functions.tokenOfOwnerByIndex(address, index);
const id = await this.contract.tokenOfOwnerByIndex(address, index);
const contribution = await this.getById(id);
contributions.push(contribution);
}
@@ -58,7 +58,7 @@ class Contribution extends Record {
ipfsHashAttr.hashSize,
];
return this.functions.add(...contribution, callOptions);
return this.contract.add(...contribution, callOptions);
});
}

View File

@@ -4,11 +4,11 @@ const formatKredits = require('../utils/format-kredits');
class Contributor extends Record {
get count () {
return this.functions.contributorsCount();
return this.contract.contributorsCount();
}
getById (id) {
return this.functions.getContributorById(id)
return this.contract.getContributorById(id)
.then(contractData => {
let data = {...contractData};
data.balanceInt = formatKredits(data.balance);
@@ -17,7 +17,7 @@ class Contributor extends Record {
}
getData (id) {
return this.functions.getContributorById(id);
return this.contract.getContributorById(id);
}
filterByAccount (search) {
@@ -62,7 +62,7 @@ class Contributor extends Record {
ipfsHashAttr.hashSize,
];
return this.functions.addContributor(...contributor, callOptions);
return this.contract.addContributor(...contributor, callOptions);
});
}
@@ -79,7 +79,7 @@ class Contributor extends Record {
return this.ipfs
.add(jsonStr)
.then(ipfsHashAttr => {
return this.functions.updateContributorProfileHash(
return this.contract.updateContributorProfileHash(
contributorId,
ipfsHashAttr.hashDigest,
ipfsHashAttr.hashFunction,

View File

@@ -11,9 +11,9 @@ class Kernel extends Base {
getApp (appName) {
if (appName === 'Acl') {
return this.functions.acl();
return this.contract.acl();
}
return this.functions.getApp(KERNEL_APP_ADDR_NAMESPACE, this.appNamehash(appName));
return this.contract.getApp(KERNEL_APP_ADDR_NAMESPACE, this.appNamehash(appName));
}
appNamehash (appName) {

View File

@@ -4,11 +4,11 @@ const deprecate = require('../utils/deprecate');
class Proposal extends Record {
get count () {
return this.functions.proposalsCount();
return this.contract.proposalsCount();
}
getById (id) {
return this.functions.getProposal(id)
return this.contract.getProposal(id)
.then(data => {
return this.ipfs.catAndMerge(data, ContributionSerializer.deserialize);
});
@@ -33,7 +33,7 @@ class Proposal extends Record {
ipfsHashAttr.hashSize,
];
return this.functions.addProposal(...proposal, callOptions);
return this.contract.addProposal(...proposal, callOptions);
});
}