Skip to content

Commit

Permalink
Merge pull request #1332 from OriginTrail/prerelease/testnet
Browse files Browse the repository at this point in the history
OriginTrail Testnet Release v4.1.9
  • Loading branch information
djordjekovac authored Aug 27, 2020
2 parents f77a089 + 1da788b commit 101209e
Show file tree
Hide file tree
Showing 31 changed files with 2,015 additions and 1,032 deletions.
37 changes: 37 additions & 0 deletions modules/Blockchain.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,10 +338,18 @@ class Blockchain {
return this.blockchain.getPurchase(purchaseId);
}

async getPurchaseStatus(purchaseId) {
return this.blockchain.getPurchaseStatus(purchaseId);
}

async getPurchasedData(importId, wallet) {
return this.blockchain.getPurchasedData(importId, wallet);
}

async getPaymentStageInterval() {
return this.blockchain.getPaymentStageInterval();
}

async initiatePurchase(
sellerIdentity, buyerIdentity,
tokenAmount,
Expand Down Expand Up @@ -372,6 +380,26 @@ class Blockchain {
return this.blockchain.takePayment(purchaseId);
}

async complainAboutNode(
purchaseId, outputIndex, inputIndexLeft, encodedOutput, encodedInputLeft,
proofOfEncodedOutput, proofOfEncodedInputLeft, urgent,
) {
return this.blockchain.complainAboutNode(
purchaseId, outputIndex, inputIndexLeft, encodedOutput, encodedInputLeft,
proofOfEncodedOutput, proofOfEncodedInputLeft, urgent,
);
}

async complainAboutRoot(
purchaseId, encodedRootHash, proofOfEncodedRootHash, rootHashIndex,
urgent,
) {
return this.blockchain.complainAboutRoot(
purchaseId, encodedRootHash, proofOfEncodedRootHash, rootHashIndex,
urgent,
);
}

async sendCommitment(importId, dvWallet, commitment) {
return this.blockchain.sendCommitment(importId, dvWallet, commitment);
}
Expand Down Expand Up @@ -612,6 +640,15 @@ class Blockchain {
async keyHasPurpose(identity, key, purpose) {
return this.blockchain.keyHasPurpose(identity, key, purpose);
}

/**
* Check how many events were emitted in a transaction from the transaction receipt
* @param receipt - the json object returned as a result of the transaction
* @return {Number | undefined} - Returns undefined if the receipt does not have a logs field
*/
numberOfEventsEmitted(receipt) {
return this.blockchain.numberOfEventsEmitted(receipt);
}
}

module.exports = Blockchain;
65 changes: 51 additions & 14 deletions modules/Blockchain/Ethereum/abi/marketplace.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
],
"payable": false,
"stateMutability": "view",
"type": "function"
"type": "function",
"signature": "0x365a86fc"
},
{
"constant": true,
Expand All @@ -25,7 +26,8 @@
],
"payable": false,
"stateMutability": "view",
"type": "function"
"type": "function",
"signature": "0x691c6deb"
},
{
"inputs": [
Expand All @@ -36,7 +38,8 @@
],
"payable": false,
"stateMutability": "nonpayable",
"type": "constructor"
"type": "constructor",
"signature": "constructor"
},
{
"anonymous": false,
Expand Down Expand Up @@ -73,7 +76,8 @@
}
],
"name": "PurchaseInitiated",
"type": "event"
"type": "event",
"signature": "0xc93d5f3be3fb6a3a357ff8618f169d1fc7f2af9dfaa690855956a3be0a5a23fd"
},
{
"anonymous": false,
Expand All @@ -90,7 +94,8 @@
}
],
"name": "KeyDeposited",
"type": "event"
"type": "event",
"signature": "0x085125356d0e6a726b611531ed99af43bc381be83e7a55a9b0f111578236168b"
},
{
"anonymous": false,
Expand All @@ -112,7 +117,31 @@
}
],
"name": "MisbehaviourProven",
"type": "event"
"type": "event",
"signature": "0xf4be0903b752a94a903248b0bab983f94b443f9fcae393f657e06b05d5405b06"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"name": "purchaseId",
"type": "bytes32"
},
{
"indexed": false,
"name": "sellerIdentity",
"type": "address"
},
{
"indexed": false,
"name": "buyerIdentity",
"type": "address"
}
],
"name": "PurchaseCompleted",
"type": "event",
"signature": "0x3c714883152f8c067c4b9eb1d7ebc8bf19da6a1999475e4842aba88c93943143"
},
{
"constant": false,
Expand All @@ -126,7 +155,8 @@
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
"type": "function",
"signature": "0xc7eb4522"
},
{
"constant": false,
Expand Down Expand Up @@ -156,7 +186,8 @@
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
"type": "function",
"signature": "0x940e6f29"
},
{
"constant": false,
Expand All @@ -174,7 +205,8 @@
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
"type": "function",
"signature": "0x10a2d0d7"
},
{
"constant": false,
Expand All @@ -188,7 +220,8 @@
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
"type": "function",
"signature": "0x2eff62c5"
},
{
"constant": false,
Expand All @@ -214,7 +247,8 @@
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
"type": "function",
"signature": "0x7a2af025"
},
{
"constant": false,
Expand Down Expand Up @@ -252,7 +286,8 @@
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
"type": "function",
"signature": "0x5c31aa65"
},
{
"constant": true,
Expand All @@ -279,7 +314,8 @@
],
"payable": false,
"stateMutability": "pure",
"type": "function"
"type": "function",
"signature": "0x92b775c6"
},
{
"constant": true,
Expand Down Expand Up @@ -310,6 +346,7 @@
],
"payable": false,
"stateMutability": "view",
"type": "function"
"type": "function",
"signature": "0x9e6731ad"
}
]
3 changes: 3 additions & 0 deletions modules/Blockchain/Ethereum/contracts/Marketplace.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ contract Marketplace {
);
event KeyDeposited(bytes32 purchaseId, bytes32 key);
event MisbehaviourProven(bytes32 purchaseId, address sellerIdentity, address buyerIdentity);
event PurchaseCompleted(bytes32 purchaseId, address sellerIdentity, address buyerIdentity);

