Skip to content

Commit

Permalink
Fix creating profile and getting funds check (#162166717) (#755)
Browse files Browse the repository at this point in the history
  • Loading branch information
kipliklotrika authored and radomir-sebek committed Nov 26, 2018
1 parent 7878174 commit 6df6a53
Show file tree
Hide file tree
Showing 16 changed files with 543 additions and 36 deletions.
4 changes: 2 additions & 2 deletions modules/Blockchain.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,8 @@ class Blockchain {
return this.blockchain.nodeHasApproval(nodeId);
}

async getBalances() {
return this.blockchain.getBalances();
async hasEnoughFunds() {
return this.blockchain.hasEnoughFunds();
}

/**
Expand Down
301 changes: 301 additions & 0 deletions modules/Blockchain/Ethereum/abi/erc725.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,301 @@
[
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"name": "key",
"type": "bytes32"
},
{
"indexed": false,
"name": "purposes",
"type": "uint256[]"
},
{
"indexed": true,
"name": "keyType",
"type": "uint256"
}
],
"name": "KeyAdded",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"name": "key",
"type": "bytes32"
},
{
"indexed": false,
"name": "purposes",
"type": "uint256[]"
},
{
"indexed": true,
"name": "keyType",
"type": "uint256"
}
],
"name": "KeyRemoved",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"name": "executionId",
"type": "uint256"
},
{
"indexed": true,
"name": "to",
"type": "address"
},
{
"indexed": true,
"name": "value",
"type": "uint256"
},
{
"indexed": false,
"name": "data",
"type": "bytes"
}
],
"name": "ExecutionRequested",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"name": "executionId",
"type": "uint256"
},
{
"indexed": true,
"name": "to",
"type": "address"
},
{
"indexed": true,
"name": "value",
"type": "uint256"
},
{
"indexed": false,
"name": "data",
"type": "bytes"
}
],
"name": "Executed",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"name": "executionId",
"type": "uint256"
},
{
"indexed": false,
"name": "approved",
"type": "bool"
}
],
"name": "Approved",
"type": "event"
},
{
"constant": false,
"inputs": [
{
"name": "_key",
"type": "bytes32"
},
{
"name": "_purposes",
"type": "uint256[]"
},
{
"name": "_type",
"type": "uint256"
}
],
"name": "addKey",
"outputs": [
{
"name": "success",
"type": "bool"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_id",
"type": "uint256"
},
{
"name": "_approve",
"type": "bool"
}
],
"name": "approve",
"outputs": [
{
"name": "success",
"type": "bool"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_to",
"type": "address"
},
{
"name": "_value",
"type": "uint256"
},
{
"name": "_data",
"type": "bytes"
}
],
"name": "execute",
"outputs": [
{
"name": "executionId",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_key",
"type": "bytes32"
}
],
"name": "removeKey",
"outputs": [
{
"name": "success",
"type": "bool"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "_key",
"type": "bytes32"
}
],
"name": "getKey",
"outputs": [
{
"name": "purposes",
"type": "uint256[]"
},
{
"name": "keyType",
"type": "uint256"
},
{
"name": "key",
"type": "bytes32"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "_key",
"type": "bytes32"
}
],
"name": "getKeyPurposes",
"outputs": [
{
"name": "purposes",
"type": "uint256[]"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "_purpose",
"type": "uint256"
}
],
"name": "getKeysByPurpose",
"outputs": [
{
"name": "keys",
"type": "bytes32[]"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "_key",
"type": "bytes32"
},
{
"name": "_purpose",
"type": "uint256"
}
],
"name": "keyHasPurpose",
"outputs": [
{
"name": "result",
"type": "bool"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
}
]
2 changes: 1 addition & 1 deletion modules/Blockchain/Ethereum/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,7 @@ class Ethereum {
* Check balances
* @returns {Promise<boolean>}
*/
async getBalances() {
async hasEnoughFunds() {
this.log.trace('Checking balances');
let enoughETH = true;
let enoughTRAC = true;
Expand Down
16 changes: 15 additions & 1 deletion modules/service/profile-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,22 @@ class ProfileService {
* @returns {Promise<boolean>}
*/
async isProfileCreated() {
if (!this.config.erc725Identity) {
throw Error('ProfileService not initialized.');
}

const profile = await this.blockchain.getProfile(this.config.erc725Identity);
return !new BN(profile.stake, 10).eq(new BN(0, 10));

const zero = new BN(0);
const stake = new BN(profile.stake, 10);
const stakeReserved = new BN(profile.stakeReserved, 10);
const reputation = new BN(profile.reputation, 10);
const withdrawalTimestamp = new BN(profile.withdrawalTimestamp, 10);
const withdrawalAmount = new BN(profile.withdrawalAmount, 10);
const nodeId = new BN(profile.nodeId, 10);
return !(stake.eq(zero) && stakeReserved.eq(zero) &&
reputation.eq(zero) && withdrawalTimestamp.eq(zero) &&
withdrawalAmount.eq(zero) && nodeId.eq(zero));
}

/**
Expand Down
Loading

0 comments on commit 6df6a53

Please sign in to comment.