Skip to content

Commit

Permalink
Release
Browse files Browse the repository at this point in the history
  • Loading branch information
schrink committed Apr 23, 2018
2 parents 6246ed2 + e76c32c commit 388f718
Show file tree
Hide file tree
Showing 28 changed files with 3,119 additions and 479 deletions.
3 changes: 3 additions & 0 deletions migrations/20180407114338-create-blockchain-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ module.exports = {
escrow_contract_address: {
type: Sequelize.STRING,
},
bidding_contract_address: {
type: Sequelize.STRING,
},
rpc_node_host: {
type: Sequelize.STRING,
},
Expand Down
39 changes: 39 additions & 0 deletions migrations/20180420094832-create-offers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

module.exports = {
up: (queryInterface, Sequelize) => queryInterface.createTable('offers', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER,
},
data_lifespan: {
type: Sequelize.INTEGER,
},
start_tender_time: {
type: Sequelize.INTEGER,
},
tender_duration: {
type: Sequelize.INTEGER,
},
min_number_applicants: {
type: Sequelize.INTEGER,
},
price_tokens: {
type: Sequelize.INTEGER,
},
data_size_bytes: {
type: Sequelize.INTEGER,
},
replication_number: {
type: Sequelize.INTEGER,
},
root_hash: {
type: Sequelize.STRING,
},
max_token_amount: {
type: Sequelize.INTEGER,
},
}),
down: (queryInterface, Sequelize) => queryInterface.dropTable('offers'),
};
39 changes: 39 additions & 0 deletions migrations/20180420095258-create-bids.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

module.exports = {
up: (queryInterface, Sequelize) => queryInterface.createTable('bids', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER,
},
bid_index: {
type: Sequelize.INTEGER,
},
price: {
type: Sequelize.INTEGER,
},
data_id: {
type: Sequelize.INTEGER,
},
dc_wallet: {
type: Sequelize.STRING,
},
hash: {
type: Sequelize.STRING,
},
dc_id: {
type: Sequelize.STRING,
},
total_escrow_time: {
type: Sequelize.INTEGER,
},
stake: {
type: Sequelize.INTEGER,
},
data_size_bytes: {
type: Sequelize.INTEGER,
},
}),
down: (queryInterface, Sequelize) => queryInterface.dropTable('bids'),
};
18 changes: 18 additions & 0 deletions models/bids.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

