Skip to content

Commit

Permalink
develop-master sync (#791)
Browse files Browse the repository at this point in the history
* Profile contract cleanup (#785)

* Set default minimal stake to 1000 TRAC

* Simplify token withdrawal logic

* Update truffle test

* Require nodeID and enable nodeID change (#777)

* Require a node to submit a nodeId when creating a profile

* Add a function for changing a profile's nodeId

* Update abi file for profile smart contract

* Handle failed finalize offer (#788)

* Bugfix/hotfixes (#789)

* bump version (#790)
  • Loading branch information
simonovic86 authored and alexveljkovic committed Dec 7, 2018
1 parent 392aeff commit f46cb4e
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 26 deletions.
46 changes: 46 additions & 0 deletions modules/Blockchain/Ethereum/abi/profile.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,20 @@
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "newMinimalStake",
"type": "uint256"
}
],
"name": "setMinimalStake",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
Expand Down Expand Up @@ -103,6 +117,24 @@
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "identity",
"type": "address"
},
{
"name": "newNodeId",
"type": "bytes32"
}
],
"name": "setNodeId",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
Expand Down Expand Up @@ -139,6 +171,20 @@
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "newWithdrawalTime",
"type": "uint256"
}
],
"name": "setWithdrawalTime",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
Expand Down
32 changes: 15 additions & 17 deletions modules/Blockchain/Ethereum/contracts/Profile.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import {Ownable, Hub} from './Hub.sol';
import {Identity, ERC725} from './Identity.sol';
import {ERC20} from './TracToken.sol';


