diff --git a/modules/Blockchain/Ethereum/bidding-contract/abi.json b/modules/Blockchain/Ethereum/bidding-contract/abi.json index 64c469dce4..8ff9aeae12 100644 --- a/modules/Blockchain/Ethereum/bidding-contract/abi.json +++ b/modules/Blockchain/Ethereum/bidding-contract/abi.json @@ -1,954 +1,891 @@ -[ - { - "constant": false, - "inputs": [ - { - "name": "import_id", - "type": "bytes32" - }, - { - "name": "DH_node_id", - "type": "bytes32" - }, - { - "name": "bid_index", - "type": "uint256" - } - ], - "name": "activatePredeterminedBid", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "import_id", - "type": "bytes32" - }, - { - "name": "DH_node_id", - "type": "bytes32" - } - ], - "name": "addBid", - "outputs": [ - { - "name": "distance", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "wallet", - "type": "address" - } - ], - "name": "addEscrow", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "import_id", - "type": "bytes32" - }, - { - "name": "bid_index", - "type": "uint256" - } - ], - "name": "cancelBid", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "import_id", - "type": "bytes32" - } - ], - "name": "cancelOffer", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "import_id", - "type": "bytes32" - } - ], - "name": "chooseBids", - "outputs": [ - { - "name": "chosen_data_holders", - "type": "uint256[]" - } - ], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "import_id", - "type": "bytes32" - }, - { - "name": "DC_node_id", - "type": "bytes32" - }, - { - "name": "total_escrow_time_in_minutes", - "type": "uint256" - }, - { - "name": "max_token_amount_per_DH", - "type": "uint256" - }, - { - "name": "min_stake_amount_per_DH", - "type": "uint256" - }, - { - "name": "min_reputation", - "type": "uint256" - }, - { - "name": "data_hash", - "type": "bytes32" - }, - { - "name": "data_size_in_bytes", - "type": "uint256" - }, - { - "name": "predetermined_DH_wallet", - "type": "address[]" - }, - { - "name": "predetermined_DH_node_id", - "type": "bytes32[]" - } - ], - "name": "createOffer", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "node_id", - "type": "bytes32" - }, - { - "name": "price_per_byte_minute", - "type": "uint256" - }, - { - "name": "stake_per_byte_minute", - "type": "uint256" - }, - { - "name": "read_stake_factor", - "type": "uint256" - }, - { - "name": "max_time_in_minutes", - "type": "uint256" - } - ], - "name": "createProfile", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "wallet", - "type": "address" - }, - { - "name": "amount", - "type": "uint256" - } - ], - "name": "decreaseBalance", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "amount", - "type": "uint256" - } - ], - "name": "depositToken", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "wallet", - "type": "address" - }, - { - "name": "amount", - "type": "uint256" - } - ], - "name": "increaseBalance", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "wallet", - "type": "address" - }, - { - "name": "amount", - "type": "uint256" - } - ], - "name": "increaseReputation", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "name": "import_id", - "type": "bytes32" - } - ], - "name": "FinalizeOfferReady", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "name": "import_id", - "type": "bytes32" - }, - { - "indexed": false, - "name": "DH_wallet", - "type": "address" - }, - { - "indexed": false, - "name": "DH_node_id", - "type": "bytes32" - }, - { - "indexed": false, - "name": "bid_index", - "type": "uint256" - }, - { - "indexed": false, - "name": "total_escrow_time_in_minutes", - "type": "uint256" - }, - { - "indexed": false, - "name": "max_token_amount_per_DH", - "type": "uint256" - }, - { - "indexed": false, - "name": "min_stake_amount_per_DH", - "type": "uint256" - }, - { - "indexed": false, - "name": "data_size_in_bytes", - "type": "uint256" - } - ], - "name": "AddedPredeterminedBid", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "name": "import_id", - "type": "bytes32" - }, - { - "indexed": false, - "name": "DH_wallet", - "type": "address" - }, - { - "indexed": false, - "name": "DH_node_id", - "type": "bytes32" - }, - { - "indexed": false, - "name": "bid_index", - "type": "uint256" - } - ], - "name": "AddedBid", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "name": "import_id", - "type": "bytes32" - } - ], - "name": "OfferCanceled", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "name": "import_id", - "type": "bytes32" - }, - { - "indexed": false, - "name": "DC_node_id", - "type": "bytes32" - }, - { - "indexed": false, - "name": "total_escrow_time_in_minutes", - "type": "uint256" - }, - { - "indexed": false, - "name": "max_token_amount_per_DH", - "type": "uint256" - }, - { - "indexed": false, - "name": "min_stake_amount_per_DH", - "type": "uint256" - }, - { - "indexed": false, - "name": "min_reputation", - "type": "uint256" - }, - { - "indexed": false, - "name": "data_size_in_bytes", - "type": "uint256" - }, - { - "indexed": false, - "name": "data_hash", - "type": "bytes32" - } - ], - "name": "OfferCreated", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "name": "wallet", - "type": "address" - }, - { - "indexed": false, - "name": "new_balance", - "type": "uint256" - } - ], - "name": "BalanceModified", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "name": "wallet", - "type": "address" - }, - { - "indexed": false, - "name": "new_balance", - "type": "uint256" - } - ], - "name": "ReputationModified", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "name": "wallet", - "type": "address" - }, - { - "indexed": false, - "name": "node_id", - "type": "bytes32" - } - ], - "name": "ProfileCreated", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "name": "import_id", - "type": "bytes32" - } - ], - "name": "OfferFinalized", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "name": "previousOwner", - "type": "address" - }, - { - "indexed": true, - "name": "newOwner", - "type": "address" - } - ], - "name": "OwnershipTransferred", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "name": "import_id", - "type": "bytes32" - }, - { - "indexed": false, - "name": "DH_wallet", - "type": "address" - } - ], - "name": "BidTaken", - "type": "event" - }, - { - "constant": false, - "inputs": [ - { - "name": "new_max_time_in_minutes", - "type": "uint256" - } - ], - "name": "setMaxTime", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "new_price_per_byte_minute", - "type": "uint256" - } - ], - "name": "setPrice", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "new_modifier", - "type": "uint256" - } - ], - "name": "setReplicationModifier", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "new_stake_per_byte_minute", - "type": "uint256" - } - ], - "name": "setStake", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "newOwner", - "type": "address" - } - ], - "name": "transferOwnership", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "name": "token_address", - "type": "address" - }, - { - "name": "escrow_address", - "type": "address" - }, - { - "name": "reading_address", - "type": "address" - } - ], - "payable": false, - "stateMutability": "nonpayable", - "type": "constructor" - }, - { - "constant": false, - "inputs": [ - { - "name": "amount", - "type": "uint256" - } - ], - "name": "withdrawToken", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "name": "a", - "type": "uint256" - }, - { - "name": "b", - "type": "uint256" - } - ], - "name": "absoluteDifference", - "outputs": [ - { - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "pure", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "active_nodes", - "outputs": [ - { - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "name": "import_id", - "type": "bytes32" - }, - { - "name": "DH_wallet", - "type": "address" - } - ], - "name": "calculateDistance", - "outputs": [ - { - "name": "distance", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "escrow", - "outputs": [ - { - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "name": "wallet", - "type": "address" - } - ], - "name": "getBalance", - "outputs": [ - { - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "name": "import_id", - "type": "bytes32" - }, - { - "name": "DH_node_id", - "type": "bytes32" - } - ], - "name": "getBidIndex", - "outputs": [ - { - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "name": "import_id", - "type": "bytes32" - } - ], - "name": "getDistanceParameters", - "outputs": [ - { - "name": "node_hash", - "type": "bytes32" - }, - { - "name": "data_hash", - "type": "bytes32" - }, - { - "name": "distance", - "type": "uint256" - }, - { - "name": "current_ranking", - "type": "uint256" - }, - { - "name": "required_bid_amount", - "type": "uint256" - }, - { - "name": "active_nodes_", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "name": "import_id", - "type": "bytes32" - } - ], - "name": "getOfferStatus", - "outputs": [ - { - "name": "isOfferFinal", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "name": "import_id", - "type": "bytes32" - }, - { - "name": "bid_index", - "type": "uint256" - } - ], - "name": "isBidChosen", - "outputs": [ - { - "name": "_isBidChosen", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "name": "", - "type": "bytes32" - } - ], - "name": "offer", - "outputs": [ - { - "name": "DC_wallet", - "type": "address" - }, - { - "name": "max_token_amount_per_DH", - "type": "uint256" - }, - { - "name": "min_stake_amount_per_DH", - "type": "uint256" - }, - { - "name": "min_reputation", - "type": "uint256" - }, - { - "name": "total_escrow_time_in_minutes", - "type": "uint256" - }, - { - "name": "data_size_in_bytes", - "type": "uint256" - }, - { - "name": "data_hash", - "type": "bytes32" - }, - { - "name": "first_bid_index", - "type": "uint256" - }, - { - "name": "replication_factor", - "type": "uint256" - }, - { - "name": "replication_modifier", - "type": "uint256" - }, - { - "name": "active", - "type": "bool" - }, - { - "name": "finalized", - "type": "bool" - } - ], - "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": "", - "type": "address" - } - ], - "name": "profile", - "outputs": [ - { - "name": "token_amount_per_byte_minute", - "type": "uint256" - }, - { - "name": "stake_amount_per_byte_minute", - "type": "uint256" - }, - { - "name": "read_stake_factor", - "type": "uint256" - }, - { - "name": "balance", - "type": "uint256" - }, - { - "name": "reputation", - "type": "uint256" - }, - { - "name": "number_of_escrows", - "type": "uint256" - }, - { - "name": "max_escrow_time_in_minutes", - "type": "uint256" - }, - { - "name": "active", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "reading", - "outputs": [ - { - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "token", - "outputs": [ - { - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - } +[ + { + "constant": false, + "inputs": [ + { + "name": "import_id", + "type": "bytes32" + }, + { + "name": "DH_node_id", + "type": "bytes32" + } + ], + "name": "addBid", + "outputs": [ + { + "name": "distance", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "new_stake_per_byte_minute", + "type": "uint256" + } + ], + "name": "setStake", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "amount", + "type": "uint256" + } + ], + "name": "withdrawToken", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "import_id", + "type": "bytes32" + }, + { + "name": "DC_node_id", + "type": "bytes32" + }, + { + "name": "total_escrow_time_in_minutes", + "type": "uint256" + }, + { + "name": "max_token_amount_per_DH", + "type": "uint256" + }, + { + "name": "min_stake_amount_per_DH", + "type": "uint256" + }, + { + "name": "min_reputation", + "type": "uint256" + }, + { + "name": "data_hash", + "type": "bytes32" + }, + { + "name": "data_size_in_bytes", + "type": "uint256" + }, + { + "name": "predetermined_DH_wallet", + "type": "address[]" + }, + { + "name": "predetermined_DH_node_id", + "type": "bytes32[]" + } + ], + "name": "createOffer", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "import_id", + "type": "bytes32" + }, + { + "name": "bid_index", + "type": "uint256" + } + ], + "name": "cancelBid", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "wallet", + "type": "address" + }, + { + "name": "amount", + "type": "uint256" + } + ], + "name": "increaseBalance", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "name": "import_id", + "type": "bytes32" + } + ], + "name": "getOfferStatus", + "outputs": [ + { + "name": "isOfferFinal", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "amount", + "type": "uint256" + } + ], + "name": "depositToken", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "name": "a", + "type": "uint256" + }, + { + "name": "b", + "type": "uint256" + } + ], + "name": "absoluteDifference", + "outputs": [ + { + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "pure", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "import_id", + "type": "bytes32" + }, + { + "name": "DH_node_id", + "type": "bytes32" + }, + { + "name": "bid_index", + "type": "uint256" + } + ], + "name": "activatePredeterminedBid", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "new_price_per_byte_minute", + "type": "uint256" + } + ], + "name": "setPrice", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "name": "import_id", + "type": "bytes32" + } + ], + "name": "getDistanceParameters", + "outputs": [ + { + "name": "node_hash", + "type": "bytes32" + }, + { + "name": "data_hash", + "type": "bytes32" + }, + { + "name": "distance", + "type": "uint256" + }, + { + "name": "current_ranking", + "type": "uint256" + }, + { + "name": "required_bid_amount", + "type": "uint256" + }, + { + "name": "active_nodes_", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "new_max_time_in_minutes", + "type": "uint256" + } + ], + "name": "setMaxTime", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "name": "", + "type": "address" + } + ], + "name": "profile", + "outputs": [ + { + "name": "token_amount_per_byte_minute", + "type": "uint256" + }, + { + "name": "stake_amount_per_byte_minute", + "type": "uint256" + }, + { + "name": "read_stake_factor", + "type": "uint256" + }, + { + "name": "balance", + "type": "uint256" + }, + { + "name": "reputation", + "type": "uint256" + }, + { + "name": "number_of_escrows", + "type": "uint256" + }, + { + "name": "max_escrow_time_in_minutes", + "type": "uint256" + }, + { + "name": "active", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "active_nodes", + "outputs": [ + { + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "name": "import_id", + "type": "bytes32" + }, + { + "name": "bid_index", + "type": "uint256" + } + ], + "name": "isBidChosen", + "outputs": [ + { + "name": "_isBidChosen", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "name": "import_id", + "type": "bytes32" + }, + { + "name": "DH_node_id", + "type": "bytes32" + } + ], + "name": "getBidIndex", + "outputs": [ + { + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "node_id", + "type": "bytes32" + }, + { + "name": "price_per_byte_minute", + "type": "uint256" + }, + { + "name": "stake_per_byte_minute", + "type": "uint256" + }, + { + "name": "read_stake_factor", + "type": "uint256" + }, + { + "name": "max_time_in_minutes", + "type": "uint256" + } + ], + "name": "createProfile", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "wallet", + "type": "address" + } + ], + "name": "addEscrow", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "import_id", + "type": "bytes32" + } + ], + "name": "chooseBids", + "outputs": [ + { + "name": "chosen_data_holders", + "type": "uint256[]" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "name": "import_id", + "type": "bytes32" + }, + { + "name": "DH_wallet", + "type": "address" + } + ], + "name": "calculateDistance", + "outputs": [ + { + "name": "distance", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "name": "", + "type": "bytes32" + } + ], + "name": "offer", + "outputs": [ + { + "name": "DC_wallet", + "type": "address" + }, + { + "name": "max_token_amount_per_DH", + "type": "uint256" + }, + { + "name": "min_stake_amount_per_DH", + "type": "uint256" + }, + { + "name": "min_reputation", + "type": "uint256" + }, + { + "name": "total_escrow_time_in_minutes", + "type": "uint256" + }, + { + "name": "data_size_in_bytes", + "type": "uint256" + }, + { + "name": "data_hash", + "type": "bytes32" + }, + { + "name": "first_bid_index", + "type": "uint256" + }, + { + "name": "replication_factor", + "type": "uint256" + }, + { + "name": "active", + "type": "bool" + }, + { + "name": "finalized", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "wallet", + "type": "address" + }, + { + "name": "amount", + "type": "uint256" + } + ], + "name": "increaseReputation", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "escrow", + "outputs": [ + { + "name": "", + "type": "address" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "name": "wallet", + "type": "address" + } + ], + "name": "getBalance", + "outputs": [ + { + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "import_id", + "type": "bytes32" + } + ], + "name": "cancelOffer", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "token", + "outputs": [ + { + "name": "", + "type": "address" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "wallet", + "type": "address" + }, + { + "name": "amount", + "type": "uint256" + } + ], + "name": "decreaseBalance", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "reading", + "outputs": [ + { + "name": "", + "type": "address" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "name": "token_address", + "type": "address" + }, + { + "name": "escrow_address", + "type": "address" + }, + { + "name": "reading_address", + "type": "address" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "name": "import_id", + "type": "bytes32" + }, + { + "indexed": false, + "name": "DC_node_id", + "type": "bytes32" + }, + { + "indexed": false, + "name": "total_escrow_time_in_minutes", + "type": "uint256" + }, + { + "indexed": false, + "name": "max_token_amount_per_DH", + "type": "uint256" + }, + { + "indexed": false, + "name": "min_stake_amount_per_DH", + "type": "uint256" + }, + { + "indexed": false, + "name": "min_reputation", + "type": "uint256" + }, + { + "indexed": false, + "name": "data_size_in_bytes", + "type": "uint256" + }, + { + "indexed": false, + "name": "data_hash", + "type": "bytes32" + } + ], + "name": "OfferCreated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "name": "import_id", + "type": "bytes32" + } + ], + "name": "OfferCanceled", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "name": "import_id", + "type": "bytes32" + }, + { + "indexed": false, + "name": "DH_wallet", + "type": "address" + }, + { + "indexed": false, + "name": "DH_node_id", + "type": "bytes32" + }, + { + "indexed": false, + "name": "bid_index", + "type": "uint256" + } + ], + "name": "AddedBid", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "name": "import_id", + "type": "bytes32" + }, + { + "indexed": false, + "name": "DH_wallet", + "type": "address" + }, + { + "indexed": false, + "name": "DH_node_id", + "type": "bytes32" + }, + { + "indexed": false, + "name": "bid_index", + "type": "uint256" + }, + { + "indexed": false, + "name": "total_escrow_time_in_minutes", + "type": "uint256" + }, + { + "indexed": false, + "name": "max_token_amount_per_DH", + "type": "uint256" + }, + { + "indexed": false, + "name": "min_stake_amount_per_DH", + "type": "uint256" + }, + { + "indexed": false, + "name": "data_size_in_bytes", + "type": "uint256" + } + ], + "name": "AddedPredeterminedBid", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "name": "import_id", + "type": "bytes32" + } + ], + "name": "FinalizeOfferReady", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "name": "import_id", + "type": "bytes32" + }, + { + "indexed": false, + "name": "DH_wallet", + "type": "address" + } + ], + "name": "BidTaken", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "name": "import_id", + "type": "bytes32" + } + ], + "name": "OfferFinalized", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "name": "wallet", + "type": "address" + }, + { + "indexed": false, + "name": "node_id", + "type": "bytes32" + } + ], + "name": "ProfileCreated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "name": "wallet", + "type": "address" + }, + { + "indexed": false, + "name": "new_balance", + "type": "uint256" + } + ], + "name": "BalanceModified", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "name": "wallet", + "type": "address" + }, + { + "indexed": false, + "name": "new_balance", + "type": "uint256" + } + ], + "name": "ReputationModified", + "type": "event" + } ] \ No newline at end of file diff --git a/modules/Blockchain/Ethereum/contracts/Bidding.sol b/modules/Blockchain/Ethereum/contracts/Bidding.sol index 168a3a95ea..004568964c 100644 --- a/modules/Blockchain/Ethereum/contracts/Bidding.sol +++ b/modules/Blockchain/Ethereum/contracts/Bidding.sol @@ -44,53 +44,13 @@ contract EscrowHolder { function initiateEscrow(address DC_wallet, address DH_wallet, bytes32 import_id, uint token_amount, uint stake_amount, uint total_time_in_minutes) public; } -/** - * @title Ownable - * @dev The Ownable contract has an owner address, and provides basic authorization control - * functions, this simplifies the implementation of "user permissions". - */ - contract Ownable { - address public owner; - - event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); - - /** - * @dev The Ownable constructor sets the original `owner` of the contract to the sender - * account. - */ - function Ownable () public { - owner = msg.sender; - } - - /** - * @dev Throws if called by any account other than the owner. - */ - modifier onlyOwner() { - require(msg.sender == owner); - _; - } - - /** - * @dev Allows the current owner to transfer control of the contract to a newOwner. - * @param newOwner The address to transfer ownership to. - */ - function transferOwnership(address newOwner) public onlyOwner { - require(newOwner != address(0)); - emit OwnershipTransferred(owner, newOwner); - owner = newOwner; - } - - } - -contract Bidding is Ownable{ +contract Bidding { using SafeMath for uint256; ERC20 public token; EscrowHolder public escrow; address public reading; - uint replication_modifier; - modifier onlyContracts() { require(EscrowHolder(msg.sender) == escrow || msg.sender == reading); _; @@ -98,17 +58,11 @@ contract Bidding is Ownable{ function Bidding(address token_address, address escrow_address, address reading_address) public{ - require(msg.sender != address(0)); require ( token_address != address(0) && escrow_address != address(0) && reading_address != address(0)); token = ERC20(token_address); escrow = EscrowHolder(escrow_address); reading = reading_address; active_nodes = 0; - replication_modifier = 1; - } - - function setReplicationModifier(uint new_modifier) public onlyOwner{ - replication_modifier = new_modifier; } @@ -132,7 +86,6 @@ contract Bidding is Ownable{ uint first_bid_index; uint replication_factor; - uint replication_modifier; bool active; bool finalized; @@ -202,14 +155,13 @@ contract Bidding is Ownable{ address[] predetermined_DH_wallet, bytes32[] predetermined_DH_node_id) public { - require(msg.sender != address(0)); OfferDefinition storage this_offer = offer[import_id]; require(max_token_amount_per_DH > 0 && total_escrow_time_in_minutes > 0 && data_size_in_bytes > 0); require(this_offer.active == false); - require(profile[msg.sender].balance >= max_token_amount_per_DH.mul(predetermined_DH_wallet.length.mul(2).add(replication_modifier))); - profile[msg.sender].balance = profile[msg.sender].balance.sub(max_token_amount_per_DH.mul(predetermined_DH_wallet.length.mul(2).add(replication_modifier))); + require(profile[msg.sender].balance >= max_token_amount_per_DH.mul(predetermined_DH_wallet.length.mul(2).add(1))); + profile[msg.sender].balance = profile[msg.sender].balance.sub(max_token_amount_per_DH.mul(predetermined_DH_wallet.length.mul(2).add(1))); emit BalanceModified(msg.sender, profile[msg.sender].balance); this_offer.DC_wallet = msg.sender; @@ -223,7 +175,6 @@ contract Bidding is Ownable{ this_offer.data_size_in_bytes = data_size_in_bytes; this_offer.replication_factor = predetermined_DH_wallet.length; - this_offer.replication_modifier = replication_modifier; this_offer.active = true; this_offer.finalized = false; @@ -244,12 +195,11 @@ contract Bidding is Ownable{ //TODO Decide when and under which conditions DC can cancel an offer function cancelOffer(bytes32 import_id) public{ - require(msg.sender != address(0)); OfferDefinition storage this_offer = offer[import_id]; require(this_offer.active && this_offer.DC_wallet == msg.sender && this_offer.finalized == false); this_offer.active = false; - uint max_total_token_amount = this_offer.max_token_amount_per_DH.mul(this_offer.replication_factor.mul(2).add(this_offer.replication_modifier)); + uint max_total_token_amount = this_offer.max_token_amount_per_DH.mul(this_offer.replication_factor.mul(2).add(1)); profile[msg.sender].balance = profile[msg.sender].balance.add(max_total_token_amount); emit BalanceModified(msg.sender, profile[msg.sender].balance); emit OfferCanceled(import_id); @@ -257,7 +207,6 @@ contract Bidding is Ownable{ function activatePredeterminedBid(bytes32 import_id, bytes32 DH_node_id, uint bid_index) public{ - require(msg.sender != address(0)); require(offer[import_id].active && !offer[import_id].finalized); OfferDefinition storage this_offer = offer[import_id]; @@ -280,7 +229,6 @@ contract Bidding is Ownable{ function getDistanceParameters(bytes32 import_id) public view returns (bytes32 node_hash, bytes32 data_hash, uint256 distance, uint256 current_ranking, uint256 required_bid_amount, uint256 active_nodes_){ - require(msg.sender != address(0)); OfferDefinition storage this_offer = offer[import_id]; node_hash = bytes32(uint128(keccak256(msg.sender))); @@ -288,7 +236,7 @@ contract Bidding is Ownable{ distance = calculateDistance(import_id, msg.sender); - required_bid_amount = this_offer.replication_factor.mul(2).add(this_offer.replication_modifier); + required_bid_amount = this_offer.replication_factor.mul(2).add(1); active_nodes_ = active_nodes; if(this_offer.first_bid_index == uint(-1)){ @@ -306,7 +254,6 @@ contract Bidding is Ownable{ function addBid(bytes32 import_id, bytes32 DH_node_id) public returns (uint distance){ - require(msg.sender != address(0)); require(offer[import_id].active && !offer[import_id].finalized); OfferDefinition storage this_offer = offer[import_id]; @@ -356,14 +303,13 @@ contract Bidding is Ownable{ } } - if(this_offer.bid.length >= this_offer.replication_factor.mul(3).add(this_offer.replication_modifier)) emit FinalizeOfferReady(import_id); + if(this_offer.bid.length >= this_offer.replication_factor.mul(3).add(1)) emit FinalizeOfferReady(import_id); emit AddedBid(import_id, msg.sender, DH_node_id, this_bid_index); // return this_bid_index; } function getBidIndex(bytes32 import_id, bytes32 DH_node_id) public view returns(uint){ - require(msg.sender != address(0)); OfferDefinition storage this_offer = offer[import_id]; uint256 i = 0; while(i < this_offer.bid.length && (offer[import_id].bid[i].DH_wallet != msg.sender || offer[import_id].bid[i].DH_node_id != DH_node_id)) i = i + 1; @@ -373,26 +319,24 @@ contract Bidding is Ownable{ function cancelBid(bytes32 import_id, uint bid_index) public{ - require(msg.sender != address(0)); require(offer[import_id].bid[bid_index].DH_wallet == msg.sender); offer[import_id].bid[bid_index].active = false; } function chooseBids(bytes32 import_id) public returns (uint256[] chosen_data_holders){ - require(msg.sender != address(0)); OfferDefinition storage this_offer = offer[import_id]; require(this_offer.active && !this_offer.finalized); - require(this_offer.replication_factor.mul(3).add(this_offer.replication_modifier) <= this_offer.bid.length); + require(this_offer.replication_factor.mul(3).add(1) <= this_offer.bid.length); // require(this_offer.offer_creation_timestamp + 5 minutes < block.timestamp); - chosen_data_holders = new uint256[](this_offer.replication_factor.mul(2).add(this_offer.replication_modifier)); + chosen_data_holders = new uint256[](this_offer.replication_factor.mul(2).add(1)); uint256 i; uint256 current_index = 0; uint256 token_amount_sent = 0; - uint256 max_total_token_amount = this_offer.max_token_amount_per_DH.mul(this_offer.replication_factor.mul(2).add(this_offer.replication_modifier)); + uint256 max_total_token_amount = this_offer.max_token_amount_per_DH.mul(this_offer.replication_factor.mul(2).add(1)); //Sending escrow requests to predetermined bids for(i = 0; i < this_offer.replication_factor; i = i + 1){ @@ -415,7 +359,7 @@ contract Bidding is Ownable{ //Sending escrow requests to network bids uint256 bid_index = this_offer.first_bid_index; - while(current_index < this_offer.replication_factor.mul(2).add(this_offer.replication_modifier)) { + while(current_index < this_offer.replication_factor.mul(2).add(1)) { while(bid_index != uint(-1) && !this_offer.bid[bid_index].active){ bid_index = this_offer.bid[bid_index].next_bid; @@ -452,12 +396,10 @@ contract Bidding is Ownable{ function isBidChosen(bytes32 import_id, uint bid_index) public constant returns (bool _isBidChosen){ - require(msg.sender != address(0)); return offer[import_id].bid[bid_index].chosen; } function getOfferStatus(bytes32 import_id) public constant returns (bool isOfferFinal){ - require(msg.sender != address(0)); return offer[import_id].finalized; } @@ -468,11 +410,10 @@ contract Bidding is Ownable{ event ReputationModified(address wallet, uint new_balance); function createProfile(bytes32 node_id, uint price_per_byte_minute, uint stake_per_byte_minute, uint read_stake_factor, uint max_time_in_minutes) public{ - require(msg.sender != address(0)); ProfileDefinition storage this_profile = profile[msg.sender]; - require(!this_profile.active); + // require(!this_profile.active); this_profile.active = true; - active_nodes = active_nodes.add(1); + if(!this_profile.active) active_nodes = active_nodes.add(1); this_profile.token_amount_per_byte_minute = price_per_byte_minute; this_profile.stake_amount_per_byte_minute = stake_per_byte_minute; @@ -484,22 +425,18 @@ contract Bidding is Ownable{ } function setPrice(uint new_price_per_byte_minute) public { - require(msg.sender != address(0)); profile[msg.sender].token_amount_per_byte_minute = new_price_per_byte_minute; } function setStake(uint new_stake_per_byte_minute) public { - require(msg.sender != address(0)); profile[msg.sender].stake_amount_per_byte_minute = new_stake_per_byte_minute; } function setMaxTime(uint new_max_time_in_minutes) public { - require(msg.sender != address(0)); profile[msg.sender].max_escrow_time_in_minutes = new_max_time_in_minutes; } function depositToken(uint amount) public { - require(msg.sender != address(0)); require(token.balanceOf(msg.sender) >= amount && token.allowance(msg.sender, this) >= amount); uint amount_to_transfer = amount; amount = 0; @@ -511,7 +448,6 @@ contract Bidding is Ownable{ } function withdrawToken(uint amount) public { - require(msg.sender != address(0)); uint256 amount_to_transfer; if(profile[msg.sender].balance >= amount){ amount_to_transfer = amount; @@ -529,32 +465,27 @@ contract Bidding is Ownable{ } function increaseBalance(address wallet, uint amount) public onlyContracts { - require(msg.sender != address(0)); profile[wallet].balance = profile[wallet].balance.add(amount); emit BalanceModified(wallet, profile[wallet].balance); } function decreaseBalance(address wallet, uint amount) public onlyContracts { - require(msg.sender != address(0)); require(profile[wallet].balance >= amount); profile[wallet].balance = profile[wallet].balance.sub(amount); emit BalanceModified(wallet, profile[wallet].balance); } function increaseReputation(address wallet, uint amount) public onlyContracts { - require(msg.sender != address(0)); profile[wallet].reputation = profile[wallet].reputation.add(amount); emit ReputationModified(wallet, profile[wallet].reputation); } function addEscrow(address wallet) public onlyContracts { - require(msg.sender != address(0)); profile[wallet].number_of_escrows = profile[wallet].number_of_escrows.add(1); } function getBalance(address wallet) public view returns (uint256) { - require(msg.sender != address(0)); return profile[wallet].balance; } @@ -617,7 +548,6 @@ contract Bidding is Ownable{ function calculateDistance(bytes32 import_id, address DH_wallet) public view returns (uint256 distance) { - require(msg.sender != address(0)); OfferDefinition storage this_offer = offer[import_id]; ProfileDefinition storage this_DH = profile[DH_wallet]; diff --git a/modules/Blockchain/Ethereum/contracts/BiddingTest.sol b/modules/Blockchain/Ethereum/contracts/BiddingTest.sol index ab0aae056e..d0e407d195 100644 --- a/modules/Blockchain/Ethereum/contracts/BiddingTest.sol +++ b/modules/Blockchain/Ethereum/contracts/BiddingTest.sol @@ -44,53 +44,13 @@ contract EscrowHolder { function initiateEscrow(address DC_wallet, address DH_wallet, bytes32 import_id, uint token_amount, uint stake_amount, uint total_time_in_minutes) public; } -/** - * @title Ownable - * @dev The Ownable contract has an owner address, and provides basic authorization control - * functions, this simplifies the implementation of "user permissions". - */ - contract Ownable { - address public owner; - - event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); - - /** - * @dev The Ownable constructor sets the original `owner` of the contract to the sender - * account. - */ - function Ownable () public { - owner = msg.sender; - } - - /** - * @dev Throws if called by any account other than the owner. - */ - modifier onlyOwner() { - require(msg.sender == owner); - _; - } - - /** - * @dev Allows the current owner to transfer control of the contract to a newOwner. - * @param newOwner The address to transfer ownership to. - */ - function transferOwnership(address newOwner) public onlyOwner { - require(newOwner != address(0)); - emit OwnershipTransferred(owner, newOwner); - owner = newOwner; - } - - } - -contract BiddingTest is Ownable{ +contract BiddingTest { using SafeMath for uint256; ERC20 public token; EscrowHolder public escrow; address public reading; - uint replication_modifier; - modifier onlyContracts() { require(EscrowHolder(msg.sender) == escrow || msg.sender == reading); _; @@ -98,17 +58,11 @@ contract BiddingTest is Ownable{ function BiddingTest(address token_address, address escrow_address, address reading_address) public{ - require(msg.sender != address(0)); require ( token_address != address(0) && escrow_address != address(0) && reading_address != address(0)); token = ERC20(token_address); escrow = EscrowHolder(escrow_address); reading = reading_address; active_nodes = 0; - replication_modifier = 1; - } - - function setReplicationModifier(uint new_modifier) public onlyOwner{ - replication_modifier = new_modifier; } @@ -132,7 +86,6 @@ contract BiddingTest is Ownable{ uint first_bid_index; uint replication_factor; - uint replication_modifier; bool active; bool finalized; @@ -202,14 +155,13 @@ contract BiddingTest is Ownable{ address[] predetermined_DH_wallet, bytes32[] predetermined_DH_node_id) public { - require(msg.sender != address(0)); OfferDefinition storage this_offer = offer[import_id]; require(max_token_amount_per_DH > 0 && total_escrow_time_in_minutes > 0 && data_size_in_bytes > 0); require(this_offer.active == false); - require(profile[msg.sender].balance >= max_token_amount_per_DH.mul(predetermined_DH_wallet.length.mul(2).add(replication_modifier))); - profile[msg.sender].balance = profile[msg.sender].balance.sub(max_token_amount_per_DH.mul(predetermined_DH_wallet.length.mul(2).add(replication_modifier))); + require(profile[msg.sender].balance >= max_token_amount_per_DH.mul(predetermined_DH_wallet.length.mul(2).add(1))); + profile[msg.sender].balance = profile[msg.sender].balance.sub(max_token_amount_per_DH.mul(predetermined_DH_wallet.length.mul(2).add(1))); emit BalanceModified(msg.sender, profile[msg.sender].balance); this_offer.DC_wallet = msg.sender; @@ -223,7 +175,6 @@ contract BiddingTest is Ownable{ this_offer.data_size_in_bytes = data_size_in_bytes; this_offer.replication_factor = predetermined_DH_wallet.length; - this_offer.replication_modifier = replication_modifier; this_offer.active = true; this_offer.finalized = false; @@ -244,12 +195,11 @@ contract BiddingTest is Ownable{ //TODO Decide when and under which conditions DC can cancel an offer function cancelOffer(bytes32 import_id) public{ - require(msg.sender != address(0)); OfferDefinition storage this_offer = offer[import_id]; require(this_offer.active && this_offer.DC_wallet == msg.sender && this_offer.finalized == false); this_offer.active = false; - uint max_total_token_amount = this_offer.max_token_amount_per_DH.mul(this_offer.replication_factor.mul(2).add(this_offer.replication_modifier)); + uint max_total_token_amount = this_offer.max_token_amount_per_DH.mul(this_offer.replication_factor.mul(2).add(1)); profile[msg.sender].balance = profile[msg.sender].balance.add(max_total_token_amount); emit BalanceModified(msg.sender, profile[msg.sender].balance); emit OfferCanceled(import_id); @@ -257,7 +207,6 @@ contract BiddingTest is Ownable{ function activatePredeterminedBid(bytes32 import_id, bytes32 DH_node_id, uint bid_index) public{ - require(msg.sender != address(0)); require(offer[import_id].active && !offer[import_id].finalized); OfferDefinition storage this_offer = offer[import_id]; @@ -280,7 +229,6 @@ contract BiddingTest is Ownable{ function getDistanceParameters(bytes32 import_id) public view returns (bytes32 node_hash, bytes32 data_hash, uint256 distance, uint256 current_ranking, uint256 required_bid_amount, uint256 active_nodes_){ - require(msg.sender != address(0)); OfferDefinition storage this_offer = offer[import_id]; node_hash = bytes32(uint128(keccak256(msg.sender))); @@ -288,7 +236,7 @@ contract BiddingTest is Ownable{ distance = calculateDistance(import_id, msg.sender); - required_bid_amount = this_offer.replication_factor.mul(2).add(this_offer.replication_modifier); + required_bid_amount = this_offer.replication_factor.mul(2).add(1); active_nodes_ = active_nodes; if(this_offer.first_bid_index == uint(-1)){ @@ -306,7 +254,6 @@ contract BiddingTest is Ownable{ function addBid(bytes32 import_id, bytes32 DH_node_id) public returns (uint distance){ - require(msg.sender != address(0)); require(offer[import_id].active && !offer[import_id].finalized); OfferDefinition storage this_offer = offer[import_id]; @@ -356,14 +303,13 @@ contract BiddingTest is Ownable{ } } - if(this_offer.bid.length >= this_offer.replication_factor.mul(3).add(this_offer.replication_modifier)) emit FinalizeOfferReady(import_id); + if(this_offer.bid.length >= this_offer.replication_factor.mul(3).add(1)) emit FinalizeOfferReady(import_id); emit AddedBid(import_id, msg.sender, DH_node_id, this_bid_index); // return this_bid_index; } function getBidIndex(bytes32 import_id, bytes32 DH_node_id) public view returns(uint){ - require(msg.sender != address(0)); OfferDefinition storage this_offer = offer[import_id]; uint256 i = 0; while(i < this_offer.bid.length && (offer[import_id].bid[i].DH_wallet != msg.sender || offer[import_id].bid[i].DH_node_id != DH_node_id)) i = i + 1; @@ -373,26 +319,24 @@ contract BiddingTest is Ownable{ function cancelBid(bytes32 import_id, uint bid_index) public{ - require(msg.sender != address(0)); require(offer[import_id].bid[bid_index].DH_wallet == msg.sender); offer[import_id].bid[bid_index].active = false; } function chooseBids(bytes32 import_id) public returns (uint256[] chosen_data_holders){ - require(msg.sender != address(0)); OfferDefinition storage this_offer = offer[import_id]; require(this_offer.active && !this_offer.finalized); - require(this_offer.replication_factor.mul(3).add(this_offer.replication_modifier) <= this_offer.bid.length); + require(this_offer.replication_factor.mul(3).add(1) <= this_offer.bid.length); // require(this_offer.offer_creation_timestamp + 5 minutes < block.timestamp); - chosen_data_holders = new uint256[](this_offer.replication_factor.mul(2).add(this_offer.replication_modifier)); + chosen_data_holders = new uint256[](this_offer.replication_factor.mul(2).add(1)); uint256 i; uint256 current_index = 0; uint256 token_amount_sent = 0; - uint256 max_total_token_amount = this_offer.max_token_amount_per_DH.mul(this_offer.replication_factor.mul(2).add(this_offer.replication_modifier)); + uint256 max_total_token_amount = this_offer.max_token_amount_per_DH.mul(this_offer.replication_factor.mul(2).add(1)); //Sending escrow requests to predetermined bids for(i = 0; i < this_offer.replication_factor; i = i + 1){ @@ -415,7 +359,7 @@ contract BiddingTest is Ownable{ //Sending escrow requests to network bids uint256 bid_index = this_offer.first_bid_index; - while(current_index < this_offer.replication_factor.mul(2).add(this_offer.replication_modifier)) { + while(current_index < this_offer.replication_factor.mul(2).add(1)) { while(bid_index != uint(-1) && !this_offer.bid[bid_index].active){ bid_index = this_offer.bid[bid_index].next_bid; @@ -452,12 +396,10 @@ contract BiddingTest is Ownable{ function isBidChosen(bytes32 import_id, uint bid_index) public constant returns (bool _isBidChosen){ - require(msg.sender != address(0)); return offer[import_id].bid[bid_index].chosen; } function getOfferStatus(bytes32 import_id) public constant returns (bool isOfferFinal){ - require(msg.sender != address(0)); return offer[import_id].finalized; } @@ -468,11 +410,11 @@ contract BiddingTest is Ownable{ event ReputationModified(address wallet, uint new_balance); function createProfile(bytes32 node_id, uint price_per_byte_minute, uint stake_per_byte_minute, uint read_stake_factor, uint max_time_in_minutes) public{ - require(msg.sender != address(0)); ProfileDefinition storage this_profile = profile[msg.sender]; - require(!this_profile.active); + // require(!this_profile.active); this_profile.active = true; active_nodes = active_nodes.add(1); + if(!this_profile.active) active_nodes = active_nodes.add(1); this_profile.token_amount_per_byte_minute = price_per_byte_minute; this_profile.stake_amount_per_byte_minute = stake_per_byte_minute; @@ -484,22 +426,18 @@ contract BiddingTest is Ownable{ } function setPrice(uint new_price_per_byte_minute) public { - require(msg.sender != address(0)); profile[msg.sender].token_amount_per_byte_minute = new_price_per_byte_minute; } function setStake(uint new_stake_per_byte_minute) public { - require(msg.sender != address(0)); profile[msg.sender].stake_amount_per_byte_minute = new_stake_per_byte_minute; } function setMaxTime(uint new_max_time_in_minutes) public { - require(msg.sender != address(0)); profile[msg.sender].max_escrow_time_in_minutes = new_max_time_in_minutes; } function depositToken(uint amount) public { - require(msg.sender != address(0)); require(token.balanceOf(msg.sender) >= amount && token.allowance(msg.sender, this) >= amount); uint amount_to_transfer = amount; amount = 0; @@ -511,7 +449,6 @@ contract BiddingTest is Ownable{ } function withdrawToken(uint amount) public { - require(msg.sender != address(0)); uint256 amount_to_transfer; if(profile[msg.sender].balance >= amount){ amount_to_transfer = amount; @@ -529,32 +466,27 @@ contract BiddingTest is Ownable{ } function increaseBalance(address wallet, uint amount) public onlyContracts { - require(msg.sender != address(0)); profile[wallet].balance = profile[wallet].balance.add(amount); emit BalanceModified(wallet, profile[wallet].balance); } function decreaseBalance(address wallet, uint amount) public onlyContracts { - require(msg.sender != address(0)); require(profile[wallet].balance >= amount); profile[wallet].balance = profile[wallet].balance.sub(amount); emit BalanceModified(wallet, profile[wallet].balance); } function increaseReputation(address wallet, uint amount) public onlyContracts { - require(msg.sender != address(0)); profile[wallet].reputation = profile[wallet].reputation.add(amount); emit ReputationModified(wallet, profile[wallet].reputation); } function addEscrow(address wallet) public onlyContracts { - require(msg.sender != address(0)); profile[wallet].number_of_escrows = profile[wallet].number_of_escrows.add(1); } function getBalance(address wallet) public view returns (uint256) { - require(msg.sender != address(0)); return profile[wallet].balance; } @@ -617,7 +549,6 @@ contract BiddingTest is Ownable{ function calculateDistance(bytes32 import_id, address DH_wallet) public view returns (uint256 distance) { - require(msg.sender != address(0)); OfferDefinition storage this_offer = offer[import_id]; ProfileDefinition storage this_DH = profile[DH_wallet]; diff --git a/modules/Blockchain/Ethereum/contracts/Escrow.sol b/modules/Blockchain/Ethereum/contracts/Escrow.sol index 3f1167ada3..68a991b347 100644 --- a/modules/Blockchain/Ethereum/contracts/Escrow.sol +++ b/modules/Blockchain/Ethereum/contracts/Escrow.sol @@ -39,7 +39,7 @@ library SafeMath { * @dev The Ownable constructor sets the original `owner` of the contract to the sender * account. */ - constructor () public { + function Ownable () public { owner = msg.sender; } @@ -56,9 +56,9 @@ library SafeMath { * @param newOwner The address to transfer ownership to. */ function transferOwnership(address newOwner) public onlyOwner { - require(newOwner != address(0)); - emit OwnershipTransferred(owner, newOwner); - owner = newOwner; + require(newOwner != address(0)); + emit OwnershipTransferred(owner, newOwner); + owner = newOwner; } } @@ -97,20 +97,13 @@ library SafeMath { Bidding public bidding; Reading public reading; - uint public litigation_interval_in_seconds; - - function setLitigationInterval(uint newInterval) public onlyOwner{ - litigation_interval_in_seconds = newInterval; - } - - constructor (address tokenAddress) + function EscrowHolder(address tokenAddress) public{ require ( tokenAddress != address(0) ); token = ERC20(tokenAddress); - litigation_interval_in_seconds = 600; } - function setBidding(address biddingAddress) + function setBidding(address biddingAddress) public onlyOwner{ require ( biddingAddress != address(0) ); bidding = Bidding(biddingAddress); @@ -139,7 +132,6 @@ library SafeMath { uint last_confirmation_time; uint end_time; uint total_time_in_seconds; - uint litigation_interval_in_seconds; bytes32 litigation_root_hash; bytes32 distribution_root_hash; @@ -157,8 +149,7 @@ library SafeMath { event EscrowCompleted(bytes32 import_id, address DH_wallet); function initiateEscrow(address DC_wallet, address DH_wallet, bytes32 import_id, uint token_amount, uint stake_amount, uint total_time_in_minutes) - public { - require (msg.sender == address(bidding)); + public onlyOwner{ EscrowDefinition storage this_escrow = escrow[import_id][DH_wallet]; require(this_escrow.escrow_status == EscrowStatus.completed || this_escrow.escrow_status == EscrowStatus.inactive); @@ -171,16 +162,14 @@ library SafeMath { this_escrow.last_confirmation_time = 0; this_escrow.end_time = 0; this_escrow.total_time_in_seconds = total_time_in_minutes.mul(60); - this_escrow.litigation_interval_in_seconds = litigation_interval_in_seconds; this_escrow.escrow_status = EscrowStatus.initiated; emit EscrowInitated(import_id, DH_wallet, token_amount, stake_amount, total_time_in_minutes); } - function addRootHashAndChecksum(bytes32 import_id, bytes32 litigation_root_hash, bytes32 distribution_root_hash, uint256 checksum) - public { - require(msg.sender != address(0)); - EscrowDefinition storage this_escrow = escrow[import_id][msg.sender]; + function addRootHashAndChecksum(bytes32 import_id, bytes32 litigation_root_hash, bytes32 distribution_root_hash, uint256 checksum) + public { + EscrowDefinition storage this_escrow = escrow[import_id][msg.sender]; require(this_escrow.escrow_status == EscrowStatus.initiated); @@ -195,17 +184,16 @@ library SafeMath { emit EscrowConfirmed(import_id, msg.sender); } - function verifyEscrow(bytes32 import_id, address DH_wallet) - public { - require(msg.sender != address(0)); - EscrowDefinition storage this_escrow = escrow[import_id][DH_wallet]; + function verifyEscrow(bytes32 import_id, address DH_wallet) + public { + EscrowDefinition storage this_escrow = escrow[import_id][DH_wallet]; require(this_escrow.DC_wallet == msg.sender && this_escrow.escrow_status == EscrowStatus.confirmed); bidding.addEscrow(msg.sender); bidding.addEscrow(DH_wallet); - + this_escrow.last_confirmation_time = block.timestamp; this_escrow.end_time = SafeMath.add(block.timestamp, this_escrow.total_time_in_seconds); @@ -215,11 +203,10 @@ library SafeMath { emit EscrowVerified(import_id, DH_wallet); } - function payOut(bytes32 import_id) - public { - require(msg.sender != address(0)); - EscrowDefinition storage this_escrow = escrow[import_id][msg.sender]; - LitigationDefinition storage this_litigation = litigation[import_id][msg.sender]; + function payOut(bytes32 import_id) + public{ + EscrowDefinition storage this_escrow = escrow[import_id][msg.sender]; + LitigationDefinition storage this_litigation = litigation[import_id][msg.sender]; require(this_escrow.escrow_status == EscrowStatus.active); require(this_litigation.litigation_status == LitigationStatus.inactive @@ -245,7 +232,7 @@ library SafeMath { assert(amount_to_send.add(this_escrow.tokens_sent) <= this_escrow.token_amount); this_escrow.last_confirmation_time = current_time; } - + if(amount_to_send > 0) { this_escrow.tokens_sent = this_escrow.tokens_sent.add(amount_to_send); bidding.increaseBalance(msg.sender, amount_to_send); @@ -254,7 +241,6 @@ library SafeMath { function cancelEscrow(bytes32 import_id, address correspondent_wallet, bool sender_is_DH) public { - require(msg.sender != address(0)); address DH_wallet; address DC_wallet; @@ -326,11 +312,10 @@ library SafeMath { mapping(bytes32 => mapping ( address => LitigationDefinition)) public litigation; - function initiateLitigation(bytes32 import_id, address DH_wallet, uint requested_data_index, bytes32[] hash_array) - public returns (bool newLitigationInitiated) { - require (msg.sender != address(0)); - LitigationDefinition storage this_litigation = litigation[import_id][DH_wallet]; - EscrowDefinition storage this_escrow = escrow[import_id][DH_wallet]; + function initiateLitigation(bytes32 import_id, address DH_wallet, uint requested_data_index, bytes32[] hash_array) + public returns (bool newLitigationInitiated){ + LitigationDefinition storage this_litigation = litigation[import_id][DH_wallet]; + EscrowDefinition storage this_escrow = escrow[import_id][DH_wallet]; require(this_escrow.DC_wallet == msg.sender && this_escrow.escrow_status == EscrowStatus.active); require(this_litigation.litigation_status == LitigationStatus.inactive || this_litigation.litigation_status == LitigationStatus.completed); @@ -345,15 +330,14 @@ library SafeMath { return true; } - function answerLitigation(bytes32 import_id, bytes32 requested_data) - public returns (bool answer_accepted) { - require (msg.sender != address(0)); - LitigationDefinition storage this_litigation = litigation[import_id][msg.sender]; - EscrowDefinition storage this_escrow = escrow[import_id][msg.sender]; + function answerLitigation(bytes32 import_id, bytes32 requested_data) + public returns (bool answer_accepted){ + LitigationDefinition storage this_litigation = litigation[import_id][msg.sender]; + EscrowDefinition storage this_escrow = escrow[import_id][msg.sender]; require(this_litigation.litigation_status == LitigationStatus.initiated); - if(block.timestamp > this_litigation.litigation_start_time + this_escrow.litigation_interval_in_seconds){ + if(block.timestamp > this_litigation.litigation_start_time + 15 minutes){ uint256 amount_to_send; uint cancelation_time = this_litigation.litigation_start_time; @@ -398,12 +382,10 @@ library SafeMath { */ function cancelInactiveLitigation(bytes32 import_id) public { - require(msg.sender != address(0)); LitigationDefinition storage this_litigation = litigation[import_id][msg.sender]; - EscrowDefinition storage this_escrow = escrow[import_id][msg.sender]; require(this_litigation.litigation_status == LitigationStatus.answered - && this_litigation.answer_timestamp + this_escrow.litigation_interval_in_seconds <= block.timestamp); + && this_litigation.answer_timestamp + 15 minutes <= block.timestamp); this_litigation.litigation_status = LitigationStatus.completed; emit LitigationCompleted(import_id, msg.sender, false); @@ -412,23 +394,22 @@ library SafeMath { function proveLitigaiton(bytes32 import_id, address DH_wallet, bytes32 proof_data) public returns (bool DH_was_penalized){ - require (msg.sender != address(0)); - LitigationDefinition storage this_litigation = litigation[import_id][DH_wallet]; - EscrowDefinition storage this_escrow = escrow[import_id][DH_wallet]; + LitigationDefinition storage this_litigation = litigation[import_id][DH_wallet]; + EscrowDefinition storage this_escrow = escrow[import_id][DH_wallet]; - require(this_escrow.DC_wallet == msg.sender && - (this_litigation.litigation_status == LitigationStatus.initiated + require(this_escrow.DC_wallet == msg.sender && + (this_litigation.litigation_status == LitigationStatus.initiated || this_litigation.litigation_status == LitigationStatus.answered)); if (this_litigation.litigation_status == LitigationStatus.initiated){ - require(this_litigation.litigation_start_time + this_escrow.litigation_interval_in_seconds <= block.timestamp); + require(this_litigation.litigation_start_time + 15 minutes <= block.timestamp); uint256 amount_to_send; uint cancelation_time = this_litigation.litigation_start_time; amount_to_send = SafeMath.mul(this_escrow.token_amount, SafeMath.sub(this_escrow.end_time,cancelation_time)) / this_escrow.total_time_in_seconds; - //Transfer the amount_to_send to DC + //Transfer the amount_to_send to DC if(amount_to_send > 0) { this_escrow.tokens_sent = this_escrow.tokens_sent.add(amount_to_send); bidding.increaseBalance(msg.sender, amount_to_send); @@ -455,8 +436,8 @@ library SafeMath { uint256 i = 0; uint256 one = 1; - bytes32 proof_hash = keccak256(proof_data, this_litigation.requested_data_index); - // bytes32 proof_hash = keccak256(abi.encodePacked(proof_data, this_litigation.requested_data_index)); + bytes32 proof_hash = keccak256(proof_data, this_litigation.requested_data_index); + // bytes32 proof_hash = keccak256(abi.encodePacked(proof_data, this_litigation.requested_data_index)); bytes32 answer_hash = this_litigation.requested_data; // ako je bit 1 on je levo @@ -490,7 +471,7 @@ library SafeMath { cancelation_time = this_litigation.litigation_start_time; amount_to_send = SafeMath.mul(this_escrow.token_amount, SafeMath.sub(this_escrow.end_time,cancelation_time)) / this_escrow.total_time_in_seconds; - //Transfer the amount_to_send to DC + //Transfer the amount_to_send to DC if(amount_to_send > 0) { this_escrow.tokens_sent = this_escrow.tokens_sent.add(amount_to_send); bidding.increaseBalance(msg.sender, amount_to_send); @@ -514,4 +495,4 @@ library SafeMath { return true; } } - } + } \ No newline at end of file diff --git a/modules/Blockchain/Ethereum/contracts/Reading.sol b/modules/Blockchain/Ethereum/contracts/Reading.sol index c9c6c5bc3b..fcb9ce3e54 100644 --- a/modules/Blockchain/Ethereum/contracts/Reading.sol +++ b/modules/Blockchain/Ethereum/contracts/Reading.sol @@ -110,21 +110,18 @@ contract Reading is Ownable{ function Reading(address escrow_address) public { - require (msg.sender != address(0)); require(escrow_address != address(0)); escrow = escrow_address; } function setBidding(address bidding_address) public onlyOwner { - require (msg.sender != address(0)); require(bidding_address != address(0)); bidding = Bidding(bidding_address); } function addReadData (bytes32 import_id, address DH_wallet, address DC_wallet, bytes32 distribution_root_hash, uint256 checksum) public onlyOwner { - require (msg.sender != address(0)); PurchasedDataDefinition storage this_purchased_data = purchased_data[import_id][DH_wallet]; this_purchased_data.DC_wallet = DC_wallet; @@ -134,7 +131,6 @@ contract Reading is Ownable{ function removeReadData (bytes32 import_id, address DH_wallet) public onlyOwner { - require (msg.sender != address(0)); PurchasedDataDefinition storage this_purchased_data = purchased_data[import_id][DH_wallet]; this_purchased_data.DC_wallet = address(0); @@ -144,7 +140,6 @@ contract Reading is Ownable{ function initiatePurchase(bytes32 import_id, address DH_wallet, uint token_amount, uint stake_factor) public { - require (msg.sender != address(0)); PurchaseDefinition storage this_purchase = purchase[DH_wallet][msg.sender][import_id]; require(this_purchase.purchase_status == PurchaseStatus.inactive || this_purchase.purchase_status == PurchaseStatus.completed); @@ -165,7 +160,6 @@ contract Reading is Ownable{ function sendCommitment(bytes32 import_id, address DV_wallet, bytes32 commitment) public { - require (msg.sender != address(0)); PurchaseDefinition storage this_purchase = purchase[msg.sender][DV_wallet][import_id]; require(this_purchase.purchase_status == PurchaseStatus.initiated); @@ -181,7 +175,6 @@ contract Reading is Ownable{ function confirmPurchase(bytes32 import_id, address DH_wallet) public { - require (msg.sender != address(0)); PurchaseDefinition storage this_purchase = purchase[DH_wallet][msg.sender][import_id]; require(this_purchase.purchase_status == PurchaseStatus.commited); @@ -191,7 +184,6 @@ contract Reading is Ownable{ function cancelPurchase(bytes32 import_id, address correspondent_wallet, bool sender_is_DH) public { - require (msg.sender != address(0)); address DH_wallet; address DV_wallet; @@ -220,7 +212,6 @@ contract Reading is Ownable{ function sendEncryptedBlock(bytes32 import_id, address DV_wallet, uint256 encrypted_block) public { - require (msg.sender != address(0)); PurchaseDefinition storage this_purchase = purchase[msg.sender][DV_wallet][import_id]; PurchasedDataDefinition storage this_purchased_data = purchased_data[import_id][DV_wallet]; PurchasedDataDefinition storage previous_purchase = purchased_data[import_id][msg.sender]; @@ -241,7 +232,6 @@ contract Reading is Ownable{ function payOut(bytes32 import_id, address DV_wallet) public { - require (msg.sender != address(0)); PurchaseDefinition storage this_purchase = purchase[msg.sender][DV_wallet][import_id]; require(this_purchase.purchase_status == PurchaseStatus.sent @@ -258,7 +248,6 @@ contract Reading is Ownable{ function initiateDispute(bytes32 import_id, address DH_wallet) public { - require (msg.sender != address(0)); PurchaseDefinition storage this_purchase = purchase[DH_wallet][msg.sender][import_id]; require(this_purchase.purchase_status == PurchaseStatus.sent @@ -273,7 +262,6 @@ contract Reading is Ownable{ uint256 random_number_1, uint256 random_number_2, uint256 decryption_key, uint256 block_index) public { - require (msg.sender != address(0)); PurchaseDefinition storage this_purchase = purchase[msg.sender][DV_wallet][import_id]; bool commitment_proof = this_purchase.commitment == keccak256(checksum_left, checksum_right, checksum_hash, random_number_1, random_number_2, decryption_key, block_index); @@ -290,4 +278,4 @@ contract Reading is Ownable{ } this_purchase.purchase_status = PurchaseStatus.completed; } -} +} \ No newline at end of file diff --git a/modules/Blockchain/Ethereum/escrow-contract/abi.json b/modules/Blockchain/Ethereum/escrow-contract/abi.json index 383d5fd1a5..90a37c5c26 100644 --- a/modules/Blockchain/Ethereum/escrow-contract/abi.json +++ b/modules/Blockchain/Ethereum/escrow-contract/abi.json @@ -1,649 +1,617 @@ -[ - { - "constant": false, - "inputs": [ - { - "name": "newInterval", - "type": "uint256" - } - ], - "name": "setLitigationInterval", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "DC_wallet", - "type": "address" - }, - { - "name": "DH_wallet", - "type": "address" - }, - { - "name": "import_id", - "type": "bytes32" - }, - { - "name": "token_amount", - "type": "uint256" - }, - { - "name": "stake_amount", - "type": "uint256" - }, - { - "name": "total_time_in_minutes", - "type": "uint256" - } - ], - "name": "initiateEscrow", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "import_id", - "type": "bytes32" - } - ], - "name": "payOut", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "litigation_interval_in_seconds", - "outputs": [ - { - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "name": "", - "type": "bytes32" - }, - { - "name": "", - "type": "address" - } - ], - "name": "litigation", - "outputs": [ - { - "name": "requested_data_index", - "type": "uint256" - }, - { - "name": "requested_data", - "type": "bytes32" - }, - { - "name": "litigation_start_time", - "type": "uint256" - }, - { - "name": "answer_timestamp", - "type": "uint256" - }, - { - "name": "litigation_status", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "owner", - "outputs": [ - { - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "import_id", - "type": "bytes32" - }, - { - "name": "DH_wallet", - "type": "address" - }, - { - "name": "requested_data_index", - "type": "uint256" - }, - { - "name": "hash_array", - "type": "bytes32[]" - } - ], - "name": "initiateLitigation", - "outputs": [ - { - "name": "newLitigationInitiated", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "import_id", - "type": "bytes32" - }, - { - "name": "litigation_root_hash", - "type": "bytes32" - }, - { - "name": "distribution_root_hash", - "type": "bytes32" - }, - { - "name": "checksum", - "type": "uint256" - } - ], - "name": "addRootHashAndChecksum", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "import_id", - "type": "bytes32" - }, - { - "name": "correspondent_wallet", - "type": "address" - }, - { - "name": "sender_is_DH", - "type": "bool" - } - ], - "name": "cancelEscrow", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "import_id", - "type": "bytes32" - } - ], - "name": "cancelInactiveLitigation", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "import_id", - "type": "bytes32" - }, - { - "name": "DH_wallet", - "type": "address" - }, - { - "name": "proof_data", - "type": "bytes32" - } - ], - "name": "proveLitigaiton", - "outputs": [ - { - "name": "DH_was_penalized", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "name": "", - "type": "bytes32" - }, - { - "name": "", - "type": "address" - } - ], - "name": "escrow", - "outputs": [ - { - "name": "DC_wallet", - "type": "address" - }, - { - "name": "token_amount", - "type": "uint256" - }, - { - "name": "tokens_sent", - "type": "uint256" - }, - { - "name": "stake_amount", - "type": "uint256" - }, - { - "name": "last_confirmation_time", - "type": "uint256" - }, - { - "name": "end_time", - "type": "uint256" - }, - { - "name": "total_time_in_seconds", - "type": "uint256" - }, - { - "name": "litigation_interval_in_seconds", - "type": "uint256" - }, - { - "name": "litigation_root_hash", - "type": "bytes32" - }, - { - "name": "distribution_root_hash", - "type": "bytes32" - }, - { - "name": "checksum", - "type": "uint256" - }, - { - "name": "escrow_status", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "bidding", - "outputs": [ - { - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "biddingAddress", - "type": "address" - } - ], - "name": "setBidding", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "readingAddress", - "type": "address" - } - ], - "name": "setReading", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "newOwner", - "type": "address" - } - ], - "name": "transferOwnership", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "import_id", - "type": "bytes32" - }, - { - "name": "DH_wallet", - "type": "address" - } - ], - "name": "verifyEscrow", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "token", - "outputs": [ - { - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "import_id", - "type": "bytes32" - }, - { - "name": "requested_data", - "type": "bytes32" - } - ], - "name": "answerLitigation", - "outputs": [ - { - "name": "answer_accepted", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "reading", - "outputs": [ - { - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "name": "tokenAddress", - "type": "address" - } - ], - "payable": false, - "stateMutability": "nonpayable", - "type": "constructor" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "name": "import_id", - "type": "bytes32" - }, - { - "indexed": false, - "name": "DH_wallet", - "type": "address" - }, - { - "indexed": false, - "name": "token_amount", - "type": "uint256" - }, - { - "indexed": false, - "name": "stake_amount", - "type": "uint256" - }, - { - "indexed": false, - "name": "total_time_in_seconds", - "type": "uint256" - } - ], - "name": "EscrowInitated", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "name": "import_id", - "type": "bytes32" - }, - { - "indexed": false, - "name": "DH_wallet", - "type": "address" - } - ], - "name": "EscrowConfirmed", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "name": "import_id", - "type": "bytes32" - }, - { - "indexed": false, - "name": "DH_wallet", - "type": "address" - } - ], - "name": "EscrowVerified", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "name": "import_id", - "type": "bytes32" - }, - { - "indexed": false, - "name": "DH_wallet", - "type": "address" - } - ], - "name": "EscrowCanceled", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "name": "import_id", - "type": "bytes32" - }, - { - "indexed": false, - "name": "DH_wallet", - "type": "address" - } - ], - "name": "EscrowCompleted", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "name": "import_id", - "type": "bytes32" - }, - { - "indexed": false, - "name": "DH_wallet", - "type": "address" - }, - { - "indexed": false, - "name": "requested_data_index", - "type": "uint256" - } - ], - "name": "LitigationInitiated", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "name": "import_id", - "type": "bytes32" - }, - { - "indexed": false, - "name": "DH_wallet", - "type": "address" - } - ], - "name": "LitigationAnswered", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "name": "import_id", - "type": "bytes32" - }, - { - "indexed": false, - "name": "DH_wallet", - "type": "address" - } - ], - "name": "LitigationTimedOut", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "name": "import_id", - "type": "bytes32" - }, - { - "indexed": false, - "name": "DH_wallet", - "type": "address" - }, - { - "indexed": false, - "name": "DH_was_penalized", - "type": "bool" - } - ], - "name": "LitigationCompleted", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "name": "previousOwner", - "type": "address" - }, - { - "indexed": true, - "name": "newOwner", - "type": "address" - } - ], - "name": "OwnershipTransferred", - "type": "event" - } +[ + { + "constant": false, + "inputs": [ + { + "name": "DC_wallet", + "type": "address" + }, + { + "name": "DH_wallet", + "type": "address" + }, + { + "name": "import_id", + "type": "bytes32" + }, + { + "name": "token_amount", + "type": "uint256" + }, + { + "name": "stake_amount", + "type": "uint256" + }, + { + "name": "total_time_in_minutes", + "type": "uint256" + } + ], + "name": "initiateEscrow", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "import_id", + "type": "bytes32" + } + ], + "name": "payOut", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "name": "", + "type": "bytes32" + }, + { + "name": "", + "type": "address" + } + ], + "name": "litigation", + "outputs": [ + { + "name": "requested_data_index", + "type": "uint256" + }, + { + "name": "requested_data", + "type": "bytes32" + }, + { + "name": "litigation_start_time", + "type": "uint256" + }, + { + "name": "answer_timestamp", + "type": "uint256" + }, + { + "name": "litigation_status", + "type": "uint8" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "owner", + "outputs": [ + { + "name": "", + "type": "address" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "import_id", + "type": "bytes32" + }, + { + "name": "DH_wallet", + "type": "address" + }, + { + "name": "requested_data_index", + "type": "uint256" + }, + { + "name": "hash_array", + "type": "bytes32[]" + } + ], + "name": "initiateLitigation", + "outputs": [ + { + "name": "newLitigationInitiated", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "import_id", + "type": "bytes32" + }, + { + "name": "litigation_root_hash", + "type": "bytes32" + }, + { + "name": "distribution_root_hash", + "type": "bytes32" + }, + { + "name": "checksum", + "type": "uint256" + } + ], + "name": "addRootHashAndChecksum", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "import_id", + "type": "bytes32" + }, + { + "name": "correspondent_wallet", + "type": "address" + }, + { + "name": "sender_is_DH", + "type": "bool" + } + ], + "name": "cancelEscrow", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "import_id", + "type": "bytes32" + } + ], + "name": "cancelInactiveLitigation", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "import_id", + "type": "bytes32" + }, + { + "name": "DH_wallet", + "type": "address" + }, + { + "name": "proof_data", + "type": "bytes32" + } + ], + "name": "proveLitigaiton", + "outputs": [ + { + "name": "DH_was_penalized", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "name": "", + "type": "bytes32" + }, + { + "name": "", + "type": "address" + } + ], + "name": "escrow", + "outputs": [ + { + "name": "DC_wallet", + "type": "address" + }, + { + "name": "token_amount", + "type": "uint256" + }, + { + "name": "tokens_sent", + "type": "uint256" + }, + { + "name": "stake_amount", + "type": "uint256" + }, + { + "name": "last_confirmation_time", + "type": "uint256" + }, + { + "name": "end_time", + "type": "uint256" + }, + { + "name": "total_time_in_seconds", + "type": "uint256" + }, + { + "name": "litigation_root_hash", + "type": "bytes32" + }, + { + "name": "distribution_root_hash", + "type": "bytes32" + }, + { + "name": "checksum", + "type": "uint256" + }, + { + "name": "escrow_status", + "type": "uint8" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "bidding", + "outputs": [ + { + "name": "", + "type": "address" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "biddingAddress", + "type": "address" + } + ], + "name": "setBidding", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "readingAddress", + "type": "address" + } + ], + "name": "setReading", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "newOwner", + "type": "address" + } + ], + "name": "transferOwnership", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "import_id", + "type": "bytes32" + }, + { + "name": "DH_wallet", + "type": "address" + } + ], + "name": "verifyEscrow", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "token", + "outputs": [ + { + "name": "", + "type": "address" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "import_id", + "type": "bytes32" + }, + { + "name": "requested_data", + "type": "bytes32" + } + ], + "name": "answerLitigation", + "outputs": [ + { + "name": "answer_accepted", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "reading", + "outputs": [ + { + "name": "", + "type": "address" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "name": "tokenAddress", + "type": "address" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "name": "import_id", + "type": "bytes32" + }, + { + "indexed": false, + "name": "DH_wallet", + "type": "address" + }, + { + "indexed": false, + "name": "token_amount", + "type": "uint256" + }, + { + "indexed": false, + "name": "stake_amount", + "type": "uint256" + }, + { + "indexed": false, + "name": "total_time_in_seconds", + "type": "uint256" + } + ], + "name": "EscrowInitated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "name": "import_id", + "type": "bytes32" + }, + { + "indexed": false, + "name": "DH_wallet", + "type": "address" + } + ], + "name": "EscrowConfirmed", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "name": "import_id", + "type": "bytes32" + }, + { + "indexed": false, + "name": "DH_wallet", + "type": "address" + } + ], + "name": "EscrowVerified", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "name": "import_id", + "type": "bytes32" + }, + { + "indexed": false, + "name": "DH_wallet", + "type": "address" + } + ], + "name": "EscrowCanceled", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "name": "import_id", + "type": "bytes32" + }, + { + "indexed": false, + "name": "DH_wallet", + "type": "address" + } + ], + "name": "EscrowCompleted", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "name": "import_id", + "type": "bytes32" + }, + { + "indexed": false, + "name": "DH_wallet", + "type": "address" + }, + { + "indexed": false, + "name": "requested_data_index", + "type": "uint256" + } + ], + "name": "LitigationInitiated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "name": "import_id", + "type": "bytes32" + }, + { + "indexed": false, + "name": "DH_wallet", + "type": "address" + } + ], + "name": "LitigationAnswered", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "name": "import_id", + "type": "bytes32" + }, + { + "indexed": false, + "name": "DH_wallet", + "type": "address" + } + ], + "name": "LitigationTimedOut", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "name": "import_id", + "type": "bytes32" + }, + { + "indexed": false, + "name": "DH_wallet", + "type": "address" + }, + { + "indexed": false, + "name": "DH_was_penalized", + "type": "bool" + } + ], + "name": "LitigationCompleted", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "name": "previousOwner", + "type": "address" + }, + { + "indexed": true, + "name": "newOwner", + "type": "address" + } + ], + "name": "OwnershipTransferred", + "type": "event" + } ] \ No newline at end of file diff --git a/modules/Blockchain/Ethereum/index.js b/modules/Blockchain/Ethereum/index.js index 02564ef9d3..e83c9bcd6c 100644 --- a/modules/Blockchain/Ethereum/index.js +++ b/modules/Blockchain/Ethereum/index.js @@ -399,14 +399,13 @@ class Ethereum { gasPrice: this.web3.utils.toHex(this.config.gas_price), to: this.biddingContractAddress, }; - - this.log.trace('Create offer on contract.'); + this.log.trace(`createOffer (${importId}, ${nodeId}, ${totalEscrowTime}, ${maxTokenAmount}, ${MinStakeAmount}, ${minReputation}, ${dataHash}, ${dataSize}, ${predeterminedDhWallets}, ${predeterminedDhNodeIds}`); return this.transactions.queueTransaction( this.biddingContractAbi, 'createOffer', [ importId, Utilities.normalizeHex(nodeId), - totalEscrowTime, + Math.round(totalEscrowTime / 1000 / 60), // In minutestotalEscrowTime maxTokenAmount, MinStakeAmount, minReputation, diff --git a/modules/Blockchain/Ethereum/migrations/2_total_migration.js b/modules/Blockchain/Ethereum/migrations/2_total_migration.js index d39a414670..8a46dabe87 100644 --- a/modules/Blockchain/Ethereum/migrations/2_total_migration.js +++ b/modules/Blockchain/Ethereum/migrations/2_total_migration.js @@ -156,6 +156,8 @@ module.exports = (deployer, network, accounts) => { await reading.setBidding(bidding.address, { from: accounts[0] }) .then(async () => { await reading.transferOwnership(escrow.address, { from: accounts[0] }) + .then(async () => { + await escrow.transferOwnership(bidding.address, { from: accounts[0] }) .then(async () => { var amounts = []; var recepients = []; @@ -183,6 +185,7 @@ module.exports = (deployer, network, accounts) => { }); }); }); + }); break; // eslint-disable-next-line case 'rinkeby': @@ -291,4 +294,3 @@ module.exports = (deployer, network, accounts) => { break; } }; - diff --git a/modules/Blockchain/Ethereum/reading-contract/abi.json b/modules/Blockchain/Ethereum/reading-contract/abi.json index 45ba8eedac..004e9e2c47 100644 --- a/modules/Blockchain/Ethereum/reading-contract/abi.json +++ b/modules/Blockchain/Ethereum/reading-contract/abi.json @@ -1,549 +1,549 @@ -[ - { - "constant": true, - "inputs": [ - { - "name": "", - "type": "bytes32" - }, - { - "name": "", - "type": "address" - } - ], - "name": "purchased_data", - "outputs": [ - { - "name": "DC_wallet", - "type": "address" - }, - { - "name": "distribution_root_hash", - "type": "bytes32" - }, - { - "name": "checksum", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "import_id", - "type": "bytes32" - }, - { - "name": "DH_wallet", - "type": "address" - } - ], - "name": "confirmPurchase", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "import_id", - "type": "bytes32" - }, - { - "name": "DH_wallet", - "type": "address" - }, - { - "name": "token_amount", - "type": "uint256" - }, - { - "name": "stake_factor", - "type": "uint256" - } - ], - "name": "initiatePurchase", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "import_id", - "type": "bytes32" - }, - { - "name": "DV_wallet", - "type": "address" - } - ], - "name": "payOut", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "import_id", - "type": "bytes32" - }, - { - "name": "DH_wallet", - "type": "address" - } - ], - "name": "initiateDispute", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "import_id", - "type": "bytes32" - }, - { - "name": "DH_wallet", - "type": "address" - } - ], - "name": "removeReadData", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "import_id", - "type": "bytes32" - }, - { - "name": "DV_wallet", - "type": "address" - }, - { - "name": "commitment", - "type": "bytes32" - } - ], - "name": "sendCommitment", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "owner", - "outputs": [ - { - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "import_id", - "type": "bytes32" - }, - { - "name": "DV_wallet", - "type": "address" - }, - { - "name": "checksum_left", - "type": "uint256" - }, - { - "name": "checksum_right", - "type": "uint256" - }, - { - "name": "checksum_hash", - "type": "bytes32" - }, - { - "name": "random_number_1", - "type": "uint256" - }, - { - "name": "random_number_2", - "type": "uint256" - }, - { - "name": "decryption_key", - "type": "uint256" - }, - { - "name": "block_index", - "type": "uint256" - } - ], - "name": "sendProofData", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "import_id", - "type": "bytes32" - }, - { - "name": "correspondent_wallet", - "type": "address" - }, - { - "name": "sender_is_DH", - "type": "bool" - } - ], - "name": "cancelPurchase", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "name": "", - "type": "address" - }, - { - "name": "", - "type": "address" - }, - { - "name": "", - "type": "bytes32" - } - ], - "name": "purchase", - "outputs": [ - { - "name": "token_amount", - "type": "uint256" - }, - { - "name": "stake_factor", - "type": "uint256" - }, - { - "name": "commitment", - "type": "bytes32" - }, - { - "name": "encrypted_block", - "type": "uint256" - }, - { - "name": "time_of_sending", - "type": "uint256" - }, - { - "name": "purchase_status", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "import_id", - "type": "bytes32" - }, - { - "name": "DV_wallet", - "type": "address" - }, - { - "name": "encrypted_block", - "type": "uint256" - } - ], - "name": "sendEncryptedBlock", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "bidding_address", - "type": "address" - } - ], - "name": "setBidding", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "import_id", - "type": "bytes32" - }, - { - "name": "DH_wallet", - "type": "address" - }, - { - "name": "DC_wallet", - "type": "address" - }, - { - "name": "distribution_root_hash", - "type": "bytes32" - }, - { - "name": "checksum", - "type": "uint256" - } - ], - "name": "addReadData", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "newOwner", - "type": "address" - } - ], - "name": "transferOwnership", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "name": "escrow_address", - "type": "address" - } - ], - "payable": false, - "stateMutability": "nonpayable", - "type": "constructor" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "name": "import_id", - "type": "bytes32" - }, - { - "indexed": false, - "name": "DH_wallet", - "type": "address" - }, - { - "indexed": false, - "name": "DV_wallet", - "type": "address" - } - ], - "name": "PurchaseInitiated", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "name": "import_id", - "type": "bytes32" - }, - { - "indexed": false, - "name": "DH_wallet", - "type": "address" - }, - { - "indexed": false, - "name": "DV_wallet", - "type": "address" - } - ], - "name": "CommitmentSent", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "name": "import_id", - "type": "bytes32" - }, - { - "indexed": false, - "name": "DH_wallet", - "type": "address" - }, - { - "indexed": false, - "name": "DV_wallet", - "type": "address" - } - ], - "name": "PurchaseConfirmed", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "name": "import_id", - "type": "bytes32" - }, - { - "indexed": false, - "name": "DH_wallet", - "type": "address" - }, - { - "indexed": false, - "name": "DV_wallet", - "type": "address" - } - ], - "name": "PurchaseCancelled", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "name": "import_id", - "type": "bytes32" - }, - { - "indexed": false, - "name": "DH_wallet", - "type": "address" - }, - { - "indexed": false, - "name": "DV_wallet", - "type": "address" - } - ], - "name": "EncryptedBlockSent", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "name": "import_id", - "type": "bytes32" - }, - { - "indexed": false, - "name": "DH_wallet", - "type": "address" - }, - { - "indexed": false, - "name": "DV_wallet", - "type": "address" - } - ], - "name": "PurchaseDisputed", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "name": "import_id", - "type": "bytes32" - }, - { - "indexed": false, - "name": "DH_wallet", - "type": "address" - }, - { - "indexed": false, - "name": "DV_wallet", - "type": "address" - }, - { - "indexed": false, - "name": "proof_was_correct", - "type": "bool" - } - ], - "name": "PurchaseDisputeCompleted", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "name": "previousOwner", - "type": "address" - }, - { - "indexed": true, - "name": "newOwner", - "type": "address" - } - ], - "name": "OwnershipTransferred", - "type": "event" - } +[ + { + "constant": true, + "inputs": [ + { + "name": "", + "type": "bytes32" + }, + { + "name": "", + "type": "address" + } + ], + "name": "purchased_data", + "outputs": [ + { + "name": "DC_wallet", + "type": "address" + }, + { + "name": "distribution_root_hash", + "type": "bytes32" + }, + { + "name": "checksum", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "import_id", + "type": "bytes32" + }, + { + "name": "DH_wallet", + "type": "address" + } + ], + "name": "confirmPurchase", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "import_id", + "type": "bytes32" + }, + { + "name": "DH_wallet", + "type": "address" + }, + { + "name": "token_amount", + "type": "uint256" + }, + { + "name": "stake_factor", + "type": "uint256" + } + ], + "name": "initiatePurchase", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "import_id", + "type": "bytes32" + }, + { + "name": "DV_wallet", + "type": "address" + } + ], + "name": "payOut", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "import_id", + "type": "bytes32" + }, + { + "name": "DH_wallet", + "type": "address" + } + ], + "name": "initiateDispute", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "import_id", + "type": "bytes32" + }, + { + "name": "DH_wallet", + "type": "address" + } + ], + "name": "removeReadData", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "import_id", + "type": "bytes32" + }, + { + "name": "DV_wallet", + "type": "address" + }, + { + "name": "commitment", + "type": "bytes32" + } + ], + "name": "sendCommitment", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "owner", + "outputs": [ + { + "name": "", + "type": "address" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "import_id", + "type": "bytes32" + }, + { + "name": "DV_wallet", + "type": "address" + }, + { + "name": "checksum_left", + "type": "uint256" + }, + { + "name": "checksum_right", + "type": "uint256" + }, + { + "name": "checksum_hash", + "type": "bytes32" + }, + { + "name": "random_number_1", + "type": "uint256" + }, + { + "name": "random_number_2", + "type": "uint256" + }, + { + "name": "decryption_key", + "type": "uint256" + }, + { + "name": "block_index", + "type": "uint256" + } + ], + "name": "sendProofData", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "import_id", + "type": "bytes32" + }, + { + "name": "correspondent_wallet", + "type": "address" + }, + { + "name": "sender_is_DH", + "type": "bool" + } + ], + "name": "cancelPurchase", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "name": "", + "type": "address" + }, + { + "name": "", + "type": "address" + }, + { + "name": "", + "type": "bytes32" + } + ], + "name": "purchase", + "outputs": [ + { + "name": "token_amount", + "type": "uint256" + }, + { + "name": "stake_factor", + "type": "uint256" + }, + { + "name": "commitment", + "type": "bytes32" + }, + { + "name": "encrypted_block", + "type": "uint256" + }, + { + "name": "time_of_sending", + "type": "uint256" + }, + { + "name": "purchase_status", + "type": "uint8" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "import_id", + "type": "bytes32" + }, + { + "name": "DV_wallet", + "type": "address" + }, + { + "name": "encrypted_block", + "type": "uint256" + } + ], + "name": "sendEncryptedBlock", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "bidding_address", + "type": "address" + } + ], + "name": "setBidding", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "import_id", + "type": "bytes32" + }, + { + "name": "DH_wallet", + "type": "address" + }, + { + "name": "DC_wallet", + "type": "address" + }, + { + "name": "distribution_root_hash", + "type": "bytes32" + }, + { + "name": "checksum", + "type": "uint256" + } + ], + "name": "addReadData", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "newOwner", + "type": "address" + } + ], + "name": "transferOwnership", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "name": "escrow_address", + "type": "address" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "name": "import_id", + "type": "bytes32" + }, + { + "indexed": false, + "name": "DH_wallet", + "type": "address" + }, + { + "indexed": false, + "name": "DV_wallet", + "type": "address" + } + ], + "name": "PurchaseInitiated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "name": "import_id", + "type": "bytes32" + }, + { + "indexed": false, + "name": "DH_wallet", + "type": "address" + }, + { + "indexed": false, + "name": "DV_wallet", + "type": "address" + } + ], + "name": "CommitmentSent", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "name": "import_id", + "type": "bytes32" + }, + { + "indexed": false, + "name": "DH_wallet", + "type": "address" + }, + { + "indexed": false, + "name": "DV_wallet", + "type": "address" + } + ], + "name": "PurchaseConfirmed", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "name": "import_id", + "type": "bytes32" + }, + { + "indexed": false, + "name": "DH_wallet", + "type": "address" + }, + { + "indexed": false, + "name": "DV_wallet", + "type": "address" + } + ], + "name": "PurchaseCancelled", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "name": "import_id", + "type": "bytes32" + }, + { + "indexed": false, + "name": "DH_wallet", + "type": "address" + }, + { + "indexed": false, + "name": "DV_wallet", + "type": "address" + } + ], + "name": "EncryptedBlockSent", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "name": "import_id", + "type": "bytes32" + }, + { + "indexed": false, + "name": "DH_wallet", + "type": "address" + }, + { + "indexed": false, + "name": "DV_wallet", + "type": "address" + } + ], + "name": "PurchaseDisputed", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "name": "import_id", + "type": "bytes32" + }, + { + "indexed": false, + "name": "DH_wallet", + "type": "address" + }, + { + "indexed": false, + "name": "DV_wallet", + "type": "address" + }, + { + "indexed": false, + "name": "proof_was_correct", + "type": "bool" + } + ], + "name": "PurchaseDisputeCompleted", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "name": "previousOwner", + "type": "address" + }, + { + "indexed": true, + "name": "newOwner", + "type": "address" + } + ], + "name": "OwnershipTransferred", + "type": "event" + } ] \ No newline at end of file diff --git a/modules/Blockchain/Ethereum/test/bidding.test.js b/modules/Blockchain/Ethereum/test/bidding.test.js index dcd6bcd549..3f190611f5 100644 --- a/modules/Blockchain/Ethereum/test/bidding.test.js +++ b/modules/Blockchain/Ethereum/test/bidding.test.js @@ -398,7 +398,7 @@ contract('Bidding testing', async (accounts) => { for (i = 1; i < 10; i += 1) { // eslint-disable-next-line no-await-in-loop response = await escrow.escrow.call(import_id, accounts[i]); - let status = response[11]; + let status = response[10]; status = status.toNumber(); switch (status) { case 0: @@ -583,7 +583,7 @@ contract('Bidding testing', async (accounts) => { for (i = 0; i < chosen_bids.length; i += 1) { // eslint-disable-next-line no-await-in-loop response = await escrow.escrow.call(import_id, accounts[chosen_bids[i]]); - let status = response[11]; + let status = response[10]; status = status.toNumber(); switch (status) { case 0: diff --git a/modules/DCService.js b/modules/DCService.js index 5a615f3ecd..cb77854703 100644 --- a/modules/DCService.js +++ b/modules/DCService.js @@ -33,6 +33,10 @@ class DCService { * @param rootHash * @param totalDocuments * @param vertices + * @param total_escrow_time + * @param max_token_amount + * @param min_stake_amount + * @param min_reputation * @return {Promise} */ async createOffer( @@ -44,7 +48,6 @@ class DCService { max_token_amount, min_stake_amount, min_reputation, - replicationId, ) { // Check if offer already exists const oldOffer = await this.blockchain.getOffer(importId); @@ -113,101 +116,108 @@ class DCService { message: 'Offer is pending', start_tender_time: Date.now(), // TODO: Problem. Actual start time is returned by SC. status: 'PENDING', - external_id: replicationId, }; const offer = await Models.offers.create(newOfferRow); // Check if root-hash already written. - const blockchainRootHash = await this.blockchain.getRootHash(config.node_wallet, importId); - - if (blockchainRootHash.toString() === '0x0000000000000000000000000000000000000000000000000000000000000000') { - await this.blockchain.writeRootHash(importId, rootHash).catch((err) => { - offer.status = 'FAILED'; - offer.save({ fields: ['status'] }); - throw Error(`Failed to write fingerprint on blockchain. ${err}`); - }); - } else if (blockchainRootHash !== rootHash) { - throw Error(`Calculated roothash (${rootHash}) differs from one on blockchain (${blockchainRootHash}).`); - } - - this.log.info('Fingerprint written on blockchain'); + this.blockchain.getRootHash(config.node_wallet, importId) + .then(async (blockchainRootHash) => { + if (blockchainRootHash.toString() === '0x0000000000000000000000000000000000000000000000000000000000000000') { + await this.blockchain.writeRootHash(importId, rootHash).catch((err) => { + offer.status = 'FAILED'; + offer.save({ fields: ['status'] }); + throw Error(`Failed to write fingerprint on blockchain. ${err}`); + }); + } else if (blockchainRootHash !== rootHash) { + throw Error(`Calculated roothash (${rootHash}) differs from one on blockchain (${blockchainRootHash}).`); + } - const profileBalance = - new BN((await this.blockchain.getProfile(config.node_wallet)).balance, 10); - const condition = maxTokenAmount.mul(new BN((dhWallets.length * 2) + 1)); + this.log.info('Fingerprint written on blockchain'); - if (profileBalance.lt(condition)) { - await this.blockchain.increaseBiddingApproval(condition.sub(profileBalance)); - await this.blockchain.depositToken(condition.sub(profileBalance)); - } + const profileBalance = + new BN((await this.blockchain.getProfile(config.node_wallet)).balance, 10); + const condition = maxTokenAmount.mul(new BN((dhWallets.length * 2) + 1)); - this.blockchain.createOffer( - importId, - config.identity, - totalEscrowTime, - maxTokenAmount, - minStakeAmount, - minReputation, - rootHash, - importSizeInBytes, - dhWallets, - dhIds, - ).then(async () => { - this.log.info('Offer written to blockchain. Started bidding phase.'); - offer.status = 'STARTED'; - offer.save({ fields: ['status'] }); - - this.blockchain.subscribeToEvent('FinalizeOfferReady', null, finalizeWaitTime, null, event => event.import_id === importId).then((event) => { - if (!event) { - this.log.notify(`Offer ${importId} not finalized. Canceling offer.`); - this.blockchain.cancelOffer(importId).then(() => { - offer.status = 'CANCELLED'; - offer.message = 'Offer not finalized'; - offer.save({ fields: ['status', 'message'] }); - this.log.trace(`Offer ${importId} canceled.`); - }).catch((error) => { - this.log.warn(`Failed to cancel offer for import ${importId}. ${error}.`); - offer.status = 'STARTED'; - offer.message = 'Failed to cancel. Still opened'; - offer.save({ fields: ['status', 'message'] }); - }); - return; + if (profileBalance.lt(condition)) { + await this.blockchain.increaseBiddingApproval(condition.sub(profileBalance)); + await this.blockchain.depositToken(condition.sub(profileBalance)); } - this.log.trace('Started choosing phase.'); - - offer.status = 'FINALIZING'; - offer.save({ fields: ['status'] }); - this.chooseBids(offer.id, totalEscrowTime).then(() => { - this.blockchain.subscribeToEvent('OfferFinalized', offer.import_id) - .then(() => { - const errorMsg = `Offer for import ${offer.import_id} finalized`; - offer.status = 'FINALIZED'; - offer.message = errorMsg; - offer.save({ fields: ['status', 'message'] }); - this.log.info(errorMsg); - }).catch((error) => { - const errorMsg = `Failed to get offer for import ${offer.import_id}). ${error}.`; + this.blockchain.createOffer( + importId, + config.identity, + totalEscrowTime, + maxTokenAmount, + minStakeAmount, + minReputation, + rootHash, + importSizeInBytes, + dhWallets, + dhIds, + ).then(async () => { + this.log.info('Offer written to blockchain. Started bidding phase.'); + offer.status = 'STARTED'; + offer.save({ fields: ['status'] }); + + this.blockchain.subscribeToEvent('FinalizeOfferReady', null, finalizeWaitTime, null, event => event.import_id === importId).then((event) => { + if (!event) { + this.log.notify(`Offer ${importId} not finalized. Canceling offer.`); + this.blockchain.cancelOffer(importId).then(() => { + offer.status = 'CANCELLED'; + offer.message = 'Offer not finalized'; + offer.save({ fields: ['status', 'message'] }); + this.log.trace(`Offer ${importId} canceled.`); + }).catch((error) => { + this.log.warn(`Failed to cancel offer for import ${importId}. ${error}.`); + offer.status = 'STARTED'; + offer.message = 'Failed to cancel. Still opened'; + offer.save({ fields: ['status', 'message'] }); + }); + return; + } + + this.log.trace('Started choosing phase.'); + + offer.status = 'FINALIZING'; + offer.save({ fields: ['status'] }); + this.chooseBids(offer.id, totalEscrowTime).then(() => { + this.blockchain.subscribeToEvent('OfferFinalized', offer.import_id) + .then(() => { + const errorMsg = `Offer for import ${offer.import_id} finalized`; + offer.status = 'FINALIZED'; + offer.message = errorMsg; + offer.save({ fields: ['status', 'message'] }); + this.log.info(errorMsg); + }).catch((error) => { + const errorMsg = `Failed to get offer for import ${offer.import_id}). ${error}.`; + offer.status = 'FAILED'; + offer.message = errorMsg; + offer.save({ fields: ['status', 'message'] }); + this.log.error(errorMsg); + }); + }).catch((err) => { + const errorMsg = `Failed to choose bids. ${err}`; offer.status = 'FAILED'; offer.message = errorMsg; offer.save({ fields: ['status', 'message'] }); this.log.error(errorMsg); }); + }); }).catch((err) => { - const errorMsg = `Failed to choose bids. ${err}`; + const errorMsg = `Failed to create offer. ${err}.`; offer.status = 'FAILED'; offer.message = errorMsg; offer.save({ fields: ['status', 'message'] }); this.log.error(errorMsg); }); + }).catch((err) => { + const errorMsg = `Failed to fetch root hash for import ${importId}. ${err}.`; + offer.status = 'FAILED'; + offer.message = errorMsg; + offer.save({ fields: ['status', 'message'] }); + this.log.error(errorMsg); }); - }).catch((err) => { - const errorMsg = `Failed to create offer. ${err}.`; - offer.status = 'FAILED'; - offer.message = errorMsg; - offer.save({ fields: ['status', 'message'] }); - this.log.error(errorMsg); - }); + return offer.external_id; } /** @@ -339,7 +349,7 @@ class DCService { importId, kadWallet, ); - this.log.warn('Data successfully verified, preparing to start challenges'); + this.log.important('Data successfully verified, preparing to start challenges'); await this.challenger.startChallenging(); await this.network.kademlia().sendVerifyImportResponse({ diff --git a/modules/DHService.js b/modules/DHService.js index aaf4f3d261..a27414b3e9 100644 --- a/modules/DHService.js +++ b/modules/DHService.js @@ -132,7 +132,7 @@ class DHService { .mul(new BN(totalEscrowTimePerMinute)); if (maxTokenAmount.lt(myPrice)) { - this.log.info(`Offer ${importId} too expensive for me.`); + this.log.info(`Offer ${importId} too cheap for me.`); return; } @@ -738,7 +738,7 @@ class DHService { this.listenPurchaseConfirmation( importId, wallet, networkReplyModel, selectedBlock, eHex, - ).then(() => this.log.info('Purchase confirmation completed')); + ).then(() => this.log.important('Purchase confirmation completed')); } /** @@ -751,11 +751,11 @@ class DHService { // Everything is ok. this.log.warn(`Purchase not confirmed for ${importId}.`); await this.blockchain.cancelPurchase(importId, wallet, true); - this.log.info(`Purchase for import ${importId} canceled.`); + this.log.important(`Purchase for import ${importId} canceled.`); return; } - this.log.info(`[DH] Purchase confirmed for import ID ${importId}`); + this.log.important(`[DH] Purchase confirmed for import ID ${importId}`); await this.blockchain.sendEncryptedBlock( importId, networkReplyModel.receiver_wallet, @@ -764,7 +764,7 @@ class DHService { Utilities.denormalizeHex(eHex), )), ); - this.log.info(`[DH] Encrypted block sent for import ID ${importId}`); + this.log.notify(`[DH] Encrypted block sent for import ID ${importId}`); this.blockchain.subscribeToEvent('PurchaseConfirmed', importId, 10 * 60 * 1000); // Call payOut() after 5 minutes. Requirement from contract. diff --git a/modules/EventEmitter.js b/modules/EventEmitter.js index 4c052d6f41..69277d4109 100644 --- a/modules/EventEmitter.js +++ b/modules/EventEmitter.js @@ -55,6 +55,27 @@ class EventEmitter { }); }); + this.apiEmitter.on('network-query-responses', async (data) => { + const { query_id } = data; + + let responses = await Models.network_query_responses.findAll({ + where: { + query_id, + }, + }); + + responses = responses.map(response => ({ + imports: JSON.parse(response.imports), + data_size: response.data_size, + data_price: response.data_price, + stake_factor: response.stake_factor, + reply_id: response.reply_id, + })); + + data.response.status(200); + data.response.send(responses); + }); + this.apiEmitter.on('trail', (data) => { product.getTrailByQuery(data.query).then((res) => { if (res.length === 0) { @@ -328,14 +349,7 @@ class EventEmitter { throw new Error('This import does not exist in the database'); } - const replicationId = uuidv4(); - - data.response.status(201); - data.response.send({ - replication_id: replicationId, - }); - - dcService.createOffer( + const replicationId = await dcService.createOffer( import_id, dataimport.root_hash, dataimport.total_documents, @@ -344,8 +358,12 @@ class EventEmitter { max_token_amount, min_stake_amount, min_reputation, - replicationId, ); + + data.response.status(201); + data.response.send({ + replication_id: replicationId, + }); } catch (error) { logger.error(`Failed to create offer. ${error}.`); data.response.status(405); @@ -787,9 +805,9 @@ class EventEmitter { this.kadEmitter.on('kad-encrypted-key-process-result', async (request) => { const { status } = request.params.message; if (status === 'SUCCESS') { - logger.info('DV successfully processed the encrypted key'); + logger.important(`DV ${request.contact[0]} successfully processed the encrypted key`); } else { - logger.info('DV failed to process the encrypted key'); + logger.important(`DV ${request.contact[0]} failed to process the encrypted key`); } }); diff --git a/modules/Network.js b/modules/Network.js index a4669f0431..3c600fb09e 100644 --- a/modules/Network.js +++ b/modules/Network.js @@ -11,6 +11,7 @@ const _ = require('lodash'); const sleep = require('sleep'); const leveldown = require('leveldown'); const PeerCache = require('./kademlia/PeerCache'); +const KadenceUtils = require('@kadenceproject/kadence/lib/utils.js'); /** * DHT module (Kademlia) @@ -249,7 +250,6 @@ class Network { this.log.info(`Connected to network via ${contact[0]} (http://${contact[1].hostname}:${contact[1].port})`); this.log.info(`Discovered ${this.node.router.size} peers from seed`); - this.log.info('Refreshing peer buckets...'); for (const node of nodes) { // async fill buckets from some of the nodes this.node.refresh(node); @@ -428,12 +428,27 @@ class Network { * @returns {{"{": Object}|Array} */ node.getContact = async (contactId, retry) => { - const contact = node.router.getContactByNodeId(contactId); + let contact = node.router.getContactByNodeId(contactId); if (contact && contact.hostname) { return contact; } await node.refresh(contactId, retry); - this.node.router.getContactByNodeId(contactId); + contact = this.node.router.getContactByNodeId(contactId); + if (contact && contact.hostname) { + return contact; + } + this.log.trace(`Trying to fetch contact ${contactId} from peercache`); + contact = await this.node.peercache.getExternalPeerInfo(contactId); + if (contact) { + const contactInfo = KadenceUtils.parseContactURL(contact); + // refresh bucket + if (contactInfo) { + // eslint-disable-next-line + contact = contactInfo[1]; + this.node.router.addContactByNodeId(contactId, contact); + } + } + return this.node.router.getContactByNodeId(contactId); }; /** diff --git a/modules/RemoteControl.js b/modules/RemoteControl.js index ba46959288..10accd7bf5 100644 --- a/modules/RemoteControl.js +++ b/modules/RemoteControl.js @@ -15,6 +15,43 @@ class RemoteControl { constructor(ctx) { this.network = ctx.network; this.graphStorage = ctx.graphStorage; + this.blockchain = ctx.blockchain; + this.log = ctx.logger; + this.config = ctx.config; + this.web3 = ctx.web3; + + + remote.set('authorization', (handshakeData, callback) => { + const request = handshakeData; + + const regex = /password=([\w0-9-]+)/g; + const match = regex.exec(request); + + const password = match[1]; + Models.node_config.findOne({ where: { key: 'houston_password' } }).then((res) => { + callback(null, res.value === password); + }); + }); + } + + async updateProfile() { + const { identity } = this.config; + const profileInfo = await this.blockchain.getProfile(this.config.node_wallet); + if (!profileInfo.active) { + this.log.info(`Profile hasn't been created for ${identity} yet`); + return; + } + + this.log.notify(`Profile is being updated for ${identity}. This could take a while...`); + await this.blockchain.createProfile( + this.config.identity, + this.config.dh_price, + this.config.dh_stake_factor, + this.config.read_stake_factor, + this.config.dh_max_time_mins, + ); + + this.log.notify('Profile successfully updated'); } async connect() { @@ -37,15 +74,17 @@ class RemoteControl { }); this.socket.on('config-update', (data) => { + let query = ''; for (var key in data) { - Storage.db.query('UPDATE node_config SET value = ? WHERE key = ?', { - replacements: [data[key], key], - }).then((res) => { - this.restartNode(); - }).catch((err) => { - console.log(err); - }); + query += `UPDATE node_config SET value = '${data[key]}' WHERE key = '${key}';`; } + Storage.db.query(query).then(async (res) => { + await this.updateProfile(); + this.socket.emit('update-complete'); + this.restartNode(); + }).catch((err) => { + console.log(err); + }); }); this.socket.on('get-imports', () => { @@ -235,17 +274,18 @@ class RemoteControl { }); } - /** * Get wallet balance * @param wallet */ getBalance() { - Utilities.getAlphaTracTokenBalance().then((trac) => { + Utilities.getAlphaTracTokenBalance( + this.web3, process.env.NODE_WALLET, + this.config.blockchain.token_contract_address, + ).then((trac) => { this.socket.emit('trac_balance', trac); }); web3.eth.getBalance(process.env.NODE_WALLET).then((balance) => { - console.log('Balance ' - balance); this.socket.emit('balance', balance); }); } diff --git a/ot-node.js b/ot-node.js index e30b4be1a7..5321474b1b 100644 --- a/ot-node.js +++ b/ot-node.js @@ -206,6 +206,13 @@ class OTNode { process.exit(1); } + // Fetching Houston access password + models.node_config.findOne({ where: { key: 'houston_password' } }).then((res) => { + log.notify('================================================================'); + log.notify(`Houston password: ${res.value}`); + log.notify('================================================================'); + }); + // Starting the kademlia const network = container.resolve('network'); const blockchain = container.resolve('blockchain'); @@ -566,6 +573,21 @@ class OTNode { }); }); + server.get('/api/query/:query_id/responses', (req, res) => { + log.trace('GET Query responses'); + if (!req.params.query_id) { + res.status(400); + res.send({ + message: 'Param query_id is required.', + }); + return; + } + emitter.emit('network-query-responses', { + query_id: req.params.query_id, + response: res, + }); + }); + server.post('/api/query/network', (req, res) => { log.trace('POST Query request received.'); if (!req.body) { diff --git a/seeders/20180407124949-node-config.js b/seeders/20180407124949-node-config.js index 15426b2eaf..37035897ea 100644 --- a/seeders/20180407124949-node-config.js +++ b/seeders/20180407124949-node-config.js @@ -1,4 +1,5 @@ require('dotenv').config(); +const uuidv4 = require('uuid/v4'); let bootstrap_nodes = []; if (process.env.BOOTSTRAP_NODE) { @@ -126,6 +127,10 @@ module.exports = { key: 'is_bootstrap_node', value: false, }, + { + key: 'houston_password', + value: uuidv4(), + }, ], {}), down: (queryInterface, Sequelize) => queryInterface.bulkDelete('node_config', null, {}), diff --git a/seeders/20180407223548-blockchain_data.js b/seeders/20180407223548-blockchain_data.js index 802760c254..f0de30166a 100644 --- a/seeders/20180407223548-blockchain_data.js +++ b/seeders/20180407223548-blockchain_data.js @@ -14,9 +14,9 @@ module.exports = { gas_price: '5000000000', ot_contract_address: '0x826b0e0b03f22c5e58557456bd8b8ede318c2e0a', token_contract_address: '0x98d9a611ad1b5761bdc1daac42c48e4d54cf5882', - escrow_contract_address: '0xbc5c1dab44e48b9f5b6b7d8dc337257de023af5d', - bidding_contract_address: '0xdd452a3a6c727037ba5ab15c5582ae7e134a0037', - reading_contract_address: '0xc818cb671c9ab0140f36649f1c58544ba7e1242c', + escrow_contract_address: '0x58c68e5f6c883cf77164116b527c55082d106d56', + bidding_contract_address: '0x9c9659aa16e18c4a8c54020cf20344204ea8468f', + reading_contract_address: '0xc16f1fd6db271a99550207e03cfab3c938fe6175', rpc_node_host: 'https://rinkeby.infura.io/1WRiEqAQ9l4SW6fGdiDt', rpc_node_port: '', wallet_address: process.env.NODE_WALLET, diff --git a/seeders/20180420143224-node-config.js b/seeders/20180420143224-node-config.js index a9f459a0ba..c87c2b8d46 100644 --- a/seeders/20180420143224-node-config.js +++ b/seeders/20180420143224-node-config.js @@ -40,7 +40,7 @@ module.exports = { }, { key: 'total_escrow_time_in_minutes', - value: 100, + value: 600000, }, { key: 'max_token_amount_per_dh', diff --git a/test/modules/utilities.test.js b/test/modules/utilities.test.js index 3c69500c2a..bf4ebe9ce1 100644 --- a/test/modules/utilities.test.js +++ b/test/modules/utilities.test.js @@ -30,7 +30,7 @@ describe('Utilities module', () => { 'ssl_authority_paths', 'network_bootstrap_nodes', 'solve_hashes', 'remote_access_whitelist', 'node_rpc_port', 'dh_min_price', 'dh_max_price', 'dh_max_stake', 'remote_control_enabled', 'remote_control_port', 'probability_threshold', 'read_stake_factor', 'dh_max_time_mins', 'dh_price', 'dh_stake_factor', 'send_logs_to_origintrail', - 'dh_min_reputation', 'dh_min_stake_amount', 'max_token_amount_per_dh', 'total_escrow_time_in_minutes', 'is_bootstrap_node'], + 'dh_min_reputation', 'dh_min_stake_amount', 'max_token_amount_per_dh', 'total_escrow_time_in_minutes', 'is_bootstrap_node', 'houston_password'], 'Some config items are missing in node_config', ); });