From e12e0210493d50b487fe1bba9862fd9af11afb0d Mon Sep 17 00:00:00 2001 From: Jack Tanner Date: Wed, 20 May 2020 14:11:27 +0200 Subject: [PATCH 1/4] Create MIT license As agreed on by all team members of the Odyssey Hackathon team --- LICENSE | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..6573447 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 Conscious-Cities + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. From a2ded2337b09a52fc4b16c3b17271ddbc9cad103 Mon Sep 17 00:00:00 2001 From: Jack Tanner Date: Thu, 25 Jun 2020 10:08:16 +0200 Subject: [PATCH 2/4] updated dockerfile to use official dfuse container --- blockchain/Dockerfile-dfuse | 37 ++++++++++++------------------------- 1 file changed, 12 insertions(+), 25 deletions(-) diff --git a/blockchain/Dockerfile-dfuse b/blockchain/Dockerfile-dfuse index 9ca735a..35ac7a4 100644 --- a/blockchain/Dockerfile-dfuse +++ b/blockchain/Dockerfile-dfuse @@ -1,28 +1,15 @@ -FROM ubuntu:18.04 -RUN apt-get update \ - && apt-get install -y --no-install-recommends wget ca-certificates software-properties-common \ - && wget https://github.com/EOSIO/eosio.cdt/releases/download/v1.7.0/eosio.cdt_1.7.0-1-ubuntu-18.04_amd64.deb \ - && apt install -y ./eosio.cdt_1.7.0-1-ubuntu-18.04_amd64.deb \ - && rm eosio.cdt_1.7.0-1-ubuntu-18.04_amd64.deb \ - && wget https://github.com/dfuse-io/eos/releases/download/v2.0.5-dm-12.0/eosio_2.0.5-dm.12.0-1-ubuntu-18.04_amd64.deb \ - && apt install -y ./eosio_2.0.5-dm.12.0-1-ubuntu-18.04_amd64.deb \ - && rm eosio_2.0.5-dm.12.0-1-ubuntu-18.04_amd64.deb \ - && wget https://github.com/dfuse-io/dfuse-eosio/releases/download/v0.1.0-beta3/dfuse-eosio_0.1.0-beta3_linux_x86_64.tar.gz \ - && tar -xzvf dfuse-eosio_0.1.0-beta3_linux_x86_64.tar.gz \ - && rm dfuse-eosio_0.1.0-beta3_linux_x86_64.tar.gz -RUN apt-get install -y curl \ - && mv dfuseeos /usr/local/bin/dfuseeos \ - && apt-get remove -y wget ca-certificates \ - && apt-get autoremove -y \ -# && apt-get clean \ - && rm -rf /var/lib/apt/lists/* \ - && cd /usr/opt/eosio.cdt/1.7.0/bin -# Hack to fix multithreading issue in eosio.cdt 1.7.0 -#RUN mv wasm-ld wasm-ld.real \ -# && echo '#!/bin/bash' > wasm-ld \ -# && echo '`dirname $0`/wasm-ld.real --no-threads "$@"' >> wasm-ld \ -# && chmod +x /usr/opt/eosio.cdt/1.7.0/bin/wasm-ld +FROM dfuse/dfuse-eosio + +RUN ln -s /app/dfuseeos /bin/dfuseeos RUN cd / \ # "y" will initialize to run a producing node, "n" will connect to existing node && (echo "y" && cat) | dfuseeos init -RUN sed -i 's/127.0.0.1:8888/0.0.0.0:8888/g' producer/config.ini \ No newline at end of file +RUN sed -i 's/127.0.0.1:8888/0.0.0.0:8888/g' producer/config.ini + +CMD dfuseeos start + +# docker-compose build dfuse +# docker-compose run dfuse + +# docker build ./blockchain/ -f Dockerfile-dfuse -t dfuse +# docker run -p 8888:8888 -p 8081:8081 -p 8080:8080 -it dfuse dfuseeos start \ No newline at end of file From 2cafdbad71fb9eecfb1d38ed7a2c8bbd2d8e8092 Mon Sep 17 00:00:00 2001 From: Jack Tanner Date: Tue, 14 Jul 2020 21:59:33 +0200 Subject: [PATCH 3/4] fixed bug in get_account.js and bootstrap not adding to database --- back-end/routes/chain/get_account.js | 92 +++--- back-end/test/bootstrap-accounts.js | 476 +++++++++++++-------------- front-end/src/services/Eosio.js | 21 +- 3 files changed, 288 insertions(+), 301 deletions(-) diff --git a/back-end/routes/chain/get_account.js b/back-end/routes/chain/get_account.js index caf3c7e..3e706c3 100644 --- a/back-end/routes/chain/get_account.js +++ b/back-end/routes/chain/get_account.js @@ -4,52 +4,56 @@ const Eosio = require('../../services/Eosio'); const eosio = new Eosio(); /* GET acounts listing. */ -module.exports = async function (req, res) { - const accountName = req.body.account_name; - if (!accountName) { - res.status(400); - res.send({ message: 'req body should contain all the data!' }); - return; - } - const accountDoc = await accountController.findOne({ accountName: accountName }); - const query = `account:eosio action:neworg (data.active.accounts.permission.actor:${accountName} OR data.owner.accounts.permission.actor:${accountName})`; - let transactionRes = await eosio.dfuseClient.searchTransactions(query); - if (!accountDoc) { - res.status(404); - res.send({ message: `Not found account with account name ${accountName}` }); - } +module.exports = async function(req, res) { + const accountName = req.body.account_name; + if (!accountName) { + res.status(400); + res.send({ message: 'req body should contain all the data!' }); + return; + } + const accountDoc = await accountController.findOne({ accountName: accountName }); + if (!accountDoc) { + res.status(404); + res.send({ message: `Not found account with account name ${accountName}` }); + } + + const query = `account:eosio action:neworg (data.active.accounts.permission.actor:${accountName} OR data.owner.accounts.permission.actor:${accountName})`; + let transactionRes = await eosio.dfuseClient.searchTransactions(query); + // get array of account names from dfuse tranactions log - // get array of account names from dfuse tranactions log - const accountNamesInfo = transactionRes.transactions - .filter(transaction => (transaction.lifecycle.transaction_status === "executed" && transaction.lifecycle.pub_keys)) - .map(transaction => { - const transactionItem = transaction.lifecycle; - const accountName = transactionItem.execution_trace.action_traces[0].act.data.name; - return accountName; - }); + let orgInfo = []; + if (transactionRes.transactions) { + const accountNamesInfo = transactionRes.transactions + .filter(transaction => (transaction.lifecycle.transaction_status === "executed" && transaction.lifecycle.pub_keys)) + .map(transaction => { + const transactionItem = transaction.lifecycle; + const accountName = transactionItem.execution_trace.action_traces[0].act.data.name; + return accountName; + }); - if (!accountNamesInfo || accountNamesInfo.length === 0) { - res.status(404); - res.send({ message: `Not found account from dfuse with account name ${accountName}` }); - return; // not sure if this is needed... - } - // get name from account name using mongodb - const orgInfo = await Promise.all(accountNamesInfo.map(async accountName => { - const orgDoc = await accountController.findOne({ accountName: accountName }); - if (!orgDoc) { - res.status(404); - res.send({ message: `Not found account with account name ${accountName}` }); - return; // not sure if this is needed... + if (!accountNamesInfo || accountNamesInfo.length === 0) { + res.status(404); + res.send({ message: `Not found account from dfuse with account name ${accountName}` }); + return; // not sure if this is needed... + } + // get name from account name using mongodb + orgInfo = await Promise.all(accountNamesInfo.map(async accountName => { + const orgDoc = await accountController.findOne({ accountName: accountName }); + if (!orgDoc) { + res.status(404); + res.send({ message: `Not found account with account name ${accountName}` }); + return; // not sure if this is needed... + } + return { name: orgDoc.name, accountName: accountName } + })) } - return { name: orgDoc.name, accountName: accountName } - })) - const accountDocInfo = { - accountType: accountDoc.accountType, - name: accountDoc.name, - organizations: orgInfo - }; + const accountDocInfo = { + accountType: accountDoc.accountType, + name: accountDoc.name, + organizations: orgInfo + }; - const retObj = req.addBlockchainRes(accountDocInfo); - res.send(retObj); -}; + const retObj = req.addBlockchainRes(accountDocInfo); + res.send(retObj); +}; \ No newline at end of file diff --git a/back-end/test/bootstrap-accounts.js b/back-end/test/bootstrap-accounts.js index 0e15718..23c2469 100644 --- a/back-end/test/bootstrap-accounts.js +++ b/back-end/test/bootstrap-accounts.js @@ -7,284 +7,280 @@ const accountController = require('../controllers/accounts.controller'); let eosio = new Eosio(); async function main() { - console.log("starting blockchain initialization"); + console.log("starting blockchain initialization"); - await mongoose.connect(settings.mongodb.url, { - useNewUrlParser: true, - useUnifiedTopology: true - }) - console.log("Connected to database"); - // Set up the system contract - let eosioAccount = { - pkey: settings.eosio.accounts.eosio.pkey, - name: "eosio", - permission: "active" - } - await eosio.login(eosioAccount); - await setupEosioAccount(); + await mongoose.connect(settings.mongodb.url, { + useNewUrlParser: true, + useUnifiedTopology: true + }) + console.log("Connected to database"); + // Set up the system contract + let eosioAccount = { + pkey: settings.eosio.accounts.eosio.pkey, + name: "eosio", + permission: "active" + } + await eosio.login(eosioAccount); + await setupEosioAccount(); + + // Create some people + eosio = new Eosio() + await eosio.login(eosioAccount); + await createNewPerson("yvo", "Yvo Hunink", settings.eosio.accounts.yvo.pubkey); + await createNewPerson("hidde", "Hidde Kamst", settings.eosio.accounts.hidde.pubkey); + await createNewPerson("tijn", "Tijn Kyuper", settings.eosio.accounts.tijn.pubkey); - // Create some people - eosio = new Eosio() - await eosio.login(eosioAccount); - const govOrg = [{accountName: "gov", name: "The Ministry of The Hague"}] - await createNewPerson("yvo", "Yvo Hunink", settings.eosio.accounts.yvo.pubkey, govOrg); - await createNewPerson("hidde", "Hidde Kamst", settings.eosio.accounts.hidde.pubkey, govOrg); - await createNewPerson("tijn", "Tijn Kyuper", settings.eosio.accounts.tijn.pubkey, govOrg); - - const ccOrg = [{accountName: "thenewfork", name: "The New Fork Partners"}] - await createNewPerson("jack", "Jack Tanner", settings.eosio.accounts.jack.pubkey, ccOrg); - await createNewPerson("kirsten", "Kirsten Coppoolse", settings.eosio.accounts.kirsten.pubkey, ccOrg); - await createNewPerson("matej", "Matej Ondrejka", settings.eosio.accounts.matej.pubkey, ccOrg); + await createNewPerson("jack", "Jack Tanner", settings.eosio.accounts.jack.pubkey); + await createNewPerson("kirsten", "Kirsten Coppoolse", settings.eosio.accounts.kirsten.pubkey); + await createNewPerson("matej", "Matej Ondrejka", settings.eosio.accounts.matej.pubkey); - // Create some new orgs - await createNewOrg("thenewfork", "The New Fork Partners", ["jack", "kirsten", "matej"], 0.66); - await createNewOrg("gov", "The Ministry of The Hague", ["hidde", "tijn", "yvo"], 0.66), [{accountName: "eosio", name: "System governance"}, {accountName: "eosio.token", name: "System currency"}]; - await createNewOrg("eosio.token", "System currency", ["gov"], 0.66); - - // Update the system contract to be controlled by the government - await updateEosioAuth(); + // Create some new orgs + await createNewOrg("thenewfork", "The New Fork Partners", ["jack", "kirsten", "matej"], 0.66); + await createNewOrg("gov", "The Ministry of The Hague", ["hidde", "tijn", "yvo"], 0.66), [{ accountName: "eosio", name: "System governance" }, { accountName: "eosio.token", name: "System currency" }]; + await createNewOrg("eosio.token", "System currency", ["gov"], 0.66); - // Create the token contract and mint tokens to government - await deploySetupToken(); + // Update the system contract to be controlled by the government + await updateEosioAuth(); - // Send some Euros around! - await transferTokens("gov", "yvo", 350, "", settings.eosio.accounts.yvo.pkey); - await transferTokens("gov", "hidde", 450, "", settings.eosio.accounts.yvo.pkey); - await transferTokens("gov", "tijn", 500, "", settings.eosio.accounts.yvo.pkey); - await transferTokens("gov", "thenewfork", 3000, "", settings.eosio.accounts.yvo.pkey); - await transferTokens("thenewfork", "jack", 600, "", settings.eosio.accounts.jack.pkey); - await transferTokens("thenewfork", "kirsten", 600, "", settings.eosio.accounts.jack.pkey); - await transferTokens("thenewfork", "matej", 600, "", settings.eosio.accounts.jack.pkey); - await transferTokens("kirsten", "jack", 50, "Bonus", settings.eosio.accounts.kirsten.pkey); - await transferTokens("matej", "jack", 100, "Sneaky tip!", settings.eosio.accounts.matej.pkey); + // Create the token contract and mint tokens to government + await deploySetupToken(); - // Vote on some policies - await voteOnPolicy("yvo", 1, "yes", settings.eosio.accounts.yvo.pkey); - await voteOnPolicy("hidde", 1, "no", settings.eosio.accounts.hidde.pkey); - await voteOnPolicy("hidde", 32, "abstain", settings.eosio.accounts.hidde.pkey); - await voteOnPolicy("matej", 32, "yes", settings.eosio.accounts.matej.pkey); - await voteOnPolicy("kirsten", 32, "no", settings.eosio.accounts.kirsten.pkey); - await voteOnPolicy("matej", 1, "yes", settings.eosio.accounts.matej.pkey); - - console.log("fin") - process.exit(0) + // Send some Euros around! + await transferTokens("gov", "yvo", 350, "", settings.eosio.accounts.yvo.pkey); + await transferTokens("gov", "hidde", 450, "", settings.eosio.accounts.yvo.pkey); + await transferTokens("gov", "tijn", 500, "", settings.eosio.accounts.yvo.pkey); + await transferTokens("gov", "thenewfork", 3000, "", settings.eosio.accounts.yvo.pkey); + await transferTokens("thenewfork", "jack", 600, "", settings.eosio.accounts.jack.pkey); + await transferTokens("thenewfork", "kirsten", 600, "", settings.eosio.accounts.jack.pkey); + await transferTokens("thenewfork", "matej", 600, "", settings.eosio.accounts.jack.pkey); + await transferTokens("kirsten", "jack", 50, "Bonus", settings.eosio.accounts.kirsten.pkey); + await transferTokens("matej", "jack", 100, "Sneaky tip!", settings.eosio.accounts.matej.pkey); + + // Vote on some policies + await voteOnPolicy("yvo", 1, "yes", settings.eosio.accounts.yvo.pkey); + await voteOnPolicy("hidde", 1, "no", settings.eosio.accounts.hidde.pkey); + await voteOnPolicy("hidde", 32, "abstain", settings.eosio.accounts.hidde.pkey); + await voteOnPolicy("matej", 32, "yes", settings.eosio.accounts.matej.pkey); + await voteOnPolicy("kirsten", 32, "no", settings.eosio.accounts.kirsten.pkey); + await voteOnPolicy("matej", 1, "yes", settings.eosio.accounts.matej.pkey); + + console.log("fin") + process.exit(0) }; Promise.resolve(main()).catch(err => { - console.error(err) - process.exit(1) + console.error(err) + process.exit(1) }) async function voteOnPolicy(voter, policyId, vote, key) { - eosioAccount = { - pkey: key, - name: voter, - permission: "active" - } - await eosio.login(eosioAccount); - await eosio.myapi.transact("eosio", "policyvote", { - voter: voter, - policy_id: policyId, - vote: vote - }); - console.log(voter + " voted " + vote + " in policy #" + policyId); + eosioAccount = { + pkey: key, + name: voter, + permission: "active" + } + await eosio.login(eosioAccount); + await eosio.myapi.transact("eosio", "policyvote", { + voter: voter, + policy_id: policyId, + vote: vote + }); + console.log(voter + " voted " + vote + " in policy #" + policyId); } async function transferTokens(from, to, amount, memo, key) { - eosioAccount = { - pkey: key, - name: from, - permission: "active" - } - await eosio.login(eosioAccount); - quant = amount.toString() + ".00 EUR"; - await eosio.myapi.transact("eosio.token", "transfer", { - from: from, - to: to, - quantity: quant, - memo: memo - }); - console.log("Transfered " + quant + " from " + from + " to " + to); + eosioAccount = { + pkey: key, + name: from, + permission: "active" + } + await eosio.login(eosioAccount); + quant = amount.toString() + ".00 EUR"; + await eosio.myapi.transact("eosio.token", "transfer", { + from: from, + to: to, + quantity: quant, + memo: memo + }); + console.log("Transfered " + quant + " from " + from + " to " + to); } async function deploySetupToken() { - eosioAccount = { - pkey: settings.eosio.accounts.yvo.pkey, - name: "eosio.token", - permission: "active" - } - await eosio.login(eosioAccount); - await eosio.myapi.deploy("eosio.token", "../contracts/eosio.token"); - console.log("Token contract deployed"); - - await eosio.myapi.transact("eosio.token", "create", { - issuer: "gov", - maximum_supply: "1000000000.00 EUR" - }); - - eosioAccount = { - pkey: settings.eosio.accounts.yvo.pkey, - name: "gov", - permission: "active" - } - await eosio.login(eosioAccount); - await eosio.myapi.transact("eosio.token", "issue", { - to: "gov", - quantity: "10000.00 EUR", - memo: "" - }); + eosioAccount = { + pkey: settings.eosio.accounts.yvo.pkey, + name: "eosio.token", + permission: "active" + } + await eosio.login(eosioAccount); + await eosio.myapi.deploy("eosio.token", "../contracts/eosio.token"); + console.log("Token contract deployed"); + + await eosio.myapi.transact("eosio.token", "create", { + issuer: "gov", + maximum_supply: "1000000000.00 EUR" + }); + + eosioAccount = { + pkey: settings.eosio.accounts.yvo.pkey, + name: "gov", + permission: "active" + } + await eosio.login(eosioAccount); + await eosio.myapi.transact("eosio.token", "issue", { + to: "gov", + quantity: "10000.00 EUR", + memo: "" + }); } async function setupEosioAccount() { - await eosio.myapi.deploy("eosio", "../contracts/eosio.bios"); - console.log("eosio.bios contract deployed"); - await accountController.insert({ - accountName: "eosio", - name: "System governance", - accountType: "organization" - }); + await eosio.myapi.deploy("eosio", "../contracts/eosio.bios"); + console.log("eosio.bios contract deployed"); + await accountController.insert({ + accountName: "eosio", + name: "System governance", + accountType: "organization" + }); } async function updateEosioAuth() { - eosioAccount = { - pkey: settings.eosio.accounts.eosio.pkey, - name: "eosio", - permission: "active" - } - await eosio.login(eosioAccount); - let data = { - account: "eosio", - permission: "active", - parent: "owner", - auth: { - accounts: [{ - permission: {actor: "gov", permission: "active"}, - weight: 1 - }], - keys: [], - threshold: 1, - waits: [] + eosioAccount = { + pkey: settings.eosio.accounts.eosio.pkey, + name: "eosio", + permission: "active" } - } - await eosio.myapi.transact("eosio", "updateauth", data); - - eosioAccount = { - pkey: settings.eosio.accounts.eosio.pkey, - name: "eosio", - permission: "owner" - } - await eosio.login(eosioAccount); - data = { - account: "eosio", - permission: "owner", - parent: "", - auth: { - accounts: [{ - permission: {actor: "gov", permission: "owner"}, - weight: 1 - }], - keys: [], - threshold: 1, - waits: [] + await eosio.login(eosioAccount); + let data = { + account: "eosio", + permission: "active", + parent: "owner", + auth: { + accounts: [{ + permission: { actor: "gov", permission: "active" }, + weight: 1 + }], + keys: [], + threshold: 1, + waits: [] + } } - } - await eosio.myapi.transact("eosio", "updateauth", data); + await eosio.myapi.transact("eosio", "updateauth", data); + + eosioAccount = { + pkey: settings.eosio.accounts.eosio.pkey, + name: "eosio", + permission: "owner" + } + await eosio.login(eosioAccount); + data = { + account: "eosio", + permission: "owner", + parent: "", + auth: { + accounts: [{ + permission: { actor: "gov", permission: "owner" }, + weight: 1 + }], + keys: [], + threshold: 1, + waits: [] + } + } + await eosio.myapi.transact("eosio", "updateauth", data); } -async function createNewPerson(accountName, name, key, organizations) { - const data = newPersonData("eosio", accountName, key, key); - await eosio.myapi.transact("eosio", "newperson", data); - await accountController.insert({ - accountName: accountName, - name: name, - accountType: "person", - organizations: organizations, - }); - console.log("Person ", accountName, " created"); +async function createNewPerson(accountName, name, key) { + const data = newPersonData("eosio", accountName, key, key); + await eosio.myapi.transact("eosio", "newperson", data); + await accountController.insert({ + accountName: accountName, + name: name, + accountType: "person", + }); + console.log("Person ", accountName, " created"); } -async function createNewOrg(accountName, name, owners, thresholdPercent, organizations) { - const data = newOrgData("eosio", accountName, owners, thresholdPercent); - await eosio.myapi.transact("eosio", "neworg", data); - let updateAccount = { - accountName: accountName, - name: name, - accountType: "organization", - } - if (organizations) updateAccount.organizations = organizations - await accountController.insert(updateAccount); - console.log("Organization ", accountName, " created"); +async function createNewOrg(accountName, name, owners, thresholdPercent) { + const data = newOrgData("eosio", accountName, owners, thresholdPercent); + await eosio.myapi.transact("eosio", "neworg", data); + let updateAccount = { + accountName: accountName, + name: name, + accountType: "organization", + } + await accountController.insert(updateAccount); + console.log("Organization ", accountName, " created"); } function newPersonData(creator, name, key, owner = "gov") { - let data = { - creator: creator, - name: name, - owner: { - threshold: 1, - keys: [], - accounts: [{ - permission: { - actor: "gov", - permission: "active" + let data = { + creator: creator, + name: name, + owner: { + threshold: 1, + keys: [], + accounts: [{ + permission: { + actor: "gov", + permission: "active" + }, + weight: 1 + }], + waits: [] }, - weight: 1 - }], - waits: [] - }, - active: { - threshold: 1, - keys: [{ - key: key, - weight: 1 - }], - accounts: [], - waits: [] + active: { + threshold: 1, + keys: [{ + key: key, + weight: 1 + }], + accounts: [], + waits: [] + } } - } - if (owner !== "gov") { - data.owner.accounts = [] - data.owner.keys = [{ - key: owner, - weight: 1 - }] - } - return data; + if (owner !== "gov") { + data.owner.accounts = [] + data.owner.keys = [{ + key: owner, + weight: 1 + }] + } + return data; } function newOrgData(creator, name, owners, thresholdPercent) { - let data = { - creator: creator, - name: name, - owner: { - threshold: Math.min(Math.floor(owners.length * thresholdPercent) + 1, owners.length), - keys: [], - accounts: [], - waits: [] - }, - active: { - threshold: 1, - keys: [], - accounts: [], - waits: [] + let data = { + creator: creator, + name: name, + owner: { + threshold: Math.min(Math.floor(owners.length * thresholdPercent) + 1, owners.length), + keys: [], + accounts: [], + waits: [] + }, + active: { + threshold: 1, + keys: [], + accounts: [], + waits: [] + } } - } - for (owner of owners) { - data.owner.accounts.push({ - permission: { - actor: owner, - permission: "active" - }, - weight: 1 - }) - data.active.accounts.push({ - permission: { - actor: owner, - permission: "active" - }, - weight: 1 - }) - } - return data; + for (owner of owners) { + data.owner.accounts.push({ + permission: { + actor: owner, + permission: "active" + }, + weight: 1 + }) + data.active.accounts.push({ + permission: { + actor: owner, + permission: "active" + }, + weight: 1 + }) + } + return data; } \ No newline at end of file diff --git a/front-end/src/services/Eosio.js b/front-end/src/services/Eosio.js index d18db27..561c0f0 100644 --- a/front-end/src/services/Eosio.js +++ b/front-end/src/services/Eosio.js @@ -8,7 +8,7 @@ import settings from '../settings'; class Eosio { constructor(network = { nodeos: settings.eosio.nodeos, dfuseOptions: settings.dfuseOptions }) { - let rpc = fetch ? new JsonRpc(network.nodeos, {fetch}) : new JsonRpc(network.nodeos); + let rpc = fetch ? new JsonRpc(network.nodeos, { fetch }) : new JsonRpc(network.nodeos); this.rpc = rpc; this.dfuseClient = createDfuseClient(network.dfuseOptions) } @@ -19,26 +19,13 @@ class Eosio { const signatureProvider = new JsSignatureProvider([accountCopy.pkey]); accountCopy.pubkey = ecc.privateToPublic(accountCopy.pkey); - // const accountRes = await this.rpc.get_account(accountCopy.name); - // const permissions = accountRes.permissions.filter((permission) => { - // if (accountCopy.permission === permission.perm_name) { - // let keys = permission.required_auth.keys.filter((key) => { - // if (key.key === accountCopy.pubkey) return true; - // return false; - // }) - // if (keys.length && keys.length > 0) return true; - // } - // return false; - // }); - // if (!(permissions.length) || permissions.length !== 1) throw Error("Permission " + accountCopy.permission + " with account " + accountCopy.name + " was not found"); - delete accountCopy.pkey; this.account = accountCopy; const rpc = this.rpc; - let api = TextEncoder - ? new Api({ rpc, signatureProvider, textDecoder: new TextDecoder(), textEncoder: new TextEncoder() }) - : new Api({ rpc, signatureProvider }); + let api = TextEncoder ? + new Api({ rpc, signatureProvider, textDecoder: new TextDecoder(), textEncoder: new TextEncoder() }) : + new Api({ rpc, signatureProvider }); this.api = api; From 120f3c5dba84d596f903362f241426166a8f0bde Mon Sep 17 00:00:00 2001 From: Jack Tanner Date: Wed, 26 Aug 2020 20:22:43 +0200 Subject: [PATCH 4/4] configured package and removed some routes --- back-end/middleware/blockchainProxy.js | 8 +- back-end/package-lock.json | 124 ++++++++++++- back-end/package.json | 71 ++++---- back-end/routes.js | 5 +- back-end/routes/home.js | 5 - back-end/server.js | 38 ++-- back-end/settings.js | 80 +++------ back-end/test/bootstrap-accounts.js | 239 ------------------------- config.sh | 2 +- scripts/README.md | 1 + 10 files changed, 212 insertions(+), 361 deletions(-) delete mode 100644 back-end/routes/home.js diff --git a/back-end/middleware/blockchainProxy.js b/back-end/middleware/blockchainProxy.js index 3ca5819..9452c40 100644 --- a/back-end/middleware/blockchainProxy.js +++ b/back-end/middleware/blockchainProxy.js @@ -19,18 +19,18 @@ const pre = async function(req, res, next) { } if (req.method === "POST" || req.method === "PUT") { let body = typeof req.body === "string" ? JSON.parse(req.body) : req.body - // body = JSON.stringify(body); + // body = JSON.stringify(body); options.body = JSON.stringify(body); req.body = body; } - const fetchResponse = await nodeFetch(url, options) + const fetchResponse = await nodeFetch(url, options); const blockchainRes = await fetchResponse.json(); req.blockchainRes = blockchainRes; req.blockchainResStatus = fetchResponse.status; - req.addBlockchainRes = function(obj) { - let retObj = obj ? obj : {}; + req.addBlockchainRes = function(obj = {}) { + let retObj = obj; for (let key in blockchainRes) { if (blockchainRes.hasOwnProperty(key)) { retObj[key] = blockchainRes[key]; diff --git a/back-end/package-lock.json b/back-end/package-lock.json index dc69e21..ceae520 100644 --- a/back-end/package-lock.json +++ b/back-end/package-lock.json @@ -278,6 +278,12 @@ "resolved": "https://registry.npmjs.org/bson/-/bson-1.1.4.tgz", "integrity": "sha512-S/yKGU1syOMzO86+dGpg2qGoDL0zvzcb262G+gqEy6TgP6rt6z6qxSFX/8X6vLC91P7G7C3nLs0+bvDzmvBA3Q==" }, + "buffer-shims": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/buffer-shims/-/buffer-shims-1.0.0.tgz", + "integrity": "sha1-mXjOMXOIxkmth5MCjDR37wRKi1E=", + "dev": true + }, "buffer-xor": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/buffer-xor/-/buffer-xor-1.0.3.tgz", @@ -737,6 +743,12 @@ "safe-buffer": "^5.1.1" } }, + "exit": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/exit/-/exit-0.1.2.tgz", + "integrity": "sha1-BjJjj42HfMghB9MKD/8aF8uhzQw=", + "dev": true + }, "express": { "version": "4.16.4", "resolved": "https://registry.npmjs.org/express/-/express-4.16.4.tgz", @@ -898,6 +910,12 @@ "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", "integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac=" }, + "fs.realpath": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", + "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", + "dev": true + }, "fsevents": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.1.2.tgz", @@ -914,6 +932,20 @@ "pump": "^3.0.0" } }, + "glob": { + "version": "7.1.6", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz", + "integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==", + "dev": true, + "requires": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.0.4", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + } + }, "glob-parent": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.1.tgz", @@ -1022,6 +1054,16 @@ "integrity": "sha1-khi5srkoojixPcT7a21XbyMUU+o=", "dev": true }, + "inflight": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", + "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", + "dev": true, + "requires": { + "once": "^1.3.0", + "wrappy": "1" + } + }, "inherits": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", @@ -1150,6 +1192,57 @@ "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=" }, + "jslint": { + "version": "0.12.1", + "resolved": "https://registry.npmjs.org/jslint/-/jslint-0.12.1.tgz", + "integrity": "sha512-q5iHswjOmJffbsGVq/1umGh4YBxb5pCArNHCZeHpkuVDDKM6IldqUn4hLehKSwQr7Bn07VXjD34Lx3nw+6j8eA==", + "dev": true, + "requires": { + "exit": "~0.1.2", + "glob": "~7.1.3", + "nopt": "~4.0.1", + "readable-stream": "~2.1.5" + }, + "dependencies": { + "nopt": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/nopt/-/nopt-4.0.3.tgz", + "integrity": "sha512-CvaGwVMztSMJLOeXPrez7fyfObdZqNUK1cPAEzLHrTybIua9pMdmmPR5YwtfNftIOMv3DPUhFaxsZMNTQO20Kg==", + "dev": true, + "requires": { + "abbrev": "1", + "osenv": "^0.1.4" + } + }, + "process-nextick-args": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-1.0.7.tgz", + "integrity": "sha1-FQ4gt1ZZCtP5EJPyWk8q2L/zC6M=", + "dev": true + }, + "readable-stream": { + "version": "2.1.5", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.1.5.tgz", + "integrity": "sha1-ZvqLcg4UOLNkaB8q0aY8YYRIydA=", + "dev": true, + "requires": { + "buffer-shims": "^1.0.0", + "core-util-is": "~1.0.0", + "inherits": "~2.0.1", + "isarray": "~1.0.0", + "process-nextick-args": "~1.0.6", + "string_decoder": "~0.10.x", + "util-deprecate": "~1.0.1" + } + }, + "string_decoder": { + "version": "0.10.31", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz", + "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=", + "dev": true + } + } + }, "json-buffer": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.0.tgz", @@ -1404,8 +1497,7 @@ "node-fetch": { "version": "2.6.0", "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.0.tgz", - "integrity": "sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA==", - "dev": true + "integrity": "sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA==" }, "nodemon": { "version": "2.0.3", @@ -1495,6 +1587,28 @@ "resolved": "https://registry.npmjs.org/one-time/-/one-time-0.0.4.tgz", "integrity": "sha1-+M33eISCb+Tf+T46nMN7HkSAdC4=" }, + "os-homedir": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/os-homedir/-/os-homedir-1.0.2.tgz", + "integrity": "sha1-/7xJiDNuDoM94MFox+8VISGqf7M=", + "dev": true + }, + "os-tmpdir": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz", + "integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ=", + "dev": true + }, + "osenv": { + "version": "0.1.5", + "resolved": "https://registry.npmjs.org/osenv/-/osenv-0.1.5.tgz", + "integrity": "sha512-0CWcCECdMVc2Rw3U5w9ZjqX6ga6ubk1xDVKxtBQPK7wis/0F2r9T6k4ydGYhecl7YUBxBVxhL5oisPsNxAPe2g==", + "dev": true, + "requires": { + "os-homedir": "^1.0.0", + "os-tmpdir": "^1.0.0" + } + }, "p-cancelable": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/p-cancelable/-/p-cancelable-1.1.0.tgz", @@ -1526,6 +1640,12 @@ "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==" }, + "path-is-absolute": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", + "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", + "dev": true + }, "path-to-regexp": { "version": "0.1.7", "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz", diff --git a/back-end/package.json b/back-end/package.json index 2f3ed0c..4d31460 100644 --- a/back-end/package.json +++ b/back-end/package.json @@ -1,34 +1,41 @@ { - "name": "back-end", - "version": "0.0.1", - "description": "eosio nodejs backend", - "private": true, - "scripts": { - "start": "npm run-script config && REACT_APP_NODE_ENV=development nodemon server.js", - "docker": "npm run-script config && REACT_APP_NODE_ENV=docker nodemon server.js", - "bootstrap": "npm run-script config && REACT_APP_NODE_ENV=docker node test/bootstrap-accounts.js", - "config": ". ../config.sh" - }, - "dependencies": { - "@dfuse/client": "^0.3.10", - "body-parser": "^1.19.0", - "cookie-parser": "~1.4.4", - "cors": "^2.8.5", - "debug": "~2.6.9", - "eosjs": "^20.0.3", - "eosjs-ecc": "^4.0.7", - "express": "^4.16.4", - "mongoose": "^5.9.10", - "morgan": "~1.9.1", - "winston": "^3.2.1", - "ws": "^7.3.0" - }, - "devDependencies": { - "node-fetch": "^2.6.0", - "nodemon": "^2.0.3", - "prettier": "2.0.5", - "util": "^0.12.2" - }, - "author": "", - "license": "ISC" + "name": "back-end", + "version": "0.0.1", + "description": "eosio nodejs backend", + "private": true, + "scripts": { + "start": "npm run-script config && REACT_APP_NODE_ENV=development nodemon server.js", + "docker": "npm run-script config && REACT_APP_NODE_ENV=docker nodemon server.js", + "bootstrap": "npm run-script config && REACT_APP_NODE_ENV=docker node test/bootstrap-accounts.js", + "config": ". ../config.sh" + }, + "dependencies": { + "@dfuse/client": "^0.3.10", + "body-parser": "^1.19.0", + "cookie-parser": "~1.4.4", + "cors": "^2.8.5", + "debug": "~2.6.9", + "eosjs": "^20.0.3", + "eosjs-ecc": "^4.0.7", + "express": "^4.16.4", + "mongoose": "^5.9.10", + "morgan": "~1.9.1", + "node-fetch": "^2.6.0", + "winston": "^3.2.1", + "ws": "^7.3.0" + }, + "devDependencies": { + "jslint": "^0.12.1", + "nodemon": "^2.0.3", + "prettier": "2.0.5", + "util": "^0.12.2" + }, + "eslintConfig": { + "env": { + "es6": true, + "node": true + } + }, + "author": "", + "license": "ISC" } diff --git a/back-end/routes.js b/back-end/routes.js index b1bae78..8676340 100644 --- a/back-end/routes.js +++ b/back-end/routes.js @@ -2,16 +2,13 @@ const express = require('express'); const router = express.Router(); const asyncRouter = require('./middleware/asyncRouter'); -const home = require('./routes/home'); const newAccount = require('./routes/new-account'); const getAccount = require('./routes/chain/get_account'); // Blockchain API extensions -router.get('/', asyncRouter(home)); router.post("/v1/chain/get_account", asyncRouter(getAccount)); // New API endpoints router.post('/new-account', asyncRouter(newAccount)); -module.exports = router; - \ No newline at end of file +module.exports = router; \ No newline at end of file diff --git a/back-end/routes/home.js b/back-end/routes/home.js deleted file mode 100644 index b134413..0000000 --- a/back-end/routes/home.js +++ /dev/null @@ -1,5 +0,0 @@ -module.exports = async function(req, res, next) { - let retValue = req.addBlockchainRes({my_message: 'respond with a resource'}); - res.status(req.blockchainResStatus); - res.send(retValue); -} \ No newline at end of file diff --git a/back-end/server.js b/back-end/server.js index ba0134f..a8f412f 100644 --- a/back-end/server.js +++ b/back-end/server.js @@ -28,28 +28,28 @@ app.use(blockchainProxy.post); // Error handler app.use(function(err, req, res, next) { - console.error(err); - res.status(err.status || 500); - res.send(err.toString()); + console.error(err); + res.status(err.status || 500); + res.send(err.toString()); }); try { - // mongoose.Promise = global.Promise; - mongoose.connect(settings.mongodb.url, { - useNewUrlParser: true, - useUnifiedTopology: true - }, (rej) => { - if (rej) { - console.error(rej.message); - process.exit(); - } - console.log("Connected to database"); - - app.listen(settings.port, () => { - console.log("Server listening on port " + settings.port); + // mongoose.Promise = global.Promise; + mongoose.connect(settings.mongodb.url, { + useNewUrlParser: true, + useUnifiedTopology: true + }, (rej) => { + if (rej) { + console.error(rej.message); + process.exit(); + } + console.log("Connected to database"); + + app.listen(settings.port, () => { + console.log("Server listening on port " + settings.port); + }); }); - }); } catch (err) { - console.error(err) - process.exit(); + console.error(err) + process.exit(); } \ No newline at end of file diff --git a/back-end/settings.js b/back-end/settings.js index 943a912..429f55e 100644 --- a/back-end/settings.js +++ b/back-end/settings.js @@ -1,66 +1,36 @@ // these settings are used on npm start -let settings = { - eosio: { - nodeos: "http://localhost:8888", - accounts: { - eosio: { - pkey: "5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3", - pubkey: "EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV" - }, - jack: { - pkey: "5K5cPZHgJaFHWt3Fy4vgzc2WfLw3cLE4E1x5c6A2kx1pjL3mEg4", - pubkey: "EOS7Jj43XvkrBiNw8Q6zUECcGK9ktbMv8jz6Vjn1qAid93389mEgr" - }, - kirsten: { - pkey: "5Kbbe6k8TT5ejHVvy4iiy2qQvt3MF43oMF7j6GqiQ6FHRT1fVLz", - pubkey: "EOS57RkHk6FVCstEPJbm3ezfJ9wSGtKytvx4fZGj72qHEbHvQjy4j" - }, - matej: { - pkey: "5JJY2YCoMRVVFrYv8SffzdjcvVneFqHWKRz2DsZRBfEZjRWNgEM", - pubkey: "EOS59cUZp45bh7hX2Q6V9ebCdBShQXmr14ANG1VZ55mESLipeCsCE" - }, - yvo: { - pkey: "5KHnMjLZ1jk2ScP4eGHufa8S6SJUSJWTpUqKgsGycVGxHZDCidB", - pubkey: "EOS7bNT2DxZVdH2kEoZFkeuWA5KoT5koDW8aeSzczPHSF4EX8WxQs" - }, - hidde: { - pkey: "5Hs9i9ybXYDKjruScvTP7NRSoEY9ZYMtMx2ncFUdjQwu6nvpZzf", - pubkey: "EOS7R4E2iBK5fXpm92y4fNowVtdc9m6muforLV8c2q9bqYUYmR18X" - }, - tijn: { - pkey: "5JtoZYtMs5Szi71dvHKyHoj7EjQPfKiMPpeJNWZu3iqE9knCQfz", - pubkey: "EOS8MKYqroL3gvHs3wFy4wpxFbsTDRWkMn1xL8A1UE7ThSPA1fvtR" - }, - } - }, - dfuseOptions: dfuseOptions = { - apiKey: "web_abcdef123456789", - authUrl: "null://", - secure: false, - network: "localhost:8080" - }, - mongodb: { - url: "mongodb://localhost:27017/conscious_dev" - }, - port: 4001, - env: "development" +const settings = { + eosio: { + nodeos: "http://localhost:8888", + }, + dfuseOptions: dfuseOptions = { + apiKey: "web_abcdef123456789", + authUrl: "null://", + secure: false, + network: "localhost:8080" + }, + mongodb: { + url: "mongodb://localhost:27017/conscious_dev" + }, + port: 4001, + env: "development" }; if (process.env.REACT_APP_NODE_ENV === "production") { - settings.env = "production"; - settings.eosio.nodeos = "http://dfuse:8888"; - settings.dfuseOptions.network = "dfuse:8080", - settings.mongodb.url = "mongodb://mongodb:27017/conscious_prod"; + settings.env = "production"; + settings.eosio.nodeos = "http://dfuse:8888"; + settings.dfuseOptions.network = "dfuse:8080"; + settings.mongodb.url = "mongodb://mongodb:27017/conscious_prod"; } else if (process.env.REACT_APP_NODE_ENV === "docker") { - settings.env = "docker"; - settings.eosio.nodeos = "http://dfuse:8888"; - settings.dfuseOptions.network = "dfuse:8080", - settings.mongodb.url = "mongodb://mongodb:27017/conscious_dev"; - settings.port = 4000 + settings.env = "docker"; + settings.eosio.nodeos = "http://dfuse:8888"; + settings.dfuseOptions.network = "dfuse:8080"; + settings.mongodb.url = "mongodb://mongodb:27017/conscious_dev"; + settings.port = 4000 } settings.isLiveEnvironment = function() { - return settings.env === "production"; + return settings.env === "production"; } module.exports = settings; \ No newline at end of file diff --git a/back-end/test/bootstrap-accounts.js b/back-end/test/bootstrap-accounts.js index 23c2469..f51f92d 100644 --- a/back-end/test/bootstrap-accounts.js +++ b/back-end/test/bootstrap-accounts.js @@ -26,43 +26,6 @@ async function main() { // Create some people eosio = new Eosio() await eosio.login(eosioAccount); - await createNewPerson("yvo", "Yvo Hunink", settings.eosio.accounts.yvo.pubkey); - await createNewPerson("hidde", "Hidde Kamst", settings.eosio.accounts.hidde.pubkey); - await createNewPerson("tijn", "Tijn Kyuper", settings.eosio.accounts.tijn.pubkey); - - await createNewPerson("jack", "Jack Tanner", settings.eosio.accounts.jack.pubkey); - await createNewPerson("kirsten", "Kirsten Coppoolse", settings.eosio.accounts.kirsten.pubkey); - await createNewPerson("matej", "Matej Ondrejka", settings.eosio.accounts.matej.pubkey); - - // Create some new orgs - await createNewOrg("thenewfork", "The New Fork Partners", ["jack", "kirsten", "matej"], 0.66); - await createNewOrg("gov", "The Ministry of The Hague", ["hidde", "tijn", "yvo"], 0.66), [{ accountName: "eosio", name: "System governance" }, { accountName: "eosio.token", name: "System currency" }]; - await createNewOrg("eosio.token", "System currency", ["gov"], 0.66); - - // Update the system contract to be controlled by the government - await updateEosioAuth(); - - // Create the token contract and mint tokens to government - await deploySetupToken(); - - // Send some Euros around! - await transferTokens("gov", "yvo", 350, "", settings.eosio.accounts.yvo.pkey); - await transferTokens("gov", "hidde", 450, "", settings.eosio.accounts.yvo.pkey); - await transferTokens("gov", "tijn", 500, "", settings.eosio.accounts.yvo.pkey); - await transferTokens("gov", "thenewfork", 3000, "", settings.eosio.accounts.yvo.pkey); - await transferTokens("thenewfork", "jack", 600, "", settings.eosio.accounts.jack.pkey); - await transferTokens("thenewfork", "kirsten", 600, "", settings.eosio.accounts.jack.pkey); - await transferTokens("thenewfork", "matej", 600, "", settings.eosio.accounts.jack.pkey); - await transferTokens("kirsten", "jack", 50, "Bonus", settings.eosio.accounts.kirsten.pkey); - await transferTokens("matej", "jack", 100, "Sneaky tip!", settings.eosio.accounts.matej.pkey); - - // Vote on some policies - await voteOnPolicy("yvo", 1, "yes", settings.eosio.accounts.yvo.pkey); - await voteOnPolicy("hidde", 1, "no", settings.eosio.accounts.hidde.pkey); - await voteOnPolicy("hidde", 32, "abstain", settings.eosio.accounts.hidde.pkey); - await voteOnPolicy("matej", 32, "yes", settings.eosio.accounts.matej.pkey); - await voteOnPolicy("kirsten", 32, "no", settings.eosio.accounts.kirsten.pkey); - await voteOnPolicy("matej", 1, "yes", settings.eosio.accounts.matej.pkey); console.log("fin") process.exit(0) @@ -73,66 +36,6 @@ Promise.resolve(main()).catch(err => { process.exit(1) }) -async function voteOnPolicy(voter, policyId, vote, key) { - eosioAccount = { - pkey: key, - name: voter, - permission: "active" - } - await eosio.login(eosioAccount); - await eosio.myapi.transact("eosio", "policyvote", { - voter: voter, - policy_id: policyId, - vote: vote - }); - console.log(voter + " voted " + vote + " in policy #" + policyId); -} - -async function transferTokens(from, to, amount, memo, key) { - eosioAccount = { - pkey: key, - name: from, - permission: "active" - } - await eosio.login(eosioAccount); - quant = amount.toString() + ".00 EUR"; - await eosio.myapi.transact("eosio.token", "transfer", { - from: from, - to: to, - quantity: quant, - memo: memo - }); - console.log("Transfered " + quant + " from " + from + " to " + to); -} - -async function deploySetupToken() { - eosioAccount = { - pkey: settings.eosio.accounts.yvo.pkey, - name: "eosio.token", - permission: "active" - } - await eosio.login(eosioAccount); - await eosio.myapi.deploy("eosio.token", "../contracts/eosio.token"); - console.log("Token contract deployed"); - - await eosio.myapi.transact("eosio.token", "create", { - issuer: "gov", - maximum_supply: "1000000000.00 EUR" - }); - - eosioAccount = { - pkey: settings.eosio.accounts.yvo.pkey, - name: "gov", - permission: "active" - } - await eosio.login(eosioAccount); - await eosio.myapi.transact("eosio.token", "issue", { - to: "gov", - quantity: "10000.00 EUR", - memo: "" - }); -} - async function setupEosioAccount() { await eosio.myapi.deploy("eosio", "../contracts/eosio.bios"); console.log("eosio.bios contract deployed"); @@ -141,146 +44,4 @@ async function setupEosioAccount() { name: "System governance", accountType: "organization" }); -} - -async function updateEosioAuth() { - eosioAccount = { - pkey: settings.eosio.accounts.eosio.pkey, - name: "eosio", - permission: "active" - } - await eosio.login(eosioAccount); - let data = { - account: "eosio", - permission: "active", - parent: "owner", - auth: { - accounts: [{ - permission: { actor: "gov", permission: "active" }, - weight: 1 - }], - keys: [], - threshold: 1, - waits: [] - } - } - await eosio.myapi.transact("eosio", "updateauth", data); - - eosioAccount = { - pkey: settings.eosio.accounts.eosio.pkey, - name: "eosio", - permission: "owner" - } - await eosio.login(eosioAccount); - data = { - account: "eosio", - permission: "owner", - parent: "", - auth: { - accounts: [{ - permission: { actor: "gov", permission: "owner" }, - weight: 1 - }], - keys: [], - threshold: 1, - waits: [] - } - } - await eosio.myapi.transact("eosio", "updateauth", data); -} - -async function createNewPerson(accountName, name, key) { - const data = newPersonData("eosio", accountName, key, key); - await eosio.myapi.transact("eosio", "newperson", data); - await accountController.insert({ - accountName: accountName, - name: name, - accountType: "person", - }); - console.log("Person ", accountName, " created"); -} - -async function createNewOrg(accountName, name, owners, thresholdPercent) { - const data = newOrgData("eosio", accountName, owners, thresholdPercent); - await eosio.myapi.transact("eosio", "neworg", data); - let updateAccount = { - accountName: accountName, - name: name, - accountType: "organization", - } - await accountController.insert(updateAccount); - console.log("Organization ", accountName, " created"); -} - -function newPersonData(creator, name, key, owner = "gov") { - let data = { - creator: creator, - name: name, - owner: { - threshold: 1, - keys: [], - accounts: [{ - permission: { - actor: "gov", - permission: "active" - }, - weight: 1 - }], - waits: [] - }, - active: { - threshold: 1, - keys: [{ - key: key, - weight: 1 - }], - accounts: [], - waits: [] - } - } - if (owner !== "gov") { - data.owner.accounts = [] - data.owner.keys = [{ - key: owner, - weight: 1 - }] - } - return data; -} - -function newOrgData(creator, name, owners, thresholdPercent) { - let data = { - creator: creator, - name: name, - owner: { - threshold: Math.min(Math.floor(owners.length * thresholdPercent) + 1, owners.length), - keys: [], - accounts: [], - waits: [] - }, - active: { - threshold: 1, - keys: [], - accounts: [], - waits: [] - } - } - - for (owner of owners) { - data.owner.accounts.push({ - permission: { - actor: owner, - permission: "active" - }, - weight: 1 - }) - data.active.accounts.push({ - permission: { - actor: owner, - permission: "active" - }, - weight: 1 - }) - } - return data; } \ No newline at end of file diff --git a/config.sh b/config.sh index e33f301..7b38b43 100755 --- a/config.sh +++ b/config.sh @@ -1,5 +1,5 @@ #!/bin/bash echo "Creating shared environment variables" -export SERVER_DOMAIN="ec2-35-178-206-104.eu-west-2.compute.amazonaws.com" +export SERVER_DOMAIN="ec2-3-8-22-249.eu-west-2.compute.amazonaws.com" export SERVER_HTTPS_DOMAIN="" \ No newline at end of file diff --git a/scripts/README.md b/scripts/README.md index 9b67ca0..814e3a3 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -30,6 +30,7 @@ New EC2 instance - > 4Gb memory (t2.medium) - > 20Gb storage Add to VPC and use security group +Set to have public DNS ## CloudFront New CloudFront distribution: Nodeos, React and Noedjs