Skip to content
This repository has been archived by the owner on Jul 19, 2019. It is now read-only.

Commit

Permalink
Merge pull request #32 from aupiff/npm-scripts
Browse files Browse the repository at this point in the history
creating npm scripts & improving contract docs
  • Loading branch information
willbach authored Mar 4, 2018
2 parents ac7c8d3 + 3e34ed2 commit e742d19
Show file tree
Hide file tree
Showing 7 changed files with 170 additions and 159 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,9 @@ block a transaction which involves any party who is too heavily in debt.

## Testing

To run all `testrpc` tests, execute `./runtest.sh`. To run only a specific
test, execute `./runtest.sh [path-to-test-file]`.
```
npm run test
```

## ABI
```[{"constant":true,"inputs":[{"name":"","type":"address"},{"name":"","type":"address"}],"name":"stakedTokensMap","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function","stateMutability":"view"},{"constant":false,"inputs":[{"name":"_ucacContractAddr","type":"address"},{"name":"creditor","type":"address"},{"name":"debtor","type":"address"},{"name":"amount","type":"uint256"},{"name":"sig1","type":"bytes32[3]"},{"name":"sig2","type":"bytes32[3]"},{"name":"memo","type":"bytes32"}],"name":"issueCredit","outputs":[],"payable":false,"type":"function","stateMutability":"nonpayable"},{"constant":true,"inputs":[],"name":"txPerGigaTokenPerHour","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function","stateMutability":"view"},{"constant":false,"inputs":[{"name":"_tokensToOwnUcac","type":"uint256"}],"name":"setTokensToOwnUcac","outputs":[],"payable":false,"type":"function","stateMutability":"nonpayable"},{"constant":false,"inputs":[{"name":"_ucacContractAddr","type":"address"},{"name":"_denomination","type":"bytes32"},{"name":"_tokensToStake","type":"uint256"}],"name":"createAndStakeUcac","outputs":[],"payable":false,"type":"function","stateMutability":"nonpayable"},{"constant":false,"inputs":[{"name":"_txPerGigaTokenPerHour","type":"uint256"}],"name":"setTxPerGigaTokenPerHour","outputs":[],"payable":false,"type":"function","stateMutability":"nonpayable"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"ucacs","outputs":[{"name":"ucacContractAddr","type":"address"},{"name":"totalStakedTokens","type":"uint256"},{"name":"txLevel","type":"uint256"},{"name":"lastTxTimestamp","type":"uint256"},{"name":"denomination","type":"bytes32"}],"payable":false,"type":"function","stateMutability":"view"},{"constant":false,"inputs":[{"name":"_ucacContractAddr","type":"address"},{"name":"_numTokens","type":"uint256"}],"name":"stakeTokens","outputs":[],"payable":false,"type":"function","stateMutability":"nonpayable"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function","stateMutability":"view"},{"constant":true,"inputs":[{"name":"","type":"address"},{"name":"","type":"address"}],"name":"nonces","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function","stateMutability":"view"},{"constant":false,"inputs":[{"name":"_ucacContractAddr","type":"address"}],"name":"executeUcacTx","outputs":[],"payable":false,"type":"function","stateMutability":"nonpayable"},{"constant":true,"inputs":[{"name":"_ucacContractAddr","type":"address"}],"name":"currentTxLevel","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function","stateMutability":"view"},{"constant":true,"inputs":[{"name":"","type":"address"},{"name":"","type":"address"}],"name":"balances","outputs":[{"name":"","type":"int256"}],"payable":false,"type":"function","stateMutability":"view"},{"constant":true,"inputs":[{"name":"p1","type":"address"},{"name":"p2","type":"address"}],"name":"getNonce","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function","stateMutability":"view"},{"constant":false,"inputs":[{"name":"_ucacContractAddr","type":"address"},{"name":"_numTokens","type":"uint256"}],"name":"unstakeTokens","outputs":[],"payable":false,"type":"function","stateMutability":"nonpayable"},{"constant":true,"inputs":[],"name":"tokensToOwnUcac","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function","stateMutability":"view"},{"constant":false,"inputs":[{"name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"type":"function","stateMutability":"nonpayable"},{"constant":true,"inputs":[],"name":"token","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function","stateMutability":"view"},{"inputs":[{"name":"_tokenContract","type":"address"},{"name":"_txPerGigaTokenPerHour","type":"uint256"},{"name":"_tokensToOwnUcac","type":"uint256"}],"payable":false,"type":"constructor","stateMutability":"nonpayable"},{"anonymous":false,"inputs":[{"indexed":true,"name":"ucac","type":"address"},{"indexed":true,"name":"creditor","type":"address"},{"indexed":true,"name":"debtor","type":"address"},{"indexed":false,"name":"amount","type":"uint256"},{"indexed":false,"name":"nonce","type":"uint256"},{"indexed":false,"name":"memo","type":"bytes32"}],"name":"IssueCredit","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"ucac","type":"address"},{"indexed":false,"name":"denomination","type":"bytes32"}],"name":"UcacCreation","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"previousOwner","type":"address"},{"indexed":true,"name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"}]```
15 changes: 9 additions & 6 deletions contracts/CreditProtocol.sol
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ contract CreditProtocol is Ownable {

// Staking

/**
@dev The gigatokens of `_txPerGigaTokenPerHour` are nominal giga tokens, that is
10 ^ 18 * 10 ^ 9 = 10 ^ 27 attotokens
**/
function setTxPerGigaTokenPerHour(uint256 _txPerGigaTokenPerHour) public onlyOwner {
txPerGigaTokenPerHour = _txPerGigaTokenPerHour;
}
Expand All @@ -111,10 +115,8 @@ contract CreditProtocol is Ownable {
}

/**
@dev msg.sender must have approved Stake contract to transfer **exactly** `_tokensToStake` tokens.
This design decision is a security precaution since this is a public function and it is desirable
to have the token owner to control exactly how many tokens can be transferred to `Stake.sol`,
regardless of who calls the function.
@dev msg.sender must have approved Stake contract to transfer at least `_tokensToStake` tokens.
`_tokensToStake` is measured in attotokens.
**/
function createAndStakeUcac( address _ucacContractAddr, bytes32 _denomination
, uint256 _tokensToStake) public {
Expand All @@ -133,7 +135,8 @@ contract CreditProtocol is Ownable {
/* Token staking functionality */

/**
@dev msg.sender must have approved Stake contract to transfer **exactly** `_numTokens` tokens
@dev msg.sender must have approved Stake contract to transfer at least `_numTokens` tokens
`_numTokens` is measured in attotokens.
**/
function stakeTokens(address _ucacContractAddr, uint256 _numTokens) public {
// check that _ucacContractAddr points to an extant UCAC
Expand All @@ -144,7 +147,7 @@ contract CreditProtocol is Ownable {
/**
@notice Checks if this address is already in this name.
@param _ucacContractAddr Id of the ucac tokens are staked to
@param _numTokens Number of tokens the user wants to unstake
@param _numTokens Number of attotokens the user wants to unstake
**/
function unstakeTokens(address _ucacContractAddr, uint256 _numTokens) public {
// SafeMath will throw if _numTokens is greater than a sender's stakedTokens amount
Expand Down
Loading

0 comments on commit e742d19

Please sign in to comment.