fix bugs and readme update
This commit is contained in:
parent
bbccb592f8
commit
d8dd256d01
|
@ -0,0 +1,6 @@
|
||||||
|
APIKEY=
|
||||||
|
USERDB=
|
||||||
|
PASSDB=
|
||||||
|
DBNAME=
|
||||||
|
INFURAKEY=
|
||||||
|
CONTRACTADDRS=
|
|
@ -1,5 +1,4 @@
|
||||||
/node_modules
|
/node_modules
|
||||||
/orbitdb
|
/orbitdb
|
||||||
package-lock.json
|
|
||||||
.env
|
.env
|
||||||
|
|
||||||
|
|
977
ABI.js
977
ABI.js
|
@ -1,437 +1,542 @@
|
||||||
const abi = [{
|
[
|
||||||
"constant": false,
|
{
|
||||||
"inputs": [],
|
"anonymous": false,
|
||||||
"name": "acceptOwnership",
|
"inputs": [
|
||||||
"outputs": [],
|
{
|
||||||
"payable": false,
|
"indexed": true,
|
||||||
"stateMutability": "nonpayable",
|
"internalType": "address",
|
||||||
"type": "function"
|
"name": "owner",
|
||||||
},
|
"type": "address"
|
||||||
{
|
},
|
||||||
"constant": false,
|
{
|
||||||
"inputs": [{
|
"indexed": true,
|
||||||
"name": "spender",
|
"internalType": "address",
|
||||||
"type": "address"
|
"name": "spender",
|
||||||
},
|
"type": "address"
|
||||||
{
|
},
|
||||||
"name": "tokens",
|
{
|
||||||
"type": "uint256"
|
"indexed": false,
|
||||||
}
|
"internalType": "uint256",
|
||||||
],
|
"name": "value",
|
||||||
"name": "approve",
|
"type": "uint256"
|
||||||
"outputs": [{
|
}
|
||||||
"name": "success",
|
],
|
||||||
"type": "bool"
|
"name": "Approval",
|
||||||
}],
|
"type": "event"
|
||||||
"payable": false,
|
},
|
||||||
"stateMutability": "nonpayable",
|
{
|
||||||
"type": "function"
|
"anonymous": false,
|
||||||
},
|
"inputs": [
|
||||||
{
|
{
|
||||||
"constant": false,
|
"indexed": true,
|
||||||
"inputs": [{
|
"internalType": "address",
|
||||||
"name": "spender",
|
"name": "previousOwner",
|
||||||
"type": "address"
|
"type": "address"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "tokens",
|
"indexed": true,
|
||||||
"type": "uint256"
|
"internalType": "address",
|
||||||
},
|
"name": "newOwner",
|
||||||
{
|
"type": "address"
|
||||||
"name": "data",
|
}
|
||||||
"type": "bytes"
|
],
|
||||||
}
|
"name": "OwnershipTransferred",
|
||||||
],
|
"type": "event"
|
||||||
"name": "approveAndCall",
|
},
|
||||||
"outputs": [{
|
{
|
||||||
"name": "success",
|
"anonymous": false,
|
||||||
"type": "bool"
|
"inputs": [
|
||||||
}],
|
{
|
||||||
"payable": false,
|
"indexed": true,
|
||||||
"stateMutability": "nonpayable",
|
"internalType": "address",
|
||||||
"type": "function"
|
"name": "from",
|
||||||
},
|
"type": "address"
|
||||||
{
|
},
|
||||||
"constant": false,
|
{
|
||||||
"inputs": [{
|
"indexed": true,
|
||||||
"name": "spender",
|
"internalType": "address",
|
||||||
"type": "address"
|
"name": "to",
|
||||||
},
|
"type": "address"
|
||||||
{
|
},
|
||||||
"name": "tokens",
|
{
|
||||||
"type": "uint256"
|
"indexed": false,
|
||||||
}
|
"internalType": "uint256",
|
||||||
],
|
"name": "value",
|
||||||
"name": "decreaseApproval",
|
"type": "uint256"
|
||||||
"outputs": [{
|
}
|
||||||
"name": "success",
|
],
|
||||||
"type": "bool"
|
"name": "Transfer",
|
||||||
}],
|
"type": "event"
|
||||||
"payable": false,
|
},
|
||||||
"stateMutability": "nonpayable",
|
{
|
||||||
"type": "function"
|
"payable": true,
|
||||||
},
|
"stateMutability": "payable",
|
||||||
{
|
"type": "fallback"
|
||||||
"constant": false,
|
},
|
||||||
"inputs": [],
|
{
|
||||||
"name": "getETH",
|
"constant": true,
|
||||||
"outputs": [],
|
"inputs": [],
|
||||||
"payable": false,
|
"name": "_CCDBAddress",
|
||||||
"stateMutability": "nonpayable",
|
"outputs": [
|
||||||
"type": "function"
|
{
|
||||||
},
|
"internalType": "string",
|
||||||
{
|
"name": "",
|
||||||
"constant": false,
|
"type": "string"
|
||||||
"inputs": [{
|
}
|
||||||
"name": "spender",
|
],
|
||||||
"type": "address"
|
"payable": false,
|
||||||
},
|
"stateMutability": "view",
|
||||||
{
|
"type": "function"
|
||||||
"name": "tokens",
|
},
|
||||||
"type": "uint256"
|
{
|
||||||
}
|
"constant": true,
|
||||||
],
|
"inputs": [
|
||||||
"name": "increaseApproval",
|
{
|
||||||
"outputs": [{
|
"internalType": "address",
|
||||||
"name": "success",
|
"name": "owner",
|
||||||
"type": "bool"
|
"type": "address"
|
||||||
}],
|
},
|
||||||
"payable": false,
|
{
|
||||||
"stateMutability": "nonpayable",
|
"internalType": "address",
|
||||||
"type": "function"
|
"name": "spender",
|
||||||
},
|
"type": "address"
|
||||||
{
|
}
|
||||||
"constant": false,
|
],
|
||||||
"inputs": [{
|
"name": "allowance",
|
||||||
"name": "to",
|
"outputs": [
|
||||||
"type": "address"
|
{
|
||||||
},
|
"internalType": "uint256",
|
||||||
{
|
"name": "",
|
||||||
"name": "tokens",
|
"type": "uint256"
|
||||||
"type": "uint256"
|
}
|
||||||
}
|
],
|
||||||
],
|
"payable": false,
|
||||||
"name": "transfer",
|
"stateMutability": "view",
|
||||||
"outputs": [{
|
"type": "function"
|
||||||
"name": "success",
|
},
|
||||||
"type": "bool"
|
{
|
||||||
}],
|
"constant": false,
|
||||||
"payable": false,
|
"inputs": [
|
||||||
"stateMutability": "nonpayable",
|
{
|
||||||
"type": "function"
|
"internalType": "uint256",
|
||||||
},
|
"name": "addDays",
|
||||||
{
|
"type": "uint256"
|
||||||
"constant": false,
|
}
|
||||||
"inputs": [{
|
],
|
||||||
"name": "tokenAddress",
|
"name": "appendDays",
|
||||||
"type": "address"
|
"outputs": [],
|
||||||
},
|
"payable": false,
|
||||||
{
|
"stateMutability": "nonpayable",
|
||||||
"name": "tokens",
|
"type": "function"
|
||||||
"type": "uint256"
|
},
|
||||||
}
|
{
|
||||||
],
|
"constant": false,
|
||||||
"name": "transferAnyERC20Token",
|
"inputs": [
|
||||||
"outputs": [{
|
{
|
||||||
"name": "success",
|
"internalType": "address",
|
||||||
"type": "bool"
|
"name": "spender",
|
||||||
}],
|
"type": "address"
|
||||||
"payable": false,
|
},
|
||||||
"stateMutability": "nonpayable",
|
{
|
||||||
"type": "function"
|
"internalType": "uint256",
|
||||||
},
|
"name": "amount",
|
||||||
{
|
"type": "uint256"
|
||||||
"constant": false,
|
}
|
||||||
"inputs": [{
|
],
|
||||||
"name": "from",
|
"name": "approve",
|
||||||
"type": "address"
|
"outputs": [
|
||||||
},
|
{
|
||||||
{
|
"internalType": "bool",
|
||||||
"name": "to",
|
"name": "",
|
||||||
"type": "address"
|
"type": "bool"
|
||||||
},
|
}
|
||||||
{
|
],
|
||||||
"name": "tokens",
|
"payable": false,
|
||||||
"type": "uint256"
|
"stateMutability": "nonpayable",
|
||||||
}
|
"type": "function"
|
||||||
],
|
},
|
||||||
"name": "transferFrom",
|
{
|
||||||
"outputs": [{
|
"constant": true,
|
||||||
"name": "success",
|
"inputs": [
|
||||||
"type": "bool"
|
{
|
||||||
}],
|
"internalType": "address",
|
||||||
"payable": false,
|
"name": "account",
|
||||||
"stateMutability": "nonpayable",
|
"type": "address"
|
||||||
"type": "function"
|
}
|
||||||
},
|
],
|
||||||
{
|
"name": "balanceOf",
|
||||||
"constant": false,
|
"outputs": [
|
||||||
"inputs": [{
|
{
|
||||||
"name": "_newOwner",
|
"internalType": "uint256",
|
||||||
"type": "address"
|
"name": "",
|
||||||
}],
|
"type": "uint256"
|
||||||
"name": "transferOwnership",
|
}
|
||||||
"outputs": [],
|
],
|
||||||
"payable": false,
|
"payable": false,
|
||||||
"stateMutability": "nonpayable",
|
"stateMutability": "view",
|
||||||
"type": "function"
|
"type": "function"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"constant": false,
|
"constant": true,
|
||||||
"inputs": [{
|
"inputs": [],
|
||||||
"name": "CCDBAddress",
|
"name": "bonus1Ends",
|
||||||
"type": "string"
|
"outputs": [
|
||||||
}],
|
{
|
||||||
"name": "updateCCDBAddress",
|
"internalType": "uint256",
|
||||||
"outputs": [],
|
"name": "",
|
||||||
"payable": false,
|
"type": "uint256"
|
||||||
"stateMutability": "nonpayable",
|
}
|
||||||
"type": "function"
|
],
|
||||||
},
|
"payable": false,
|
||||||
{
|
"stateMutability": "view",
|
||||||
"payable": true,
|
"type": "function"
|
||||||
"stateMutability": "payable",
|
},
|
||||||
"type": "fallback"
|
{
|
||||||
},
|
"constant": true,
|
||||||
{
|
"inputs": [],
|
||||||
"anonymous": false,
|
"name": "bonus2Ends",
|
||||||
"inputs": [{
|
"outputs": [
|
||||||
"indexed": true,
|
{
|
||||||
"name": "_from",
|
"internalType": "uint256",
|
||||||
"type": "address"
|
"name": "",
|
||||||
},
|
"type": "uint256"
|
||||||
{
|
}
|
||||||
"indexed": true,
|
],
|
||||||
"name": "_to",
|
"payable": false,
|
||||||
"type": "address"
|
"stateMutability": "view",
|
||||||
}
|
"type": "function"
|
||||||
],
|
},
|
||||||
"name": "OwnershipTransferred",
|
{
|
||||||
"type": "event"
|
"constant": true,
|
||||||
},
|
"inputs": [],
|
||||||
{
|
"name": "decimals",
|
||||||
"anonymous": false,
|
"outputs": [
|
||||||
"inputs": [{
|
{
|
||||||
"indexed": true,
|
"internalType": "uint8",
|
||||||
"name": "from",
|
"name": "",
|
||||||
"type": "address"
|
"type": "uint8"
|
||||||
},
|
}
|
||||||
{
|
],
|
||||||
"indexed": true,
|
"payable": false,
|
||||||
"name": "to",
|
"stateMutability": "view",
|
||||||
"type": "address"
|
"type": "function"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"indexed": false,
|
"constant": false,
|
||||||
"name": "tokens",
|
"inputs": [
|
||||||
"type": "uint256"
|
{
|
||||||
}
|
"internalType": "address",
|
||||||
],
|
"name": "spender",
|
||||||
"name": "Transfer",
|
"type": "address"
|
||||||
"type": "event"
|
},
|
||||||
},
|
{
|
||||||
{
|
"internalType": "uint256",
|
||||||
"anonymous": false,
|
"name": "subtractedValue",
|
||||||
"inputs": [{
|
"type": "uint256"
|
||||||
"indexed": true,
|
}
|
||||||
"name": "tokenOwner",
|
],
|
||||||
"type": "address"
|
"name": "decreaseAllowance",
|
||||||
},
|
"outputs": [
|
||||||
{
|
{
|
||||||
"indexed": true,
|
"internalType": "bool",
|
||||||
"name": "spender",
|
"name": "",
|
||||||
"type": "address"
|
"type": "bool"
|
||||||
},
|
}
|
||||||
{
|
],
|
||||||
"indexed": false,
|
"payable": false,
|
||||||
"name": "tokens",
|
"stateMutability": "nonpayable",
|
||||||
"type": "uint256"
|
"type": "function"
|
||||||
}
|
},
|
||||||
],
|
{
|
||||||
"name": "Approval",
|
"constant": true,
|
||||||
"type": "event"
|
"inputs": [],
|
||||||
},
|
"name": "endDate",
|
||||||
{
|
"outputs": [
|
||||||
"constant": true,
|
{
|
||||||
"inputs": [],
|
"internalType": "uint256",
|
||||||
"name": "_CCDBAddress",
|
"name": "",
|
||||||
"outputs": [{
|
"type": "uint256"
|
||||||
"name": "",
|
}
|
||||||
"type": "string"
|
],
|
||||||
}],
|
"payable": false,
|
||||||
"payable": false,
|
"stateMutability": "view",
|
||||||
"stateMutability": "view",
|
"type": "function"
|
||||||
"type": "function"
|
},
|
||||||
},
|
{
|
||||||
{
|
"constant": false,
|
||||||
"constant": true,
|
"inputs": [],
|
||||||
"inputs": [],
|
"name": "getETH",
|
||||||
"name": "_totalSupply",
|
"outputs": [],
|
||||||
"outputs": [{
|
"payable": false,
|
||||||
"name": "",
|
"stateMutability": "nonpayable",
|
||||||
"type": "uint256"
|
"type": "function"
|
||||||
}],
|
},
|
||||||
"payable": false,
|
{
|
||||||
"stateMutability": "view",
|
"constant": true,
|
||||||
"type": "function"
|
"inputs": [],
|
||||||
},
|
"name": "getPause",
|
||||||
{
|
"outputs": [
|
||||||
"constant": true,
|
{
|
||||||
"inputs": [{
|
"internalType": "bool",
|
||||||
"name": "tokenOwner",
|
"name": "",
|
||||||
"type": "address"
|
"type": "bool"
|
||||||
},
|
}
|
||||||
{
|
],
|
||||||
"name": "spender",
|
"payable": false,
|
||||||
"type": "address"
|
"stateMutability": "view",
|
||||||
}
|
"type": "function"
|
||||||
],
|
},
|
||||||
"name": "allowance",
|
{
|
||||||
"outputs": [{
|
"constant": false,
|
||||||
"name": "remaining",
|
"inputs": [
|
||||||
"type": "uint256"
|
{
|
||||||
}],
|
"internalType": "address",
|
||||||
"payable": false,
|
"name": "spender",
|
||||||
"stateMutability": "view",
|
"type": "address"
|
||||||
"type": "function"
|
},
|
||||||
},
|
{
|
||||||
{
|
"internalType": "uint256",
|
||||||
"constant": true,
|
"name": "addedValue",
|
||||||
"inputs": [{
|
"type": "uint256"
|
||||||
"name": "tokenOwner",
|
}
|
||||||
"type": "address"
|
],
|
||||||
}],
|
"name": "increaseAllowance",
|
||||||
"name": "balanceOf",
|
"outputs": [
|
||||||
"outputs": [{
|
{
|
||||||
"name": "balance",
|
"internalType": "bool",
|
||||||
"type": "uint256"
|
"name": "",
|
||||||
}],
|
"type": "bool"
|
||||||
"payable": false,
|
}
|
||||||
"stateMutability": "view",
|
],
|
||||||
"type": "function"
|
"payable": false,
|
||||||
},
|
"stateMutability": "nonpayable",
|
||||||
{
|
"type": "function"
|
||||||
"constant": true,
|
},
|
||||||
"inputs": [],
|
{
|
||||||
"name": "bonus1Ends",
|
"constant": true,
|
||||||
"outputs": [{
|
"inputs": [],
|
||||||
"name": "",
|
"name": "isOwner",
|
||||||
"type": "uint256"
|
"outputs": [
|
||||||
}],
|
{
|
||||||
"payable": false,
|
"internalType": "bool",
|
||||||
"stateMutability": "view",
|
"name": "",
|
||||||
"type": "function"
|
"type": "bool"
|
||||||
},
|
}
|
||||||
{
|
],
|
||||||
"constant": true,
|
"payable": false,
|
||||||
"inputs": [],
|
"stateMutability": "view",
|
||||||
"name": "bonus2Ends",
|
"type": "function"
|
||||||
"outputs": [{
|
},
|
||||||
"name": "",
|
{
|
||||||
"type": "uint256"
|
"constant": true,
|
||||||
}],
|
"inputs": [],
|
||||||
"payable": false,
|
"name": "name",
|
||||||
"stateMutability": "view",
|
"outputs": [
|
||||||
"type": "function"
|
{
|
||||||
},
|
"internalType": "string",
|
||||||
{
|
"name": "",
|
||||||
"constant": true,
|
"type": "string"
|
||||||
"inputs": [],
|
}
|
||||||
"name": "decimals",
|
],
|
||||||
"outputs": [{
|
"payable": false,
|
||||||
"name": "",
|
"stateMutability": "view",
|
||||||
"type": "uint8"
|
"type": "function"
|
||||||
}],
|
},
|
||||||
"payable": false,
|
{
|
||||||
"stateMutability": "view",
|
"constant": true,
|
||||||
"type": "function"
|
"inputs": [],
|
||||||
},
|
"name": "owner",
|
||||||
{
|
"outputs": [
|
||||||
"constant": true,
|
{
|
||||||
"inputs": [],
|
"internalType": "address payable",
|
||||||
"name": "endDate",
|
"name": "",
|
||||||
"outputs": [{
|
"type": "address"
|
||||||
"name": "",
|
}
|
||||||
"type": "uint256"
|
],
|
||||||
}],
|
"payable": false,
|
||||||
"payable": false,
|
"stateMutability": "view",
|
||||||
"stateMutability": "view",
|
"type": "function"
|
||||||
"type": "function"
|
},
|
||||||
},
|
{
|
||||||
{
|
"constant": true,
|
||||||
"constant": true,
|
"inputs": [],
|
||||||
"inputs": [],
|
"name": "preICOEnds",
|
||||||
"name": "name",
|
"outputs": [
|
||||||
"outputs": [{
|
{
|
||||||
"name": "",
|
"internalType": "uint256",
|
||||||
"type": "string"
|
"name": "",
|
||||||
}],
|
"type": "uint256"
|
||||||
"payable": false,
|
}
|
||||||
"stateMutability": "view",
|
],
|
||||||
"type": "function"
|
"payable": false,
|
||||||
},
|
"stateMutability": "view",
|
||||||
{
|
"type": "function"
|
||||||
"constant": true,
|
},
|
||||||
"inputs": [],
|
{
|
||||||
"name": "newOwner",
|
"constant": false,
|
||||||
"outputs": [{
|
"inputs": [],
|
||||||
"name": "",
|
"name": "renounceOwnership",
|
||||||
"type": "address"
|
"outputs": [],
|
||||||
}],
|
"payable": false,
|
||||||
"payable": false,
|
"stateMutability": "nonpayable",
|
||||||
"stateMutability": "view",
|
"type": "function"
|
||||||
"type": "function"
|
},
|
||||||
},
|
{
|
||||||
{
|
"constant": false,
|
||||||
"constant": true,
|
"inputs": [
|
||||||
"inputs": [],
|
{
|
||||||
"name": "owner",
|
"internalType": "bool",
|
||||||
"outputs": [{
|
"name": "p",
|
||||||
"name": "",
|
"type": "bool"
|
||||||
"type": "address"
|
}
|
||||||
}],
|
],
|
||||||
"payable": false,
|
"name": "setPause",
|
||||||
"stateMutability": "view",
|
"outputs": [],
|
||||||
"type": "function"
|
"payable": false,
|
||||||
},
|
"stateMutability": "nonpayable",
|
||||||
{
|
"type": "function"
|
||||||
"constant": true,
|
},
|
||||||
"inputs": [],
|
{
|
||||||
"name": "preICOEnds",
|
"constant": true,
|
||||||
"outputs": [{
|
"inputs": [],
|
||||||
"name": "",
|
"name": "symbol",
|
||||||
"type": "uint256"
|
"outputs": [
|
||||||
}],
|
{
|
||||||
"payable": false,
|
"internalType": "string",
|
||||||
"stateMutability": "view",
|
"name": "",
|
||||||
"type": "function"
|
"type": "string"
|
||||||
},
|
}
|
||||||
{
|
],
|
||||||
"constant": true,
|
"payable": false,
|
||||||
"inputs": [],
|
"stateMutability": "view",
|
||||||
"name": "symbol",
|
"type": "function"
|
||||||
"outputs": [{
|
},
|
||||||
"name": "",
|
{
|
||||||
"type": "string"
|
"constant": true,
|
||||||
}],
|
"inputs": [],
|
||||||
"payable": false,
|
"name": "totalSupply",
|
||||||
"stateMutability": "view",
|
"outputs": [
|
||||||
"type": "function"
|
{
|
||||||
},
|
"internalType": "uint256",
|
||||||
{
|
"name": "",
|
||||||
"constant": true,
|
"type": "uint256"
|
||||||
"inputs": [],
|
}
|
||||||
"name": "totalSupply",
|
],
|
||||||
"outputs": [{
|
"payable": false,
|
||||||
"name": "",
|
"stateMutability": "view",
|
||||||
"type": "uint256"
|
"type": "function"
|
||||||
}],
|
},
|
||||||
"payable": false,
|
{
|
||||||
"stateMutability": "view",
|
"constant": false,
|
||||||
"type": "function"
|
"inputs": [
|
||||||
}
|
{
|
||||||
|
"internalType": "address",
|
||||||
|
"name": "recipient",
|
||||||
|
"type": "address"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"internalType": "uint256",
|
||||||
|
"name": "amount",
|
||||||
|
"type": "uint256"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "transfer",
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"internalType": "bool",
|
||||||
|
"name": "",
|
||||||
|
"type": "bool"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"payable": false,
|
||||||
|
"stateMutability": "nonpayable",
|
||||||
|
"type": "function"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"constant": false,
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"internalType": "address payable",
|
||||||
|
"name": "tokenAddress",
|
||||||
|
"type": "address"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"internalType": "uint256",
|
||||||
|
"name": "tokens",
|
||||||
|
"type": "uint256"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "transferAnyERC20Token",
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"internalType": "bool",
|
||||||
|
"name": "success",
|
||||||
|
"type": "bool"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"payable": false,
|
||||||
|
"stateMutability": "nonpayable",
|
||||||
|
"type": "function"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"constant": false,
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"internalType": "address",
|
||||||
|
"name": "sender",
|
||||||
|
"type": "address"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"internalType": "address",
|
||||||
|
"name": "recipient",
|
||||||
|
"type": "address"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"internalType": "uint256",
|
||||||
|
"name": "amount",
|
||||||
|
"type": "uint256"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "transferFrom",
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"internalType": "bool",
|
||||||
|
"name": "",
|
||||||
|
"type": "bool"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"payable": false,
|
||||||
|
"stateMutability": "nonpayable",
|
||||||
|
"type": "function"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"constant": false,
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"internalType": "address payable",
|
||||||
|
"name": "newOwner",
|
||||||
|
"type": "address"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "transferOwnership",
|
||||||
|
"outputs": [],
|
||||||
|
"payable": false,
|
||||||
|
"stateMutability": "nonpayable",
|
||||||
|
"type": "function"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"constant": false,
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"internalType": "string",
|
||||||
|
"name": "newCCDBAddress",
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "updateCCDBAddress",
|
||||||
|
"outputs": [],
|
||||||
|
"payable": false,
|
||||||
|
"stateMutability": "nonpayable",
|
||||||
|
"type": "function"
|
||||||
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = abi
|
|
242
README.md
242
README.md
|
@ -1,3 +1,243 @@
|
||||||
# DecaGraphics
|
# DecaGraphics
|
||||||
|
|
||||||
Deca Graphics
|
DECA Charts Code and settings to calculate price, quantity and percentage of reserve in carbon credits.
|
||||||
|
|
||||||
|
**IMPORTANT: Please verify that the database address matches the smart contract address.**
|
||||||
|
|
||||||
|
Official Carbon credits database address ([orbitdb](https://github.com/orbitdb/orbit-db))
|
||||||
|
**/orbitdb/zdpuAykPJ4qtBg2toS2vxr5eaPfGEBJmvGerM7V7x8qn5c8hW/decaCCDB**
|
||||||
|
|
||||||
|
## Table of Contents
|
||||||
|
|
||||||
|
[[_TOC_]]
|
||||||
|
|
||||||
|
## General Folder Structure
|
||||||
|
|
||||||
|
```sh
|
||||||
|
├── ABI.js
|
||||||
|
├── getEth.js
|
||||||
|
├── index.js
|
||||||
|
├── package.json
|
||||||
|
├── README.md
|
||||||
|
├── scriptChildNode.js
|
||||||
|
├── scriptMainNode.js
|
||||||
|
└── services
|
||||||
|
├── decaGraphicsChild.service
|
||||||
|
└── decaGraphicsMain.service
|
||||||
|
```
|
||||||
|
|
||||||
|
## Prerequisites
|
||||||
|
|
||||||
|
Before you begin, ensure you have met the following requirements:
|
||||||
|
|
||||||
|
* Node.js >= 10
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
**Download and install Node.js v10.x and npm.**
|
||||||
|
|
||||||
|
> Using Ubuntu
|
||||||
|
|
||||||
|
```sh
|
||||||
|
$ curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
|
||||||
|
$ sudo apt-get install -y nodejs
|
||||||
|
```
|
||||||
|
|
||||||
|
> Using Debian, as root
|
||||||
|
|
||||||
|
```sh
|
||||||
|
$ curl -sL https://deb.nodesource.com/setup_10.x | bash -
|
||||||
|
$ apt-get install -y nodejs
|
||||||
|
```
|
||||||
|
|
||||||
|
**Clone the repo, switch to decagraphics and run npm install**
|
||||||
|
|
||||||
|
```sh
|
||||||
|
$ git clone https://gitlab.com/deca-currency/decagraphics.git
|
||||||
|
$ cd decagraphics
|
||||||
|
$ npm install
|
||||||
|
```
|
||||||
|
|
||||||
|
> It's recommended to fix security vulnerabilities in dependencies using the command.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
$ npm audit fix
|
||||||
|
```
|
||||||
|
|
||||||
|
It is necessary to have installed mongodb locally in case of making a connection to another server modify the connection url of mongodb.
|
||||||
|
|
||||||
|
> Once the installation is done, it is necessary to create a database with three collections with the following names:
|
||||||
|
```sh
|
||||||
|
$ mongo
|
||||||
|
use DecaGraphics
|
||||||
|
db.createCollection("decaPrice")
|
||||||
|
db.createCollection("decaGeth")
|
||||||
|
db.createCollection("decaCCTS")
|
||||||
|
```
|
||||||
|
|
||||||
|
> After that it is necessary to set the environment variables in an .env file as in the example .envSample file.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
APIKEY=
|
||||||
|
USERDB=
|
||||||
|
PASSDB=
|
||||||
|
DBNAME=
|
||||||
|
INFURAKEY=
|
||||||
|
CONTRACTADDRS=
|
||||||
|
```
|
||||||
|
|
||||||
|
In both scripts it is necessary to set the variable 'dates' to the following date in unixtime from there the script will start to run the calculations automatically.
|
||||||
|
|
||||||
|
**Once everything is configured it is necessary to have ipfs running as a service the configuration can be found in [carboncreditsbacklog](https://gitlab.com/deca-currency/carboncreditsbacklog) as well connecting to the nodes mentioned there in order to replicate the orbitdb carbon credits database bd.**
|
||||||
|
|
||||||
|
> The scripts can be tested using node as well the service rest which will take the data from mongodb and expose it in a json format in order to do the calculations on the web page
|
||||||
|
|
||||||
|
```sh
|
||||||
|
$ node scriptMainNode.js
|
||||||
|
$ node index.js
|
||||||
|
```
|
||||||
|
|
||||||
|
To verify the data can be done from a browser taking into account the use of cors or from a bash.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
$ curl localhost:5000/decaPrice
|
||||||
|
$ curl localhost:5000/decaGeth
|
||||||
|
$ curl localhost:5000/decaCCTS
|
||||||
|
```
|
||||||
|
|
||||||
|
## Development
|
||||||
|
|
||||||
|
* The dependencies are already in the package.json
|
||||||
|
* Ethereum Node
|
||||||
|
* Bitcoinaverage Api
|
||||||
|
|
||||||
|
The rest service was made in express.js and cors was applied to accept only requests coming from deca.eco as well as helmet.js was used to give a better security to the application and the good practices of [express](https://expressjs.com/es/advanced/best-practice-security.html).
|
||||||
|
|
||||||
|
The main script is scriptMainNode.js performs the calculations found in the document [DECAAnalyticsETHPrice](./pdf/DECAAnalyticsETHPrice.pdf) the other script is backup and is used on another node in case the main one fails.
|
||||||
|
|
||||||
|
|
||||||
|
## Deploy
|
||||||
|
|
||||||
|
### Prerequisites
|
||||||
|
|
||||||
|
* Nginx >= 1.14.0
|
||||||
|
* Certbot >= 1.6
|
||||||
|
|
||||||
|
Install Nginx
|
||||||
|
|
||||||
|
```sh
|
||||||
|
$ sudo apt update
|
||||||
|
$ sudo apt install nginx
|
||||||
|
```
|
||||||
|
|
||||||
|
Install Certbot
|
||||||
|
|
||||||
|
```sh
|
||||||
|
$ sudo add-apt-repository ppa:certbot/certbot
|
||||||
|
```
|
||||||
|
|
||||||
|
> The script is configured as a service to be able to perform the calculations automatically. The configuration file is located in the service folder.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
$ sudo vim /etc/systemd/system/decaGraphics.service
|
||||||
|
[Unit]
|
||||||
|
Description=Deca Graphics Updater
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
WorkingDirectory=/home/nodemaster/decagraphics/
|
||||||
|
ExecStart=/usr/local/bin/node /home/nodemaster/decagraphics/scriptMainNode.js
|
||||||
|
User=nodemaster
|
||||||
|
Restart=always
|
||||||
|
LimitNOFILE=10240
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
```
|
||||||
|
|
||||||
|
**NOTE: in this example user that runs ipfs, node and orbitdb instance is nodemaster, also the node location is at /usr/local/bin/node**
|
||||||
|
|
||||||
|
**NOTE1: set WorkingDirectory where is the repository, for this example /home/nodemaster/decagraphics/**
|
||||||
|
|
||||||
|
**NOTE2: set where is index.js mostly in the repository as follow path to node path, for this example /home/nodemaster/decagraphics/scriptMainNode.js**
|
||||||
|
|
||||||
|
> Enable the service
|
||||||
|
|
||||||
|
```sh
|
||||||
|
$ sudo systemctl daemon-reload
|
||||||
|
$ sudo systemctl enable decaGraphics.service
|
||||||
|
$ sudo systemctl start decaGraphics.service
|
||||||
|
$ sudo systemctl status decaGraphics.service
|
||||||
|
```
|
||||||
|
**NOTE: service must be set as active (running), if not please verify the preview steps**
|
||||||
|
|
||||||
|
> It is possible to check in the service logs if any error occurred in the service.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
● graphicsDeca.service - Graphing Calculator
|
||||||
|
Loaded: loaded (/lib/systemd/system/graphicsDeca.service; enabled; vendor preset: enabled)
|
||||||
|
Active: active (running) since Thu 2020-07-23 17:18:50 UTC; 4h 23min ago
|
||||||
|
Main PID: 629182 (node)
|
||||||
|
Tasks: 12 (limit: 464185)
|
||||||
|
CGroup: /system.slice/graphicsDeca.service
|
||||||
|
└─629182 /usr/bin/node /home/nodemaster/decagraphics/scriptMainNode.js
|
||||||
|
|
||||||
|
Jul 23 21:40:02 icowebsrv node[629182]: zdpuAzCgWw1vAt8yKXFUR49uyhuD4W2jN4fKVmzwXwc9QvKzm
|
||||||
|
Jul 23 21:40:02 icowebsrv node[629182]: Insert decaPrice
|
||||||
|
Jul 23 21:40:02 icowebsrv node[629182]: zdpuB1YDWAcW9Ljq6WFo4HKXoaHRYKXfL1B9H4dMDRttcGzXF
|
||||||
|
Jul 23 21:40:02 icowebsrv node[629182]: Insert decaGeth
|
||||||
|
Jul 23 21:40:02 icowebsrv node[629182]: zdpuAwMn2mjAMAq9w2siJzi6wqc1W7rDi1fw61iuJdaUTnji8
|
||||||
|
Jul 23 21:40:02 icowebsrv node[629182]: Insert decaCCTS
|
||||||
|
```
|
||||||
|
|
||||||
|
Once the service is working properly it is necessary to configure the service subtract to be able to access the data from [deca.eco](https://deca.eco/).
|
||||||
|
|
||||||
|
In the nginx config add the proxy pass
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
```sh
|
||||||
|
$ vim /etc/nginx/conf.d/example.com.conf
|
||||||
|
server {
|
||||||
|
listen 80 default_server;
|
||||||
|
listen [::]:80 default_server;
|
||||||
|
server_name example.com www.example.com;
|
||||||
|
root /var/www/example.com;
|
||||||
|
index index.html;
|
||||||
|
try_files $uri /index.html;
|
||||||
|
location / {
|
||||||
|
proxy_pass http://localhost:5000;
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
|
proxy_set_header Connection 'upgrade';
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
proxy_cache_bypass $http_upgrade;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Remember to open the port in the firewall**
|
||||||
|
|
||||||
|
**Remember to leave the rest service running in a tmux session and check the port.**
|
||||||
|
|
||||||
|
**Now restart up Nginx!**
|
||||||
|
|
||||||
|
|
||||||
|
### Add SSL Certificate
|
||||||
|
|
||||||
|
```sh
|
||||||
|
$ sudo certbot --nginx -d api.deca.eco
|
||||||
|
```
|
||||||
|
|
||||||
|
**It is recommended to redirect all http traffic to https**
|
||||||
|
|
||||||
|
Finally renew the certificate with the following command and restart nginx
|
||||||
|
|
||||||
|
```sh
|
||||||
|
$ sudo certbot renew --dry-run
|
||||||
|
$ sudo service nginx restart
|
||||||
|
```
|
||||||
|
|
||||||
|
# Information and contacts.
|
||||||
|
|
||||||
|
***Developers***
|
||||||
|
- Jose [jose@deca.eco](mailto:jose@deca.eco)
|
|
@ -0,0 +1,58 @@
|
||||||
|
require('dotenv').config()
|
||||||
|
var helmet = require('helmet');
|
||||||
|
const MongoClient = require('mongodb').MongoClient;
|
||||||
|
const url = "mongodb://" + process.env.USERDB + ":" + encodeURIComponent(process.env.PASSDB) + "@localhost:27017/" + process.env.DBNAME
|
||||||
|
const express = require("express");
|
||||||
|
const app = express();
|
||||||
|
const cors = require('cors')
|
||||||
|
|
||||||
|
app.use(express.json());
|
||||||
|
app.use(cors({
|
||||||
|
origin: 'https://deca.eco',
|
||||||
|
methods: ['GET']
|
||||||
|
}));
|
||||||
|
app.use(helmet())
|
||||||
|
|
||||||
|
app.listen(5000, () => {
|
||||||
|
|
||||||
|
app.get('/decaPrice', async function (req, res) {
|
||||||
|
const dbm = await MongoClient.connect(url, {
|
||||||
|
useUnifiedTopology: true
|
||||||
|
}).catch(err => {
|
||||||
|
console.log(err);
|
||||||
|
});
|
||||||
|
var db = dbm.db("DECAGraphics");
|
||||||
|
db.collection("decaPrice").find({}).toArray(function (err, response) {
|
||||||
|
if (err) throw err;
|
||||||
|
res.json(response);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
app.get('/decaGeth', async function (req, res) {
|
||||||
|
const dbm = await MongoClient.connect(url, {
|
||||||
|
useUnifiedTopology: true
|
||||||
|
}).catch(err => {
|
||||||
|
console.log(err);
|
||||||
|
});
|
||||||
|
var db = dbm.db("DECAGraphics");
|
||||||
|
db.collection("decaGeth").find({}).toArray(function (err, response) {
|
||||||
|
if (err) throw err;
|
||||||
|
res.json(response);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
app.get('/decaCCTS', async function (req, res) {
|
||||||
|
const dbm = await MongoClient.connect(url, {
|
||||||
|
useUnifiedTopology: true
|
||||||
|
}).catch(err => {
|
||||||
|
console.log(err);
|
||||||
|
});
|
||||||
|
var db = dbm.db("DECAGraphics");
|
||||||
|
db.collection("decaCCTS").find({}).toArray(function (err, response) {
|
||||||
|
if (err) throw err;
|
||||||
|
res.json(response);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log("El servidor está inicializado en el puerto 5000");
|
||||||
|
});
|
21
package.json
21
package.json
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "scriptgraficas",
|
"name": "decagraphics",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "",
|
"description": "Script to generate and send data to show graphs in deca.eco",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
@ -15,6 +15,19 @@
|
||||||
"orbit-db": "^0.24.1",
|
"orbit-db": "^0.24.1",
|
||||||
"orbit-db-docstore": "^1.9.0",
|
"orbit-db-docstore": "^1.9.0",
|
||||||
"orbit-db-store": "^3.3.0",
|
"orbit-db-store": "^3.3.0",
|
||||||
"dotenv": "^8.2.0"
|
"body-parser": "^1.19.0",
|
||||||
}
|
"cors": "^2.8.5",
|
||||||
|
"dotenv": "^8.2.0",
|
||||||
|
"express": "^4.17.1",
|
||||||
|
"helmet": "^3.23.3",
|
||||||
|
"mongodb": "^3.5.9"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+ssh://git@gitlab.com:deca-currency/decagraphics.git"
|
||||||
|
},
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://gitlab.com/deca-currency/decagraphics/issues"
|
||||||
|
},
|
||||||
|
"homepage": "https://gitlab.com/deca-currency/decagraphics"
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
|
@ -1,13 +1,12 @@
|
||||||
//Load Environment Variables
|
//Load Environment Variables
|
||||||
require('dotenv').config()
|
require('dotenv').config()
|
||||||
|
|
||||||
//IPFS
|
//IPFS
|
||||||
const IpfsClient = require('ipfs-http-client');
|
const IpfsClient = require('ipfs-http-client');
|
||||||
const OrbitDB = require('orbit-db');
|
const OrbitDB = require('orbit-db');
|
||||||
//Instance of IPFS locally in IPFS daemon
|
//Instance of IPFS locally in IPFS daemon
|
||||||
const node = IpfsClient('http://localhost:5001');
|
const node = IpfsClient('http://localhost:5001');
|
||||||
const MongoClient = require('mongodb').MongoClient;
|
const MongoClient = require('mongodb').MongoClient;
|
||||||
const url = "mongodb://"+process.env.USERDB+":"+process.env.PASSDB+"@localhost:27017/"+process.env.DBNAME;
|
const url = "mongodb://" + process.env.USERDB + ":" + encodeURIComponent(process.env.PASSDB) + "@localhost:27017/" + process.env.DBNAME;
|
||||||
|
|
||||||
//Module for get prices
|
//Module for get prices
|
||||||
var getEth = require('./getEth');
|
var getEth = require('./getEth');
|
||||||
|
@ -20,86 +19,12 @@ const Web3 = require('web3');
|
||||||
const web3 = new Web3(new Web3.providers.WebsocketProvider(process.env.INFURAKEY));
|
const web3 = new Web3(new Web3.providers.WebsocketProvider(process.env.INFURAKEY));
|
||||||
|
|
||||||
//DECA Contract instance
|
//DECA Contract instance
|
||||||
const decaContract = new web3.eth.Contract(abi, '0xD60DC0805f44d10cAc6594f1a501c67929448957');
|
const decaContract = new web3.eth.Contract(abi, process.env.CONTRACTADDRS);
|
||||||
|
|
||||||
async function index() {
|
|
||||||
//Open and load orbitdb databases
|
|
||||||
const orbitdb = await OrbitDB.createInstance(node)
|
|
||||||
const db = await orbitdb.docs('/orbitdb/zdpuAykPJ4qtBg2toS2vxr5eaPfGEBJmvGerM7V7x8qn5c8hW/decaCCDB', {
|
|
||||||
indexBy: 'CCID'
|
|
||||||
});
|
|
||||||
await db.load();
|
|
||||||
const db2 = await orbitdb.docs('decaPrices', {
|
|
||||||
indexBy: 'dates'
|
|
||||||
});
|
|
||||||
await db2.load();
|
|
||||||
const db3 = await orbitdb.docs('decaGeth', {
|
|
||||||
indexBy: 'dates'
|
|
||||||
});
|
|
||||||
await db3.load();
|
|
||||||
const db4 = await orbitdb.docs('decaCCTS', {
|
|
||||||
indexBy: 'dates'
|
|
||||||
});
|
|
||||||
await db4.load();
|
|
||||||
const dbm = await MongoClient.connect(url, { useUnifiedTopology: true }).catch(err => { console.log(err); });
|
|
||||||
//Flag to save the following data
|
|
||||||
let dates = 1593553845;
|
|
||||||
while (true) {
|
|
||||||
//Get Carbon Credits Data
|
|
||||||
const data = db.get('');
|
|
||||||
//Compare flag and unixtime to add data
|
|
||||||
if (Math.round(new Date().getTime() / 1000) == dates) {
|
|
||||||
var dbo = dbm.db("DECA");
|
|
||||||
//Get data from functions
|
|
||||||
let elemsGeth = await getGethElems(dates);
|
|
||||||
let elemsDECAPrice = await getEth(dates);
|
|
||||||
let ccTotalEth = await getEthSum(data, dates);
|
|
||||||
//checks every 2 minutes to see if the data has already been inserted into the DBs if not
|
|
||||||
setTimeout(async function () {
|
|
||||||
const query1 = db2.query((doc) => doc.dates == dates);
|
|
||||||
const query2 = db3.query((doc) => doc.dates == dates);
|
|
||||||
const query3 = db4.query((doc) => doc.dates == dates);
|
|
||||||
dbo.collection("decaPrice").insertOne(elemsDECAPrice, function(err, res) {
|
|
||||||
if (err) throw err;
|
|
||||||
console.log("Insert decaPrice")
|
|
||||||
});
|
|
||||||
dbo.collection("decaGeth").insertOne(elemsGeth, function(err, res) {
|
|
||||||
if (err) throw err;
|
|
||||||
console.log("Insert decaGeth")
|
|
||||||
});
|
|
||||||
dbo.collection("decaCCTS").insertOne(ccTotalEth, function(err, res) {
|
|
||||||
if (err) throw err;
|
|
||||||
console.log("Insert decaCCTS")
|
|
||||||
});
|
|
||||||
if (query1.length > 0) {
|
|
||||||
let elemsDECAPrice = await getEth(dates);
|
|
||||||
const hash1 = await db2.put(elemsDECAPrice);
|
|
||||||
console.log(hash1);
|
|
||||||
}
|
|
||||||
if (query2.length > 0) {
|
|
||||||
let elemsGeth = await getGethElems(dates);
|
|
||||||
|
|
||||||
const hash2 = await db3.put(elemsGeth);
|
|
||||||
console.log(hash2);
|
|
||||||
}
|
|
||||||
if (query3.length > 0) {
|
|
||||||
let ccTotalEth = await getEthSum(data, dates);
|
|
||||||
|
|
||||||
const hash3 = await db4.put(ccTotalEth);
|
|
||||||
console.log(hash3);
|
|
||||||
}
|
|
||||||
dates += 60;
|
|
||||||
}, 10000);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
index();
|
|
||||||
|
|
||||||
//Function to save data from web3 and contract (ret TotalSupply, Ethereum, Date)
|
//Function to save data from web3 and contract (ret TotalSupply, Ethereum, Date)
|
||||||
const getGethElems = async (dates) => {
|
const getGethElems = async (dates) => {
|
||||||
let ret = {};
|
let ret = {};
|
||||||
var balanceEthereum = await web3.eth.getBalance('0xD60DC0805f44d10cAc6594f1a501c67929448957');
|
var balanceEthereum = await web3.eth.getBalance(process.env.CONTRACTADDRS);
|
||||||
var totalSupply = await decaContract.methods.totalSupply().call();
|
var totalSupply = await decaContract.methods.totalSupply().call();
|
||||||
totalSupply = web3.utils.fromWei(totalSupply, 'ether');
|
totalSupply = web3.utils.fromWei(totalSupply, 'ether');
|
||||||
balanceEthereum = web3.utils.fromWei(balanceEthereum, 'ether');
|
balanceEthereum = web3.utils.fromWei(balanceEthereum, 'ether');
|
||||||
|
@ -116,8 +41,6 @@ const getEthSum = async (elemsCC, dates) => {
|
||||||
let sumCC = 0;
|
let sumCC = 0;
|
||||||
for (let key in elemsCC) {
|
for (let key in elemsCC) {
|
||||||
sum += elemsCC[key]['conversionPrice']['ETH'];
|
sum += elemsCC[key]['conversionPrice']['ETH'];
|
||||||
}
|
|
||||||
for (let key in elemsCC) {
|
|
||||||
sumCC += 1;
|
sumCC += 1;
|
||||||
}
|
}
|
||||||
ret.ccTotal = sumCC;
|
ret.ccTotal = sumCC;
|
||||||
|
@ -125,3 +48,74 @@ const getEthSum = async (elemsCC, dates) => {
|
||||||
ret.dates = dates;
|
ret.dates = dates;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function index() {
|
||||||
|
//Open and load orbitdb databases
|
||||||
|
const orbitdb = await OrbitDB.createInstance(node)
|
||||||
|
const db = await orbitdb.docs('/orbitdb/zdpuAykPJ4qtBg2toS2vxr5eaPfGEBJmvGerM7V7x8qn5c8hW/decaCCDB', {
|
||||||
|
indexBy: 'CCID'
|
||||||
|
});
|
||||||
|
await db.load();
|
||||||
|
const db2 = await orbitdb.docs('/orbitdb/zdpuB1E3gfmmo17cFD2LEgxsjLzU9pxyW1q1Wde5TNL5QjiJG/decaPrice', {
|
||||||
|
indexBy: 'dates'
|
||||||
|
});
|
||||||
|
await db2.load();
|
||||||
|
const db3 = await orbitdb.docs('/orbitdb/zdpuB3ND1iK3NvYQx939ErZ2WXCaDoz4Lw3hazFUkdVupstBv/decaGeth', {
|
||||||
|
indexBy: 'dates'
|
||||||
|
});
|
||||||
|
await db3.load();
|
||||||
|
const db4 = await orbitdb.docs('/orbitdb/zdpuB2ZiX2QX8Qwwc1EXxo1y944tG6JcBk5UTLHm9b9Nv3Gna/decaCCTS', {
|
||||||
|
indexBy: 'dates'
|
||||||
|
});
|
||||||
|
await db4.load();
|
||||||
|
const dbm = await MongoClient.connect(url, {
|
||||||
|
useUnifiedTopology: true
|
||||||
|
}).catch(err => {
|
||||||
|
console.log(err);
|
||||||
|
});
|
||||||
|
//Flag to save the following data
|
||||||
|
let dates = 1594230300;
|
||||||
|
while (true) {
|
||||||
|
//Compare flag and unixtime to add data
|
||||||
|
if (Math.round(new Date().getTime() / 1000) == dates) {
|
||||||
|
var dbo = dbm.db(process.env.DBNAME);
|
||||||
|
//Get data from functions
|
||||||
|
const data = db.get('');
|
||||||
|
let elemsGeth = await getGethElems(dates);
|
||||||
|
let elemsDECAPrice = await getEth(dates);
|
||||||
|
let ccTotalEth = await getEthSum(data, dates);
|
||||||
|
//checks every 2 minutes to see if the data has already been inserted into the DBs if not
|
||||||
|
const query1 = db2.query((doc) => doc.dates == dates);
|
||||||
|
const query2 = db3.query((doc) => doc.dates == dates);
|
||||||
|
const query3 = db4.query((doc) => doc.dates == dates);
|
||||||
|
dbo.collection("decaPrice").insertOne(elemsDECAPrice, function (err, res) {
|
||||||
|
if (err) throw err;
|
||||||
|
console.log("Insert decaPrice")
|
||||||
|
});
|
||||||
|
dbo.collection("decaGeth").insertOne(elemsGeth, function (err, res) {
|
||||||
|
if (err) throw err;
|
||||||
|
console.log("Insert decaGeth")
|
||||||
|
});
|
||||||
|
dbo.collection("decaCCTS").insertOne(ccTotalEth, function (err, res) {
|
||||||
|
if (err) throw err;
|
||||||
|
console.log("Insert decaCCTS")
|
||||||
|
});
|
||||||
|
await new Promise(r => setTimeout(r, 180000));
|
||||||
|
if (query1.length > 0) {
|
||||||
|
const hash1 = await db2.put(elemsDECAPrice);
|
||||||
|
console.log(hash1);
|
||||||
|
}
|
||||||
|
if (query2.length > 0) {
|
||||||
|
const hash2 = await db3.put(elemsGeth);
|
||||||
|
console.log(hash2);
|
||||||
|
}
|
||||||
|
if (query3.length > 0) {
|
||||||
|
const hash3 = await db4.put(ccTotalEth);
|
||||||
|
console.log(hash3);
|
||||||
|
}
|
||||||
|
dates += 300;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
index();
|
|
@ -6,7 +6,7 @@ const OrbitDB = require('orbit-db');
|
||||||
//Instance of IPFS locally in IPFS daemon
|
//Instance of IPFS locally in IPFS daemon
|
||||||
const node = IpfsClient('http://localhost:5001');
|
const node = IpfsClient('http://localhost:5001');
|
||||||
const MongoClient = require('mongodb').MongoClient;
|
const MongoClient = require('mongodb').MongoClient;
|
||||||
const url = "mongodb://accountUser:Asd123456!@localhost:27017/DECA";
|
const url = "mongodb://" + process.env.USERDB + ":" + encodeURIComponent(process.env.PASSDB) + "@localhost:27017/" + process.env.DBNAME;
|
||||||
|
|
||||||
//Module for get prices
|
//Module for get prices
|
||||||
var getEth = require('./getEth');
|
var getEth = require('./getEth');
|
||||||
|
@ -19,81 +19,12 @@ const Web3 = require('web3');
|
||||||
const web3 = new Web3(new Web3.providers.WebsocketProvider(process.env.INFURAKEY));
|
const web3 = new Web3(new Web3.providers.WebsocketProvider(process.env.INFURAKEY));
|
||||||
|
|
||||||
//DECA Contract instance
|
//DECA Contract instance
|
||||||
const decaContract = new web3.eth.Contract(abi, '0xE453a11fC1925605638cC590897498375973D301');
|
const decaContract = new web3.eth.Contract(abi, process.env.CONTRACTADDRS);
|
||||||
|
|
||||||
async function index() {
|
|
||||||
//Open and load orbitdb databases
|
|
||||||
const orbitdb = await OrbitDB.createInstance(node)
|
|
||||||
const db = await orbitdb.docs('/orbitdb/zdpuAykPJ4qtBg2toS2vxr5eaPfGEBJmvGerM7V7x8qn5c8hW/decaCCDB', {
|
|
||||||
indexBy: 'CCID'
|
|
||||||
});
|
|
||||||
await db.load();
|
|
||||||
const db2 = await orbitdb.docs('decaPrice', {
|
|
||||||
indexBy: 'dates'
|
|
||||||
});
|
|
||||||
await db2.load();
|
|
||||||
const db3 = await orbitdb.docs('decaGeth', {
|
|
||||||
indexBy: 'dates'
|
|
||||||
});
|
|
||||||
await db3.load();
|
|
||||||
const db4 = await orbitdb.docs('decaCCTS', {
|
|
||||||
indexBy: 'dates'
|
|
||||||
});
|
|
||||||
await db4.load();
|
|
||||||
const dbm = await MongoClient.connect(url, { useUnifiedTopology: true })
|
|
||||||
.catch(err => { console.log(err); });
|
|
||||||
//Flag to save the following data
|
|
||||||
let dates = 1593552592;
|
|
||||||
while (true) {
|
|
||||||
//Compare flag and unixtime to add data
|
|
||||||
if (Math.round(new Date().getTime() / 1000) == dates) {
|
|
||||||
dates += 30;
|
|
||||||
//Get data from functions
|
|
||||||
var dbo = dbm.db("DECA");
|
|
||||||
try{
|
|
||||||
let elemsDECAPrice = await getEth(dates);
|
|
||||||
const hash1 = await db2.put(elemsDECAPrice);
|
|
||||||
dbo.collection("decaPrice").insertOne(elemsDECAPrice, function(err, res) {
|
|
||||||
if (err) throw err;
|
|
||||||
console.log("Insert decaPrice")
|
|
||||||
});
|
|
||||||
console.log(hash1);
|
|
||||||
}catch{
|
|
||||||
console.error("Error in DECA Prices");
|
|
||||||
}
|
|
||||||
try{
|
|
||||||
let elemsGeth = await getGethElems(dates);
|
|
||||||
const hash2 = await db3.put(elemsGeth);
|
|
||||||
dbo.collection("decaGeth").insertOne(elemsGeth, function(err, res) {
|
|
||||||
if (err) throw err;
|
|
||||||
console.log("Insert decaGeth")
|
|
||||||
});
|
|
||||||
console.log(hash2);
|
|
||||||
}catch{
|
|
||||||
console.error("Error in GETH");
|
|
||||||
}
|
|
||||||
try{
|
|
||||||
const data = await db.get('');
|
|
||||||
let ccTotalEth = await getEthSum(data, dates);
|
|
||||||
const hash3 = await db4.put(ccTotalEth);
|
|
||||||
dbo.collection("decaCCTS").insertOne(ccTotalEth, function(err, res) {
|
|
||||||
if (err) throw err;
|
|
||||||
console.log("Insert decaCCTS")
|
|
||||||
});
|
|
||||||
console.log(hash3);
|
|
||||||
}catch{
|
|
||||||
console.error("Error in CCDB")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
index();
|
|
||||||
|
|
||||||
//Function to save data from web3 and contract (ret TotalSupply, Ethereum, Date)
|
//Function to save data from web3 and contract (ret TotalSupply, Ethereum, Date)
|
||||||
const getGethElems = async (dates) => {
|
const getGethElems = async (dates) => {
|
||||||
let ret = {};
|
let ret = {};
|
||||||
var balanceEthereum = await web3.eth.getBalance('0xD60DC0805f44d10cAc6594f1a501c67929448957');
|
var balanceEthereum = await web3.eth.getBalance(process.env.CONTRACTADDRS);
|
||||||
var totalSupply = await decaContract.methods.totalSupply().call();
|
var totalSupply = await decaContract.methods.totalSupply().call();
|
||||||
totalSupply = web3.utils.fromWei(totalSupply, 'ether');
|
totalSupply = web3.utils.fromWei(totalSupply, 'ether');
|
||||||
balanceEthereum = web3.utils.fromWei(balanceEthereum, 'ether');
|
balanceEthereum = web3.utils.fromWei(balanceEthereum, 'ether');
|
||||||
|
@ -117,3 +48,80 @@ const getEthSum = async (elemsCC, dates) => {
|
||||||
ret.dates = dates;
|
ret.dates = dates;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function index() {
|
||||||
|
//Open and load orbitdb databases
|
||||||
|
const orbitdb = await OrbitDB.createInstance(node)
|
||||||
|
const db = await orbitdb.docs('/orbitdb/zdpuAykPJ4qtBg2toS2vxr5eaPfGEBJmvGerM7V7x8qn5c8hW/decaCCDB', {
|
||||||
|
indexBy: 'CCID'
|
||||||
|
});
|
||||||
|
await db.load();
|
||||||
|
const db2 = await orbitdb.docs('/orbitdb/zdpuB1E3gfmmo17cFD2LEgxsjLzU9pxyW1q1Wde5TNL5QjiJG/decaPrice', {
|
||||||
|
indexBy: 'dates'
|
||||||
|
});
|
||||||
|
await db2.load();
|
||||||
|
const db3 = await orbitdb.docs('/orbitdb/zdpuB3ND1iK3NvYQx939ErZ2WXCaDoz4Lw3hazFUkdVupstBv/decaGeth', {
|
||||||
|
indexBy: 'dates'
|
||||||
|
});
|
||||||
|
await db3.load();
|
||||||
|
const db4 = await orbitdb.docs('/orbitdb/zdpuB2ZiX2QX8Qwwc1EXxo1y944tG6JcBk5UTLHm9b9Nv3Gna/decaCCTS', {
|
||||||
|
indexBy: 'dates'
|
||||||
|
});
|
||||||
|
await db4.load();
|
||||||
|
const dbm = await MongoClient.connect(url, {
|
||||||
|
useUnifiedTopology: true
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.log(err);
|
||||||
|
});
|
||||||
|
//Flag to save the following data
|
||||||
|
let dates = 1595524800;
|
||||||
|
while (true) {
|
||||||
|
//Compare flag and unixtime to add data
|
||||||
|
if (Math.round(new Date().getTime() / 1000) == dates) {
|
||||||
|
dates += 300;
|
||||||
|
//Get data from functions
|
||||||
|
var dbo = dbm.db(process.env.DBNAME);
|
||||||
|
try {
|
||||||
|
let elemsDECAPrice = await getEth(dates);
|
||||||
|
const hash1 = await db2.put(elemsDECAPrice);
|
||||||
|
dbo.collection("decaPrice").insertOne(elemsDECAPrice, function (err, res) {
|
||||||
|
if (err) throw err;
|
||||||
|
console.log("Insert decaPrice")
|
||||||
|
});
|
||||||
|
console.log(hash1);
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
console.error("Error in DECA Prices");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
let elemsGeth = await getGethElems(dates);
|
||||||
|
console.log(elemsGeth)
|
||||||
|
const hash2 = await db3.put(elemsGeth);
|
||||||
|
dbo.collection("decaGeth").insertOne(elemsGeth, function (err, res) {
|
||||||
|
if (err) throw err;
|
||||||
|
console.log("Insert decaGeth")
|
||||||
|
});
|
||||||
|
console.log(hash2);
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
console.error("Error in GETH");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const data = await db.get('');
|
||||||
|
let ccTotalEth = await getEthSum(data, dates);
|
||||||
|
const hash3 = await db4.put(ccTotalEth);
|
||||||
|
dbo.collection("decaCCTS").insertOne(ccTotalEth, function (err, res) {
|
||||||
|
if (err) throw err;
|
||||||
|
console.log("Insert decaCCTS")
|
||||||
|
});
|
||||||
|
console.log(hash3);
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
console.error("Error in CCDB")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
index();
|
|
@ -0,0 +1,12 @@
|
||||||
|
[Unit]
|
||||||
|
Description=Deca Graphics Updater
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
WorkingDirectory=/home/nodemaster/decagraphics/
|
||||||
|
ExecStart=/usr/local/bin/node /home/nodemaster/decagraphics/scriptChildNode.js
|
||||||
|
User=nodemaster
|
||||||
|
Restart=always
|
||||||
|
LimitNOFILE=10240
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
|
@ -0,0 +1,12 @@
|
||||||
|
[Unit]
|
||||||
|
Description=Deca Graphics Updater
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
WorkingDirectory=/home/nodemaster/decagraphics/
|
||||||
|
ExecStart=/usr/local/bin/node /home/nodemaster/decagraphics/scriptMainNode.js
|
||||||
|
User=nodemaster
|
||||||
|
Restart=always
|
||||||
|
LimitNOFILE=10240
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
Loading…
Reference in New Issue