diff --git a/README.md b/README.md index c3aed06..37a344c 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,16 @@ # blockchain2-demo -blockchain2 demo + +This repository contains a PoC of Anchor APIs using the Quorum blockchain network. + +* API documentation can be found here [Swagger](anchor_api/swagger.yaml) +The actual implementation is designed using Node.js ecosystem. +The web service will expose operations in which, an anchor defined as JSON, will be stored, updated, fetched or removed. +All operations are executed over the Quorum blockchain network using a smart contract. +The smart contract are intended to be implemented using Solidity and Truffle framework [47]. U +sing the demo Anchor API, one can store a data anchor (generating a proof of existence receipt) to prove the existence of some data at some point in time using the Quorum blockchain. +Following operations will be exposed by the PoC + +* POST /data_anchors - Create a new data anchor +* GET - /data_anchors /{anchorId} - Get an anchor by its identifier +* PUT - /data_anchors /{anchorId} - Update an anchor by its identifier + diff --git a/anchor_api/.env b/anchor_api/.env index 696f00f..1ed776f 100644 --- a/anchor_api/.env +++ b/anchor_api/.env @@ -1,2 +1,3 @@ -WEB3_PROVIDER=http://3.10.195.154:8545 -WEB3_ACCOUNT=0x66d66805E29EaB59901f8B7c4CAE0E38aF31cb0e \ No newline at end of file +WEB3_PROVIDER=http://18.132.141.64:8545 +WEB3_ACCOUNT=0x66d66805E29EaB59901f8B7c4CAE0E38aF31cb0e +WEB3_PASSWORD= \ No newline at end of file diff --git a/anchor_api/README.md b/anchor_api/README.md new file mode 100644 index 0000000..d6c1543 --- /dev/null +++ b/anchor_api/README.md @@ -0,0 +1,3 @@ +``` +helm install --set env.web3_provider=http://172.20.123.13:8545 --set env.web3_account=0x66d66805E29EaB59901f8B7c4CAE0E38aF31cb0e anchor-api helm-charts/ +``` \ No newline at end of file diff --git a/anchor_api/build/contracts/DataAnchor.json b/anchor_api/build/contracts/DataAnchor.json index 3b06458..48b76f6 100644 --- a/anchor_api/build/contracts/DataAnchor.json +++ b/anchor_api/build/contracts/DataAnchor.json @@ -1736,7 +1736,7 @@ }, "networks": {}, "schemaVersion": "3.2.0", - "updatedAt": "2020-06-29T16:03:04.665Z", + "updatedAt": "2020-07-06T11:13:56.783Z", "devdoc": { "methods": {} }, diff --git a/anchor_api/build/contracts/Migrations.json b/anchor_api/build/contracts/Migrations.json index 79ab5a7..38a7879 100644 --- a/anchor_api/build/contracts/Migrations.json +++ b/anchor_api/build/contracts/Migrations.json @@ -56,22 +56,22 @@ "metadata": "{\"compiler\":{\"version\":\"0.5.16+commit.9c3226ce\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"constant\":true,\"inputs\":[],\"name\":\"last_completed_migration\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"owner\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"completed\",\"type\":\"uint256\"}],\"name\":\"setCompleted\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"}],\"devdoc\":{\"methods\":{}},\"userdoc\":{\"methods\":{}}},\"settings\":{\"compilationTarget\":{\"/Users/arman/Projects/blockchain2-demo/anchor_api/contracts/Migrations.sol\":\"Migrations\"},\"evmVersion\":\"istanbul\",\"libraries\":{},\"optimizer\":{\"enabled\":false,\"runs\":200},\"remappings\":[]},\"sources\":{\"/Users/arman/Projects/blockchain2-demo/anchor_api/contracts/Migrations.sol\":{\"keccak256\":\"0x5b3bf470fddc971545b13240a991587d98d71ca0bcff91819e54bd51e32ab21a\",\"urls\":[\"bzz-raw://7f783f6433812edb781db0ea7432e04652dac4796dde274d3e194dafdae19c14\",\"dweb:/ipfs/QmZFZNLk25y7UBLDNnjAzoH8SXBPfEN6bWNzGZ2x9C9aVK\"]}},\"version\":1}", "bytecode": "0x608060405234801561001057600080fd5b50336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555061019c806100606000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c8063445df0ac146100465780638da5cb5b14610064578063fdacd576146100ae575b600080fd5b61004e6100dc565b6040518082815260200191505060405180910390f35b61006c6100e2565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6100da600480360360208110156100c457600080fd5b8101908080359060200190929190505050610107565b005b60015481565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141561016457806001819055505b5056fea265627a7a7231582076cc54bc27371ed6cb393559694ccad1db25bd1be661d54d879cc03b1f6f708464736f6c63430005100032", "deployedBytecode": "0x608060405234801561001057600080fd5b50600436106100415760003560e01c8063445df0ac146100465780638da5cb5b14610064578063fdacd576146100ae575b600080fd5b61004e6100dc565b6040518082815260200191505060405180910390f35b61006c6100e2565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6100da600480360360208110156100c457600080fd5b8101908080359060200190929190505050610107565b005b60015481565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141561016457806001819055505b5056fea265627a7a7231582076cc54bc27371ed6cb393559694ccad1db25bd1be661d54d879cc03b1f6f708464736f6c63430005100032", - "sourceMap": "34:311:0:-;;;123:50;8:9:-1;5:2;;;30:1;27;20:12;5:2;123:50:0;158:10;150:5;;:18;;;;;;;;;;;;;;;;;;34:311;;;;;;", - "deployedSourceMap": "34:311:0:-;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;34:311:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;82:36;;;:::i;:::-;;;;;;;;;;;;;;;;;;;58:20;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;240:103;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;240:103:0;;;;;;;;;;;;;;;;;:::i;:::-;;82:36;;;;:::o;58:20::-;;;;;;;;;;;;;:::o;240:103::-;223:5;;;;;;;;;;;209:19;;:10;:19;;;205:26;;;329:9;302:24;:36;;;;205:26;240:103;:::o", + "sourceMap": "34:311:1:-;;;123:50;8:9:-1;5:2;;;30:1;27;20:12;5:2;123:50:1;158:10;150:5;;:18;;;;;;;;;;;;;;;;;;34:311;;;;;;", + "deployedSourceMap": "34:311:1:-;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;34:311:1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;82:36;;;:::i;:::-;;;;;;;;;;;;;;;;;;;58:20;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;240:103;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;240:103:1;;;;;;;;;;;;;;;;;:::i;:::-;;82:36;;;;:::o;58:20::-;;;;;;;;;;;;;:::o;240:103::-;223:5;;;;;;;;;;;209:19;;:10;:19;;;205:26;;;329:9;302:24;:36;;;;205:26;240:103;:::o", "source": "pragma solidity >=0.4.21 <0.7.0;\n\ncontract Migrations {\n address public owner;\n uint public last_completed_migration;\n\n constructor() public {\n owner = msg.sender;\n }\n\n modifier restricted() {\n if (msg.sender == owner) _;\n }\n\n function setCompleted(uint completed) public restricted {\n last_completed_migration = completed;\n }\n}\n", "sourcePath": "/Users/arman/Projects/blockchain2-demo/anchor_api/contracts/Migrations.sol", "ast": { "absolutePath": "/Users/arman/Projects/blockchain2-demo/anchor_api/contracts/Migrations.sol", "exportedSymbols": { "Migrations": [ - 36 + 103 ] }, - "id": 37, + "id": 104, "nodeType": "SourceUnit", "nodes": [ { - "id": 1, + "id": 68, "literals": [ "solidity", ">=", @@ -82,7 +82,7 @@ ".0" ], "nodeType": "PragmaDirective", - "src": "0:32:0" + "src": "0:32:1" }, { "baseContracts": [], @@ -90,20 +90,20 @@ "contractKind": "contract", "documentation": null, "fullyImplemented": true, - "id": 36, + "id": 103, "linearizedBaseContracts": [ - 36 + 103 ], "name": "Migrations", "nodeType": "ContractDefinition", "nodes": [ { "constant": false, - "id": 3, + "id": 70, "name": "owner", "nodeType": "VariableDeclaration", - "scope": 36, - "src": "58:20:0", + "scope": 103, + "src": "58:20:1", "stateVariable": true, "storageLocation": "default", "typeDescriptions": { @@ -111,10 +111,10 @@ "typeString": "address" }, "typeName": { - "id": 2, + "id": 69, "name": "address", "nodeType": "ElementaryTypeName", - "src": "58:7:0", + "src": "58:7:1", "stateMutability": "nonpayable", "typeDescriptions": { "typeIdentifier": "t_address", @@ -126,11 +126,11 @@ }, { "constant": false, - "id": 5, + "id": 72, "name": "last_completed_migration", "nodeType": "VariableDeclaration", - "scope": 36, - "src": "82:36:0", + "scope": 103, + "src": "82:36:1", "stateVariable": true, "storageLocation": "default", "typeDescriptions": { @@ -138,10 +138,10 @@ "typeString": "uint256" }, "typeName": { - "id": 4, + "id": 71, "name": "uint", "nodeType": "ElementaryTypeName", - "src": "82:4:0", + "src": "82:4:1", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" @@ -152,26 +152,26 @@ }, { "body": { - "id": 13, + "id": 80, "nodeType": "Block", - "src": "144:29:0", + "src": "144:29:1", "statements": [ { "expression": { "argumentTypes": null, - "id": 11, + "id": 78, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftHandSide": { "argumentTypes": null, - "id": 8, + "id": 75, "name": "owner", "nodeType": "Identifier", "overloadedDeclarations": [], - "referencedDeclaration": 3, - "src": "150:5:0", + "referencedDeclaration": 70, + "src": "150:5:1", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" @@ -183,18 +183,18 @@ "argumentTypes": null, "expression": { "argumentTypes": null, - "id": 9, + "id": 76, "name": "msg", "nodeType": "Identifier", "overloadedDeclarations": [], - "referencedDeclaration": 84, - "src": "158:3:0", + "referencedDeclaration": 118, + "src": "158:3:1", "typeDescriptions": { "typeIdentifier": "t_magic_message", "typeString": "msg" } }, - "id": 10, + "id": 77, "isConstant": false, "isLValue": false, "isPure": false, @@ -202,54 +202,54 @@ "memberName": "sender", "nodeType": "MemberAccess", "referencedDeclaration": null, - "src": "158:10:0", + "src": "158:10:1", "typeDescriptions": { "typeIdentifier": "t_address_payable", "typeString": "address payable" } }, - "src": "150:18:0", + "src": "150:18:1", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" } }, - "id": 12, + "id": 79, "nodeType": "ExpressionStatement", - "src": "150:18:0" + "src": "150:18:1" } ] }, "documentation": null, - "id": 14, + "id": 81, "implemented": true, "kind": "constructor", "modifiers": [], "name": "", "nodeType": "FunctionDefinition", "parameters": { - "id": 6, + "id": 73, "nodeType": "ParameterList", "parameters": [], - "src": "134:2:0" + "src": "134:2:1" }, "returnParameters": { - "id": 7, + "id": 74, "nodeType": "ParameterList", "parameters": [], - "src": "144:0:0" + "src": "144:0:1" }, - "scope": 36, - "src": "123:50:0", + "scope": 103, + "src": "123:50:1", "stateMutability": "nonpayable", "superFunction": null, "visibility": "public" }, { "body": { - "id": 22, + "id": 89, "nodeType": "Block", - "src": "199:37:0", + "src": "199:37:1", "statements": [ { "condition": { @@ -258,7 +258,7 @@ "typeIdentifier": "t_address", "typeString": "address" }, - "id": 19, + "id": 86, "isConstant": false, "isLValue": false, "isPure": false, @@ -267,18 +267,18 @@ "argumentTypes": null, "expression": { "argumentTypes": null, - "id": 16, + "id": 83, "name": "msg", "nodeType": "Identifier", "overloadedDeclarations": [], - "referencedDeclaration": 84, - "src": "209:3:0", + "referencedDeclaration": 118, + "src": "209:3:1", "typeDescriptions": { "typeIdentifier": "t_magic_message", "typeString": "msg" } }, - "id": 17, + "id": 84, "isConstant": false, "isLValue": false, "isPure": false, @@ -286,7 +286,7 @@ "memberName": "sender", "nodeType": "MemberAccess", "referencedDeclaration": null, - "src": "209:10:0", + "src": "209:10:1", "typeDescriptions": { "typeIdentifier": "t_address_payable", "typeString": "address payable" @@ -296,70 +296,70 @@ "operator": "==", "rightExpression": { "argumentTypes": null, - "id": 18, + "id": 85, "name": "owner", "nodeType": "Identifier", "overloadedDeclarations": [], - "referencedDeclaration": 3, - "src": "223:5:0", + "referencedDeclaration": 70, + "src": "223:5:1", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" } }, - "src": "209:19:0", + "src": "209:19:1", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "falseBody": null, - "id": 21, + "id": 88, "nodeType": "IfStatement", - "src": "205:26:0", + "src": "205:26:1", "trueBody": { - "id": 20, + "id": 87, "nodeType": "PlaceholderStatement", - "src": "230:1:0" + "src": "230:1:1" } } ] }, "documentation": null, - "id": 23, + "id": 90, "name": "restricted", "nodeType": "ModifierDefinition", "parameters": { - "id": 15, + "id": 82, "nodeType": "ParameterList", "parameters": [], - "src": "196:2:0" + "src": "196:2:1" }, - "src": "177:59:0", + "src": "177:59:1", "visibility": "internal" }, { "body": { - "id": 34, + "id": 101, "nodeType": "Block", - "src": "296:47:0", + "src": "296:47:1", "statements": [ { "expression": { "argumentTypes": null, - "id": 32, + "id": 99, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftHandSide": { "argumentTypes": null, - "id": 30, + "id": 97, "name": "last_completed_migration", "nodeType": "Identifier", "overloadedDeclarations": [], - "referencedDeclaration": 5, - "src": "302:24:0", + "referencedDeclaration": 72, + "src": "302:24:1", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" @@ -369,67 +369,67 @@ "operator": "=", "rightHandSide": { "argumentTypes": null, - "id": 31, + "id": 98, "name": "completed", "nodeType": "Identifier", "overloadedDeclarations": [], - "referencedDeclaration": 25, - "src": "329:9:0", + "referencedDeclaration": 92, + "src": "329:9:1", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, - "src": "302:36:0", + "src": "302:36:1", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, - "id": 33, + "id": 100, "nodeType": "ExpressionStatement", - "src": "302:36:0" + "src": "302:36:1" } ] }, "documentation": null, - "id": 35, + "id": 102, "implemented": true, "kind": "function", "modifiers": [ { "arguments": null, - "id": 28, + "id": 95, "modifierName": { "argumentTypes": null, - "id": 27, + "id": 94, "name": "restricted", "nodeType": "Identifier", "overloadedDeclarations": [], - "referencedDeclaration": 23, - "src": "285:10:0", + "referencedDeclaration": 90, + "src": "285:10:1", "typeDescriptions": { "typeIdentifier": "t_modifier$__$", "typeString": "modifier ()" } }, "nodeType": "ModifierInvocation", - "src": "285:10:0" + "src": "285:10:1" } ], "name": "setCompleted", "nodeType": "FunctionDefinition", "parameters": { - "id": 26, + "id": 93, "nodeType": "ParameterList", "parameters": [ { "constant": false, - "id": 25, + "id": 92, "name": "completed", "nodeType": "VariableDeclaration", - "scope": 35, - "src": "262:14:0", + "scope": 102, + "src": "262:14:1", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { @@ -437,10 +437,10 @@ "typeString": "uint256" }, "typeName": { - "id": 24, + "id": 91, "name": "uint", "nodeType": "ElementaryTypeName", - "src": "262:4:0", + "src": "262:4:1", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" @@ -450,39 +450,39 @@ "visibility": "internal" } ], - "src": "261:16:0" + "src": "261:16:1" }, "returnParameters": { - "id": 29, + "id": 96, "nodeType": "ParameterList", "parameters": [], - "src": "296:0:0" + "src": "296:0:1" }, - "scope": 36, - "src": "240:103:0", + "scope": 103, + "src": "240:103:1", "stateMutability": "nonpayable", "superFunction": null, "visibility": "public" } ], - "scope": 37, - "src": "34:311:0" + "scope": 104, + "src": "34:311:1" } ], - "src": "0:346:0" + "src": "0:346:1" }, "legacyAST": { "absolutePath": "/Users/arman/Projects/blockchain2-demo/anchor_api/contracts/Migrations.sol", "exportedSymbols": { "Migrations": [ - 36 + 103 ] }, - "id": 37, + "id": 104, "nodeType": "SourceUnit", "nodes": [ { - "id": 1, + "id": 68, "literals": [ "solidity", ">=", @@ -493,7 +493,7 @@ ".0" ], "nodeType": "PragmaDirective", - "src": "0:32:0" + "src": "0:32:1" }, { "baseContracts": [], @@ -501,20 +501,20 @@ "contractKind": "contract", "documentation": null, "fullyImplemented": true, - "id": 36, + "id": 103, "linearizedBaseContracts": [ - 36 + 103 ], "name": "Migrations", "nodeType": "ContractDefinition", "nodes": [ { "constant": false, - "id": 3, + "id": 70, "name": "owner", "nodeType": "VariableDeclaration", - "scope": 36, - "src": "58:20:0", + "scope": 103, + "src": "58:20:1", "stateVariable": true, "storageLocation": "default", "typeDescriptions": { @@ -522,10 +522,10 @@ "typeString": "address" }, "typeName": { - "id": 2, + "id": 69, "name": "address", "nodeType": "ElementaryTypeName", - "src": "58:7:0", + "src": "58:7:1", "stateMutability": "nonpayable", "typeDescriptions": { "typeIdentifier": "t_address", @@ -537,11 +537,11 @@ }, { "constant": false, - "id": 5, + "id": 72, "name": "last_completed_migration", "nodeType": "VariableDeclaration", - "scope": 36, - "src": "82:36:0", + "scope": 103, + "src": "82:36:1", "stateVariable": true, "storageLocation": "default", "typeDescriptions": { @@ -549,10 +549,10 @@ "typeString": "uint256" }, "typeName": { - "id": 4, + "id": 71, "name": "uint", "nodeType": "ElementaryTypeName", - "src": "82:4:0", + "src": "82:4:1", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" @@ -563,26 +563,26 @@ }, { "body": { - "id": 13, + "id": 80, "nodeType": "Block", - "src": "144:29:0", + "src": "144:29:1", "statements": [ { "expression": { "argumentTypes": null, - "id": 11, + "id": 78, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftHandSide": { "argumentTypes": null, - "id": 8, + "id": 75, "name": "owner", "nodeType": "Identifier", "overloadedDeclarations": [], - "referencedDeclaration": 3, - "src": "150:5:0", + "referencedDeclaration": 70, + "src": "150:5:1", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" @@ -594,18 +594,18 @@ "argumentTypes": null, "expression": { "argumentTypes": null, - "id": 9, + "id": 76, "name": "msg", "nodeType": "Identifier", "overloadedDeclarations": [], - "referencedDeclaration": 84, - "src": "158:3:0", + "referencedDeclaration": 118, + "src": "158:3:1", "typeDescriptions": { "typeIdentifier": "t_magic_message", "typeString": "msg" } }, - "id": 10, + "id": 77, "isConstant": false, "isLValue": false, "isPure": false, @@ -613,54 +613,54 @@ "memberName": "sender", "nodeType": "MemberAccess", "referencedDeclaration": null, - "src": "158:10:0", + "src": "158:10:1", "typeDescriptions": { "typeIdentifier": "t_address_payable", "typeString": "address payable" } }, - "src": "150:18:0", + "src": "150:18:1", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" } }, - "id": 12, + "id": 79, "nodeType": "ExpressionStatement", - "src": "150:18:0" + "src": "150:18:1" } ] }, "documentation": null, - "id": 14, + "id": 81, "implemented": true, "kind": "constructor", "modifiers": [], "name": "", "nodeType": "FunctionDefinition", "parameters": { - "id": 6, + "id": 73, "nodeType": "ParameterList", "parameters": [], - "src": "134:2:0" + "src": "134:2:1" }, "returnParameters": { - "id": 7, + "id": 74, "nodeType": "ParameterList", "parameters": [], - "src": "144:0:0" + "src": "144:0:1" }, - "scope": 36, - "src": "123:50:0", + "scope": 103, + "src": "123:50:1", "stateMutability": "nonpayable", "superFunction": null, "visibility": "public" }, { "body": { - "id": 22, + "id": 89, "nodeType": "Block", - "src": "199:37:0", + "src": "199:37:1", "statements": [ { "condition": { @@ -669,7 +669,7 @@ "typeIdentifier": "t_address", "typeString": "address" }, - "id": 19, + "id": 86, "isConstant": false, "isLValue": false, "isPure": false, @@ -678,18 +678,18 @@ "argumentTypes": null, "expression": { "argumentTypes": null, - "id": 16, + "id": 83, "name": "msg", "nodeType": "Identifier", "overloadedDeclarations": [], - "referencedDeclaration": 84, - "src": "209:3:0", + "referencedDeclaration": 118, + "src": "209:3:1", "typeDescriptions": { "typeIdentifier": "t_magic_message", "typeString": "msg" } }, - "id": 17, + "id": 84, "isConstant": false, "isLValue": false, "isPure": false, @@ -697,7 +697,7 @@ "memberName": "sender", "nodeType": "MemberAccess", "referencedDeclaration": null, - "src": "209:10:0", + "src": "209:10:1", "typeDescriptions": { "typeIdentifier": "t_address_payable", "typeString": "address payable" @@ -707,70 +707,70 @@ "operator": "==", "rightExpression": { "argumentTypes": null, - "id": 18, + "id": 85, "name": "owner", "nodeType": "Identifier", "overloadedDeclarations": [], - "referencedDeclaration": 3, - "src": "223:5:0", + "referencedDeclaration": 70, + "src": "223:5:1", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" } }, - "src": "209:19:0", + "src": "209:19:1", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "falseBody": null, - "id": 21, + "id": 88, "nodeType": "IfStatement", - "src": "205:26:0", + "src": "205:26:1", "trueBody": { - "id": 20, + "id": 87, "nodeType": "PlaceholderStatement", - "src": "230:1:0" + "src": "230:1:1" } } ] }, "documentation": null, - "id": 23, + "id": 90, "name": "restricted", "nodeType": "ModifierDefinition", "parameters": { - "id": 15, + "id": 82, "nodeType": "ParameterList", "parameters": [], - "src": "196:2:0" + "src": "196:2:1" }, - "src": "177:59:0", + "src": "177:59:1", "visibility": "internal" }, { "body": { - "id": 34, + "id": 101, "nodeType": "Block", - "src": "296:47:0", + "src": "296:47:1", "statements": [ { "expression": { "argumentTypes": null, - "id": 32, + "id": 99, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftHandSide": { "argumentTypes": null, - "id": 30, + "id": 97, "name": "last_completed_migration", "nodeType": "Identifier", "overloadedDeclarations": [], - "referencedDeclaration": 5, - "src": "302:24:0", + "referencedDeclaration": 72, + "src": "302:24:1", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" @@ -780,67 +780,67 @@ "operator": "=", "rightHandSide": { "argumentTypes": null, - "id": 31, + "id": 98, "name": "completed", "nodeType": "Identifier", "overloadedDeclarations": [], - "referencedDeclaration": 25, - "src": "329:9:0", + "referencedDeclaration": 92, + "src": "329:9:1", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, - "src": "302:36:0", + "src": "302:36:1", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, - "id": 33, + "id": 100, "nodeType": "ExpressionStatement", - "src": "302:36:0" + "src": "302:36:1" } ] }, "documentation": null, - "id": 35, + "id": 102, "implemented": true, "kind": "function", "modifiers": [ { "arguments": null, - "id": 28, + "id": 95, "modifierName": { "argumentTypes": null, - "id": 27, + "id": 94, "name": "restricted", "nodeType": "Identifier", "overloadedDeclarations": [], - "referencedDeclaration": 23, - "src": "285:10:0", + "referencedDeclaration": 90, + "src": "285:10:1", "typeDescriptions": { "typeIdentifier": "t_modifier$__$", "typeString": "modifier ()" } }, "nodeType": "ModifierInvocation", - "src": "285:10:0" + "src": "285:10:1" } ], "name": "setCompleted", "nodeType": "FunctionDefinition", "parameters": { - "id": 26, + "id": 93, "nodeType": "ParameterList", "parameters": [ { "constant": false, - "id": 25, + "id": 92, "name": "completed", "nodeType": "VariableDeclaration", - "scope": 35, - "src": "262:14:0", + "scope": 102, + "src": "262:14:1", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { @@ -848,10 +848,10 @@ "typeString": "uint256" }, "typeName": { - "id": 24, + "id": 91, "name": "uint", "nodeType": "ElementaryTypeName", - "src": "262:4:0", + "src": "262:4:1", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" @@ -861,42 +861,34 @@ "visibility": "internal" } ], - "src": "261:16:0" + "src": "261:16:1" }, "returnParameters": { - "id": 29, + "id": 96, "nodeType": "ParameterList", "parameters": [], - "src": "296:0:0" + "src": "296:0:1" }, - "scope": 36, - "src": "240:103:0", + "scope": 103, + "src": "240:103:1", "stateMutability": "nonpayable", "superFunction": null, "visibility": "public" } ], - "scope": 37, - "src": "34:311:0" + "scope": 104, + "src": "34:311:1" } ], - "src": "0:346:0" + "src": "0:346:1" }, "compiler": { "name": "solc", "version": "0.5.16+commit.9c3226ce.Emscripten.clang" }, - "networks": { - "1101": { - "events": {}, - "links": {}, - "address": "0xcCC46A73d616A3adD5f0E5b448BAfeDD4A2Da61A", - "transactionHash": "0x1be22c21d160797feeca6f0bf4bab6175f807c17d90f207d5d79ea7d471376e2" - } - }, + "networks": {}, "schemaVersion": "3.2.0", - "updatedAt": "2020-07-01T10:48:34.610Z", - "networkType": "quorum", + "updatedAt": "2020-07-06T11:13:56.784Z", "devdoc": { "methods": {} }, diff --git a/anchor_api/config/custom-environment-variables.json b/anchor_api/config/custom-environment-variables.json index 32db03e..0514266 100644 --- a/anchor_api/config/custom-environment-variables.json +++ b/anchor_api/config/custom-environment-variables.json @@ -1,6 +1,7 @@ { "web3": { "provider": "WEB3_PROVIDER", - "account": "WEB3_ACCOUNT" + "account": "WEB3_ACCOUNT", + "password": "WEB3_PASSWORD" } } diff --git a/anchor_api/index.js b/anchor_api/index.js index 7bda931..ed2715f 100644 --- a/anchor_api/index.js +++ b/anchor_api/index.js @@ -17,6 +17,10 @@ const express = require('express') , account = config.get('web3.account'); DataAnchor.setProvider(web3.currentProvider); +DataAnchor.autoGas = true; +DataAnchor.defaults({ + from: account +}) // adding Helmet to enhance your API's security app.use(helmet()); @@ -47,38 +51,92 @@ app.get('/', (req, res) => { }); app.post('/data_anchors', async (req, res) => { - const instance = await DataAnchor.new(req.body.name, req.body.hash, JSON.stringify(req.body.metadata), {from: account}); - const data = await instance.getData.call(); - await res.json({ - anchorId: data[0], - name: data[1], - hash: data[2], - metadata: JSON.parse(data[3]), - }); + + try { + let unlocked = false; + + if (config.get('web3.password') && !unlocked) { + console.log('>> Unlocking account ' + account + ' with password ' + config.get('web3.password')); + unlocked = await web3.eth.personal.unlockAccount(account, config.get('web3.password'), 36000); + } + + const instance = await DataAnchor.new(req.body.name, req.body.hash, JSON.stringify(req.body.metadata), {from: account}); + const data = await instance.getData.call(); + + if (config.get('web3.password') && unlocked) { + console.log('>> Locking account ' + account); + unlocked = await web3.eth.personal.lockAccount(account); + } + + await res.json({ + anchorId: data[0], + name: data[1], + hash: data[2], + metadata: JSON.parse(data[3]), + }); + } catch (error) { + console.log(error) + res.json({}); + } }); app.get('/data_anchors/:anchorId', async (req, res) => { - const instance = await DataAnchor.at(req.params.anchorId); - const data = await instance.getData.call(); - await res.json({ - anchorId: data[0], - name: data[1], - hash: data[2], - metadata: JSON.parse(data[3]), - }); + try { + let unlocked = false; + + if (config.get('web3.password') && !unlocked) { + console.log('>> Unlocking account ' + account + ' with password ' + config.get('web3.password')); + unlocked = await web3.eth.personal.unlockAccount(account, config.get('web3.password'), 36000); + } + + const instance = await DataAnchor.at(req.params.anchorId); + const data = await instance.getData.call(); + + if (config.get('web3.password') && unlocked) { + console.log('>> Locking account ' + account); + unlocked = await web3.eth.personal.lockAccount(account); + } + + await res.json({ + anchorId: data[0], + name: data[1], + hash: data[2], + metadata: JSON.parse(data[3]), + }); + } catch (error) { + console.log(error) + res.json({}); + } }); app.put('/data_anchors/:anchorId', async (req, res) => { - console.log(req.body); - const instance = await DataAnchor.at(req.params.anchorId); - const result = await instance.setData.sendTransaction(req.body.name, JSON.stringify(req.body.metadata), {from: account}); - const data = await instance.getData.call(); - await res.json({ - anchorId: data[0], - name: data[1], - hash: data[2], - metadata: JSON.parse(data[3]), - }); + try { + let unlocked = false; + + if (config.get('web3.password') && !unlocked) { + console.log('>> Unlocking account ' + account + ' with password ' + config.get('web3.password')); + unlocked = await web3.eth.personal.unlockAccount(account, config.get('web3.password'), 36000); + } + + const instance = await DataAnchor.at(req.params.anchorId); + const result = await instance.setData.sendTransaction(req.body.name, JSON.stringify(req.body.metadata), {from: account}); + const data = await instance.getData.call(); + + if (config.get('web3.password') && unlocked) { + console.log('>> Locking account ' + account); + unlocked = await web3.eth.personal.lockAccount(account); + } + + await res.json({ + anchorId: data[0], + name: data[1], + hash: data[2], + metadata: JSON.parse(data[3]), + }); + } catch (error) { + console.log(error) + res.json({error: error}); + } }); // starting the server diff --git a/anchor_api/package-lock.json b/anchor_api/package-lock.json index e0f5025..5ed8cec 100644 --- a/anchor_api/package-lock.json +++ b/anchor_api/package-lock.json @@ -3127,6 +3127,19 @@ "has-flag": "^3.0.0" } }, + "swagger-ui-dist": { + "version": "3.28.0", + "resolved": "https://registry.npmjs.org/swagger-ui-dist/-/swagger-ui-dist-3.28.0.tgz", + "integrity": "sha512-aPkfTzPv9djSiZI1NUkWr5HynCUsH+jaJ0WSx+/t19wq7MMGg9clHm9nGoIpAtqml1G51ofI+I75Ym72pukzFg==" + }, + "swagger-ui-express": { + "version": "4.1.4", + "resolved": "https://registry.npmjs.org/swagger-ui-express/-/swagger-ui-express-4.1.4.tgz", + "integrity": "sha512-Ea96ecpC+Iq9GUqkeD/LFR32xSs8gYqmTW1gXCuKg81c26WV6ZC2FsBSPVExQP6WkyUuz5HEiR0sEv/HCC343g==", + "requires": { + "swagger-ui-dist": "^3.18.1" + } + }, "swarm-js": { "version": "0.1.39", "resolved": "https://registry.npmjs.org/swarm-js/-/swarm-js-0.1.39.tgz", diff --git a/anchor_api/package.json b/anchor_api/package.json index e2cade7..759d65d 100644 --- a/anchor_api/package.json +++ b/anchor_api/package.json @@ -15,6 +15,7 @@ "express": "^4.17.1", "helmet": "^3.23.1", "morgan": "^1.10.0", + "swagger-ui-express": "^4.1.4", "truffle": "^5.1.30", "web3": "^1.2.9" }, diff --git a/anchor_api/swagger.yaml b/anchor_api/swagger.yaml index 7581719..b7b6df5 100644 --- a/anchor_api/swagger.yaml +++ b/anchor_api/swagger.yaml @@ -115,24 +115,6 @@ paths: description: Unexpected error schema: $ref: '#/definitions/Error' - delete: - tags: - - data-anchoring - summary: Delete an anchor by its identifier - operationId: deleteDataAnchor - parameters: - - name: anchorId - in: path - required: true - description: The id of the anchor to delete - type: string - responses: - '204': - description: The anchor was deleted successfully. - default: - description: Unexpected error - schema: - $ref: '#/definitions/Error' definitions: DataAnchor: description: 'A data anchor (generating a proof of existence receipt) allows to prove the existence of some data at some point in time.' @@ -163,9 +145,9 @@ definitions: type: string format: date-time description: "Time of last modification. Format should be RFC 3339" - txId: + anchorId: type: string - description: "Identifier of the blockchain transaction where the anchoring occurred." + description: "Identifier of the anchor" Error: description: Error object type: object diff --git a/anchor_api/truffle-config/default.json b/anchor_api/truffle-config/default.json index 365d116..2f41282 100644 --- a/anchor_api/truffle-config/default.json +++ b/anchor_api/truffle-config/default.json @@ -1,11 +1,12 @@ { "truffle": { - "host": "3.10.195.154", + "host": "3.9.53.187", "port": 8545, "network_id": "*", "gasPrice": 0, "gas": 4500000, - "type": "quorum", - "from": "0x66d66805E29EaB59901f8B7c4CAE0E38aF31cb0e" + "type": "ethereum", + "from": "0x3852360755845889E675C4b683f3F26bf8f12aeA", + "password": "lst7upm" } }