Skip to content

Dapp V0 Functional Specs

Don Marti edited this page Jul 28, 2017 · 2 revisions

Market Contract - V0 - tooling up

Milestone: https://github.com/mvscorg/bugmark/milestone/2

Goal

Code up a smart contract, with a full suite of unit tests, that demonstrates a successful Reward transaction.

Constraints:

  • One contract
  • No UI.
  • Only one repo can be set up.
  • Reward contract type only - no forecast.
  • Only user info available is the ethereum account of that user. No logins.
  • Only one person can take the other side of a contract, and they must take the entire contract amount as a counterparty.
  • No escrow accounts in this version - all eth goes into the main account
  • This milestone just covers the smart contracts and assumes no oracle or user interface - it runs on unit tests.

Data Structures

Note: the word "contract" is terribly overloaded and a solidity keyword.

/// Issue Market Contract
im_contract {
    enum im_contract_type { reward, forecast };
    address publisher;  /// account of user who published
    address counterparty;  /// account of user who took the other side
    address escrow;  /// Next version - The escrow account used to hold funds
    string criteria;  /// json string of issue criteria, i.e. { "label":"open", "label":"cve" }
    uint amount;  /// in wei
    uint end_date;  /// unixtime; seconds since epoch === now in solidity
    enum im_contract_winner { publisher, counterparty };
    enum status { published, live, resolved, expired };
};
mapping(uint => im_contract) im_contracts;

issue_tracker { string tracker_url; string criteria; string status; }

issue { string issue_url; }
mapping(uint => issue) issues;

user { address user_address; }
mapping(uint => user;) users;

Functions:

Contract handling: publishing contracts, taking the other side of contracts as a counterparty, and processing of awards based on contract closure.

User management: CRUD user accounts

Repo/Issue management: CRUD repo, CRUD issues

Contract Handling Functions

publishReward(user, issue, amount, end_date)

Publishes an im_contract of type reward for a user. Puts their cash into the contracts escrow account.

counterpartyImContract(user, im_contract_id)

Takes the other side of a im_contract for a user. Puts their cash into an escrow account. Registers contract as live until a certain date.

closeImContract(im_contract_id)

Closes an im_contract that has was live. Marks the winner. Calls the reward algorithm contract to payout money in escrow to the winner.

imContractExpired(im_contract_id)

Closes an im_contract that was not live. Returns any money that was in escrow to the original owner.

imContracts()

Return all data on all im_contracts.

User Management Functions:

registerUser(user)

Registers an ethereum account with the system as a user. We might not technically need this since any transaction should come from a metamask user that has to authorize the expenditure, and that includes their account address. We only need to register when the first transaction is made, if we choose to.

imUsers()

Return all data on all users. This could be pulled from contracts, if we don't have users.

Repo/Issue Management Functions:

registerIssueTracker(issue_tracker_url)

Registers a issue tracker with the system.

issueTrackers()

Return all data on all issue_trackers. There is only one at the moment.

registerNewIssue(issue_url, status, criteria)

Registers an issue in the system as a new issue, associated with the issue tracker, and gives it a name, any number of labels, and a status.

updateIssue(issue_url, status, criteria)

Updates the name, labels, or status of an issue.

imIssues(tracker)

Returns all issue records in the market for a given tracker.

Basic Payout Contract

Functions:

This Reward Algorithm contract issues payments based on a simple algorithm.

payoutNetZero(im_contract)

Pays all money in im_contract escrow account to the winner defined in the im_contract data structure immediately.