name: Integration of TCRs, CPM, and Ocean tokens with Solidity
type: development
status: initial draft
editor: Fang Gong <fang@oceanprotocol.com>
collaborator: Aitor Argomaniz <aitor@oceanprotocol.com>
date: 06/01/2018
In this POC, we put following modules together:
The following project exposes the following public interfaces:
//Allows a user to start an application. Takes tokens from user and sets apply stage end time.
function apply(bytes32 _listingHash, uint _amount, string _data);
// Allows the owner of a listingHash to increase their unstaked deposit.
function deposit(bytes32 _listingHash, uint _amount);
//Allows the owner of a listingHash to decrease their unstaked deposit.
function withdraw(bytes32 _listingHash, uint _amount);
// Allows the owner of a listingHash to remove the listingHash from the whitelist
function exit(bytes32 _listingHash);
// Starts a poll for a listingHash which is either in the apply stage or already in the whitelist.
function challenge(bytes32 _listingHash, string _data);
// Updates a listingHash’s status from ‘application’ to ‘listing’ or resolves a challenge if one exists.
function updateStatus(bytes32 _listingHash);
// Called by a voter to claim their reward for each completed vote.
function claimReward(uint _challengeID, uint _salt);
// Calculates the provided voter’s token reward for the given poll.
function voterReward(address _voter, uint _challengeID, uint _salt);
// Determines whether the given listingHash be whitelisted.
function canBeWhitelisted(bytes32 _listingHash);
// Returns true if the provided listingHash is whitelisted
function isWhitelisted(bytes32 _listingHash);
// Determines the number of tokens awarded to the winning party in a challenge.
function determineReward(uint _challengeID);
// Register provider and assets (upload by changing uploadBits)
function register(uint256 assetId) public returns (bool success);
// publish consumption information about an Asset
function publish(uint256 assetId, bytes32 url, bytes32 token) external returns (bool success);
// purchase an asset and get the consumption information
function purchase(uint256 assetId) external returns (bytes32 url, bytes32 token);
// Return the list of available assets
function listAssets() external view returns (uint256[50]);
// Return the number of drops associated to the message.sender to an Asset
function dropsBalance(uint256 assetId) public view returns (uint256);
// Return true or false if an Asset is active given the assetId
function checkAsset(uint256 assetId) public view returns (bool);
// Get the url attribute associated to a given the assetId
function getAssetUrl(uint256 assetId) public view returns (bytes32);
// Get the token attribute associated to a given the assetId
function getAssetToken(uint256 assetId) public view returns (bytes32);
// Retrieve the msg.sender Provider token balance
function tokenBalance() public view returns (uint256);
// Asset Events
event AssetRegistered(uint256 indexed _assetId, address indexed _owner);
event AssetPublished(uint256 indexed _assetId, address indexed _owner);
event AssetPurchased(uint256 indexed _assetId, address indexed _owner);
// Token Events
event TokenWithdraw(address indexed _requester, uint256 amount);
event TokenBuyDrops(address indexed _requester, uint256 indexed _assetId, uint256 _ocn, uint256 _drops);
event TokenSellDrops(address indexed _requester, uint256 indexed _assetId, uint256 _ocn, uint256 _drops);
There are several folders and each includes solidity source files for each module:
The dependency between different modules are illustrated as below:
First draft of UML class diagram
Use $ npm install
to download all the required libraries
Use $ truffle compile
to compile those solidity files:
Then deploy them into testRPC $ truffle migrate
:
Note:
Error: run out of gas
because we try to deploy so many contracts as one single transaction. Tune the gas
value in truffle.js
file to make them run through.truffle.js
and it will use the first account in testRPC or ganache-cli by default.Test them with $ truffle test test/registry.js
:
Version | Tag | Published |
---|---|---|
0.0.2 | latest | 4yrs ago |