Address Contract Partially Verified
Address
0xBCf0d1AD453728F75e9cFD4358ED187598A45e6c
Balance
0 ETH
Nonce
1
Code Size
9907 bytes
Creator
0xac96570C...6af8 at tx 0x9963d4e8...bde617
Last Active
Indexed Transactions
2 (24,315,226 → 24,315,240)
Gas Used (indexed)
101,952
Contract Bytecode
9907 bytes
0x6080604052600436106100fb5763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416630c7ac7b681146101005780632fbe3b031461018a578063311a6c56146101b45780633de0c7ef146101d15780636cc6cde1146101e95780636e72b4521461021a5780637b44cdb5146102255780637e69b7b0146102305780639ace38c21461023b578063a527aa6a146102ec578063a6a7f0eb14610301578063b329036b1461035f578063ec9aa20a14610374578063ee22610b146103ec578063ef48eee614610404578063f42cadc11461041f578063f94cdf9614610437578063fe43a992146104a8575b600080fd5b34801561010c57600080fd5b506101156104c3565b6040805160208082528351818301528351919283929083019185019080838360005b8381101561014f578181015183820152602001610137565b50505050905090810190601f16801561017c5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561019657600080fd5b506101a260043561054e565b60408051918252519081900360200190f35b3480156101c057600080fd5b506101cf600435602435610560565b005b3480156101dd57600080fd5b506101cf6004356106f1565b3480156101f557600080fd5b506101fe610851565b60408051600160a060020a039092168252519081900360200190f35b6101cf600435610860565b6101cf600435610b81565b6101cf600435610e7c565b34801561024757600080fd5b50610253600435610fa7565b604051808b600160a060020a0316600160a060020a031681526020018a600160a060020a0316600160a060020a0316815260200189815260200188600160a060020a0316600160a060020a031681526020018781526020018681526020018581526020018481526020018381526020018260048111156102cf57fe5b60ff1681526020019a505050505050505050505060405180910390f35b3480156102f857600080fd5b506101a261101b565b34801561030d57600080fd5b5060408051602060046024803582810135601f81018590048502860185019096528585526101cf9583359536956044949193909101919081908401838280828437509497506110219650505050505050565b34801561036b57600080fd5b506101a2611224565b34801561038057600080fd5b50604080516020600460843581810135601f81018490048402850184019095528484526101a29482359460248035600160a060020a039081169660443596606435909216953695929460a4949093910191819084018382808284375094975061122a9650505050505050565b3480156103f857600080fd5b506101cf60043561159b565b34801561041057600080fd5b506101cf6004356024356117b7565b34801561042b57600080fd5b506101cf600435611a7a565b34801561044357600080fd5b50610458600160a060020a0360043516611bd8565b60408051602080825283518183015283519192839290830191858101910280838360005b8381101561049457818101518382015260200161047c565b505050509050019250505060405180910390f35b3480156104b457600080fd5b506101cf600435602435611d58565b6002805460408051602060018416156101000260001901909316849004601f810184900484028201840190925281815292918301828280156105465780601f1061051b57610100808354040283529160200191610546565b820191906000526020600020905b81548152906001019060200180831161052957829003601f168201915b505050505081565b60046020526000908152604090205481565b600082815260046020526040812054815490919081908390811061058057fe5b60009182526020909120600154600a909202019150600160a060020a0316331461061a576040805160e560020a62461bcd02815260206004820152602260248201527f5468652063616c6c6572206d757374206265207468652061726269747261746f60448201527f722e000000000000000000000000000000000000000000000000000000000000606482015290519081900360840190fd5b6003600982015460ff16600481111561062f57fe5b146106aa576040805160e560020a62461bcd02815260206004820152602660248201527f54686520646973707574652068617320616c7265616479206265656e2072657360448201527f6f6c7665642e0000000000000000000000000000000000000000000000000000606482015290519081900360840190fd5b604080518481529051859133917f394027a5fa6e098a1191094d1719d6929b9abc535fcc0c8f448d6a4e756222769181900360200190a36106eb8284611f80565b50505050565b6000808281548110151561070157fe5b60009182526020909120600a9091020190506001600982015460ff16600481111561072857fe5b146107a3576040805160e560020a62461bcd02815260206004820152602d60248201527f546865207472616e73616374696f6e206973206e6f742077616974696e67206f60448201527f6e207468652073656e6465722e00000000000000000000000000000000000000606482015290519081900360840190fd5b600354600882015442031015610803576040805160e560020a62461bcd02815260206004820181905260248201527f54696d656f75742074696d6520686173206e6f7420706173736564207965742e604482015290519081900360640190fd5b6006810154156108415780546006820154604051600160a060020a039092169181156108fc0291906000818181858888f15050600060068501555050505b61084d8260025b611f80565b5050565b600154600160a060020a031681565b60008060008381548110151561087257fe5b6000918252602091829020600180546040517ff7434ea9000000000000000000000000000000000000000000000000000000008152600481019586526002805460001994811615610100029490940190931683900460248201819052600a9095029093019650600160a060020a03169363f7434ea99391929091829160440190849080156109415780601f1061091657610100808354040283529160200191610941565b820191906000526020600020905b81548152906001019060200180831161092457829003601f168201915b505092505050602060405180830381600087803b15801561096157600080fd5b505af1158015610975573d6000803e3d6000fd5b505050506040513d602081101561098b57600080fd5b505190506003600983015460ff1660048111156109a457fe5b10610a1f576040805160e560020a62461bcd02815260206004820152602160248201527f446973707574652068617320616c7265616479206265656e206372656174656460448201527f2e00000000000000000000000000000000000000000000000000000000000000606482015290519081900360840190fd5b6001820154600160a060020a03163314610a83576040805160e560020a62461bcd02815260206004820181905260248201527f5468652063616c6c6572206d757374206265207468652072656365697665722e604482015290519081900360640190fd5b600782018054340190819055811115610b0c576040805160e560020a62461bcd02815260206004820152602e60248201527f54686520726563656976657220666565206d75737420636f766572206172626960448201527f74726174696f6e20636f7374732e000000000000000000000000000000000000606482015290519081900360840190fd5b4260088301556006820154811115610b725760098201805460ff1916600117905560405183907fc74b9f7dedf2887cd3c113b6d8da9cea19e55c1116e25f1f0e1b72d7543179b59060009080825b60ff16815260200191505060405180910390a2610b7c565b610b7c8382612404565b505050565b600080600083815481101515610b9357fe5b6000918252602091829020600180546040517ff7434ea9000000000000000000000000000000000000000000000000000000008152600481019586526002805460001994811615610100029490940190931683900460248201819052600a9095029093019650600160a060020a03169363f7434ea9939192909182916044019084908015610c625780601f10610c3757610100808354040283529160200191610c62565b820191906000526020600020905b815481529060010190602001808311610c4557829003601f168201915b505092505050602060405180830381600087803b158015610c8257600080fd5b505af1158015610c96573d6000803e3d6000fd5b505050506040513d6020811015610cac57600080fd5b505190506003600983015460ff166004811115610cc557fe5b10610d40576040805160e560020a62461bcd02815260206004820152602160248201527f446973707574652068617320616c7265616479206265656e206372656174656460448201527f2e00000000000000000000000000000000000000000000000000000000000000606482015290519081900360840190fd5b8154600160a060020a03163314610da1576040805160e560020a62461bcd02815260206004820152601e60248201527f5468652063616c6c6572206d757374206265207468652073656e6465722e0000604482015290519081900360640190fd5b600682018054340190819055811115610e2a576040805160e560020a62461bcd02815260206004820152602c60248201527f5468652073656e64657220666565206d75737420636f7665722061726269747260448201527f6174696f6e20636f7374732e0000000000000000000000000000000000000000606482015290519081900360840190fd5b4260088301556007820154811115610b725760098201805460ff1916600217905560405183907fc74b9f7dedf2887cd3c113b6d8da9cea19e55c1116e25f1f0e1b72d7543179b5906001908082610b5a565b60008082815481101515610e8c57fe5b6000918252602090912060018054600a9093029091016005810154604080517f49912f8800000000000000000000000000000000000000000000000000000000815260048101838152602482019283526002805461010097811615979097026000190190961686900460448301819052949750600160a060020a03909616956349912f88953495909391926064019084908015610f6a5780601f10610f3f57610100808354040283529160200191610f6a565b820191906000526020600020905b815481529060010190602001808311610f4d57829003601f168201915b505093505050506000604051808303818588803b158015610f8a57600080fd5b505af1158015610f9e573d6000803e3d6000fd5b50505050505050565b6000805482908110610fb557fe5b60009182526020909120600a90910201805460018201546002830154600384015460048501546005860154600687015460078801546008890154600990990154600160a060020a039889169a509688169895979094169592949193909290919060ff168a565b60005490565b6000808381548110151561103157fe5b60009182526020909120600a909102016001810154909150600160a060020a031633148061106857508054600160a060020a031633145b15156110e4576040805160e560020a62461bcd02815260206004820152602e60248201527f5468652063616c6c6572206d757374206265207468652072656365697665722060448201527f6f72207468652073656e6465722e000000000000000000000000000000000000606482015290519081900360840190fd5b6004600982015460ff1660048111156110f957fe5b10611174576040805160e560020a62461bcd02815260206004820152603260248201527f4d757374206e6f742073656e642065766964656e63652069662074686520646960448201527f7370757465206973207265736f6c7665642e0000000000000000000000000000606482015290519081900360840190fd5b600154604080516020808252855181830152855133948894600160a060020a03909116937fdccf2f8b2cc26eafcd61905cba744cff4b81d14740725f6376390dc6298a6a3c938993919283929083019185019080838360005b838110156111e55781810151838201526020016111cd565b50505050905090810190601f1680156112125780820380516001836020036101000a031916815260200191505b509250505060405180910390a4505050565b60035481565b604080517f23b872dd000000000000000000000000000000000000000000000000000000008152336004820152306024820152604481018790529051600091600160a060020a038716916323b872dd9160648082019260209290919082900301818787803b15801561129b57600080fd5b505af11580156112af573d6000803e3d6000fd5b505050506040513d60208110156112c557600080fd5b50511515611343576040805160e560020a62461bcd02815260206004820152602b60248201527f53656e64657220646f6573206e6f74206861766520656e6f756768206170707260448201527f6f7665642066756e64732e000000000000000000000000000000000000000000606482015290519081900360840190fd5b60006101406040519081016040528033600160a060020a0316815260200185600160a060020a0316815260200188815260200187600160a060020a03168152602001868152602001600081526020016000815260200160008152602001428152602001600060048111156113b357fe5b90528154600180820180855560009485526020948590208451600a90940201805473ffffffffffffffffffffffffffffffffffffffff19908116600160a060020a039586161782559585015181840180548816918616919091179055604085015160028201556060850151600382018054909716941693909317909455608083015160048084019190915560a0840151600584015560c0840151600684015560e0840151600784015561010084015160088401556101208401516009840180549193909260ff1990921691849081111561148957fe5b02179055505050506001600080549050037f61606860eb6c87306811e2695215385101daab53bd6ab4e9f9049aead9363c7d836040518080602001828103825283818151815260200191508051906020019080838360005b838110156114f95781810151838201526020016114e1565b50505050905090810190601f1680156115265780820380516001836020036101000a031916815260200191505b509250505060405180910390a2600054604080516000199092018252600160a060020a03878116602084015282820189905290519085169133917ff2ca096bdb2dc51a1c4a6b9a2b23f4be3e2344121e59d457f38b4b7258ffcdef9181900360600190a3506000546000190195945050505050565b6000806000838154811015156115ad57fe5b90600052602060002090600a0201915081600401548260080154420310151515611621576040805160e560020a62461bcd02815260206004820152601f60248201527f5468652074696d656f757420686173206e6f7420706173736564207965742e00604482015290519081900360640190fd5b6000600983015460ff16600481111561163657fe5b146116b1576040805160e560020a62461bcd02815260206004820152602660248201527f546865207472616e73616374696f6e2073686f756c646e27742062652064697360448201527f70757465642e0000000000000000000000000000000000000000000000000000606482015290519081900360840190fd5b5060028101805460009091556009820180546004919060ff19166001830217905550600382015460018301546040805160e060020a63a9059cbb028152600160a060020a039283166004820152602481018590529051919092169163a9059cbb9160448083019260209291908290030181600087803b15801561173357600080fd5b505af1158015611747573d6000803e3d6000fd5b505050506040513d602081101561175d57600080fd5b50511515610b7c576040805160e560020a62461bcd02815260206004820152602660248201526000805160206126688339815191526044820152600080516020612648833981519152606482015290519081900360840190fd5b600080838154811015156117c757fe5b60009182526020909120600a909102018054909150600160a060020a0316331461183b576040805160e560020a62461bcd02815260206004820152601e60248201527f5468652063616c6c6572206d757374206265207468652073656e6465722e0000604482015290519081900360640190fd5b6000600982015460ff16600481111561185057fe5b146118cb576040805160e560020a62461bcd02815260206004820152602660248201527f546865207472616e73616374696f6e2073686f756c646e27742062652064697360448201527f70757465642e0000000000000000000000000000000000000000000000000000606482015290519081900360840190fd5b600281015482111561194d576040805160e560020a62461bcd02815260206004820152603d60248201527f54686520616d6f756e7420706169642068617320746f206265206c657373206f60448201527f7220657175616c207468616e20746865207472616e73616374696f6e2e000000606482015290519081900360840190fd5b6002810180548390039055600381015460018201546040805160e060020a63a9059cbb028152600160a060020a039283166004820152602481018690529051919092169163a9059cbb9160448083019260209291908290030181600087803b1580156119b857600080fd5b505af11580156119cc573d6000803e3d6000fd5b505050506040513d60208110156119e257600080fd5b50511515611a3c576040805160e560020a62461bcd02815260206004820152602660248201526000805160206126688339815191526044820152600080516020612648833981519152606482015290519081900360840190fd5b60408051838152336020820152815185927fd1432ca9a38d944f01b256a411861b109bc4bfe200c40d7144e919a16b86a8a8928290030190a2505050565b60008082815481101515611a8a57fe5b60009182526020909120600a9091020190506002600982015460ff166004811115611ab157fe5b14611b2c576040805160e560020a62461bcd02815260206004820152602f60248201527f546865207472616e73616374696f6e206973206e6f742077616974696e67206f60448201527f6e207468652072656365697665722e0000000000000000000000000000000000606482015290519081900360840190fd5b600354600882015442031015611b8c576040805160e560020a62461bcd02815260206004820181905260248201527f54696d656f75742074696d6520686173206e6f7420706173736564207965742e604482015290519081900360640190fd5b600781015415611bcd5760018101546007820154604051600160a060020a039092169181156108fc0291906000818181858888f15050600060078501555050505b61084d826001610848565b6060600080805b600054821015611c725784600160a060020a0316600083815481101515611c0257fe5b60009182526020909120600a9091020154600160a060020a03161480611c5b575084600160a060020a0316600083815481101515611c3c57fe5b600091825260209091206001600a909202010154600160a060020a0316145b15611c67576001909201915b600190910190611bdf565b82604051908082528060200260200182016040528015611c9c578160200160208202803883390190505b50935060009250600090505b600054811015611d505784600160a060020a0316600082815481101515611ccb57fe5b60009182526020909120600a9091020154600160a060020a03161480611d24575084600160a060020a0316600082815481101515611d0557fe5b600091825260209091206001600a909202010154600160a060020a0316145b15611d48578351600184019382918691908110611d3d57fe5b602090810290910101525b600101611ca8565b505050919050565b60008083815481101515611d6857fe5b600091825260209091206001600a9092020190810154909150600160a060020a03163314611de0576040805160e560020a62461bcd02815260206004820181905260248201527f5468652063616c6c6572206d757374206265207468652072656365697665722e604482015290519081900360640190fd5b6000600982015460ff166004811115611df557fe5b14611e70576040805160e560020a62461bcd02815260206004820152602660248201527f546865207472616e73616374696f6e2073686f756c646e27742062652064697360448201527f70757465642e0000000000000000000000000000000000000000000000000000606482015290519081900360840190fd5b6002810154821115611f18576040805160e560020a62461bcd02815260206004820152604360248201527f54686520616d6f756e74207265696d6275727365642068617320746f2062652060448201527f6c657373206f7220657175616c207468616e20746865207472616e736163746960648201527f6f6e2e0000000000000000000000000000000000000000000000000000000000608482015290519081900360a40190fd5b6002810180548390039055600381015481546040805160e060020a63a9059cbb028152600160a060020a039283166004820152602481018690529051919092169163a9059cbb9160448083019260209291908290030181600087803b1580156119b857600080fd5b60008060008060008087815481101515611f9657fe5b60009182526020909120600a9091020194506002861115612001576040805160e560020a62461bcd02815260206004820152600f60248201527f496e76616c69642072756c696e672e0000000000000000000000000000000000604482015290519081900360640190fd5b600285018054600687018054600789018054600095869055928590559390935560098801805460ff191660041790559095509093509150600186141561214f578454604051600160a060020a039091169084156108fc029085906000818181858888f1505050600387015487546040805160e060020a63a9059cbb028152600160a060020a039283166004820152602481018a9052905191909216935063a9059cbb925060448083019260209291908290030181600087803b1580156120c657600080fd5b505af11580156120da573d6000803e3d6000fd5b505050506040513d60208110156120f057600080fd5b5051151561214a576040805160e560020a62461bcd02815260206004820152602660248201526000805160206126688339815191526044820152600080516020612648833981519152606482015290519081900360840190fd5b610f9e565b60028614156121e3576001850154604051600160a060020a039091169083156108fc029084906000818181858888f1505050600387015460018801546040805160e060020a63a9059cbb028152600160a060020a039283166004820152602481018a9052905191909216935063a9059cbb925060448083019260209291908290030181600087803b1580156120c657600080fd5b5060018401546040516002840491600160a060020a0316906108fc8315029083906000818181858888f150508754604051600160a060020a03909116935084156108fc0292508491506000818181858888f150505050600386015460018701546040805160e060020a63a9059cbb028152600160a060020a039283166004820152600289046024820152905191909216925063a9059cbb916044808201926020929091908290030181600087803b15801561229d57600080fd5b505af11580156122b1573d6000803e3d6000fd5b505050506040513d60208110156122c757600080fd5b50511515612321576040805160e560020a62461bcd02815260206004820152602660248201526000805160206126688339815191526044820152600080516020612648833981519152606482015290519081900360840190fd5b600385015485546040805160e060020a63a9059cbb028152600160a060020a0392831660048201526002880460248201529051919092169163a9059cbb9160448083019260209291908290030181600087803b15801561238057600080fd5b505af1158015612394573d6000803e3d6000fd5b505050506040513d60208110156123aa57600080fd5b50511515610f9e576040805160e560020a62461bcd02815260206004820152602660248201526000805160206126688339815191526044820152600080516020612648833981519152606482015290519081900360840190fd5b6000806000808581548110151561241757fe5b600091825260209091206009600a90920201908101805460ff1916600317905560018054604080517fc13517e100000000000000000000000000000000000000000000000000000000815260026004820181815260248301938452815461010096811615969096026000190190951681900460448301819052959850600160a060020a039093169463c13517e1948a949384939192909160640190849080156125015780601f106124d657610100808354040283529160200191612501565b820191906000526020600020905b8154815290600101906020018083116124e457829003601f168201915b505093505050506020604051808303818588803b15801561252157600080fd5b505af1158015612535573d6000803e3d6000fd5b50505050506040513d602081101561254c57600080fd5b5051600584018181556000918252600460209081526040928390208890559054600154835189815292830189905283519193600160a060020a03909116927f74baab670a4015ab2f1b467c5252a96141a2573f2908e58a92081e80d3cfde3d929081900390910190a383836006015411156125f857600683018054908590558354604051918690039350600160a060020a03169083156108fc029084906000818181858888f150505050505b838360070154111561264057506007820180549084905560018301546040519185900391600160a060020a039091169082156108fc029083906000818181858888f150505050505b50505050505600206661696c2e000000000000000000000000000000000000000000000000000054686520607472616e73666572602066756e6374696f6e206d757374206e6f74a165627a7a72305820122bc9dc0bc69c7fac25c854123ce9a911fbcbe6fdfdd6aacb638c07c949d5dd0029
Verified Source Code Partial Match
Compiler: v0.4.25+commit.59dbf8f1
EVM: byzantium
Optimization: Yes (200 runs)
MultipleArbitrableTokenTransaction.sol 1003 lines
/**
*Submitted for verification at Etherscan.io on 2019-03-05
*/
/**
* @authors: [@mtsalenc, @clesaege]
* @reviewers: [@clesaege]
* @auditors: []
* @bounties: []
* @deployments: []
*/
/* solium-disable max-len*/
pragma solidity 0.4.25;
/**
* @title ArbitrableTokenList
* This contract is an arbitrable token curated registry for tokens, sometimes referred to as a Token² Curated Registry. Users can send requests to register or remove tokens from the registry, which can in turn, be challenged by parties that disagree with them.
* A crowdsourced insurance system allows parties to contribute to arbitration fees and win rewards if the side they backed ultimately wins a dispute.
* NOTE: This contract trusts that the Arbitrator is honest and will not reenter or modify its costs during a call. This contract is only to be used with an arbitrator returning appealPeriod and having non-zero fees. The governor contract (which will be a DAO) is also to be trusted.
*/
/**
* @title CappedMath
* @dev Math operations with caps for under and overflow.
*/
library CappedMath {
uint constant private UINT_MAX = 2**256 - 1;
/**
* @dev Adds two unsigned integers, returns 2^256 - 1 on overflow.
*/
function addCap(uint _a, uint _b) internal pure returns (uint) {
uint c = _a + _b;
return c >= _a ? c : UINT_MAX;
}
/**
* @dev Subtracts two integers, returns 0 on underflow.
*/
function subCap(uint _a, uint _b) internal pure returns (uint) {
if (_b > _a)
return 0;
else
return _a - _b;
}
/**
* @dev Multiplies two unsigned integers, returns 2^256 - 1 on overflow.
*/
function mulCap(uint _a, uint _b) internal pure returns (uint) {
// Gas optimization: this is cheaper than requiring '_a' not being zero, but the
// benefit is lost if '_b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
if (_a == 0)
return 0;
uint c = _a * _b;
return c / _a == _b ? c : UINT_MAX;
}
}
/** @title Arbitrator
* Arbitrator abstract contract.
* When developing arbitrator contracts we need to:
* -Define the functions for dispute creation (createDispute) and appeal (appeal). Don't forget to store the arbitrated contract and the disputeID (which should be unique, use nbDisputes).
* -Define the functions for cost display (arbitrationCost and appealCost).
* -Allow giving rulings. For this a function must call arbitrable.rule(disputeID, ruling).
*/
contract Arbitrator {
enum DisputeStatus {Waiting, Appealable, Solved}
modifier requireArbitrationFee(bytes _extraData) {
require(msg.value >= arbitrationCost(_extraData), "Not enough ETH to cover arbitration costs.");
_;
}
modifier requireAppealFee(uint _disputeID, bytes _extraData) {
require(msg.value >= appealCost(_disputeID, _extraData), "Not enough ETH to cover appeal costs.");
_;
}
/** @dev To be raised when a dispute is created.
* @param _disputeID ID of the dispute.
* @param _arbitrable The contract which created the dispute.
*/
event DisputeCreation(uint indexed _disputeID, Arbitrable indexed _arbitrable);
/** @dev To be raised when a dispute can be appealed.
* @param _disputeID ID of the dispute.
*/
event AppealPossible(uint indexed _disputeID, Arbitrable indexed _arbitrable);
/** @dev To be raised when the current ruling is appealed.
* @param _disputeID ID of the dispute.
* @param _arbitrable The contract which created the dispute.
*/
event AppealDecision(uint indexed _disputeID, Arbitrable indexed _arbitrable);
/** @dev Create a dispute. Must be called by the arbitrable contract.
* Must be paid at least arbitrationCost(_extraData).
* @param _choices Amount of choices the arbitrator can make in this dispute.
* @param _extraData Can be used to give additional info on the dispute to be created.
* @return disputeID ID of the dispute created.
*/
function createDispute(uint _choices, bytes _extraData) public requireArbitrationFee(_extraData) payable returns(uint disputeID) {}
/** @dev Compute the cost of arbitration. It is recommended not to increase it often, as it can be highly time and gas consuming for the arbitrated contracts to cope with fee augmentation.
* @param _extraData Can be used to give additional info on the dispute to be created.
* @return fee Amount to be paid.
*/
function arbitrationCost(bytes _extraData) public view returns(uint fee);
/** @dev Appeal a ruling. Note that it has to be called before the arbitrator contract calls rule.
* @param _disputeID ID of the dispute to be appealed.
* @param _extraData Can be used to give extra info on the appeal.
*/
function appeal(uint _disputeID, bytes _extraData) public requireAppealFee(_disputeID,_extraData) payable {
emit AppealDecision(_disputeID, Arbitrable(msg.sender));
}
/** @dev Compute the cost of appeal. It is recommended not to increase it often, as it can be higly time and gas consuming for the arbitrated contracts to cope with fee augmentation.
* @param _disputeID ID of the dispute to be appealed.
* @param _extraData Can be used to give additional info on the dispute to be created.
* @return fee Amount to be paid.
*/
function appealCost(uint _disputeID, bytes _extraData) public view returns(uint fee);
/** @dev Compute the start and end of the dispute's current or next appeal period, if possible.
* @param _disputeID ID of the dispute.
* @return The start and end of the period.
*/
function appealPeriod(uint _disputeID) public view returns(uint start, uint end) {}
/** @dev Return the status of a dispute.
* @param _disputeID ID of the dispute to rule.
* @return status The status of the dispute.
*/
function disputeStatus(uint _disputeID) public view returns(DisputeStatus status);
/** @dev Return the current ruling of a dispute. This is useful for parties to know if they should appeal.
* @param _disputeID ID of the dispute.
* @return ruling The ruling which has been given or the one which will be given if there is no appeal.
*/
function currentRuling(uint _disputeID) public view returns(uint ruling);
}
/** @title IArbitrable
* Arbitrable interface.
* When developing arbitrable contracts, we need to:
* -Define the action taken when a ruling is received by the contract. We should do so in executeRuling.
* -Allow dispute creation. For this a function must:
* -Call arbitrator.createDispute.value(_fee)(_choices,_extraData);
* -Create the event Dispute(_arbitrator,_disputeID,_rulingOptions);
*/
interface IArbitrable {
/** @dev To be emmited when meta-evidence is submitted.
* @param _metaEvidenceID Unique identifier of meta-evidence.
* @param _evidence A link to the meta-evidence JSON.
*/
event MetaEvidence(uint indexed _metaEvidenceID, string _evidence);
/** @dev To be emmited when a dispute is created to link the correct meta-evidence to the disputeID
* @param _arbitrator The arbitrator of the contract.
* @param _disputeID ID of the dispute in the Arbitrator contract.
* @param _metaEvidenceID Unique identifier of meta-evidence.
* @param _evidenceGroupID Unique identifier of the evidence group that is linked to this dispute.
*/
event Dispute(Arbitrator indexed _arbitrator, uint indexed _disputeID, uint _metaEvidenceID, uint _evidenceGroupID);
/** @dev To be raised when evidence are submitted. Should point to the ressource (evidences are not to be stored on chain due to gas considerations).
* @param _arbitrator The arbitrator of the contract.
* @param _evidenceGroupID Unique identifier of the evidence group the evidence belongs to.
* @param _party The address of the party submiting the evidence. Note that 0x0 refers to evidence not submitted by any party.
* @param _evidence A URI to the evidence JSON file whose name should be its keccak256 hash followed by .json.
*/
event Evidence(Arbitrator indexed _arbitrator, uint indexed _evidenceGroupID, address indexed _party, string _evidence);
/** @dev To be raised when a ruling is given.
* @param _arbitrator The arbitrator giving the ruling.
* @param _disputeID ID of the dispute in the Arbitrator contract.
* @param _ruling The ruling which was given.
*/
event Ruling(Arbitrator indexed _arbitrator, uint indexed _disputeID, uint _ruling);
/** @dev Give a ruling for a dispute. Must be called by the arbitrator.
* The purpose of this function is to ensure that the address calling it has the right to rule on the contract.
* @param _disputeID ID of the dispute in the Arbitrator contract.
* @param _ruling Ruling given by the arbitrator. Note that 0 is reserved for "Not able/wanting to make a decision".
*/
function rule(uint _disputeID, uint _ruling) public;
}
/** @title Arbitrable
* Arbitrable abstract contract.
* When developing arbitrable contracts, we need to:
* -Define the action taken when a ruling is received by the contract. We should do so in executeRuling.
* -Allow dispute creation. For this a function must:
* -Call arbitrator.createDispute.value(_fee)(_choices,_extraData);
* -Create the event Dispute(_arbitrator,_disputeID,_rulingOptions);
*/
contract Arbitrable is IArbitrable {
Arbitrator public arbitrator;
bytes public arbitratorExtraData; // Extra data to require particular dispute and appeal behaviour.
modifier onlyArbitrator {require(msg.sender == address(arbitrator), "Can only be called by the arbitrator."); _;}
/** @dev Constructor. Choose the arbitrator.
* @param _arbitrator The arbitrator of the contract.
* @param _arbitratorExtraData Extra data for the arbitrator.
*/
constructor(Arbitrator _arbitrator, bytes _arbitratorExtraData) public {
arbitrator = _arbitrator;
arbitratorExtraData = _arbitratorExtraData;
}
/** @dev Give a ruling for a dispute. Must be called by the arbitrator.
* The purpose of this function is to ensure that the address calling it has the right to rule on the contract.
* @param _disputeID ID of the dispute in the Arbitrator contract.
* @param _ruling Ruling given by the arbitrator. Note that 0 is reserved for "Not able/wanting to make a decision".
*/
function rule(uint _disputeID, uint _ruling) public onlyArbitrator {
emit Ruling(Arbitrator(msg.sender),_disputeID,_ruling);
executeRuling(_disputeID,_ruling);
}
/** @dev Execute a ruling of a dispute.
* @param _disputeID ID of the dispute in the Arbitrator contract.
* @param _ruling Ruling given by the arbitrator. Note that 0 is reserved for "Not able/wanting to make a decision".
*/
function executeRuling(uint _disputeID, uint _ruling) internal;
}
/**
* @title Permission Interface
* This is a permission interface for arbitrary values. The values can be cast to the required types.
*/
interface PermissionInterface{
/* External */
/**
* @dev Return true if the value is allowed.
* @param _value The value we want to check.
* @return allowed True if the value is allowed, false otherwise.
*/
function isPermitted(bytes32 _value) external view returns (bool allowed);
}
/**
* @dev Interface of the ERC20 standard as defined in the EIP. Does not include
* the optional functions; to access them see `ERC20Detailed`.
*/
interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a `Transfer` event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through `transferFrom`. This is
* zero by default.
*
* This value changes when `approve` or `transferFrom` are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* > Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an `Approval` event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a `Transfer` event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to `approve`. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
}
library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a, "SafeMath: subtraction overflow");
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// Solidity only automatically asserts when dividing by 0
require(b > 0, "SafeMath: division by zero");
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b != 0, "SafeMath: modulo by zero");
return a % b;
}
}
contract ERC20 is IERC20 {
using SafeMath for uint256;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 private _totalSupply;
/**
* @dev See `IERC20.totalSupply`.
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev See `IERC20.balanceOf`.
*/
function balanceOf(address account) public view returns (uint256) {
return _balances[account];
}
/**
* @dev See `IERC20.transfer`.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public returns (bool) {
_transfer(msg.sender, recipient, amount);
return true;
}
/**
* @dev See `IERC20.allowance`.
*/
function allowance(address owner, address spender) public view returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See `IERC20.approve`.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 value) public returns (bool) {
_approve(msg.sender, spender, value);
return true;
}
/**
* @dev See `IERC20.transferFrom`.
*
* Emits an `Approval` event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of `ERC20`;
*
* Requirements:
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `value`.
* - the caller must have allowance for `sender`'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, msg.sender, _allowances[sender][msg.sender].sub(amount));
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to `approve` that can be used as a mitigation for
* problems described in `IERC20.approve`.
*
* Emits an `Approval` event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].add(addedValue));
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to `approve` that can be used as a mitigation for
* problems described in `IERC20.approve`.
*
* Emits an `Approval` event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].sub(subtractedValue));
return true;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to `transfer`, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a `Transfer` event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
function _transfer(address sender, address recipient, uint256 amount) internal {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_balances[sender] = _balances[sender].sub(amount);
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a `Transfer` event with `from` set to the zero address.
*
* Requirements
*
* - `to` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal {
require(account != address(0), "ERC20: mint to the zero address");
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a `Transfer` event with `to` set to the zero address.
*
* Requirements
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 value) internal {
require(account != address(0), "ERC20: burn from the zero address");
_totalSupply = _totalSupply.sub(value);
_balances[account] = _balances[account].sub(value);
emit Transfer(account, address(0), value);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an `Approval` event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(address owner, address spender, uint256 value) internal {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = value;
emit Approval(owner, spender, value);
}
/**
* @dev Destoys `amount` tokens from `account`.`amount` is then deducted
* from the caller's allowance.
*
* See `_burn` and `_approve`.
*/
function _burnFrom(address account, uint256 amount) internal {
_burn(account, amount);
_approve(account, msg.sender, _allowances[account][msg.sender].sub(amount));
}
}
contract MultipleArbitrableTokenTransaction is IArbitrable {
// **************************** //
// * Contract variables * //
// **************************** //
uint8 constant AMOUNT_OF_CHOICES = 2;
enum Party {Sender, Receiver}
enum Status {NoDispute, WaitingSender, WaitingReceiver, DisputeCreated, Resolved}
enum RulingOptions {NoRuling, SenderWins, ReceiverWins}
struct Transaction {
address sender;
address receiver;
uint amount;
ERC20 token;
uint timeoutPayment; // Time in seconds after which the transaction can be automatically executed if not disputed.
uint disputeId; // If dispute exists, the ID of the dispute.
uint senderFee; // Total fees paid by the sender.
uint receiverFee; // Total fees paid by the receiver.
uint lastInteraction; // Last interaction for the dispute procedure.
Status status;
}
Transaction[] public transactions;
Arbitrator public arbitrator; // Address of the arbitrator contract.
bytes public arbitratorExtraData; // Extra data to set up the arbitration.
uint public feeTimeout; // Time in seconds a party can take to pay arbitration fees before being considered unresponding and lose the dispute.
mapping (uint => uint) public disputeIDtoTransactionID;
// **************************** //
// * Events * //
// **************************** //
/** @dev To be emitted when a party pays or reimburses the other.
* @param _transactionID The index of the transaction.
* @param _amount The amount paid.
* @param _party The party that paid.
*/
event Payment(uint indexed _transactionID, uint _amount, address _party);
/** @dev Indicate that a party has to pay a fee or would otherwise be considered as losing.
* @param _transactionID The index of the transaction.
* @param _party The party who has to pay.
*/
event HasToPayFee(uint indexed _transactionID, Party _party);
/** @dev Emitted when the final ruling of a dispute is given by the arbitrator.
* @param _arbitrator The arbitrator giving the ruling.
* @param _disputeID ID of the dispute in the Arbitrator contract.
* @param _ruling The ruling which was given.
*/
event Ruling(Arbitrator indexed _arbitrator, uint indexed _disputeID, uint _ruling);
/** @dev Emitted when a transaction is created.
* @param _transactionID The index of the transaction.
* @param _sender The address of the sender.
* @param _receiver The address of the receiver.
* @param _token The token address.
* @param _amount The initial amount of the token.
*/
event TransactionCreated(uint _transactionID, address indexed _sender, address indexed _receiver, ERC20 _token, uint _amount);
// **************************** //
// * Arbitrable functions * //
// * Modifying the state * //
// **************************** //
/** @dev Constructor.
* @param _arbitrator The arbitrator of the contract.
* @param _arbitratorExtraData Extra data for the arbitrator.
* @param _feeTimeout Arbitration fee timeout for the parties.
*/
constructor (
Arbitrator _arbitrator,
bytes _arbitratorExtraData,
uint _feeTimeout
) public {
arbitrator = _arbitrator;
arbitratorExtraData = _arbitratorExtraData;
feeTimeout = _feeTimeout;
}
/** @dev Create a transaction. UNTRUSTED.
* @param _amount The amount of tokens in this transaction.
* @param _token The ERC20 token contract.
* @param _timeoutPayment Time after which a party automatically loses a dispute.
* @param _receiver The recipient of the transaction.
* @param _metaEvidence Link to the meta-evidence.
* @return The index of the transaction.
*/
function createTransaction(
uint _amount,
ERC20 _token,
uint _timeoutPayment,
address _receiver,
string _metaEvidence
) public returns (uint transactionIndex) {
// Transfers token from sender wallet to contract.
require(_token.transferFrom(msg.sender, address(this), _amount), "Sender does not have enough approved funds.");
transactions.push(Transaction({
sender: msg.sender,
receiver: _receiver,
amount: _amount,
token: _token,
timeoutPayment: _timeoutPayment,
disputeId: 0,
senderFee: 0,
receiverFee: 0,
lastInteraction: now,
status: Status.NoDispute
}));
emit MetaEvidence(transactions.length - 1, _metaEvidence);
emit TransactionCreated(transactions.length - 1, msg.sender, _receiver, _token, _amount);
return transactions.length - 1;
}
/** @dev Pay receiver. To be called if the good or service is provided. UNTRUSTED.
* @param _transactionID The index of the transaction.
* @param _amount Amount to pay in tokens.
*/
function pay(uint _transactionID, uint _amount) public {
Transaction storage transaction = transactions[_transactionID];
require(transaction.sender == msg.sender, "The caller must be the sender.");
require(transaction.status == Status.NoDispute, "The transaction shouldn't be disputed.");
require(_amount <= transaction.amount, "The amount paid has to be less or equal than the transaction.");
transaction.amount -= _amount;
require(transaction.token.transfer(transaction.receiver, _amount), "The `transfer` function must not fail.");
emit Payment(_transactionID, _amount, msg.sender);
}
/** @dev Reimburse sender. To be called if the good or service can't be fully provided. UNTRUSTED.
* @param _transactionID The index of the transaction.
* @param _amountReimbursed Amount to reimburse in tokens.
*/
function reimburse(uint _transactionID, uint _amountReimbursed) public {
Transaction storage transaction = transactions[_transactionID];
require(transaction.receiver == msg.sender, "The caller must be the receiver.");
require(transaction.status == Status.NoDispute, "The transaction shouldn't be disputed.");
require(_amountReimbursed <= transaction.amount, "The amount reimbursed has to be less or equal than the transaction.");
transaction.amount -= _amountReimbursed;
require(transaction.token.transfer(transaction.sender, _amountReimbursed), "The `transfer` function must not fail.");
emit Payment(_transactionID, _amountReimbursed, msg.sender);
}
/** @dev Transfer the transaction's amount to the receiver if the timeout has passed. UNTRUSTED.
* @param _transactionID The index of the transaction.
*/
function executeTransaction(uint _transactionID) public {
Transaction storage transaction = transactions[_transactionID];
require(now - transaction.lastInteraction >= transaction.timeoutPayment, "The timeout has not passed yet.");
require(transaction.status == Status.NoDispute, "The transaction shouldn't be disputed.");
uint amount = transaction.amount;
transaction.amount = 0;
transaction.status = Status.Resolved;
require(transaction.token.transfer(transaction.receiver, amount), "The `transfer` function must not fail.");
}
/** @dev Reimburse sender if receiver fails to pay the fee. UNTRUSTED.
* @param _transactionID The index of the transaction.
*/
function timeOutBySender(uint _transactionID) public {
Transaction storage transaction = transactions[_transactionID];
require(transaction.status == Status.WaitingReceiver, "The transaction is not waiting on the receiver.");
require(now - transaction.lastInteraction >= feeTimeout, "Timeout time has not passed yet.");
if (transaction.receiverFee != 0) {
transaction.receiver.send(transaction.receiverFee);
transaction.receiverFee = 0;
}
executeRuling(_transactionID, uint(RulingOptions.SenderWins));
}
/** @dev Pay receiver if sender fails to pay the fee. UNTRUSTED.
* @param _transactionID The index of the transaction.
*/
function timeOutByReceiver(uint _transactionID) public {
Transaction storage transaction = transactions[_transactionID];
require(transaction.status == Status.WaitingSender, "The transaction is not waiting on the sender.");
require(now - transaction.lastInteraction >= feeTimeout, "Timeout time has not passed yet.");
if (transaction.senderFee != 0) {
transaction.sender.send(transaction.senderFee);
transaction.senderFee = 0;
}
executeRuling(_transactionID, uint(RulingOptions.ReceiverWins));
}
/** @dev Pay the arbitration fee to raise a dispute. To be called by the sender. UNTRUSTED.
* Note that the arbitrator can have `createDispute` throw, which will make this function throw and therefore lead to a party being timed-out.
* This is not a vulnerability as the arbitrator can rule in favor of one party anyway.
* @param _transactionID The index of the transaction.
*/
function payArbitrationFeeBySender(uint _transactionID) public payable {
Transaction storage transaction = transactions[_transactionID];
uint arbitrationCost = arbitrator.arbitrationCost(arbitratorExtraData);
require(transaction.status < Status.DisputeCreated, "Dispute has already been created.");
require(msg.sender == transaction.sender, "The caller must be the sender.");
transaction.senderFee += msg.value;
// Require that the total paid to be at least the arbitration cost.
require(transaction.senderFee >= arbitrationCost, "The sender fee must cover arbitration costs.");
transaction.lastInteraction = now;
// The receiver still has to pay. This can also happen if he has paid, but `arbitrationCost` has increased.
if (transaction.receiverFee < arbitrationCost) {
transaction.status = Status.WaitingReceiver;
emit HasToPayFee(_transactionID, Party.Receiver);
} else { // The receiver has also paid the fee. We create the dispute.
raiseDispute(_transactionID, arbitrationCost);
}
}
/** @dev Pay the arbitration fee to raise a dispute. To be called by the receiver. UNTRUSTED.
* Note that this function mirrors payArbitrationFeeBySender.
* @param _transactionID The index of the transaction.
*/
function payArbitrationFeeByReceiver(uint _transactionID) public payable {
Transaction storage transaction = transactions[_transactionID];
uint arbitrationCost = arbitrator.arbitrationCost(arbitratorExtraData);
require(transaction.status < Status.DisputeCreated, "Dispute has already been created.");
require(msg.sender == transaction.receiver, "The caller must be the receiver.");
transaction.receiverFee += msg.value;
// Require that the total paid to be at least the arbitration cost.
require(transaction.receiverFee >= arbitrationCost, "The receiver fee must cover arbitration costs.");
transaction.lastInteraction = now;
// The sender still has to pay. This can also happen if he has paid, but arbitrationCost has increased.
if (transaction.senderFee < arbitrationCost) {
transaction.status = Status.WaitingSender;
emit HasToPayFee(_transactionID, Party.Sender);
} else { // The sender has also paid the fee. We create the dispute.
raiseDispute(_transactionID, arbitrationCost);
}
}
/** @dev Create a dispute. UNTRUSTED.
* @param _transactionID The index of the transaction.
* @param _arbitrationCost Amount to pay the arbitrator.
*/
function raiseDispute(uint _transactionID, uint _arbitrationCost) internal {
Transaction storage transaction = transactions[_transactionID];
transaction.status = Status.DisputeCreated;
transaction.disputeId = arbitrator.createDispute.value(_arbitrationCost)(AMOUNT_OF_CHOICES, arbitratorExtraData);
disputeIDtoTransactionID[transaction.disputeId] = _transactionID;
emit Dispute(arbitrator, transaction.disputeId, _transactionID, _transactionID);
// Refund sender if it overpaid.
if (transaction.senderFee > _arbitrationCost) {
uint extraFeeSender = transaction.senderFee - _arbitrationCost;
transaction.senderFee = _arbitrationCost;
transaction.sender.send(extraFeeSender);
}
// Refund receiver if it overpaid.
if (transaction.receiverFee > _arbitrationCost) {
uint extraFeeReceiver = transaction.receiverFee - _arbitrationCost;
transaction.receiverFee = _arbitrationCost;
transaction.receiver.send(extraFeeReceiver);
}
}
/** @dev Submit a reference to evidence. EVENT.
* @param _transactionID The index of the transaction.
* @param _evidence A link to an evidence using its URI.
*/
function submitEvidence(uint _transactionID, string _evidence) public {
Transaction storage transaction = transactions[_transactionID];
require(
msg.sender == transaction.receiver || msg.sender == transaction.sender,
"The caller must be the receiver or the sender."
);
require(
transaction.status < Status.Resolved,
"Must not send evidence if the dispute is resolved."
);
emit Evidence(arbitrator, _transactionID, msg.sender, _evidence);
}
/** @dev Appeal an appealable ruling. UNTRUSTED.
* Transfer the funds to the arbitrator.
* Note that no checks are required as the checks are done by the arbitrator.
* @param _transactionID The index of the transaction.
*/
function appeal(uint _transactionID) public payable {
Transaction storage transaction = transactions[_transactionID];
arbitrator.appeal.value(msg.value)(transaction.disputeId, arbitratorExtraData);
}
/** @dev Give a ruling for a dispute. Must be called by the arbitrator to enforce the final ruling.
* The purpose of this function is to ensure that the address calling it has the right to rule on the contract.
* @param _disputeID ID of the dispute in the Arbitrator contract.
* @param _ruling Ruling given by the arbitrator. Note that 0 is reserved for "Not able/wanting to make a decision".
*/
function rule(uint _disputeID, uint _ruling) public {
uint transactionID = disputeIDtoTransactionID[_disputeID];
Transaction storage transaction = transactions[transactionID];
require(msg.sender == address(arbitrator), "The caller must be the arbitrator.");
require(transaction.status == Status.DisputeCreated, "The dispute has already been resolved.");
emit Ruling(Arbitrator(msg.sender), _disputeID, _ruling);
executeRuling(transactionID, _ruling);
}
/** @dev Execute a ruling of a dispute. It reimburses the fee to the winning party.
* @param _transactionID The index of the transaction.
* @param _ruling Ruling given by the arbitrator. 1: Reimburse the receiver. 2: Pay the sender.
*/
function executeRuling(uint _transactionID, uint _ruling) internal {
Transaction storage transaction = transactions[_transactionID];
require(_ruling <= AMOUNT_OF_CHOICES, "Invalid ruling.");
uint amount = transaction.amount;
uint senderFee = transaction.senderFee;
uint receiverFee = transaction.receiverFee;
transaction.amount = 0;
transaction.senderFee = 0;
transaction.receiverFee = 0;
transaction.status = Status.Resolved;
// Give the arbitration fee back.
// Note that we use `send` to prevent a party from blocking the execution.
if (_ruling == uint(RulingOptions.SenderWins)) {
transaction.sender.send(senderFee);
require(transaction.token.transfer(transaction.sender, amount), "The `transfer` function must not fail.");
} else if (_ruling == uint(RulingOptions.ReceiverWins)) {
transaction.receiver.send(receiverFee);
require(transaction.token.transfer(transaction.receiver, amount), "The `transfer` function must not fail.");
} else {
// `senderFee` and `receiverFee` are equal to the arbitration cost.
uint splitArbitrationFee = senderFee / 2;
transaction.receiver.send(splitArbitrationFee);
transaction.sender.send(splitArbitrationFee);
// In the case of an uneven token amount, one basic token unit can be burnt.
require(transaction.token.transfer(transaction.receiver, amount / 2), "The `transfer` function must not fail.");
require(transaction.token.transfer(transaction.sender, amount / 2), "The `transfer` function must not fail.");
}
}
// **************************** //
// * Constant getters * //
// **************************** //
/** @dev Getter to know the count of transactions.
* @return countTransactions The count of transactions.
*/
function getCountTransactions() public view returns (uint countTransactions) {
return transactions.length;
}
/** @dev Get IDs for transactions where the specified address is the receiver and/or the sender.
* This function must be used by the UI and not by other smart contracts.
* Note that the complexity is O(t), where t is amount of arbitrable transactions.
* @param _address The specified address.
* @return transactionIDs The transaction IDs.
*/
function getTransactionIDsByAddress(address _address) public view returns (uint[] transactionIDs) {
uint count = 0;
for (uint i = 0; i < transactions.length; i++) {
if (transactions[i].sender == _address || transactions[i].receiver == _address)
count++;
}
transactionIDs = new uint[](count);
count = 0;
for (uint j = 0; j < transactions.length; j++) {
if (transactions[j].sender == _address || transactions[j].receiver == _address)
transactionIDs[count++] = j;
}
}
}
Read Contract
arbitrator 0x6cc6cde1 → address
arbitratorExtraData 0x0c7ac7b6 → bytes
disputeIDtoTransactionID 0x2fbe3b03 → uint256
feeTimeout 0xb329036b → uint256
getCountTransactions 0xa527aa6a → uint256
getTransactionIDsByAddress 0xf94cdf96 → uint256[]
transactions 0x9ace38c2 → address, address, uint256, address, uint256, uint256, uint256, uint256, uint256, uint8
Write Contract 11 functions
These functions modify contract state and require a wallet transaction to execute.
appeal 0x7e69b7b0
uint256 _transactionID
createTransaction 0xec9aa20a
uint256 _amount
address _token
uint256 _timeoutPayment
address _receiver
string _metaEvidence
returns: uint256
executeTransaction 0xee22610b
uint256 _transactionID
pay 0xef48eee6
uint256 _transactionID
uint256 _amount
payArbitrationFeeByReceiver 0x6e72b452
uint256 _transactionID
payArbitrationFeeBySender 0x7b44cdb5
uint256 _transactionID
reimburse 0xfe43a992
uint256 _transactionID
uint256 _amountReimbursed
rule 0x311a6c56
uint256 _disputeID
uint256 _ruling
submitEvidence 0xa6a7f0eb
uint256 _transactionID
string _evidence
timeOutByReceiver 0x3de0c7ef
uint256 _transactionID
timeOutBySender 0xf42cadc1
uint256 _transactionID
Top Interactions
| Address | Txns | Sent | Received |
|---|---|---|---|
| 0xC18970de...58B0 | 2 | 2 |
Token Balances (2)
View Transfers →Recent Transactions
|
| Hash | Block | Age | From/To | Value | |
|---|---|---|---|---|---|
| 0x25bfd6f8...05aacf | 24,315,240 | IN | 0xC18970de...58B0 | 0 ETH | |
| 0xe7d36821...bd4adf | 24,315,226 | IN | 0xC18970de...58B0 | 0 ETH |