diff --git a/config/seeds.js b/config/seeds.js new file mode 100644 index 0000000..c975e75 --- /dev/null +++ b/config/seeds.js @@ -0,0 +1,63 @@ +let contractCalls = { + Operator: { + addContributor: [ + // make sure to use an IPFS hash of one of the objects in ipfsContent + ['0x24dd2aedd8a9fe52ac071b3a23b2fc8f225c185e', '0x272bbfc66166f26cae9c9b96b7f9590e095f02edf342ac2dd71e1667a12116ca', 18, 32, true], // QmQyZJT9uikzDYTZLhhyVZ5ReZVCoMucYzyvDokDJsijhj + ['0xa502eb4021f3b9ab62f75b57a94e1cfbf81fd827', '0x9569ed44826286597982e40bbdff919c6b7752e29d13250efca452644e6b4b25', 18, 32, true] // QmYPu8zvtfDy18ZqHCviVxnKtxycw5UTJLJyk9oAEjWfnL + ], + addProposal: [ + [1, 23, 'QmQNA1hhVyL1Vm6HiRxXe9xmc6LUMBDyiNMVgsjThtyevs'], + [2, 42, 'QmQNA1hhVyL1Vm6HiRxXe9xmc6LUMBDyiNMVgsjThtyevs'] + [2, 100, 'QmQNA1hhVyL1Vm6HiRxXe9xmc6LUMBDyiNMVgsjThtyevs'] + ], + vote: [ + [1] + ] + } +}; +let ipfsContent = [ + { + "@context": "https://schema.kosmos.org", + "@type": "Contributor", + "kind": "person", + "name": "Râu Cao", + "url": "https://sebastian.kip.pe", + "accounts": [ + { + "site": "github.com", + "username": "skddc", + "uid": 842, + "url": "https://github.com/skddc/" + }, + ] + }, + { + "@context": "https://schema.kosmos.org", + "@type": "Contributor", + "kind": "person", + "name": "Bumi", + "url": "https://michaelbumann.com", + "accounts": [ + { + "site": "github.com", + "username": "bumi", + "uid": 318, + "url": "https://github.com/bumi/" + }, + ] + }, + { + "@context": "https://schema.kosmos.org", + "@type": "Contribution", + "contributor": { + "ipfs": "QmQ2ZZS2bXgneQfKtVTVxe6dV7pcJuXnTeZJQtoVUFsAtJ" + }, + "kind": "dev", + "description": "hacking hacking on kredits", + "url": "https://github.com/67P/kredits-web/pull/11", + "details": {} + } + +] + +module.exports = { contractCalls, ipfsContent }; diff --git a/package.json b/package.json index eff2b44..afdecf8 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ }, "scripts": { "build-json": "truffle compile && node ./scripts/build-json.js", + "bootstrap": "truffle migrate --reset && truffle exec scripts/seeds.js && npm run build-json", "test": "echo \"Error: no test specified\" && exit 1" }, "repository": { @@ -21,8 +22,9 @@ }, "homepage": "https://github.com/67P/truffle-kredits#readme", "devDependencies": { - "zeppelin-solidity": "^1.7.0", + "ganache-cli": "^6.0.3", + "ipfs-api": "^19.0.0", "truffle": "^4.1.3", - "ganache-cli": "^6.0.3" + "zeppelin-solidity": "^1.7.0" } } diff --git a/scripts/multihash.js b/scripts/multihash.js new file mode 100644 index 0000000..bf59b2f --- /dev/null +++ b/scripts/multihash.js @@ -0,0 +1,35 @@ +var bs58 = require('bs58'); + +function getBytes32FromMultiash(multihash) { + const decoded = bs58.decode(multihash); + + return { + digest: `0x${decoded.slice(2).toString('hex')}`, + hashFunction: decoded[0], + size: decoded[1], + }; +} + + +function getMultihashFromBytes32(multihash) { + const { digest, hashFunction, size } = multihash; + if (size === 0) return null; + + // cut off leading "0x" + const hashBytes = Buffer.from(digest.slice(2), 'hex'); + + // prepend hashFunction and digest size + //const multihashBytes = new (hashBytes.constructor)(2 + hashBytes.length); + const multihashBytes = new Buffer(2 + hashBytes.length); + + console.log(hashBytes.constructor); + + multihashBytes[0] = hashFunction; + multihashBytes[1] = size; + multihashBytes.set(hashBytes, 2); + + return bs58.encode(multihashBytes); +} + +var m = getBytes32FromMultiash(process.argv[2]); +console.log(m) diff --git a/scripts/seeds.js b/scripts/seeds.js new file mode 100644 index 0000000..773519f --- /dev/null +++ b/scripts/seeds.js @@ -0,0 +1,32 @@ +const path = require('path'); +const seeds = require(path.join(__dirname, '..', '/config/seeds.js')); +const IPFS = require('ipfs-api'); + +var ipfs = IPFS({host: 'localhost', port: '5001', protocol: 'http'}) + +module.exports = function(callback) { + const Registry = artifacts.require('./Registry.sol'); + + const contracts = {}; + Registry.deployed().then((registry) => { + Object.keys(seeds.contractCalls).forEach(async (contract) => { + var address = await registry.getProxyFor(contract); + console.log(`Using ${contract} at ${address}`); + contracts[contract] = await artifacts.require(contract).at(address); + + Object.keys(seeds.contractCalls[contract]).forEach((method) => { + seeds.contractCalls[contract][method].forEach((args) => { + console.log(`[Sending] ${contract}.#${method}(${JSON.stringify(args)})`); + contracts[contract][method](...args).then((result) => { + console.log(`[Result] ${contract}.${method}(${JSON.stringify(args)}) => ${result.tx}`); + }); + }); + }); + }); + }); + + + seeds.ipfsContent.forEach((content) => { + ipfs.add(new ipfs.Buffer(JSON.stringify(content))).then((result) => { console.log(`[IPFS] added ${result[0].hash}`) }); + }); +}