contract Profile {
using SafeMath for uint256;
Hub public hub;
ProfileStorage public profileStorage;

uint256 public minimalStake = 10**20; // TODO Determine minimum stake
uint256 public minimalStake = 10**21;
uint256 public withdrawalTime = 5 minutes;

constructor(address hubAddress) public {
Expand Down Expand Up @@ -44,6 +45,7 @@ contract Profile {
ERC20 tokenContract = ERC20(hub.tokenAddress());
require(tokenContract.allowance(msg.sender, this) >= initialBalance, "Sender allowance must be equal to or higher than initial balance");
require(tokenContract.balanceOf(msg.sender) >= initialBalance, "Sender balance must be equal to or higher than initial balance!");
require(uint256(profileNodeId) != 0, "Cannot create a profile without a nodeId submitted");

tokenContract.transferFrom(msg.sender, address(profileStorage), initialBalance);

Expand Down Expand Up @@ -92,21 +94,7 @@ contract Profile {
// Verify sender
require(ERC725(identity).keyHasPurpose(keccak256(abi.encodePacked(msg.sender)), 2));

if(profileStorage.getWithdrawalPending(identity)){
if(block.timestamp < profileStorage.getWithdrawalTimestamp(identity)){
// Transfer already reserved tokens to user identity
profileStorage.transferTokens(msg.sender, profileStorage.getWithdrawalAmount(identity));

uint256 balance = profileStorage.getStake(identity);
balance = balance.sub(profileStorage.getWithdrawalAmount(identity));
profileStorage.setStake(identity, balance);

emit TokensWithdrawn(identity, profileStorage.getWithdrawalAmount(identity), balance);
}
else {
require(false, "Withrdrawal process already pending!");
}
}
require(profileStorage.getWithdrawalPending(identity) == false, "Withrdrawal process already pending!");

uint256 availableBalance = profileStorage.getStake(identity).sub(profileStorage.getStakeReserved(identity));

Expand Down Expand Up @@ -147,7 +135,17 @@ contract Profile {
profileStorage.getStake(identity).sub(profileStorage.getWithdrawalAmount(identity))
);
}


function setNodeId(address identity, bytes32 newNodeId)
public {
// Verify sender
require(ERC725(identity).keyHasPurpose(keccak256(abi.encodePacked(msg.sender)), 2),
"Sender does not have action permission for submitted identity");
require(uint256(newNodeId) != 0, "Cannot set a blank nodeId");

profileStorage.setNodeId(identity, newNodeId);
}

function reserveTokens(address payer, address identity1, address identity2, address identity3, uint256 amount)
public onlyHolding {
if(profileStorage.getWithdrawalPending(payer)) {
Expand Down
4 changes: 2 additions & 2 deletions modules/Blockchain/Ethereum/test/offer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var errored = true;
var DC_identity;
var DC_wallet;
var offerId;
var tokensToDeposit = (new BN(5)).mul(new BN(10).pow(new BN(20)));
var tokensToDeposit = (new BN(5)).mul(new BN(10).pow(new BN(21)));

// Offer variables
const dataSetId = '0x8cad6896887d99d70db8ce035d331ba2ade1a5e1161f38ff7fda76cf7c308cde';
Expand Down Expand Up @@ -89,7 +89,7 @@ contract('Offer testing', async (accounts) => {
for (var i = 0; i < accounts.length; i += 1) {
promises[i] = trac.increaseApproval(
profile.address,
(new BN(5)).mul(new BN(10).pow(new BN(20))),
tokensToDeposit,
{ from: accounts[i] },
);
}
Expand Down
2 changes: 1 addition & 1 deletion modules/Blockchain/Ethereum/test/profile.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var web3;
var Ganache = require('ganache-core');

// Global values
const amountToDeposit = (new BN(10)).pow(new BN(20));
const amountToDeposit = (new BN(10)).pow(new BN(21));
const amountToWithdraw = (new BN(100));
const nodeId = '0x4cad6896887d99d70db8ce035d331ba2ade1a5e1161f38ff7fda76cf7c308cde';

Expand Down
11 changes: 11 additions & 0 deletions modules/Database/Arangojs.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,17 @@ class ArangoJS {
OUTBOUND 'ot_vertices/${startVertex._key}'
ot_edges
OPTIONS {bfs: false, uniqueVertices: 'path'}
FILTER edge.edge_type != 'IDENTIFIES'
AND edge.edge_type != 'IDENTIFIED_BY'
AND edge._to != 'ot_vertices/Actor'
AND edge._to != 'ot_vertices/Product'
AND edge._to != 'ot_vertices/Location'
AND edge._to != 'ot_vertices/Transport'
AND edge._to != 'ot_vertices/Transformation'
AND edge._to != 'ot_vertices/Observation'
AND edge._to != 'ot_vertices/Ownership'
AND vertex.vertex_type != 'CLASS'
AND vertex.vertex_type != 'IDENTIFIER'
RETURN path`;

const rawGraph = await this.runQuery(queryString);
Expand Down
8 changes: 4 additions & 4 deletions modules/GS1Importer.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ class GS1Importer {
}
}

if (eventListElement.extension && eventListElement.extension.TransformationEvent) {
for (const transformationEvent of
this.helper.arrayze(eventListElement.extension.TransformationEvent)) {
events.push(transformationEvent);
if (eventListElement.extension) {
const extensions = this.helper.arrayze(eventListElement.extension);
for (const currentExtension of extensions) {
events.push(currentExtension.TransformationEvent);
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions modules/command/dc/dc-offer-finalize-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ class DCOfferFinalizeCommand extends Command {
commands: [depositToken],
};
}

this.logger.error(`Offer ${offerId} has not been finalized.`);

offer.status = 'FAILED';
offer.message = `Offer for ${offerId} has not been finalized. ${err.message}`;
await offer.save({ fields: ['status', 'message'] });

await this.replicationService.cleanup(offer.id);
return Command.empty();
}

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "origintrail_node",
"version": "2.0.29",
"version": "2.0.30",
"description": "OriginTrail node",
"main": ".eslintrc.js",
"config": {
Expand Down

0 comments on commit f46cb4e

Please sign in to comment.