hacking
This commit is contained in:
@@ -1 +1 @@
|
||||
{"42":"0x205fe1b3dac678b594c5f0535e7d158e38591f93","100":"0xa7fc9b1f678c41396b53904f94f50a42ff44d826"}
|
||||
{"42":"0x205fe1b3dac678b594c5f0535e7d158e38591f93","100":"0x6ebe4c6a39216e37f5efafd9ce89e2bed293270e"}
|
||||
@@ -1 +1 @@
|
||||
{"42":"0x9fd66ee78a5ebe86006f12b37ff59c63f9caa15b","100":"0x95d3bd7d136bb0b7ac9988097e964236f8a9976e"}
|
||||
{"42":"0x9fd66ee78a5ebe86006f12b37ff59c63f9caa15b","100":"0x38062ac7ac5f910471ce490eabf0af1c4ac92c5f"}
|
||||
@@ -1 +1 @@
|
||||
{"42":"0xc270e6ea4fe303df9f1a3d4a132ac425264082e7","100":"0x513f8e80a8fbb9fa188320ecf231efcf2f6da9c5"}
|
||||
{"42":"0xc270e6ea4fe303df9f1a3d4a132ac425264082e7","100":"0x2cf47d9c33590ade7261bba063082e5ee1469911"}
|
||||
@@ -1 +1 @@
|
||||
{"42":"0xf71ccf7ab48044ef9ae0b5e6983dbd3266b78b36","100":"0x3fc29fbe40c2d0ca78c7e81342f00226650fe2ad"}
|
||||
{"42":"0xf71ccf7ab48044ef9ae0b5e6983dbd3266b78b36","100":"0x98547fe20531018a2fd5e4a70be11c4ecbeb0520"}
|
||||
@@ -3,6 +3,10 @@ class Base {
|
||||
this.contract = contract;
|
||||
}
|
||||
|
||||
get address() {
|
||||
return this.contract.address;
|
||||
}
|
||||
|
||||
get functions() {
|
||||
return this.contract.functions;
|
||||
}
|
||||
|
||||
@@ -42,13 +42,14 @@ class Contributor extends Base {
|
||||
.add(json)
|
||||
.then((ipfsHashAttr) => {
|
||||
let contributor = [
|
||||
contributorAttr.address,
|
||||
contributorAttr.account,
|
||||
ipfsHashAttr.hashDigest,
|
||||
ipfsHashAttr.hashFunction,
|
||||
ipfsHashAttr.hashSize,
|
||||
contributorAttr.isCore,
|
||||
];
|
||||
|
||||
console.log(contributor);
|
||||
return this.functions.addContributor(...contributor);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
module.exports = {
|
||||
Contributors: require('./contributor'),
|
||||
Operator: require('./operator'),
|
||||
Token: require('./token')
|
||||
Token: require('./token'),
|
||||
Registry: require('./registry')
|
||||
}
|
||||
|
||||
8
lib/contracts/registry.js
Normal file
8
lib/contracts/registry.js
Normal file
@@ -0,0 +1,8 @@
|
||||
const Base = require('./base');
|
||||
|
||||
class Registry extends Base {
|
||||
}
|
||||
|
||||
module.exports = Registry;
|
||||
|
||||
|
||||
24
lib/healthcheck.js
Normal file
24
lib/healthcheck.js
Normal file
@@ -0,0 +1,24 @@
|
||||
class Healthcheck {
|
||||
constructor(kredits) {
|
||||
this.kredits = kredits;
|
||||
}
|
||||
|
||||
check() {
|
||||
return this.kredits.ipfs._ipfsAPI.id()
|
||||
.catch((error) => {
|
||||
throw new Error(`IPFS node not available; config: ${JSON.stringify(this.kredits.ipfs.config)} - ${error.message}`);
|
||||
})
|
||||
.then(() => {
|
||||
return Object.keys(this.kredits.contracts).map((name) => {
|
||||
let contract = this.kredits.contracts[name];
|
||||
this.kredits.provider.getCode(contract.address).then((code) => {
|
||||
// not sure if we always get the same return value of the code is not available
|
||||
// that's why checking if it is < 5 long
|
||||
if (code === '0x00' || code.length < 5) {
|
||||
throw new Error(`Registry not found at ${contract.address} on network ${this.kredits.provider.chainId}`);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,13 @@
|
||||
const ethers = require('ethers');
|
||||
const RSVP = require('rsvp');
|
||||
|
||||
const abis = {
|
||||
const ABIs = {
|
||||
Contributors: require('./abis/Contributors.json'),
|
||||
Operator: require('./abis/Operator.json'),
|
||||
Registry: require('./abis/Registry.json'),
|
||||
Token: require('./abis/Token.json')
|
||||
};
|
||||
const addresses = {
|
||||
const ADDRESSES = {
|
||||
Registry: require('./addresses/Registry.json')
|
||||
};
|
||||
|
||||
@@ -22,7 +22,7 @@ function capitalize(word) {
|
||||
|
||||
class Kredits {
|
||||
static get contractNames() {
|
||||
return Object.keys(abis);
|
||||
return Object.keys(ABIs);
|
||||
}
|
||||
|
||||
constructor(provider, signer, addresses) {
|
||||
@@ -30,11 +30,26 @@ class Kredits {
|
||||
this.signer = signer;
|
||||
|
||||
// Initialize our registry contract
|
||||
this.addresses = addresses;
|
||||
this.addresses = addresses || ADDRESSES[this.provider.chainId];
|
||||
this.abis = ABIs;
|
||||
this.contracts = {};
|
||||
this.ipfs = new IPFS();
|
||||
}
|
||||
|
||||
init(names) {
|
||||
let contractsToLoad = names || Kredits.contractNames;
|
||||
let addressPromises = contractsToLoad.map((contractName) => {
|
||||
return this.Registry.functions.getProxyFor(contractName).then((address) => {
|
||||
this.addresses[contractName] = address;
|
||||
}).catch((error) => {
|
||||
throw new Error(`Failed to get address for ${contractName} from registry at ${this.Registry.address}
|
||||
- correct registry? does it have version entry? - ${error.message}`
|
||||
);
|
||||
});
|
||||
});
|
||||
return RSVP.all(addressPromises).then(() => { return this });
|
||||
}
|
||||
|
||||
static setup(provider, signer, ipfsConfig = null) {
|
||||
let ipfsAPI = new IPFS(ipfsConfig);
|
||||
|
||||
@@ -64,11 +79,11 @@ class Kredits {
|
||||
}
|
||||
|
||||
static initRegistryContract(provider) {
|
||||
let address = addresses['Registry'][provider.chainId];
|
||||
let address = ADDRESSES['Registry'][provider.chainId];
|
||||
if (!address) {
|
||||
throw new Error(`Registry address not found; invalid network?
|
||||
requested network: ${provider.chainId}
|
||||
supported networks: ${Object.keys(addresses['Registry'])}
|
||||
supported networks: ${Object.keys(ADDRESSES['Registry'])}
|
||||
`);
|
||||
}
|
||||
provider.getCode(address).then((code) => {
|
||||
@@ -78,10 +93,14 @@ class Kredits {
|
||||
throw new Error(`Registry not found at ${address} on network ${provider.chainId}`);
|
||||
}
|
||||
});
|
||||
let abi = abis['Registry'];
|
||||
let abi = ABIs['Registry'];
|
||||
return new ethers.Contract(address, abi, provider);
|
||||
}
|
||||
|
||||
get Registry() {
|
||||
return this.contractFor('registry');
|
||||
}
|
||||
|
||||
get Contributor() {
|
||||
// TODO: rename to contributor
|
||||
return this.contractFor('contributors');
|
||||
@@ -103,10 +122,11 @@ class Kredits {
|
||||
|
||||
let contractName = capitalize(name);
|
||||
let address = this.addresses[contractName];
|
||||
if (!address || !abis[contractName]) {
|
||||
let abi = this.abis[contractName];
|
||||
if (!address || !abi) {
|
||||
throw new Error(`Address or ABI not found for ${contractName}`);
|
||||
}
|
||||
let contract = new ethers.Contract(address, abis[contractName], this.signer);
|
||||
let contract = new ethers.Contract(address, abi, this.signer);
|
||||
this.contracts[name] = new contracts[contractName](contract);
|
||||
this.contracts[name].ipfs = this.ipfs;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user