Added natspec to the remaining ownership contracts and payment contracts

pull/210/head
João Gabriel Carvalho 8 years ago committed by maurelian
parent 602c18b394
commit 1547922b61
  1. 16
      contracts/ownership/HasNoContracts.sol
  2. 48
      contracts/ownership/HasNoEther.sol
  3. 24
      contracts/ownership/HasNoTokens.sol
  4. 10
      contracts/ownership/NoOwner.sol
  5. 52
      contracts/ownership/Shareable.sol
  6. 18
      contracts/payment/PullPayment.sol

@ -2,15 +2,17 @@ pragma solidity ^0.4.8;
import "./Ownable.sol"; import "./Ownable.sol";
/// @title Contracts that should not own Contracts /** @title Contracts that should not own Contracts
/// @author Remco Bloemen <remco@2π.com> * @author Remco Bloemen <remco@2π.com>
/// * @dev Should contracts (anything Ownable) end up being owned by this contract, it allows the owner of this contract to reclaim ownership of the contracts.
/// Should contracts (anything Ownable) end up being owned by */
/// this contract, it allows the owner of this contract to
/// reclaim ownership of the contracts.
contract HasNoContracts is Ownable { contract HasNoContracts is Ownable {
/// Reclaim ownership of Ownable contracts /**
* @dev Reclaim ownership of Ownable contracts
* @param contractAddr address The Ownable contract address wished to
be reclaimed
*/
function reclaimContract(address contractAddr) external onlyOwner { function reclaimContract(address contractAddr) external onlyOwner {
Ownable contractInst = Ownable(contractAddr); Ownable contractInst = Ownable(contractAddr);
contractInst.transferOwnership(owner); contractInst.transferOwnership(owner);

@ -2,38 +2,44 @@ pragma solidity ^0.4.8;
import "./Ownable.sol"; import "./Ownable.sol";
/// @title Contracts that should not own Ether /** @title Contracts that should not own Ether
/// @author Remco Bloemen <remco@2π.com> * @author Remco Bloemen <remco@2π.com>
///
/// This tries to block incoming ether to prevent accidental * @dev This tries to block incoming ether to prevent accidental loss of Ether.
/// loss of Ether. Should Ether end up in the contrat, it will Should Ether end up in the contrat, it will allow the owner to reclaim
/// allow the owner to reclaim this ether. this ether.
/// * @notice Ether can still be send to this contract by:
/// @notice Ether can still be send to this contract by: * calling functions labeled `payable`
/// * calling functions labeled `payable` * `selfdestruct(contract_address)`
/// * `selfdestruct(contract_address)` * mining directly to the contract address
/// * mining directly to the contract address */
contract HasNoEther is Ownable { contract HasNoEther is Ownable {
/// Constructor that rejects incoming Ether /**
/// @dev The flag `payable` is added so we can access `msg.value` * @dev Constructor that rejects incoming Ether
/// without compiler warning. If we leave out payable, then * @dev The flag `payable` is added so we can access `msg.value`
/// Solidity will allow inheriting contracts to implement a without compiler warning. If we leave out payable, then
/// payable constructor. By doing it this way we prevent a Solidity will allow inheriting contracts to implement a
/// payable constructor from working. payable constructor. By doing it this way we prevent a
/// Alternatively we could use assembly to access msg.value. payable constructor from working. Alternatively we could
use assembly to access msg.value.
*/
function HasNoEther() payable { function HasNoEther() payable {
if(msg.value > 0) { if(msg.value > 0) {
throw; throw;
} }
} }
/// Disallow direct send by settings a default function without `payable` /**
* @dev Disallow direct send by settings a default function without `payable`
*/
function() external { function() external {
} }
/// Transfer all Ether owned by the contract to the owner /**
/// @dev What if owner is itself a contract marked HasNoEther? * @dev Transfer all Ether owned by the contract to the owner
* @dev What if owner is itself a contract marked HasNoEther?
*/
function reclaimEther() external onlyOwner { function reclaimEther() external onlyOwner {
if(!owner.send(this.balance)) { if(!owner.send(this.balance)) {
throw; throw;

@ -3,21 +3,27 @@ pragma solidity ^0.4.8;
import "./Ownable.sol"; import "./Ownable.sol";
import "../token/ERC20Basic.sol"; import "../token/ERC20Basic.sol";
/// @title Contracts that should not own Tokens /** @title Contracts that should not own Tokens
/// @author Remco Bloemen <remco@2π.com> * @author Remco Bloemen <remco@2π.com>
/// * @dev This blocks incoming ERC23 tokens to prevent accidental loss of tokens.
/// This blocks incoming ERC23 tokens to prevent accidental Should tokens (any ERC20Basic compatible) end up in the contract, it allows the
/// loss of tokens. Should tokens (any ERC20Basic compatible) owner to reclaim the tokens.
/// end up in the contract, it allows the owner to reclaim */
/// the tokens.
contract HasNoTokens is Ownable { contract HasNoTokens is Ownable {
/// Reject all ERC23 compatible tokens /** @dev Reject all ERC23 compatible tokens
* @param from_ address The address that is transfering the tokens
* @param value_ Uint the amount of the specified token
* @param data_ Bytes The data passed from the caller.
*/
function tokenFallback(address from_, uint value_, bytes data_) external { function tokenFallback(address from_, uint value_, bytes data_) external {
throw; throw;
} }
/// Reclaim all ERC20Basic compatible tokens /**
* @dev Reclaim all ERC20Basic compatible tokens
* @param tokenAddr address The address of the token contract
*/
function reclaimToken(address tokenAddr) external onlyOwner { function reclaimToken(address tokenAddr) external onlyOwner {
ERC20Basic tokenInst = ERC20Basic(tokenAddr); ERC20Basic tokenInst = ERC20Basic(tokenAddr);
uint256 balance = tokenInst.balanceOf(this); uint256 balance = tokenInst.balanceOf(this);

@ -4,11 +4,9 @@ import "./HasNoEther.sol";
import "./HasNoTokens.sol"; import "./HasNoTokens.sol";
import "./HasNoContracts.sol"; import "./HasNoContracts.sol";
/// @title Base contract for contracts that should not own things. /** @title Base contract for contracts that should not own things.
/// @author Remco Bloemen <remco@2π.com> * @author Remco Bloemen <remco@2π.com>
/// * @devSolves a class of errors where a contract accidentally becomes owner of Ether, Tokens or Owned contracts. See respective base contracts for details.
/// Solves a class of errors where a contract accidentally */
/// becomes owner of Ether, Tokens or Owned contracts. See
/// respective base contracts for details.
contract NoOwner is HasNoEther, HasNoTokens, HasNoContracts { contract NoOwner is HasNoEther, HasNoTokens, HasNoContracts {
} }

@ -1,17 +1,14 @@
pragma solidity ^0.4.8; pragma solidity ^0.4.8;
/* /**
* Shareable * @title Shareable
* @dev inheritable "property" contract that enables methods to be protected by requiring the acquiescence of either a single, or, crucially, each of a number of, designated owners.
* *
* Based on https://github.com/ethereum/dapp-bin/blob/master/wallet/wallet.sol * @dev Usage: use modifiers onlyowner (just own owned) or onlymanyowners(hash), whereby the same hash must be provided by some number (specified in constructor) of the set of owners (specified in the constructor) before the interior is executed.
*
* inheritable "property" contract that enables methods to be protected by requiring the acquiescence of either a single, or, crucially, each of a number of, designated owners.
*
* usage:
* use modifiers onlyowner (just own owned) or onlymanyowners(hash), whereby the same hash must be provided by some number (specified in constructor) of the set of owners (specified in the constructor) before the interior is executed.
*/ */
contract Shareable { contract Shareable {
// struct for the status of a pending operation. // struct for the status of a pending operation.
struct PendingState { struct PendingState {
uint yetNeeded; uint yetNeeded;
@ -54,8 +51,11 @@ contract Shareable {
} }
} }
// constructor is given number of sigs required to do protected "onlymanyowners" transactions /** @dev Constructor is given number of sigs required to do protected "onlymanyowners" transactions
// as well as the selection of addresses capable of confirming them. * as well as the selection of addresses capable of confirming them.
* @param _owners address[] A list of owners
* @param _required Uint The amout required for a transaction to be approved.
*/
function Shareable(address[] _owners, uint _required) { function Shareable(address[] _owners, uint _required) {
owners[1] = msg.sender; owners[1] = msg.sender;
ownerIndex[msg.sender] = 1; ownerIndex[msg.sender] = 1;
@ -69,7 +69,10 @@ contract Shareable {
} }
} }
// Revokes a prior confirmation of the given operation /**
* @dev Revokes a prior confirmation of the given operation
* @param _operation bytes32 A string the identfies the operation.
*/
function revoke(bytes32 _operation) external { function revoke(bytes32 _operation) external {
uint index = ownerIndex[msg.sender]; uint index = ownerIndex[msg.sender];
// make sure they're an owner // make sure they're an owner
@ -85,15 +88,30 @@ contract Shareable {
} }
} }
// Gets an owner by 0-indexed position (using numOwners as the count) /**
* @dev Gets an owner by 0-indexed position (using numOwners as the count)
* @param ownerIndex Uint The index of the owner
* @return The address of the owner
*/
function getOwner(uint ownerIndex) external constant returns (address) { function getOwner(uint ownerIndex) external constant returns (address) {
return address(owners[ownerIndex + 1]); return address(owners[ownerIndex + 1]);
} }
/**
* @dev Checks if given address is an owner.
* @param _addr address The address which you want to check.
* @return True if the address is an owner and fase otherwise.
*/
function isOwner(address _addr) constant returns (bool) { function isOwner(address _addr) constant returns (bool) {
return ownerIndex[_addr] > 0; return ownerIndex[_addr] > 0;
} }
/**
* @dev Function to check is specific owner has already confirme the operation
* @param _operation bytes32 The operation identifier
* @param _owner address The owner address
* @return True if the owner has confirmed and flase otherwise
*/
function hasConfirmed(bytes32 _operation, address _owner) constant returns (bool) { function hasConfirmed(bytes32 _operation, address _owner) constant returns (bool) {
var pending = pendings[_operation]; var pending = pendings[_operation];
uint index = ownerIndex[_owner]; uint index = ownerIndex[_owner];
@ -108,7 +126,11 @@ contract Shareable {
return !(pending.ownersDone & ownerIndexBit == 0); return !(pending.ownersDone & ownerIndexBit == 0);
} }
// returns true when operation can be executed /**
* @dev Confirm and operation and checks if it's already executable
* @param _operation bytes32 The operation identifier
* @return returns true when operation can be executed
*/
function confirmAndCheck(bytes32 _operation) internal returns (bool) { function confirmAndCheck(bytes32 _operation) internal returns (bool) {
// determine what index the present sender is: // determine what index the present sender is:
uint index = ownerIndex[msg.sender]; uint index = ownerIndex[msg.sender];
@ -147,6 +169,10 @@ contract Shareable {
return false; return false;
} }
/**
* @dev Clear the pedings list.
*/
function clearPending() internal { function clearPending() internal {
uint length = pendingsIndex.length; uint length = pendingsIndex.length;
for (uint i = 0; i < length; ++i) { for (uint i = 0; i < length; ++i) {

@ -4,10 +4,10 @@ pragma solidity ^0.4.8;
import '../SafeMath.sol'; import '../SafeMath.sol';
/* /**
* PullPayment * @title PullPayment
* Base contract supporting async send for pull payments. * @dev Base contract supporting async send for pull payments. Inherit from this
* Inherit from this contract and use asyncSend instead of send. contract and use asyncSend instead of send.
*/ */
contract PullPayment { contract PullPayment {
using SafeMath for uint; using SafeMath for uint;
@ -15,13 +15,19 @@ contract PullPayment {
mapping(address => uint) public payments; mapping(address => uint) public payments;
uint public totalPayments; uint public totalPayments;
// store sent amount as credit to be pulled, called by payer /**
* @dev store sent amount as credit to be pulled, called by payer
* @param dest address The destination address of the funds
* @param amount uint The amount to transfer
*/
function asyncSend(address dest, uint amount) internal { function asyncSend(address dest, uint amount) internal {
payments[dest] = payments[dest].add(amount); payments[dest] = payments[dest].add(amount);
totalPayments = totalPayments.add(amount); totalPayments = totalPayments.add(amount);
} }
// withdraw accumulated balance, called by payee /**
@dev withdraw accumulated balance, called by payee.
*/
function withdrawPayments() { function withdrawPayments() {
address payee = msg.sender; address payee = msg.sender;
uint payment = payments[payee]; uint payment = payments[payee];

Loading…
Cancel
Save