function initiatePurchase(
address sellerIdentity,
Expand Down Expand Up @@ -130,6 +131,8 @@ contract Marketplace {

marketplaceStorage.setStage(purchaseId, 3);
marketplaceStorage.setTimestamp(purchaseId, block.timestamp);

emit PurchaseCompleted(purchaseId, sellerIdentity, buyerIdentity);
}

function reserveTokens(address party, uint256 amount)
Expand Down
61 changes: 61 additions & 0 deletions modules/Blockchain/Ethereum/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -966,11 +966,22 @@ class Ethereum {
return this.marketplaceStorageContract.methods.purchase(purchaseId).call();
}

async getPurchaseStatus(purchaseId) {
this.logger.trace(`Asking for purchase with id [${purchaseId}].`);
return this.marketplaceStorageContract.methods.getStage(purchaseId).call();
}

async getPurchasedData(importId, wallet) {
this.logger.trace(`Asking purchased data for import ${importId} and wallet ${wallet}.`);
return this.readingContract.methods.purchased_data(importId, wallet).call();
}

async getPaymentStageInterval() {
this.logger.trace('Reading payment stage interval from blockchain.');
return this.marketplaceContract.methods.paymentStageInterval().call();
}


async initiatePurchase(
sellerIdentity, buyerIdentity,
tokenAmount,
Expand Down Expand Up @@ -1047,6 +1058,44 @@ class Ethereum {
);
}

async complainAboutNode(
purchaseId, outputIndex, inputIndexLeft, encodedOutput, encodedInputLeft,
proofOfEncodedOutput, proofOfEncodedInputLeft, urgent,
) {
const gasPrice = await this.getGasPrice(urgent);
const options = {
gasLimit: this.web3.utils.toHex(this.config.gas_limit),
gasPrice: this.web3.utils.toHex(gasPrice),
to: this.marketplaceContractAddress,
};

this.logger.trace(`complainAboutNode(${purchaseId},${outputIndex},${inputIndexLeft},` +
`${encodedOutput},${encodedInputLeft},${proofOfEncodedOutput},${proofOfEncodedInputLeft})`);
return this.transactions.queueTransaction(
this.marketplaceContractAbi, 'complainAboutNode',
[purchaseId, outputIndex, inputIndexLeft, encodedOutput, encodedInputLeft,
proofOfEncodedOutput, proofOfEncodedInputLeft], options,
);
}

async complainAboutRoot(
purchaseId, encodedRootHash, proofOfEncodedRootHash, rootHashIndex,
urgent,
) {
const gasPrice = await this.getGasPrice(urgent);
const options = {
gasLimit: this.web3.utils.toHex(this.config.gas_limit),
gasPrice: this.web3.utils.toHex(gasPrice),
to: this.marketplaceContractAddress,
};

this.logger.trace(`complainAboutRoot(${purchaseId},${encodedRootHash},${proofOfEncodedRootHash},${rootHashIndex})`);
return this.transactions.queueTransaction(
this.marketplaceContractAbi, 'complainAboutRoot',
[purchaseId, encodedRootHash, proofOfEncodedRootHash, rootHashIndex], options,
);
}

async sendCommitment(importId, dvWallet, commitment) {
const gasPrice = await this.getGasPrice();
const options = {
Expand Down Expand Up @@ -1547,6 +1596,18 @@ class Ethereum {
return gasPrice;
}
}

/**
* Check how many events were emitted in a transaction from the transaction receipt
* @param receipt - the json object returned as a result of the transaction
* @return {Number | undefined} - Returns undefined if the receipt does not have a logs field
*/
numberOfEventsEmitted(receipt) {
if (!receipt || !receipt.logs || !Array.isArray(receipt.logs)) {
return undefined;
}
return receipt.logs.length;
}
}

module.exports = Ethereum;
Loading

0 comments on commit 101209e

Please sign in to comment.