From 28ca1186b55bc35fbd1c40f4f4a3661918904054 Mon Sep 17 00:00:00 2001 From: Onuwa Nnachi Isaac Date: Wed, 24 Apr 2019 12:56:08 +0100 Subject: [PATCH 1/6] Update dependencies --- package.json | 2 +- yarn.lock | 31 +++---------------------------- 2 files changed, 4 insertions(+), 29 deletions(-) diff --git a/package.json b/package.json index 598e416..82fc3f0 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,6 @@ "dependencies": { "ethereumjs-tx": "^1.3.7", "truffle-contract": "^4.0.12", - "web3": "^0.20.7" + "web3": "^1.0.0-beta.37" } } diff --git a/yarn.lock b/yarn.lock index 2601280..009f016 100644 --- a/yarn.lock +++ b/yarn.lock @@ -113,10 +113,6 @@ bignumber.js@^7.2.1: resolved "https://registry.yarnpkg.com/bignumber.js/-/bignumber.js-7.2.1.tgz#80c048759d826800807c4bfd521e50edbba57a5f" integrity sha512-S4XzBk5sMB+Rcb/LNcpzXr57VRTxgAvaAEDAl1AwRx27j00hT84O6OkteE7u8UB3NuaaygCRrEpqox4uDOrbdQ== -"bignumber.js@git+https://github.com/frozeman/bignumber.js-nolookahead.git": - version "2.0.7" - resolved "git+https://github.com/frozeman/bignumber.js-nolookahead.git#57692b3ecfc98bbdd6b3a516cb2353652ea49934" - bindings@^1.2.1: version "1.5.0" resolved "https://registry.yarnpkg.com/bindings/-/bindings-1.5.0.tgz#10353c9e945334bc0511a6d90b38fbc7c9c504df" @@ -429,11 +425,6 @@ crypto-browserify@3.12.0: randombytes "^2.0.0" randomfill "^1.0.3" -crypto-js@^3.1.4: - version "3.1.8" - resolved "https://registry.yarnpkg.com/crypto-js/-/crypto-js-3.1.8.tgz#715f070bf6014f2ae992a98b3929258b713f08d5" - integrity sha1-cV8HC/YBTyrpkqmLOSkli3E/CNU= - crypto-js@^3.1.9-1: version "3.1.9-1" resolved "https://registry.yarnpkg.com/crypto-js/-/crypto-js-3.1.9-1.tgz#fda19e761fc077e01ffbfdc6e9fdfc59e8806cd8" @@ -2193,11 +2184,6 @@ utf8@2.1.1: resolved "https://registry.yarnpkg.com/utf8/-/utf8-2.1.1.tgz#2e01db02f7d8d0944f77104f1609eb0c304cf768" integrity sha1-LgHbAvfY0JRPdxBPFgnrDDBM92g= -utf8@^2.1.1: - version "2.1.2" - resolved "https://registry.yarnpkg.com/utf8/-/utf8-2.1.2.tgz#1fa0d9270e9be850d9b05027f63519bf46457d96" - integrity sha1-H6DZJw6b6FDZsFAn9jUZv0ZFfZY= - util-deprecate@~1.0.1: version "1.0.2" resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf" @@ -2448,7 +2434,7 @@ web3-utils@1.0.0-beta.37: underscore "1.8.3" utf8 "2.1.1" -web3@1.0.0-beta.37: +web3@1.0.0-beta.37, web3@^1.0.0-beta.37: version "1.0.0-beta.37" resolved "https://registry.yarnpkg.com/web3/-/web3-1.0.0-beta.37.tgz#b42c30e67195f816cd19d048fda872f70eca7083" integrity sha512-8XLgUspdzicC/xHG82TLrcF/Fxzj2XYNJ1KTYnepOI77bj5rvpsxxwHYBWQ6/JOjk0HkZqoBfnXWgcIHCDhZhQ== @@ -2461,17 +2447,6 @@ web3@1.0.0-beta.37: web3-shh "1.0.0-beta.37" web3-utils "1.0.0-beta.37" -web3@^0.20.7: - version "0.20.7" - resolved "https://registry.yarnpkg.com/web3/-/web3-0.20.7.tgz#1605e6d81399ed6f85a471a4f3da0c8be57df2f7" - integrity sha512-VU6/DSUX93d1fCzBz7WP/SGCQizO1rKZi4Px9j/3yRyfssHyFcZamMw2/sj4E8TlfMXONvZLoforR8B4bRoyTQ== - dependencies: - bignumber.js "git+https://github.com/frozeman/bignumber.js-nolookahead.git" - crypto-js "^3.1.4" - utf8 "^2.1.1" - xhr2-cookies "^1.1.0" - xmlhttprequest "*" - "websocket@git://github.com/frozeman/WebSocket-Node.git#browserifyCompatible": version "1.0.26" resolved "git://github.com/frozeman/WebSocket-Node.git#6c72925e3f8aaaea8dc8450f97627e85263999f2" @@ -2515,7 +2490,7 @@ xhr-request@^1.0.1: url-set-query "^1.0.0" xhr "^2.0.4" -xhr2-cookies@1.1.0, xhr2-cookies@^1.1.0: +xhr2-cookies@1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/xhr2-cookies/-/xhr2-cookies-1.1.0.tgz#7d77449d0999197f155cb73b23df72505ed89d48" integrity sha1-fXdEnQmZGX8VXLc7I99yUF7YnUg= @@ -2532,7 +2507,7 @@ xhr@^2.0.4, xhr@^2.3.3: parse-headers "^2.0.0" xtend "^4.0.0" -xmlhttprequest@*, xmlhttprequest@1.8.0: +xmlhttprequest@1.8.0: version "1.8.0" resolved "https://registry.yarnpkg.com/xmlhttprequest/-/xmlhttprequest-1.8.0.tgz#67fe075c5c24fef39f9d65f5f7b7fe75171968fc" integrity sha1-Z/4HXFwk/vOfnWX197f+dRcZaPw= From c1a678fbf8669ed78d08697d4ad859f6cb554751 Mon Sep 17 00:00:00 2001 From: Onuwa Nnachi Isaac Date: Fri, 26 Apr 2019 14:11:29 +0100 Subject: [PATCH 2/6] Update contract --- build/contracts/abi.json | 648 ++++++++++++++++-------------- contracts/Migrations.sol | 24 -- contracts/Ribbon.sol | 185 --------- migrations/1_initial_migration.js | 5 - migrations/2_deploy_contract.js | 5 - 5 files changed, 345 insertions(+), 522 deletions(-) delete mode 100644 contracts/Migrations.sol delete mode 100644 contracts/Ribbon.sol delete mode 100644 migrations/1_initial_migration.js delete mode 100644 migrations/2_deploy_contract.js diff --git a/build/contracts/abi.json b/build/contracts/abi.json index 995d517..9d5a10a 100644 --- a/build/contracts/abi.json +++ b/build/contracts/abi.json @@ -1,304 +1,346 @@ [ - { - "constant": false, - "inputs": [ - { - "name": "token", - "type": "address" - }, - { - "name": "tokens", - "type": "uint256" - } - ], - "name": "recoverTokens", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "_minimumFee", - "type": "uint256" - } - ], - "name": "setMinimumFee", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "minimumFee", - "outputs": [ - { - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "numberOfChildren", - "outputs": [ - { - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "name": "", - "type": "uint256" - } - ], - "name": "children", - "outputs": [ - { - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": false, - "inputs": [], - "name": "acceptOwnership", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "owner", - "outputs": [ - { - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "newAddress", - "outputs": [ - { - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "symbol", - "type": "string" - }, - { - "name": "name", - "type": "string" - }, - { - "name": "decimals", - "type": "uint8" - }, - { - "name": "totalSupply", - "type": "uint256" - } - ], - "name": "deployTokenContract", - "outputs": [ - { - "name": "token", - "type": "address" - } - ], - "payable": true, - "stateMutability": "payable", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "newOwner", - "outputs": [ - { - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "_newAddress", - "type": "address" - } - ], - "name": "deprecateFactory", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "_newOwner", - "type": "address" - } - ], - "name": "transferOwnership", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "name": "", - "type": "address" - } - ], - "name": "isChild", - "outputs": [ - { - "name": "", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "constructor" - }, - { - "payable": true, - "stateMutability": "payable", - "type": "fallback" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "name": "_newAddress", - "type": "address" - } - ], - "name": "FactoryDeprecated", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "name": "oldFee", - "type": "uint256" - }, - { - "indexed": false, - "name": "newFee", - "type": "uint256" - } - ], - "name": "MinimumFeeUpdated", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "name": "owner", - "type": "address" - }, - { - "indexed": true, - "name": "token", - "type": "address" - }, - { - "indexed": false, - "name": "symbol", - "type": "string" - }, - { - "indexed": false, - "name": "name", - "type": "string" - }, - { - "indexed": false, - "name": "decimals", - "type": "uint8" - }, - { - "indexed": false, - "name": "totalSupply", - "type": "uint256" - } - ], - "name": "TokenDeployed", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "name": "_from", - "type": "address" - }, - { - "indexed": true, - "name": "_to", - "type": "address" - } - ], - "name": "OwnershipTransferred", - "type": "event" - } -] \ No newline at end of file + { + "constant": false, + "inputs": [], + "name": "acceptOwnership", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "spender", + "type": "address" + }, + { + "name": "tokens", + "type": "uint256" + } + ], + "name": "approve", + "outputs": [ + { + "name": "success", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "spender", + "type": "address" + }, + { + "name": "tokens", + "type": "uint256" + }, + { + "name": "data", + "type": "bytes" + } + ], + "name": "approveAndCall", + "outputs": [ + { + "name": "success", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "to", + "type": "address" + }, + { + "name": "tokens", + "type": "uint256" + } + ], + "name": "transfer", + "outputs": [ + { + "name": "success", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "tokenAddress", + "type": "address" + }, + { + "name": "tokens", + "type": "uint256" + } + ], + "name": "transferAnyERC20Token", + "outputs": [ + { + "name": "success", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "from", + "type": "address" + }, + { + "name": "to", + "type": "address" + }, + { + "name": "tokens", + "type": "uint256" + } + ], + "name": "transferFrom", + "outputs": [ + { + "name": "success", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "_newOwner", + "type": "address" + } + ], + "name": "transferOwnership", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "payable": true, + "stateMutability": "payable", + "type": "fallback" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "name": "_from", + "type": "address" + }, + { + "indexed": true, + "name": "_to", + "type": "address" + } + ], + "name": "OwnershipTransferred", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "name": "from", + "type": "address" + }, + { + "indexed": true, + "name": "to", + "type": "address" + }, + { + "indexed": false, + "name": "tokens", + "type": "uint256" + } + ], + "name": "Transfer", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "name": "tokenOwner", + "type": "address" + }, + { + "indexed": true, + "name": "spender", + "type": "address" + }, + { + "indexed": false, + "name": "tokens", + "type": "uint256" + } + ], + "name": "Approval", + "type": "event" + }, + { + "constant": true, + "inputs": [ + { + "name": "tokenOwner", + "type": "address" + }, + { + "name": "spender", + "type": "address" + } + ], + "name": "allowance", + "outputs": [ + { + "name": "remaining", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "name": "tokenOwner", + "type": "address" + } + ], + "name": "balanceOf", + "outputs": [ + { + "name": "balance", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "decimals", + "outputs": [ + { + "name": "", + "type": "uint8" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "name", + "outputs": [ + { + "name": "", + "type": "string" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "newOwner", + "outputs": [ + { + "name": "", + "type": "address" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "owner", + "outputs": [ + { + "name": "", + "type": "address" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "symbol", + "outputs": [ + { + "name": "", + "type": "string" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "totalSupply", + "outputs": [ + { + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + } +] diff --git a/contracts/Migrations.sol b/contracts/Migrations.sol deleted file mode 100644 index b5210a6..0000000 --- a/contracts/Migrations.sol +++ /dev/null @@ -1,24 +0,0 @@ - -pragma solidity ^0.5.0; - -contract Migrations { - address public owner; - uint public last_completed_migration; - - constructor() public { - owner = msg.sender; - } - - modifier restricted() { - if (msg.sender == owner) _; - } - - function setCompleted(uint completed) public restricted { - last_completed_migration = completed; - } - - function upgrade(address new_address) public restricted { - Migrations upgraded = Migrations(new_address); - upgraded.setCompleted(last_completed_migration); - } -} \ No newline at end of file diff --git a/contracts/Ribbon.sol b/contracts/Ribbon.sol deleted file mode 100644 index a0735f1..0000000 --- a/contracts/Ribbon.sol +++ /dev/null @@ -1,185 +0,0 @@ -pragma solidity ^0.5.0; -// ---------------------------------------------------------------------------- -// 'RBN' 'Ribbon Token' token contract -// -// Symbol : RBN -// Name : Ribbon Token -// Total supply: 1,000,000.000000000000000000 -// Decimals : 18 -// -// Enjoy. -// -// ---------------------------------------------------------------------------- -// ---------------------------------------------------------------------------- -// Safe maths -// ---------------------------------------------------------------------------- -library SafeMath { - function add(uint a, uint b) internal pure returns (uint c) { - c = a + b; - require(c >= a); - } - function sub(uint a, uint b) internal pure returns (uint c) { - require(b <= a); - c = a - b; - } - function mul(uint a, uint b) internal pure returns (uint c) { - c = a * b; - require(a == 0 || c / a == b); - } - function div(uint a, uint b) internal pure returns (uint c) { - require(b > 0); - c = a / b; - } -} -// ---------------------------------------------------------------------------- -// ERC Token Standard #20 Interface -// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md -// ---------------------------------------------------------------------------- -contract ERC20Interface { - function totalSupply() public view returns (uint); - function balanceOf(address tokenOwner) public view returns (uint balance); - function allowance(address tokenOwner, address spender) public view returns (uint remaining); - function transfer(address to, uint tokens) public returns (bool success); - function approve(address spender, uint tokens) public returns (bool success); - function transferFrom(address from, address to, uint tokens) public returns (bool success); - event Transfer(address indexed from, address indexed to, uint tokens); - event Approval(address indexed tokenOwner, address indexed spender, uint tokens); -} -// ---------------------------------------------------------------------------- -// Contract function to receive approval and execute function in one call -// -// Borrowed from MiniMeToken -// ---------------------------------------------------------------------------- -contract ApproveAndCallFallBack { - function receiveApproval(address from, uint256 tokens, address token, bytes memory data) public; -} -// ---------------------------------------------------------------------------- -// Owned contract -// ---------------------------------------------------------------------------- -contract Owned { - address public owner; - address public newOwner; - event OwnershipTransferred(address indexed _from, address indexed _to); - constructor() public { - owner = msg.sender; - } - modifier onlyOwner { - require(msg.sender == owner); - _; - } - function transferOwnership(address _newOwner) public onlyOwner { - newOwner = _newOwner; - } - function acceptOwnership() public { - require(msg.sender == newOwner); - emit OwnershipTransferred(owner, newOwner); - owner = newOwner; - newOwner = address(0); - } -} -// ---------------------------------------------------------------------------- -// ERC20 Token, with the addition of symbol, name and decimals and a -// fixed supply -// ---------------------------------------------------------------------------- -contract FixedSupplyToken is ERC20Interface, Owned { - using SafeMath for uint; - string public symbol; - string public name; - uint8 public decimals; - uint _totalSupply; - mapping(address => uint) balances; - mapping(address => mapping(address => uint)) allowed; - // ------------------------------------------------------------------------ - // Constructor - // ------------------------------------------------------------------------ - constructor() public { - symbol = "RBN"; - name = "Ribbon Token"; - decimals = 18; - _totalSupply = 1000000 * 10**uint(decimals); - balances[owner] = _totalSupply; - emit Transfer(address(0), owner, _totalSupply); - } - // ------------------------------------------------------------------------ - // Total supply - // ------------------------------------------------------------------------ - function totalSupply() public view returns (uint) { - return _totalSupply.sub(balances[address(0)]); - } - // ------------------------------------------------------------------------ - // Get the token balance for account `tokenOwner` - // ------------------------------------------------------------------------ - function balanceOf(address tokenOwner) public view returns (uint balance) { - return balances[tokenOwner]; - } - // ------------------------------------------------------------------------ - // Transfer the balance from token owner's account to `to` account - // - Owner's account must have sufficient balance to transfer - // - 0 value transfers are allowed - // ------------------------------------------------------------------------ - function transfer(address to, uint tokens) public returns (bool success) { - balances[msg.sender] = balances[msg.sender].sub(tokens); - balances[to] = balances[to].add(tokens); - emit Transfer(msg.sender, to, tokens); - return true; - } - // ------------------------------------------------------------------------ - // Token owner can approve for `spender` to transferFrom(...) `tokens` - // from the token owner's account - // - // https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md - // recommends that there are no checks for the approval double-spend attack - // as this should be implemented in user interfaces - // ------------------------------------------------------------------------ - function approve(address spender, uint tokens) public returns (bool success) { - allowed[msg.sender][spender] = tokens; - emit Approval(msg.sender, spender, tokens); - return true; - } - // ------------------------------------------------------------------------ - // Transfer `tokens` from the `from` account to the `to` account - // - // The calling account must already have sufficient tokens approve(...)-d - // for spending from the `from` account and - // - From account must have sufficient balance to transfer - // - Spender must have sufficient allowance to transfer - // - 0 value transfers are allowed - // ------------------------------------------------------------------------ - function transferFrom(address from, address to, uint tokens) public returns (bool success) { - balances[from] = balances[from].sub(tokens); - allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens); - balances[to] = balances[to].add(tokens); - emit Transfer(from, to, tokens); - return true; - } - // ------------------------------------------------------------------------ - // Returns the amount of tokens approved by the owner that can be - // transferred to the spender's account - // ------------------------------------------------------------------------ - function allowance(address tokenOwner, address spender) public view returns (uint remaining) { - return allowed[tokenOwner][spender]; - } - // ------------------------------------------------------------------------ - // Token owner can approve for `spender` to transferFrom(...) `tokens` - // from the token owner's account. The `spender` contract function - // `receiveApproval(...)` is then executed - // ------------------------------------------------------------------------ - function approveAndCall(address spender, uint tokens, bytes memory data) public returns (bool success) { - allowed[msg.sender][spender] = tokens; - emit Approval(msg.sender, spender, tokens); - ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, address(this), data); - return true; - } - // ------------------------------------------------------------------------ - // Don't accept ETH - // ------------------------------------------------------------------------ - function () external payable { - revert(); - } - // ------------------------------------------------------------------------ - // Owner can transfer out any accidentally sent ERC20 tokens - // ------------------------------------------------------------------------ - function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) { - return ERC20Interface(tokenAddress).transfer(owner, tokens); - } -} diff --git a/migrations/1_initial_migration.js b/migrations/1_initial_migration.js deleted file mode 100644 index ee2135d..0000000 --- a/migrations/1_initial_migration.js +++ /dev/null @@ -1,5 +0,0 @@ -const Migrations = artifacts.require("Migrations"); - -module.exports = function(deployer) { - deployer.deploy(Migrations); -}; diff --git a/migrations/2_deploy_contract.js b/migrations/2_deploy_contract.js deleted file mode 100644 index d19620e..0000000 --- a/migrations/2_deploy_contract.js +++ /dev/null @@ -1,5 +0,0 @@ -let RibbonIncentivesContract = require("../contracts/Ribbon.sol"); - -module.exports = function(deployer) { - deployer.deploy(RibbonIncentivesContract); -}; \ No newline at end of file From c46d2704010e854b686aef03d78a48f72bfbeeb2 Mon Sep 17 00:00:00 2001 From: Onuwa Nnachi Isaac Date: Fri, 26 Apr 2019 14:11:44 +0100 Subject: [PATCH 3/6] Install deps --- package.json | 5 ++ yarn.lock | 212 +++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 210 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 82fc3f0..dcc0cbe 100644 --- a/package.json +++ b/package.json @@ -4,8 +4,13 @@ "main": "index.js", "license": "MIT", "dependencies": { + "aws-sdk": "^2.442.0", + "dynogels": "^9.0.0", "ethereumjs-tx": "^1.3.7", + "joi": "^14.3.1", + "lodash": "^4.17.11", "truffle-contract": "^4.0.12", + "uuid": "^3.3.2", "web3": "^1.0.0-beta.37" } } diff --git a/yarn.lock b/yarn.lock index 009f016..7ef4b64 100644 --- a/yarn.lock +++ b/yarn.lock @@ -76,11 +76,49 @@ async-limiter@~1.0.0: resolved "https://registry.yarnpkg.com/async-limiter/-/async-limiter-1.0.0.tgz#78faed8c3d074ab81f22b4e985d79e8738f720f8" integrity sha512-jp/uFnooOiO+L211eZOoSyzpOITMXx1rBITauYykG3BRYPu8h0UcxsPNB04RR5vo4Tyz3+ay17tR6JVf9qzYWg== +async@2.5.0: + version "2.5.0" + resolved "https://registry.yarnpkg.com/async/-/async-2.5.0.tgz#843190fd6b7357a0b9e1c956edddd5ec8462b54d" + integrity sha512-e+lJAJeNWuPCNyxZKOBdaJGyLGHugXVQtrAwtuAe2vhxTYxFTKE73p8JuTmdH0qdQZtDvI4dhJwjZc5zsfIsYw== + dependencies: + lodash "^4.14.0" + asynckit@^0.4.0: version "0.4.0" resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79" integrity sha1-x57Zf380y48robyXkLzDZkdLS3k= +aws-sdk@2.131.0: + version "2.131.0" + resolved "https://registry.yarnpkg.com/aws-sdk/-/aws-sdk-2.131.0.tgz#5b213fa493ce36a88130b50bef0e9a0cb6cd9f72" + integrity sha1-WyE/pJPONqiBMLUL7w6aDLbNn3I= + dependencies: + buffer "4.9.1" + crypto-browserify "1.0.9" + events "^1.1.1" + jmespath "0.15.0" + querystring "0.2.0" + sax "1.2.1" + url "0.10.3" + uuid "3.1.0" + xml2js "0.4.17" + xmlbuilder "4.2.1" + +aws-sdk@^2.442.0: + version "2.442.0" + resolved "https://registry.yarnpkg.com/aws-sdk/-/aws-sdk-2.442.0.tgz#2b6848bbdcb53d1e7f955a7c7149072192ca4195" + integrity sha512-1KWya47PNEKJiIRQ4l3B+31gSwfaxa+1ow/o8HMmUAQl7wM5SDotUz+v6y2e08R4sL3u7UN+DWMkhg1itpYZIQ== + dependencies: + buffer "4.9.1" + events "1.1.1" + ieee754 "1.1.8" + jmespath "0.15.0" + querystring "0.2.0" + sax "1.2.1" + url "0.10.3" + uuid "3.3.2" + xml2js "0.4.19" + aws-sign2@~0.7.0: version "0.7.0" resolved "https://registry.yarnpkg.com/aws-sign2/-/aws-sign2-0.7.0.tgz#b46e890934a9591f2d2f6f86d7e6a9f1b3fe76a8" @@ -284,6 +322,15 @@ buffer-xor@^1.0.3: resolved "https://registry.yarnpkg.com/buffer-xor/-/buffer-xor-1.0.3.tgz#26e61ed1422fb70dd42e6e36729ed51d855fe8d9" integrity sha1-JuYe0UIvtw3ULm42cp7VHYVf6Nk= +buffer@4.9.1: + version "4.9.1" + resolved "https://registry.yarnpkg.com/buffer/-/buffer-4.9.1.tgz#6d1bb601b07a4efced97094132093027c95bc298" + integrity sha1-bRu2AbB6TvztlwlBMgkwJ8lbwpg= + dependencies: + base64-js "^1.0.2" + ieee754 "^1.1.4" + isarray "^1.0.0" + buffer@^5.0.5, buffer@^5.2.1: version "5.2.1" resolved "https://registry.yarnpkg.com/buffer/-/buffer-5.2.1.tgz#dd57fa0f109ac59c602479044dca7b8b3d0b71d6" @@ -408,6 +455,11 @@ create-hmac@^1.1.0, create-hmac@^1.1.2, create-hmac@^1.1.4: safe-buffer "^5.0.1" sha.js "^2.4.8" +crypto-browserify@1.0.9: + version "1.0.9" + resolved "https://registry.yarnpkg.com/crypto-browserify/-/crypto-browserify-1.0.9.tgz#cc5449685dfb85eb11c9828acc7cb87ab5bbfcc0" + integrity sha1-zFRJaF37hesRyYKKzHy4erW7/MA= + crypto-browserify@3.12.0: version "3.12.0" resolved "https://registry.yarnpkg.com/crypto-browserify/-/crypto-browserify-3.12.0.tgz#396cf9f3137f03e4b8e532c58f698254e00f80ec" @@ -574,6 +626,17 @@ duplexer3@^0.1.4: resolved "https://registry.yarnpkg.com/duplexer3/-/duplexer3-0.1.4.tgz#ee01dd1cac0ed3cbc7fdbea37dc0a8f1ce002ce2" integrity sha1-7gHdHKwO08vH/b6jfcCo8c4ALOI= +dynogels@^9.0.0: + version "9.0.0" + resolved "https://registry.yarnpkg.com/dynogels/-/dynogels-9.0.0.tgz#cb863764647dfd027afeb9be20bc5082423d5125" + integrity sha1-y4Y3ZGR9/QJ6/rm+ILxQgkI9USU= + dependencies: + async "2.5.0" + aws-sdk "2.131.0" + joi "11.3.4" + lodash "4.17.4" + uuid "3.1.0" + ecc-jsbn@~0.1.1: version "0.1.2" resolved "https://registry.yarnpkg.com/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz#3a83a904e54353287874c564b7549386849a98c9" @@ -762,6 +825,11 @@ eventemitter3@1.1.1: resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-1.1.1.tgz#47786bdaa087caf7b1b75e73abc5c7d540158cd0" integrity sha1-R3hr2qCHyvext15zq8XH1UAVjNA= +events@1.1.1, events@^1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/events/-/events-1.1.1.tgz#9ebdb7635ad099c70dcc4c2a1f5004288e8bd924" + integrity sha1-nr23Y1rQmccNzEwqH1AEKI6L2SQ= + evp_bytestokey@^1.0.0, evp_bytestokey@^1.0.3: version "1.0.3" resolved "https://registry.yarnpkg.com/evp_bytestokey/-/evp_bytestokey-1.0.3.tgz#7fcbdb198dc71959432efe13842684e0525acb02" @@ -1090,6 +1158,16 @@ hmac-drbg@^1.0.0: minimalistic-assert "^1.0.0" minimalistic-crypto-utils "^1.0.1" +hoek@4.x.x: + version "4.2.1" + resolved "https://registry.yarnpkg.com/hoek/-/hoek-4.2.1.tgz#9634502aa12c445dd5a7c5734b572bb8738aacbb" + integrity sha512-QLg82fGkfnJ/4iy1xZ81/9SIJiq1NGFUMGs6ParyjBZr6jW2Ufj/snDqTHixNlHdPNwN2RLVD0Pi3igeK9+JfA== + +hoek@6.x.x: + version "6.1.3" + resolved "https://registry.yarnpkg.com/hoek/-/hoek-6.1.3.tgz#73b7d33952e01fe27a38b0457294b79dd8da242c" + integrity sha512-YXXAAhmF9zpQbC7LEcREFtXfGq5K1fmd+4PHkBq8NUqmzW3G+Dq10bI/i0KucLRwss3YYFQ0fSfoxBZYiGUqtQ== + http-errors@1.6.3, http-errors@~1.6.2, http-errors@~1.6.3: version "1.6.3" resolved "https://registry.yarnpkg.com/http-errors/-/http-errors-1.6.3.tgz#8b55680bb4be283a0b5bf4ea2e38580be1d9320d" @@ -1128,6 +1206,11 @@ idna-uts46-hx@^2.3.1: dependencies: punycode "2.1.0" +ieee754@1.1.8: + version "1.1.8" + resolved "https://registry.yarnpkg.com/ieee754/-/ieee754-1.1.8.tgz#be33d40ac10ef1926701f6f08a2d86fbfd1ad3e4" + integrity sha1-vjPUCsEO8ZJnAfbwii2G+/0a0+Q= + ieee754@^1.1.4: version "1.1.13" resolved "https://registry.yarnpkg.com/ieee754/-/ieee754-1.1.13.tgz#ec168558e95aa181fd87d37f55c32bbcb6708b84" @@ -1215,11 +1298,18 @@ is-typedarray@^1.0.0, is-typedarray@~1.0.0: resolved "https://registry.yarnpkg.com/is-typedarray/-/is-typedarray-1.0.0.tgz#e479c80858df0c1b11ddda6940f96011fcda4a9a" integrity sha1-5HnICFjfDBsR3dppQPlgEfzaSpo= -isarray@~1.0.0: +isarray@^1.0.0, isarray@~1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11" integrity sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE= +isemail@3.x.x: + version "3.2.0" + resolved "https://registry.yarnpkg.com/isemail/-/isemail-3.2.0.tgz#59310a021931a9fb06bbb51e155ce0b3f236832c" + integrity sha512-zKqkK+O+dGqevc93KNsbZ/TqTUFd46MwWjYOoMrjIMZ51eU7DtQG3Wmd9SQQT7i7RVnuTPEiYEWHU3MSbxC1Tg== + dependencies: + punycode "2.x.x" + isstream@~0.1.2: version "0.1.2" resolved "https://registry.yarnpkg.com/isstream/-/isstream-0.1.2.tgz#47e63f7af55afa6f92e1500e690eb8b8529c099a" @@ -1233,6 +1323,29 @@ isurl@^1.0.0-alpha5: has-to-string-tag-x "^1.2.0" is-object "^1.0.1" +jmespath@0.15.0: + version "0.15.0" + resolved "https://registry.yarnpkg.com/jmespath/-/jmespath-0.15.0.tgz#a3f222a9aae9f966f5d27c796510e28091764217" + integrity sha1-o/Iiqarp+Wb10nx5ZRDigJF2Qhc= + +joi@11.3.4: + version "11.3.4" + resolved "https://registry.yarnpkg.com/joi/-/joi-11.3.4.tgz#c25fc2598c3847865f92c51b5249b519af3e51cb" + integrity sha512-2eytkbHJ0qhXaNgElrKFrruv1sZ8MtuFg7fJe1Linb028x/3+flYsrtZIc+7wYVY7oCtXv6Ou7dCzAZaV/Qubg== + dependencies: + hoek "4.x.x" + isemail "3.x.x" + topo "2.x.x" + +joi@^14.3.1: + version "14.3.1" + resolved "https://registry.yarnpkg.com/joi/-/joi-14.3.1.tgz#164a262ec0b855466e0c35eea2a885ae8b6c703c" + integrity sha512-LQDdM+pkOrpAn4Lp+neNIFV3axv1Vna3j38bisbQhETPMANYRbFJFUyOZcOClYvM/hppMhGWuKSFEK9vjrB+bQ== + dependencies: + hoek "6.x.x" + isemail "3.x.x" + topo "3.x.x" + js-sha3@0.5.7, js-sha3@^0.5.7: version "0.5.7" resolved "https://registry.yarnpkg.com/js-sha3/-/js-sha3-0.5.7.tgz#0d4ffd8002d5333aabaf4a23eed2f6374c9f28e7" @@ -1303,6 +1416,16 @@ keccakjs@^0.2.1: browserify-sha3 "^0.0.4" sha3 "^1.2.2" +lodash@4.17.4: + version "4.17.4" + resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae" + integrity sha1-eCA6TRwyiuHYbcpkYONptX9AVa4= + +lodash@^4.0.0, lodash@^4.14.0, lodash@^4.17.11: + version "4.17.11" + resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.11.tgz#b39ea6229ef607ecd89e2c8df12536891cac9b8d" + integrity sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg== + lowercase-keys@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/lowercase-keys/-/lowercase-keys-1.0.1.tgz#6f9e30b47084d971a7c820ff15a6c5167b74c26f" @@ -1640,21 +1763,26 @@ public-encrypt@^4.0.0: randombytes "^2.0.1" safe-buffer "^5.1.2" +punycode@1.3.2: + version "1.3.2" + resolved "https://registry.yarnpkg.com/punycode/-/punycode-1.3.2.tgz#9653a036fb7c1ee42342f2325cceefea3926c48d" + integrity sha1-llOgNvt8HuQjQvIyXM7v6jkmxI0= + punycode@2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.1.0.tgz#5f863edc89b96db09074bad7947bf09056ca4e7d" integrity sha1-X4Y+3Im5bbCQdLrXlHvwkFbKTn0= +punycode@2.x.x, punycode@^2.1.0: + version "2.1.1" + resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.1.1.tgz#b58b010ac40c22c5657616c8d2c2c02c7bf479ec" + integrity sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A== + punycode@^1.4.1: version "1.4.1" resolved "https://registry.yarnpkg.com/punycode/-/punycode-1.4.1.tgz#c0d5a63b2718800ad8e1eb0fa5269c84dd41845e" integrity sha1-wNWmOycYgArY4esPpSachN1BhF4= -punycode@^2.1.0: - version "2.1.1" - resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.1.1.tgz#b58b010ac40c22c5657616c8d2c2c02c7bf479ec" - integrity sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A== - qs@6.5.2, qs@~6.5.2: version "6.5.2" resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.2.tgz#cb3ae806e8740444584ef154ce8ee98d403f3e36" @@ -1669,6 +1797,11 @@ query-string@^5.0.1: object-assign "^4.1.0" strict-uri-encode "^1.0.0" +querystring@0.2.0: + version "0.2.0" + resolved "https://registry.yarnpkg.com/querystring/-/querystring-0.2.0.tgz#b209849203bb25df820da756e747005878521620" + integrity sha1-sgmEkgO7Jd+CDadW50cAWHhSFiA= + randombytes@^2.0.0, randombytes@^2.0.1, randombytes@^2.0.5: version "2.1.0" resolved "https://registry.yarnpkg.com/randombytes/-/randombytes-2.1.0.tgz#df6f84372f0270dc65cdf6291349ab7a473d4f2a" @@ -1776,6 +1909,16 @@ safe-buffer@5.1.2, safe-buffer@^5.0.1, safe-buffer@^5.1.0, safe-buffer@^5.1.1, s resolved "https://registry.yarnpkg.com/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a" integrity sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg== +sax@1.2.1: + version "1.2.1" + resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.1.tgz#7b8e656190b228e81a66aea748480d828cd2d37a" + integrity sha1-e45lYZCyKOgaZq6nSEgNgozS03o= + +sax@>=0.6.0: + version "1.2.4" + resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9" + integrity sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw== + scrypt-js@2.0.3: version "2.0.3" resolved "https://registry.yarnpkg.com/scrypt-js/-/scrypt-js-2.0.3.tgz#bb0040be03043da9a012a2cea9fc9f852cfc87d4" @@ -2054,6 +2197,20 @@ to-buffer@^1.1.1: resolved "https://registry.yarnpkg.com/to-buffer/-/to-buffer-1.1.1.tgz#493bd48f62d7c43fcded313a03dcadb2e1213a80" integrity sha512-lx9B5iv7msuFYE3dytT+KE5tap+rNYw+K4jVkb9R/asAb+pbBSM17jtunHplhBe6RRJdZx3Pn2Jph24O32mOVg== +topo@2.x.x: + version "2.0.2" + resolved "https://registry.yarnpkg.com/topo/-/topo-2.0.2.tgz#cd5615752539057c0dc0491a621c3bc6fbe1d182" + integrity sha1-zVYVdSU5BXwNwEkaYhw7xvvh0YI= + dependencies: + hoek "4.x.x" + +topo@3.x.x: + version "3.0.3" + resolved "https://registry.yarnpkg.com/topo/-/topo-3.0.3.tgz#d5a67fb2e69307ebeeb08402ec2a2a6f5f7ad95c" + integrity sha512-IgpPtvD4kjrJ7CRA3ov2FhWQADwv+Tdqbsf1ZnPUSAtCJ9e1Z44MmoSGDXGk4IppoZA7jd/QRkNddlLJWlUZsQ== + dependencies: + hoek "6.x.x" + tough-cookie@~2.4.3: version "2.4.3" resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-2.4.3.tgz#53f36da3f47783b0925afa06ff9f3b165280f781" @@ -2179,6 +2336,14 @@ url-to-options@^1.0.1: resolved "https://registry.yarnpkg.com/url-to-options/-/url-to-options-1.0.1.tgz#1505a03a289a48cbd7a434efbaeec5055f5633a9" integrity sha1-FQWgOiiaSMvXpDTvuu7FBV9WM6k= +url@0.10.3: + version "0.10.3" + resolved "https://registry.yarnpkg.com/url/-/url-0.10.3.tgz#021e4d9c7705f21bbf37d03ceb58767402774c64" + integrity sha1-Ah5NnHcF8hu/N9A861h2dAJ3TGQ= + dependencies: + punycode "1.3.2" + querystring "0.2.0" + utf8@2.1.1: version "2.1.1" resolved "https://registry.yarnpkg.com/utf8/-/utf8-2.1.1.tgz#2e01db02f7d8d0944f77104f1609eb0c304cf768" @@ -2199,7 +2364,12 @@ uuid@2.0.1: resolved "https://registry.yarnpkg.com/uuid/-/uuid-2.0.1.tgz#c2a30dedb3e535d72ccf82e343941a50ba8533ac" integrity sha1-wqMN7bPlNdcsz4LjQ5QaULqFM6w= -uuid@^3.3.2: +uuid@3.1.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.1.0.tgz#3dd3d3e790abc24d7b0d3a034ffababe28ebbc04" + integrity sha512-DIWtzUkw04M4k3bf1IcpS2tngXEL26YUD2M0tMDUpnUrz2hgzUBlD55a4FjdLGPvfHxS6uluGWvaVEqgBcVa+g== + +uuid@3.3.2, uuid@^3.3.2: version "3.3.2" resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.3.2.tgz#1b4af4955eb3077c501c23872fc6513811587131" integrity sha512-yXJmeNaw3DnnKAOKJE51sL/ZaYfWJRl1pK9dr19YFCu0ObS231AB1/LbqTKRAQ5kw8A90rA6fr4riOUpTZvQZA== @@ -2507,6 +2677,34 @@ xhr@^2.0.4, xhr@^2.3.3: parse-headers "^2.0.0" xtend "^4.0.0" +xml2js@0.4.17: + version "0.4.17" + resolved "https://registry.yarnpkg.com/xml2js/-/xml2js-0.4.17.tgz#17be93eaae3f3b779359c795b419705a8817e868" + integrity sha1-F76T6q4/O3eTWceVtBlwWogX6Gg= + dependencies: + sax ">=0.6.0" + xmlbuilder "^4.1.0" + +xml2js@0.4.19: + version "0.4.19" + resolved "https://registry.yarnpkg.com/xml2js/-/xml2js-0.4.19.tgz#686c20f213209e94abf0d1bcf1efaa291c7827a7" + integrity sha512-esZnJZJOiJR9wWKMyuvSE1y6Dq5LCuJanqhxslH2bxM6duahNZ+HMpCLhBQGZkbX6xRf8x1Y2eJlgt2q3qo49Q== + dependencies: + sax ">=0.6.0" + xmlbuilder "~9.0.1" + +xmlbuilder@4.2.1, xmlbuilder@^4.1.0: + version "4.2.1" + resolved "https://registry.yarnpkg.com/xmlbuilder/-/xmlbuilder-4.2.1.tgz#aa58a3041a066f90eaa16c2f5389ff19f3f461a5" + integrity sha1-qlijBBoGb5DqoWwvU4n/GfP0YaU= + dependencies: + lodash "^4.0.0" + +xmlbuilder@~9.0.1: + version "9.0.7" + resolved "https://registry.yarnpkg.com/xmlbuilder/-/xmlbuilder-9.0.7.tgz#132ee63d2ec5565c557e20f4c22df9aca686b10d" + integrity sha1-Ey7mPS7FVlxVfiD0wi35rKaGsQ0= + xmlhttprequest@1.8.0: version "1.8.0" resolved "https://registry.yarnpkg.com/xmlhttprequest/-/xmlhttprequest-1.8.0.tgz#67fe075c5c24fef39f9d65f5f7b7fe75171968fc" From ac70a6d3bff693a01c1f7071dd66b594881dd622 Mon Sep 17 00:00:00 2001 From: Onuwa Nnachi Isaac Date: Fri, 26 Apr 2019 14:11:53 +0100 Subject: [PATCH 4/6] Add codes --- .gitignore | 3 +- config/ribbon-token.js | 6 + config/web3.js | 9 ++ index.js | 258 +++++++++++++++++++++++++------ libraries/Dynamo.js | 121 +++++++++++++++ models/Interaction.model.js | 78 ++++++++++ models/Patient.model.js | 52 +++++++ models/Practitioner.model.js | 34 ++++ models/schema/interactions.js | 33 ++++ models/schema/patients.js | 30 ++++ models/schema/practitioner.js | 23 +++ sample/index.js | 54 ++++++- services/Interaction.service.js | 98 ++++++++++++ services/Patient.service.js | 76 +++++++++ services/Practitioner.service.js | 60 +++++++ utils/index.js | 117 ++++++++++++++ 16 files changed, 1002 insertions(+), 50 deletions(-) create mode 100644 config/ribbon-token.js create mode 100644 config/web3.js create mode 100644 libraries/Dynamo.js create mode 100644 models/Interaction.model.js create mode 100644 models/Patient.model.js create mode 100644 models/Practitioner.model.js create mode 100644 models/schema/interactions.js create mode 100644 models/schema/patients.js create mode 100644 models/schema/practitioner.js create mode 100644 services/Interaction.service.js create mode 100644 services/Patient.service.js create mode 100644 services/Practitioner.service.js create mode 100644 utils/index.js diff --git a/.gitignore b/.gitignore index 2983a51..be59eef 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /node_modules -/.theia \ No newline at end of file +/.theia +/sample \ No newline at end of file diff --git a/config/ribbon-token.js b/config/ribbon-token.js new file mode 100644 index 0000000..72f450e --- /dev/null +++ b/config/ribbon-token.js @@ -0,0 +1,6 @@ +const web3 = require("./web3"); +const contractAddress = "0x180170386b1794ccf5bb5bb420658b76bcdb5262"; + +const abi = require("../build/contracts/abi.json"); + +module.exports = new web3.eth.Contract(abi, contractAddress); diff --git a/config/web3.js b/config/web3.js new file mode 100644 index 0000000..14278d7 --- /dev/null +++ b/config/web3.js @@ -0,0 +1,9 @@ +const Web3 = require("web3"); + +const web3 = new Web3( + new Web3.providers.HttpProvider( + "https://rinkeby.infura.io/v3/a8853810b5054964b0fbe19c8e02e9c1" + ) +); + +module.exports = web3; diff --git a/index.js b/index.js index 9b5d9b7..e867130 100644 --- a/index.js +++ b/index.js @@ -1,48 +1,216 @@ -const Web3 = require('web3'); -const TruffleContract = require('truffle-contract'); -const Tx = require('ethereumjs-tx'); -const contractAddress = '0x17CA197aB5a0e75Caa104E6b2377ed9a4EE90317'; -const privateKey = '97CBBF9B269F0F58D1C4B0F3AF662DC627937A2A1A6AA959219C7051B4306371'; -const RibbonBlockchainContract = require('./build/contracts/ERC20Interface.json') +const Util = require("./utils/index"); +const PatientService = require("./services/Patient.service"); +const PractitionerService = require("./services/Practitioner.service"); +const InteractionService = require("./services/Interaction.service"); exports.handler = (event, context, callback) => { - switch (event.field) { - case 'createEvent': - callback(null, RibbonBlockchainContract) - break; - case 'test': - const myAddress = '0xdb0B020Ab16129983045C80692fa1D1916133471' - const web3 = new Web3(new Web3.providers.HttpProvider('https://rinkeby.infura.io/v3/a8853810b5054964b0fbe19c8e02e9c1')); - const contract = web3.eth.contract(RibbonBlockchainContract).at(contractAddress) - console.log(contract.methods) - // let accounts = web3.eth.getAccounts(); - // let account = web3.eth.accounts.privateKeyToAccount('0x' + privateKey); - // const to = '0x9A8A9958ac1B70c49ccE9693CCb0230f13F63505' - // var gasPriceGwei = 3; - // var gasLimit = 3000000; - // const rawTransaction = { - // from: myAddress, - // to: contractAddress, - // "gasPrice": web3.utils.toHex(gasPriceGwei * 1e9), - // "gasLimit": web3.utils.toHex(gasLimit), - // value: '0x0', - // data: contract.methods.transfer(to, 1000).encodeABI(), - // chainId: 3 - // } - // var tx = new Tx(rawTransaction); - // tx.sign(privKey); - // var serializedTx = tx.serialize(); - // var receipt = web3.eth.sendSignedTransaction('0x' + serializedTx.toString('hex')); - // balance = contract.balanceOf(myAddress); - // console.log(`Balance after send: ${(balance)}`); + let errors; - // contract.totalSupply().call((err, result) => { - // console.log(err, result) - // }) - callback(null, true) - break; - default: - throw new Error('Unknown method'); - break; - } -} \ No newline at end of file + switch (event.field || event.fields) { + case "createPatient": + errors = Util.checkRequestBody(event.arguments, [ + "patientId", + "firstName", + "lastName", + "phoneNumber" + ]); + if (errors) { + callback( + Util.handleResponse({ + error: true, + message: "Invalid input/entry provided", + data: errors + }) + ); + } else { + PatientService.create(event.arguments, response => { + if (response.error) { + callback(response.message); + } else { + callback(null, response.data); + } + }); + } + break; + case "patients": + PatientService.getAll(response => { + if (response.error) { + callback(response.message); + } else { + callback(null, response.data); + } + }); + break; + case "patient": + errors = Util.checkRequestBody(event.arguments, ["id"]); + if (errors) { + callback( + Util.handleResponse({ + error: true, + message: "Invalid input/entry provided.", + data: errors + }) + ); + } else { + PatientService.get(event.arguments.id, response => { + if (response.error) { + callback(response.message); + } else { + callback(null, response.data); + } + }); + } + break; + case "createPractitioner": + errors = Util.checkRequestBody(event.arguments, [ + "practitionerId", + "firstName", + "lastName", + "phoneNumber" + ]); + if (errors) { + callback( + Util.handleResponse({ + error: true, + message: "Invalid input/entry provided", + data: errors + }) + ); + } else { + PractitionerService.create(event.arguments, response => { + if (response.error) { + callback(response.message); + } else { + callback(null, response.data); + } + }); + } + break; + + case "practitioners": + PractitionerService.getAll(response => { + if (response.error) { + callback(response.message); + } else { + callback(null, response.data); + } + }); + break; + case "practitioner": + errors = Util.checkRequestBody(event.arguments, ["id"]); + if (errors) { + callback( + Util.handleResponse({ + error: true, + message: "Invalid input/entry provided.", + data: errors + }) + ); + } else { + PractitionerService.get(event.arguments.id, response => { + if (response.error) { + callback(response.message); + } else { + callback(null, response.data); + } + }); + } + break; + case "createInteraction": + errors = Util.checkRequestBody(event.arguments, [ + "patientId", + "practitionerId", + "interaction" + ]); + if (errors) { + callback( + Util.handleResponse({ + error: true, + message: "Invalid input/entry provided.", + data: errors + }) + ); + } else { + InteractionService.create(event.arguments, response => { + if (response.error) { + callback(response.message); + } else { + callback(null, response.data); + } + }); + } + // Util.sendToken("0xB0793421c0E8dD39439CD6916140acfA9F563e90", 100); + break; + case "interactions": + InteractionService.getAll(response => { + if (response.error) { + callback(response.message); + } else { + callback(null, response.data); + } + }); + break; + case "interaction": + errors = Util.checkRequestBody(event.arguments, ["id"]); + if (errors) { + callback( + Util.handleResponse({ + error: true, + message: "Invalid input/entry provided.", + data: errors + }) + ); + } else { + InteractionService.get(event.arguments.id, response => { + if (response.error) { + callback(response.message); + } else { + callback(null, response.data); + } + }); + } + break; + case "patientInteractions": + errors = Util.checkRequestBody(event.arguments, ["id"]); + if (errors) { + callback( + Util.handleResponse({ + error: true, + message: "Invalid input/entry provided.", + data: errors + }) + ); + } else { + InteractionService.getByPatient(event.arguments.id, response => { + if (response.error) { + callback(response.message); + } else { + callback(null, response.data); + } + }); + } + break; + case "practitionerInteractions": + errors = Util.checkRequestBody(event.arguments, ["id"]); + if (errors) { + callback( + Util.handleResponse({ + error: true, + message: "Invalid input/entry provided.", + data: errors + }) + ); + } else { + InteractionService.getByPractitioner(event.arguments.id, response => { + if (response.error) { + callback(response.message); + } else { + callback(null, response.data); + } + }); + } + break; + default: + throw new Error("Unknown method"); + } +}; diff --git a/libraries/Dynamo.js b/libraries/Dynamo.js new file mode 100644 index 0000000..73b2f09 --- /dev/null +++ b/libraries/Dynamo.js @@ -0,0 +1,121 @@ +const AWS = require("aws-sdk"); + +AWS.config.update({ + region: "eu-west-1", + accessKeyId: "AKIA4NND44SJYEQKSMEC", + secretAccessKey: "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" +}); + +const docClient = new AWS.DynamoDB.DocumentClient({ apiVersion: "2012-08-10" }); + +const Dynamo = { + _createTable: (table, key, callback) => { + const dynamo = new AWS.DynamoDB(); + const params = { + TableName: table, + KeySchema: [{ AttributeName: key, KeyType: "HASH" }], + AttributeDefinitions: [{ AttributeName: key, AttributeType: "S" }], + ProvisionedThroughput: { + ReadCapacityUnits: 10, + WriteCapacityUnits: 10 + } + }; + + dynamo.createTable(params, (err, res) => { + if (err) return callback(err); + else console.log(`${params.TableName} successfully created`); + }); + }, + + _save: (param, callback) => { + docClient.put(param, (err, savedData) => { + if (err != null) return callback(Dynamo.handleError(err)); + else return callback(param.Item); + }); + }, + + _update: (data, callback) => { + docClient.update(data, (err, returnData) => { + if (err) return callback(Dynamo.handleError(err)); + else return callback(returnData); + }); + }, + + _getByKey: (param, callback) => { + docClient.get(param, (err, data) => { + if (err) return callback(Dynamo.handleError(err)); + else return callback(data); + }); + }, + + _getAllByKey: (query, callback) => { + docClient.query(query, (err, data) => { + if (err) { + return callback(Dynamo.handleError(err)); + } else { + return callback(data); + } + }); + }, + + _get: (query, callback) => { + docClient.scan(query, (err, data) => { + if (err) { + return callback(Dynamo.handleError(err)); + } else { + return callback(data); + } + }); + }, + + _findAll: function(param, callback) { + docClient.scan(param, (error, data) => { + if (error) { + return callback(Dynamo.handleError(error)); + } else { + callback(data); + } + }); + }, + + onScan: (err, data) => { + if (err) return callback(Dynamo.handleError(err)); + else { + if (typeof data.LastEvaluatedKey !== "undefined") { + param.ExclusiveStartKey = data.LastEvaluatedKey; + docClient.scan(param, onScan); + } + return callback(data); + } + }, + _delete: (params, callback) => { + docClient.delete(params, (err, data) => { + if (err) { + callback(Dynamo.handleError(err)); + } else { + callback(data); + } + }); + }, + + scan: (key, value, table, callback) => { + let params = { + TableName: table, + FilterExpression: `${key} = :value`, + ExpressionAttributeValues: { ":value": value } + }; + docClient.scan(params, (err, data) => { + if (err) { + callback(Dynamo.handleError(err)); + } else { + callback(data); + } + }); + }, + + handleError: report => { + return { error: true, message: report }; + } +}; + +module.exports = Dynamo; diff --git a/models/Interaction.model.js b/models/Interaction.model.js new file mode 100644 index 0000000..f8dda17 --- /dev/null +++ b/models/Interaction.model.js @@ -0,0 +1,78 @@ +const Dynamo = require("../libraries/Dynamo"); +const Util = require("../utils"); + +const TABLE_NAME = "interactions"; + +const PractitionerModel = { + save: (data, callback) => { + let param = { + TableName: TABLE_NAME, + Item: data + }; + Dynamo._save(param, state => { + return callback(state); + }); + }, + getAll: callback => { + let param = { + TableName: TABLE_NAME + }; + Dynamo._findAll(param, state => { + return callback(state); + }); + }, + getOneByKey: (id, callback) => { + let params = { + TableName: TABLE_NAME, + Key: { id: id } + }; + Dynamo._getByKey(params, state => { + return callback(state); + }); + }, + getByPatientId: (id, callback) => { + let params = { + TableName: TABLE_NAME, + IndexName: "patientId-index", + KeyConditionExpression: Util.generateKeyExpressions({ + patientId: id + }), + ExpressionAttributeValues: Util.generateExpressionAttributeValues({ + patientId: id + }), + Key: { patientId: id } + }; + Dynamo._getAllByKey(params, state => { + return callback(state); + }); + }, + + getByPractitionerId: (id, callback) => { + let params = { + TableName: TABLE_NAME, + IndexName: "practitionerId-index", + KeyConditionExpression: Util.generateKeyExpressions({ + practitionerId: id + }), + ExpressionAttributeValues: Util.generateExpressionAttributeValues({ + practitionerId: id + }), + Key: { practitionerId: id } + }; + Dynamo._getAllByKey(params, state => { + return callback(state); + }); + }, + + delete: id => { + let params = { + TableName: TABLE_NAME, + Key: id + }; + Dynamo._delete(params, state => { + return callback(state); + }); + } +}; + +module.exports = PractitionerModel; diff --git a/models/Patient.model.js b/models/Patient.model.js new file mode 100644 index 0000000..3eb4f07 --- /dev/null +++ b/models/Patient.model.js @@ -0,0 +1,52 @@ +const Dynamo = require("../libraries/Dynamo"); +const Util = require("../utils"); + +const TABLE_NAME = "patients"; + +const PatientModel = { + save: (data, callback) => { + let param = { + TableName: TABLE_NAME, + Item: data + }; + Dynamo._save(param, state => { + return callback(state); + }); + }, + getAll: callback => { + let param = { + TableName: TABLE_NAME + }; + Dynamo._findAll(param, state => { + return callback(state); + }); + }, + getOneByKey: (id, callback) => { + let params = { + TableName: TABLE_NAME, + Key: { id: id } + }; + Dynamo._getByKey(params, state => { + return callback(state); + }); + }, + getOneByPatientId: (id, callback) => { + let params = { + TableName: TABLE_NAME, + Key: { id: id }, + IndexName: "patientId-index", + KeyConditionExpression: Util.generateKeyExpressions({ + patientId: id + }), + ExpressionAttributeValues: Util.generateExpressionAttributeValues({ + patientId: id + }) + }; + Dynamo._get(params, state => { + console.log(state); + return callback(state); + }); + } +}; + +module.exports = PatientModel; diff --git a/models/Practitioner.model.js b/models/Practitioner.model.js new file mode 100644 index 0000000..c6bac07 --- /dev/null +++ b/models/Practitioner.model.js @@ -0,0 +1,34 @@ +const Dynamo = require("../libraries/Dynamo"); + +const TABLE_NAME = "practitioners"; + +const PractitionerModel = { + save: (data, callback) => { + let param = { + TableName: TABLE_NAME, + Item: data + }; + Dynamo._save(param, state => { + return callback(state); + }); + }, + getAll: callback => { + let param = { + TableName: TABLE_NAME + }; + Dynamo._findAll(param, state => { + return callback(state); + }); + }, + getOneByKey: (id, callback) => { + let params = { + TableName: TABLE_NAME, + Key: { id: id } + }; + Dynamo._getByKey(params, state => { + return callback(state); + }); + } +}; + +module.exports = PractitionerModel; diff --git a/models/schema/interactions.js b/models/schema/interactions.js new file mode 100644 index 0000000..4a42e29 --- /dev/null +++ b/models/schema/interactions.js @@ -0,0 +1,33 @@ +const joi = require("joi"); +const dynogels = require("dynogels"); + +dynogels.AWS.config.update({ + accessKeyId: "AKIA4NND44SJYEQKSMEC", + secretAccessKey: "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", + region: "eu-west-1" +}); + +let Interactions = dynogels.define("Interactions", { + hashKey: "id", + timestamps: true, + schema: { + id: dynogels.types.uuid(), + practitioner: joi.string().required(), + patient: joi.string().required(), + interaction: joi.string().required() + }, + indexes: [ + { + hashKey: "patient", + name: "patientIndex", + type: "global" + }, + { + hashKey: "practitioner", + name: "practitionerIndex", + type: "global" + } + ] +}); + +module.exports.Interactions = Interactions; diff --git a/models/schema/patients.js b/models/schema/patients.js new file mode 100644 index 0000000..9ef6e25 --- /dev/null +++ b/models/schema/patients.js @@ -0,0 +1,30 @@ +const joi = require("joi"); +const dynogels = require("dynogels"); + +dynogels.AWS.config.update({ + accessKeyId: "AKIA4NND44SJYEQKSMEC", + secretAccessKey: "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", + region: "eu-west-1" +}); + +let Patients = dynogels.define("Patients", { + hashKey: "id", + timestamps: true, + schema: { + id: dynogels.types.uuid(), + patientId: joi.string().required(), + firstName: joi.string().required(), + lastName: joi.string().required(), + phoneNumber: joi.string().required(), + address: joi.string().required() + }, + indexes: [ + { + hashKey: "patient", + name: "patientIndex", + type: "global" + } + ] +}); + +module.exports.Patients = Patients; diff --git a/models/schema/practitioner.js b/models/schema/practitioner.js new file mode 100644 index 0000000..ab69cd9 --- /dev/null +++ b/models/schema/practitioner.js @@ -0,0 +1,23 @@ +const joi = require("joi"); +const dynogels = require("dynogels"); + +dynogels.AWS.config.update({ + accessKeyId: "AKIA4NND44SJYEQKSMEC", + secretAccessKey: "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", + region: "eu-west-1" +}); + +let Practitioner = dynogels.define("Practitioner", { + hashKey: "id", + timestamps: true, + schema: { + id: dynogels.types.uuid(), + practitionerId: joi.string().required(), + firstName: joi.string().required(), + lastName: joi.string().required(), + phoneNumber: joi.string().required(), + address: joi.string().required() + } +}); + +module.exports.Practitioner = Practitioner; diff --git a/sample/index.js b/sample/index.js index c1436e9..77c0b90 100644 --- a/sample/index.js +++ b/sample/index.js @@ -1,5 +1,51 @@ +// module.exports = { +// field: "createPractitioner", +// arguments: { +// firstName: "John", +// lastName: "Doe", +// phoneNumber: "+2348062457326", +// practitionerId: 123 +// } +// }; + +// module.exports = { +// field: "practitioner", +// arguments: { +// id: "658a9116-0bc2-45a4-aac6-70558c9dd3d3" +// } +// }; + +// module.exports = { +// field: "createInteraction", +// arguments: { +// patientId: "b33f9a67-b61c-46a9-8124-b730ddf88abd", +// practitionerId: "658a9116-0bc2-45a4-aac6-70558c9dd3d3", +// interaction: "Visitation to the less priviledged" +// } +// }; + +// module.exports = { +// field: "interactions", +// arguments: {} +// }; + +// module.exports = { +// field: "interaction", +// arguments: { +// id: "ed3f9b0c-1249-435a-bb78-c18d8d95b6ea" +// } +// }; + module.exports = { - field: 'test', - arguments: { - } -} \ No newline at end of file + field: "patientInteractions", + arguments: { + id: "b33f9a67-b61c-46a9-8124-b730ddf88abd" + } +}; + +// module.exports = { +// field: "practitionerInteractions", +// arguments: { +// id: "658a9116-0bc2-45a4-aac6-70558c9dd3d3" +// } +// }; diff --git a/services/Interaction.service.js b/services/Interaction.service.js new file mode 100644 index 0000000..6b726a4 --- /dev/null +++ b/services/Interaction.service.js @@ -0,0 +1,98 @@ +const _ = require("lodash"); +const uuid = require("uuid/v4"); +const InteractionModal = require("../models/Interaction.model"); +const Util = require("../utils"); + +const InteractionService = { + create: (data, callback) => { + let allowedParameters = [ + "patientId", + "practitionerId", + "interaction", + ]; + let interaction = _.pick(data, allowedParameters); + interaction["id"] = uuid(); + interaction["createdAt"] = new Date().toISOString(); + + InteractionModal.save(interaction, response => { + if (response.error) { + callback({ error: true, message: response.message.message }); + } else { + Util.sendToken(data.address, data.amount) + .then(response => { + callback({ error: false, data: response }); + }) + .catch(error => { + InteractionModal.delete(id); + callback({ error: true, message: error }); + }); + } + }); + }, + + getByPatient: (id, callback) => { + InteractionModal.getByPatientId(id, response => { + if (response.Items.length < 1) { + callback({ + error: true, + message: "Interactions for patient does not exist" + }); + } else { + callback({ + error: false, + data: response.Items + }); + } + }); + }, + + getByPractitioner: (id, callback) => { + InteractionModal.getByPractitionerId(id, response => { + if (response.Items.length < 1) { + callback({ + error: true, + message: "Interactions for practitioner does not exist" + }); + } else { + callback({ + error: false, + data: response.Items + }); + } + }); + }, + + getAll: callback => { + InteractionModal.getAll(response => { + if (response.Items.length < 1) { + callback({ + error: true, + message: `Could not fetch interactions` + }); + } else { + callback({ + error: false, + data: response.Items + }); + } + }); + }, + + get: (id, callback) => { + InteractionModal.getOneByKey(id, response => { + if (response.Item.id) { + callback({ + error: false, + data: response.Item + }); + } else { + callback({ + error: true, + message: `Could not fetch interaction` + }); + } + }); + } +}; + +module.exports = InteractionService; diff --git a/services/Patient.service.js b/services/Patient.service.js new file mode 100644 index 0000000..38fb97e --- /dev/null +++ b/services/Patient.service.js @@ -0,0 +1,76 @@ +const _ = require("lodash"); +const uuid = require("uuid/v4"); +const PatientModel = require("../models/Patient.model"); + +const PatientService = { + create: (data, callback) => { + let allowedParameters = [ + "patientId", + "firstName", + "lastName", + "phoneNumber", + "address" + ]; + let patient = _.pick(data, allowedParameters); + patient["id"] = uuid(); + patient["createdAt"] = new Date().toISOString(); + + PatientModel.save(patient, response => { + if (response.error) { + callback({ error: true, message: response.message.message }); + } else { + callback({ error: false, data: response }); + } + }); + }, + + // get: (id, callback) => { + // PatientModel.getOneByPatientId(id, response => { + // if (!response.Item) { + // callback({ + // error: true, + // message: "Patient does not exist" + // }); + // } else { + // callback({ + // error: false, + // data: response.Item + // }); + // } + // }); + // }, + + getAll: callback => { + PatientModel.getAll(response => { + if (response.Items.length < 1) { + callback({ + error: true, + message: `Could not fetch patients` + }); + } else { + callback({ + error: false, + data: response.Item || response.Items + }); + } + }); + }, + + get: (id, callback) => { + PatientModel.getOneByKey(id, response => { + if (response.Item.id) { + callback({ + error: false, + data: response.Item + }); + } else { + callback({ + error: true, + message: `Could not fetch patients` + }); + } + }); + } +}; + +module.exports = PatientService; diff --git a/services/Practitioner.service.js b/services/Practitioner.service.js new file mode 100644 index 0000000..706eb38 --- /dev/null +++ b/services/Practitioner.service.js @@ -0,0 +1,60 @@ +const _ = require("lodash"); +const uuid = require("uuid/v4"); +const PractitionerModel = require("../models/Practitioner.model"); + +const Practitioner = { + create: (data, callback) => { + let allowedParameters = [ + "practitionerID", + "firstName", + "lastName", + "phoneNumber", + "address" + ]; + let practitioner = _.pick(data, allowedParameters); + practitioner["id"] = uuid(); + practitioner["createdAt"] = new Date().toISOString(); + + PractitionerModel.save(practitioner, response => { + if (response.error) { + callback({ error: true, message: response.message.message }); + } else { + callback({ error: false, data: response }); + } + }); + }, + + get: (id, callback) => { + PractitionerModel.getOneByKey(id, response => { + if (!response.Item) { + callback({ + error: true, + message: "Practitioner does not exist" + }); + } else { + callback({ + error: false, + data: response.Item + }); + } + }); + }, + + getAll: callback => { + PractitionerModel.getAll(response => { + if (response.Items.length < 1) { + callback({ + error: true, + message: `Could not fetch practitioners` + }); + } else { + callback({ + error: false, + data: response.Items + }); + } + }); + } +}; + +module.exports = Practitioner; diff --git a/utils/index.js b/utils/index.js new file mode 100644 index 0000000..b8d5de0 --- /dev/null +++ b/utils/index.js @@ -0,0 +1,117 @@ +const _ = require("lodash"); +const Tx = require("ethereumjs-tx"); +const web3 = require("../config/web3"); +const contract = require("../config/ribbon-token"); +const privateKey = + "97CBBF9B269F0F58D1C4B0F3AF662DC627937A2A1A6AA959219C7051B4306371"; + +const Utility = { + handleResponse: data => { + if (data.data) data = data.data; + let body = JSON.stringify({ + error: data.error, + code: data.code, + message: data.message, + response: data + }); + return { + headers: { "content-type": "application/json" }, + body: body + }; + }, + + checkRequestBody: (params, requiredFields) => { + let errors = {}; + for (let i = 0; i < requiredFields.length; i++) { + if (!params.hasOwnProperty(requiredFields[i])) { + errors[requiredFields[i]] = "is required"; + } + } + if (_.isEmpty(errors)) { + return null; + } else { + return errors; + } + }, + + generateUpdateExpressions: data => { + let updateStr = "set "; + Object.keys(data).forEach((key, index) => { + if (Object.keys(data).length - 1 === index) { + updateStr += `#${key} = :${key}`; + } else { + updateStr += `${key} = :${key} ,`; + } + }); + return updateStr; + }, + + generateExpressionAttributeValues: data => { + let expNames = {}; + Object.keys(data).forEach((key, index) => { + expNames[`:${key}`] = data[key]; + }); + return expNames; + }, + + generateExpressionAttributeNames: data => { + let exp = {}; + Object.keys(data).forEach((key, index) => { + exp[`#${key}`] = key; + }); + return exp; + }, + + generateKeyExpressions: data => { + let updateStr = ""; + Object.keys(data).forEach((key, index) => { + updateStr += `${key} = :${key}`; + }); + return updateStr; + }, + + sendToken: async (receiver, amount) => { + const contractOwner = { + addr: "0x1de929d52b94a06f21d57dafe202d36c6ca71c7a", + key: privateKey + }; + console.log(`Start to send ${amount} tokens to ${receiver}`); + console.log( + `Private Key ${contractOwner.key} ${Buffer.from( + `0x${contractOwner.key}`, + "hex" + )}` + ); + // Was having some issues with the amount being sent in this function + const data = contract.methods.transfer(receiver, 10).encodeABI(); // encodeABI() is required in order to get the method data into opcode/binary format + const gasPrice = await web3.eth.getGasPrice(); // await added since the function returns a promise + const nonce = await web3.eth.getTransactionCount(contractOwner.addr); //We need the nonce of the account added await since the function returns a promise + const gasLimit = 1200000; //Increased the gaslimit after checking one of the successful transactions one the contract + const rawTransaction = { + from: contractOwner.addr, + nonce: web3.utils.toHex(nonce), + gasPrice: web3.utils.toHex(gasPrice), + gasLimit: web3.utils.toHex(gasLimit), + to: "0x180170386b1794ccf5bb5bb420658b76bcdb5262", + value: "0x00", //value should be hex + data: data, + chainId: 4 + }; + + const privKey = Buffer.from(contractOwner.key, "hex"); + const tx = new Tx(rawTransaction); + tx.sign(privKey); + const serializedTx = tx.serialize(); + web3.eth + .sendSignedTransaction("0x" + serializedTx.toString("hex")) //sendRawTransaction is now deprecated, replaced with sendSignedTransaction + .on("transactionHash", function(hash) { + console.log("hash:" + hash); + web3.eth.getTransaction(hash).then(console.log); + }) + .on("receipt", function(receipt) { + console.log("receipt: " + JSON.stringify(receipt)); + }) + .on("error", console.error); + } +}; +module.exports = Utility; From 79fadbbc02bfd37d3aed70c5c0c6caa9f026a2d0 Mon Sep 17 00:00:00 2001 From: Onuwa Nnachi Isaac Date: Fri, 26 Apr 2019 14:19:49 +0100 Subject: [PATCH 5/6] Add .env config --- .env.sample | 3 +++ .gitignore | 3 ++- index.js | 2 ++ libraries/Dynamo.js | 6 +++--- models/schema/interactions.js | 6 +++--- models/schema/patients.js | 6 +++--- models/schema/practitioner.js | 6 +++--- package.json | 1 + yarn.lock | 5 +++++ 9 files changed, 25 insertions(+), 13 deletions(-) create mode 100644 .env.sample diff --git a/.env.sample b/.env.sample new file mode 100644 index 0000000..7461e0f --- /dev/null +++ b/.env.sample @@ -0,0 +1,3 @@ +ACCESS_KEY_ID= +SECRET_ACCESS_KEY= +REGION=' \ No newline at end of file diff --git a/.gitignore b/.gitignore index be59eef..e350d31 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /node_modules /.theia -/sample \ No newline at end of file +/sample +.env \ No newline at end of file diff --git a/index.js b/index.js index e867130..99dda49 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,5 @@ +require("dotenv").config(); + const Util = require("./utils/index"); const PatientService = require("./services/Patient.service"); const PractitionerService = require("./services/Practitioner.service"); diff --git a/libraries/Dynamo.js b/libraries/Dynamo.js index 73b2f09..911f9ac 100644 --- a/libraries/Dynamo.js +++ b/libraries/Dynamo.js @@ -1,9 +1,9 @@ const AWS = require("aws-sdk"); AWS.config.update({ - region: "eu-west-1", - accessKeyId: "AKIA4NND44SJYEQKSMEC", - secretAccessKey: "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" + region: process.env.REGION, + accessKeyId: process.env.ACCESS_KEY_ID, + secretAccessKey: process.env.SECRET_ACCESS_KEY }); const docClient = new AWS.DynamoDB.DocumentClient({ apiVersion: "2012-08-10" }); diff --git a/models/schema/interactions.js b/models/schema/interactions.js index 4a42e29..759dbb9 100644 --- a/models/schema/interactions.js +++ b/models/schema/interactions.js @@ -2,9 +2,9 @@ const joi = require("joi"); const dynogels = require("dynogels"); dynogels.AWS.config.update({ - accessKeyId: "AKIA4NND44SJYEQKSMEC", - secretAccessKey: "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", - region: "eu-west-1" + accessKeyId: process.env.ACCESS_KEY_ID, + secretAccessKey: process.env.SECRET_ACCESS_KEY, + region: process.env.REGION }); let Interactions = dynogels.define("Interactions", { diff --git a/models/schema/patients.js b/models/schema/patients.js index 9ef6e25..f0d4d58 100644 --- a/models/schema/patients.js +++ b/models/schema/patients.js @@ -2,9 +2,9 @@ const joi = require("joi"); const dynogels = require("dynogels"); dynogels.AWS.config.update({ - accessKeyId: "AKIA4NND44SJYEQKSMEC", - secretAccessKey: "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", - region: "eu-west-1" + accessKeyId: process.env.ACCESS_KEY_ID, + secretAccessKey: process.env.SECRET_ACCESS_KEY, + region: process.env.REGION }); let Patients = dynogels.define("Patients", { diff --git a/models/schema/practitioner.js b/models/schema/practitioner.js index ab69cd9..b1a7c4a 100644 --- a/models/schema/practitioner.js +++ b/models/schema/practitioner.js @@ -2,9 +2,9 @@ const joi = require("joi"); const dynogels = require("dynogels"); dynogels.AWS.config.update({ - accessKeyId: "AKIA4NND44SJYEQKSMEC", - secretAccessKey: "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", - region: "eu-west-1" + accessKeyId: process.env.ACCESS_KEY_ID, + secretAccessKey: process.env.SECRET_ACCESS_KEY, + region: process.env.REGION }); let Practitioner = dynogels.define("Practitioner", { diff --git a/package.json b/package.json index dcc0cbe..239d43d 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "license": "MIT", "dependencies": { "aws-sdk": "^2.442.0", + "dotenv": "^7.0.0", "dynogels": "^9.0.0", "ethereumjs-tx": "^1.3.7", "joi": "^14.3.1", diff --git a/yarn.lock b/yarn.lock index 7ef4b64..8b9d322 100644 --- a/yarn.lock +++ b/yarn.lock @@ -612,6 +612,11 @@ dom-walk@^0.1.0: resolved "https://registry.yarnpkg.com/dom-walk/-/dom-walk-0.1.1.tgz#672226dc74c8f799ad35307df936aba11acd6018" integrity sha1-ZyIm3HTI95mtNTB9+TaroRrNYBg= +dotenv@^7.0.0: + version "7.0.0" + resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-7.0.0.tgz#a2be3cd52736673206e8a85fb5210eea29628e7c" + integrity sha512-M3NhsLbV1i6HuGzBUH8vXrtxOk+tWmzWKDMbAVSUp3Zsjm7ywFeuwrUXhmhQyRK1q5B5GGy7hcXPbj3bnfZg2g== + drbg.js@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/drbg.js/-/drbg.js-1.0.1.tgz#3e36b6c42b37043823cdbc332d58f31e2445480b" From 55f692672096cabf0921d5a0685e4ab72bd16ac6 Mon Sep 17 00:00:00 2001 From: Onuwa Nnachi Isaac Date: Fri, 26 Apr 2019 14:22:46 +0100 Subject: [PATCH 6/6] Update .env config keys --- .env.sample | 7 ++++++- config/ribbon-token.js | 2 +- config/web3.js | 2 +- utils/index.js | 3 +-- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/.env.sample b/.env.sample index 7461e0f..4c0f80e 100644 --- a/.env.sample +++ b/.env.sample @@ -1,3 +1,8 @@ ACCESS_KEY_ID= SECRET_ACCESS_KEY= -REGION=' \ No newline at end of file +REGION= + + +INFURA_TOKEN= +CONTRACT_ADDRESS= +PRIVATE_KEY= \ No newline at end of file diff --git a/config/ribbon-token.js b/config/ribbon-token.js index 72f450e..1960047 100644 --- a/config/ribbon-token.js +++ b/config/ribbon-token.js @@ -1,5 +1,5 @@ const web3 = require("./web3"); -const contractAddress = "0x180170386b1794ccf5bb5bb420658b76bcdb5262"; +const contractAddress = process.env.CONTRACT_ADDRESS; const abi = require("../build/contracts/abi.json"); diff --git a/config/web3.js b/config/web3.js index 14278d7..0f57f7f 100644 --- a/config/web3.js +++ b/config/web3.js @@ -2,7 +2,7 @@ const Web3 = require("web3"); const web3 = new Web3( new Web3.providers.HttpProvider( - "https://rinkeby.infura.io/v3/a8853810b5054964b0fbe19c8e02e9c1" + `https://rinkeby.infura.io/v3/${process.env.INFURA_TOKEN}` ) ); diff --git a/utils/index.js b/utils/index.js index b8d5de0..a89d010 100644 --- a/utils/index.js +++ b/utils/index.js @@ -2,8 +2,7 @@ const _ = require("lodash"); const Tx = require("ethereumjs-tx"); const web3 = require("../config/web3"); const contract = require("../config/ribbon-token"); -const privateKey = - "97CBBF9B269F0F58D1C4B0F3AF662DC627937A2A1A6AA959219C7051B4306371"; +const privateKey = process.env.PRIVATE_KEY; const Utility = { handleResponse: data => {