module.exports = (sequelize, DataTypes) => {
const bids = sequelize.define('bids', {
bid_index: DataTypes.INTEGER,
price: DataTypes.INTEGER,
hash: DataTypes.STRING(128),
data_id: DataTypes.INTEGER,
dc_wallet: DataTypes.STRING,
dc_id: DataTypes.STRING,
total_escrow_time: DataTypes.INTEGER,
stake: DataTypes.INTEGER,
data_size_bytes: DataTypes.INTEGER,
}, {});
bids.associate = function (models) {
// associations can be defined here
};
return bids;
};
1 change: 1 addition & 0 deletions models/blockchain_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = (sequelize, DataTypes) => {
ot_contract_address: DataTypes.STRING(50),
token_contract_address: DataTypes.STRING(50),
escrow_contract_address: DataTypes.STRING(50),
bidding_contract_address: DataTypes.STRING(50),
rpc_node_host: DataTypes.STRING(256),
rpc_node_port: DataTypes.INTEGER,
wallet_address: DataTypes.STRING(50),
Expand Down
18 changes: 18 additions & 0 deletions models/offers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

module.exports = (sequelize, DataTypes) => {
var offers = sequelize.define('offers', {
data_lifespan: DataTypes.INTEGER,
start_tender_time: DataTypes.INTEGER,
tender_duration: DataTypes.INTEGER,
min_number_applicants: DataTypes.INTEGER,
price_tokens: DataTypes.INTEGER,
data_size_bytes: DataTypes.INTEGER,
replication_number: DataTypes.INTEGER,
root_hash: DataTypes.STRING,
max_token_amount: DataTypes.INTEGER,
}, {});
offers.associate = function (models) {
// associations can be defined here
};
return offers;
};
132 changes: 123 additions & 9 deletions modules/Blockchain.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,25 @@ class Blockchain {
}

/**
* Initiating escrow for data holding
* @param {string} - dhWallet
* @param {number} - dataId
* @param {number} - tokenAmount
* @param {number} - totalTime
* Increase token approval for bidding contract
* @param {number} tokenAmountIncrease
* @returns {Promise}
*/
initiateEscrow(dhWallet, dataId, tokenAmount, totalTime) {
return this.blockchain.initiateEscrow(dhWallet, dataId, tokenAmount, totalTime);
increaseBiddingApproval(tokenAmountIncrease) {
return this.blockchain.increaseBiddingApproval(tokenAmountIncrease);
}

/**
* Verify escrow contract contract data and start data holding process
* @param {string} - dcWallet
* @param {number} - dataId
* @param {number} - tokenAmount
* @param {number} - stakeAmount
* @param {number} - totalTime
* @returns {Promise}
*/
verifyEscrow(dcWallet, dataId, tokenAmount, totalTime) {
return this.blockchain.verifyEscrow(dcWallet, dataId, tokenAmount, totalTime);
verifyEscrow(dcWallet, dataId, tokenAmount, stakeAmount, totalTime) {
return this.blockchain.verifyEscrow(dcWallet, dataId, tokenAmount, stakeAmount, totalTime);
}

/**
Expand All @@ -77,6 +75,122 @@ class Blockchain {
payOut(dcWallet, dataId) {
return this.blockchain.payOut(dcWallet, dataId);
}

/**
* Creates offer for the data storing on the Ethereum blockchain.
* @param dataId Data ID of the offer.
* @param nodeId KADemlia node ID of offer creator
* @param totalEscrowTime Total time of the escrow in milliseconds
* @param maxTokenAmount Maximum price per DH
* @param MinStakeAmount Minimum stake in tokens
* @param biddingTime Total time of the bid in milliseconds
* @param minNumberOfBids Number of bid required for offer to be successful
* @param dataSize Size of the data for storing in bytes
* @param ReplicationFactor Number of replications
* @returns {Promise<any>} Return choose start-time.
*/
createOffer(
dataId, nodeId,
totalEscrowTime,
maxTokenAmount,
MinStakeAmount,
biddingTime,
minNumberOfBids,
dataSize, ReplicationFactor,
) {
return this.blockchain.createOffer(
dataId, nodeId,
totalEscrowTime,
maxTokenAmount,
MinStakeAmount,
biddingTime,
minNumberOfBids,
dataSize, ReplicationFactor,
);
}

/**
* Cancel offer for data storing on Ethereum blockchain.
* @param dataId Data if of the offer.
*/
cancelOffer(dataId) {
return this.blockchain.cancelOffer(dataId);
}

/**
* Subscribe to a particular event
* @param contractName Ethereum contract instance
* @param event Event name
* @param eventOpts Event options (filter, range, etc.)
* @param callback Callback to be executed on success/error (callback returns stop flag)
* @param periodMills Repeating period for checking past events
* @param untilMills Subscription termination
*/
subscribeToEvent(contractName, event, eventOpts, callback, periodMills, untilMills) {
return this.blockchain
.subscribeToEvent(contractName, event, eventOpts, callback, periodMills, untilMills);
}

/**
* Adds bid to the offer on Ethereum blockchain
* @param dcWallet Wallet of the bidder
* @param dataId ID of the data of the bid
* @param nodeId KADemlia ID of this node
* @param bidHash Hashed bid that will be revealed once
* revealBid() is called. @note token amount cannot be greater then max token amount
* @returns {Promise<any>} Index of the bid.
*/
addBid(dcWallet, dataId, nodeId, bidHash) {
return this.blockchain.addBid(dcWallet, dataId, nodeId, bidHash);
}

/**
* Cancel the bid on Ethereum blockchain
* @param dcWallet Wallet of the bidder
* @param dataId ID of the data of the bid
* @param bidIndex Index of the bid
* @returns {Promise<any>}
*/
cancelBid(dcWallet, dataId, bidIndex) {
return this.blockchain.cancelBid(dcWallet, dataId, bidIndex);
}

/**
* Reveals the bid of the offer
* @param dcWallet Wallet of the DC who's offer is
* @param dataId Id of the data in the offer
* @param nodeId KADemlia ID of bidder
* @param tokenAmount Amount of the token
* @param stakeAmount Amount of the stake
* @param bidIndex Index of the bid
* @returns {Promise<any>}
*/
revealBid(dcWallet, dataId, nodeId, tokenAmount, stakeAmount, bidIndex) {
return this.blockchain.revealBid(
dcWallet, dataId, nodeId,
tokenAmount, stakeAmount, bidIndex,
);
}

/**
* Starts choosing bids from contract escrow on Ethereum blockchain
* @param dataId ID of data of the bid
* @returns {Promise<any>} Array of bid indices of chosen ones.
*/
chooseBids(dataId) {
return this.blockchain.chooseBids(dataId);
}

/**
*
* @param dcWallet
* @param dataId
* @param bidIndex
* @returns {Promise<any>}
*/
getBid(dcWallet, dataId, bidIndex) {
return this.blockchain.getBid(dcWallet, dataId, bidIndex);
}
}

module.exports = Blockchain;
1 change: 0 additions & 1 deletion modules/Blockchain/Ethereum/Transactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class Transactions {
newTransaction.args,
newTransaction.options,
);

const transaction = new Tx(rawTx);
transaction.sign(this.privateKey);

Expand Down
Loading

0 comments on commit 388f718

Please sign in to comment.