Contract Overview
Balance: 0 Ether
Ether Value: $0
Transactions: 1 txn
Misc:
Address Watch: Add To Watch List
Contract Creator: 0x10de91f04304b58605e6c945ea16e79daa37cc25at txn 0xd76cb7c7633e8d66d2590ba73fa4e4cbac82184c1f82cfbd7debead697cc6c66
 Internal Transactions as a result of Contract Execution
View All
ParentTxHash Block Age From To Value
Warning: The Compiled Contract might be susceptible to ExpExponentCleanup (medium/high-severity), EventStructWrongData (very low-severity) SolidityCompiler Bugs.

Contract Source Code Verified (Exact Match)
Contract Name: AtomicSwap
Compiler Text: v0.4.24+commit.e67f0147
Optimization Enabled: No
Runs (Optimiser):  200



  Contract Source Code   Find Similiar Contracts

pragma solidity ^0.4.19;

contract ERC20Basic {
  function totalSupply() public view returns (uint256);
  function balanceOf(address who) public view returns (uint256);
  function transfer(address to, uint256 value) public returns (bool);
  event Transfer(address indexed from, address indexed to, uint256 value);
}

contract ERC20 is ERC20Basic {
  function allowance(address owner, address spender) public view returns (uint256);
  function transferFrom(address from, address to, uint256 value) public returns (bool);
  function approve(address spender, uint256 value) public returns (bool);
  event Approval(address indexed owner, address indexed spender, uint256 value);
}

contract AtomicSwap {
  struct Swap {
    uint expiration;
    address initiator;
    address participant;
    uint256 value;
    bool isToken;
    address token;
    bool exists;
  }

  event InitiateSwap(address _initiator, address _participant, uint _expiration, bytes20 _hash, address _token, bool _isToken, uint256 _value);
  event RedeemSwap(address _participant, bytes20 _hash, bytes32 _secret);
  event RefundSwap(address _initiator, address _participant, bytes20 _hash);
  // maps the redeemer and bytes20 hash to a swap    
  mapping(address => mapping(bytes20 => Swap)) public swaps;

  function initiate(uint _expiration, bytes20 _hash, address _participant, address _token, bool _isToken, uint256 _value) payable public {
    Swap storage s = swaps[_participant][_hash];
    // make sure you aren't overwriting a pre-existing swap
    // (so the original initiator can't rewrite the terms)
    require (s.exists == false);
    // don't allow the creation of already expired swaps
    require (now < _expiration);

    if (_isToken) {
      // require that the sender has allowed the tokens to be withdrawn from their account
      ERC20 token = ERC20(_token);
      require(token.allowance(msg.sender, this) == _value);
      token.transferFrom(msg.sender, this, _value);
    }
    // create the new swap
    swaps[_participant][_hash] = Swap(_expiration, msg.sender, _participant, _isToken ? _value : msg.value, _isToken, _token, true);
    InitiateSwap(msg.sender, _participant, _expiration, _hash, _token, _isToken, _isToken ? _value : msg.value);
  }

  function redeem(bytes32 _secret) public {
    // get a swap from the mapping. we can do it directly because there is no way to 
    // fake the secret.
    bytes20 hash = ripemd160(_secret);
    Swap storage s = swaps[msg.sender][hash];
    
    // make sure the swap was not redeemed or refunded
    require(s.exists);
    // make sure the swap did not expire already
    require(now < s.expiration);
    
    // clean up and send
    s.exists = false;
    if (s.isToken) {
      ERC20 token = ERC20(s.token);
      token.transfer(msg.sender, s.value);
    } else {
      msg.sender.transfer(s.value);
    }

    RedeemSwap(msg.sender, hash, _secret);
  }

  function refund(bytes20 _hash, address _participant) public {
    Swap storage s = swaps[_participant][_hash];
    // don't allow refund if swap did not expire
    require(now > s.expiration);
    // don't allow refunds if the caller is not the initator
    require(msg.sender == s.initiator);
    // make sure the swap was not redeemed or refunded
    require(s.exists);

    s.exists = false;
    if (s.isToken) {
      ERC20 token = ERC20(s.token);
      token.transfer(msg.sender, s.value);
    } else {
      msg.sender.transfer(s.value);
    }

    RefundSwap(msg.sender, s.participant, _hash);
  }
}

    Contract ABI  
[{"constant":false,"inputs":[{"name":"_expiration","type":"uint256"},{"name":"_hash","type":"bytes20"},{"name":"_participant","type":"address"},{"name":"_token","type":"address"},{"name":"_isToken","type":"bool"},{"name":"_value","type":"uint256"}],"name":"initiate","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"},{"name":"","type":"bytes20"}],"name":"swaps","outputs":[{"name":"expiration","type":"uint256"},{"name":"initiator","type":"address"},{"name":"participant","type":"address"},{"name":"value","type":"uint256"},{"name":"isToken","type":"bool"},{"name":"token","type":"address"},{"name":"exists","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_secret","type":"bytes32"}],"name":"redeem","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_hash","type":"bytes20"},{"name":"_participant","type":"address"}],"name":"refund","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"anonymous":false,"inputs":[{"indexed":false,"name":"_initiator","type":"address"},{"indexed":false,"name":"_participant","type":"address"},{"indexed":false,"name":"_expiration","type":"uint256"},{"indexed":false,"name":"_hash","type":"bytes20"},{"indexed":false,"name":"_token","type":"address"},{"indexed":false,"name":"_isToken","type":"bool"},{"indexed":false,"name":"_value","type":"uint256"}],"name":"InitiateSwap","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"_participant","type":"address"},{"indexed":false,"name":"_hash","type":"bytes20"},{"indexed":false,"name":"_secret","type":"bytes32"}],"name":"RedeemSwap","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"_initiator","type":"address"},{"indexed":false,"name":"_participant","type":"address"},{"indexed":false,"name":"_hash","type":"bytes20"}],"name":"RefundSwap","type":"event"}]

  Contract Creation Code Switch To Opcodes View
608060405234801561001057600080fd5b5061104e806100206000396000f300608060405260043610610062576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680637337c99314610067578063e2ca481c146100f6578063eda1122c1461021c578063f66c75e51461024d575b600080fd5b6100f46004803603810190808035906020019092919080356bffffffffffffffffffffffff19169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803515159060200190929190803590602001909291905050506102a9565b005b34801561010257600080fd5b50610150600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080356bffffffffffffffffffffffff191690602001909291905050506108c4565b604051808881526020018773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001858152602001841515151581526020018373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018215151515815260200197505050505050505060405180910390f35b34801561022857600080fd5b5061024b600480360381019080803560001916906020019092919050505061098d565b005b34801561025957600080fd5b506102a760048036038101908080356bffffffffffffffffffffffff19169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610cad565b005b6000806000808773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000886bffffffffffffffffffffffff19166bffffffffffffffffffffffff191681526020019081526020016000209150600015158260040160159054906101000a900460ff16151514151561033f57600080fd5b874210151561034d57600080fd5b831561058157849050828173ffffffffffffffffffffffffffffffffffffffff1663dd62ed3e33306040518363ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200192505050602060405180830381600087803b15801561042657600080fd5b505af115801561043a573d6000803e3d6000fd5b505050506040513d602081101561045057600080fd5b810190808051906020019092919050505014151561046d57600080fd5b8073ffffffffffffffffffffffffffffffffffffffff166323b872dd3330866040518463ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019350505050602060405180830381600087803b15801561054457600080fd5b505af1158015610558573d6000803e3d6000fd5b505050506040513d602081101561056e57600080fd5b8101908080519060200190929190505050505b60e0604051908101604052808981526020013373ffffffffffffffffffffffffffffffffffffffff1681526020018773ffffffffffffffffffffffffffffffffffffffff168152602001856105d657346105d8565b845b815260200185151581526020018673ffffffffffffffffffffffffffffffffffffffff168152602001600115158152506000808873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000896bffffffffffffffffffffffff19166bffffffffffffffffffffffff191681526020019081526020016000206000820151816000015560208201518160010160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060408201518160020160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506060820151816003015560808201518160040160006101000a81548160ff02191690831515021790555060a08201518160040160016101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060c08201518160040160156101000a81548160ff0219169083151502179055509050507fcdcddbe9ff8b399081a21b2d1e89d5ff9d445fe8fbc0b20a78c0d090503b1a5233878a8a89898a6107d357346107d5565b895b604051808873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001868152602001856bffffffffffffffffffffffff19166bffffffffffffffffffffffff191681526020018473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018315151515815260200182815260200197505050505050505060405180910390a15050505050505050565b6000602052816000526040600020602052806000526040600020600091509150508060000154908060010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16908060020160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16908060030154908060040160009054906101000a900460ff16908060040160019054906101000a900473ffffffffffffffffffffffffffffffffffffffff16908060040160159054906101000a900460ff16905087565b60008060006003846040518082600019166000191681526020019150506020604051808303816000865af11580156109c9573d6000803e3d6000fd5b505050604051516c010000000000000000000000000292506000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000846bffffffffffffffffffffffff19166bffffffffffffffffffffffff1916815260200190815260200160002091508160040160159054906101000a900460ff161515610a6d57600080fd5b816000015442101515610a7f57600080fd5b60008260040160156101000a81548160ff0219169083151502179055508160040160009054906101000a900460ff1615610bc2578160040160019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1690508073ffffffffffffffffffffffffffffffffffffffff1663a9059cbb3384600301546040518363ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200182815260200192505050602060405180830381600087803b158015610b8157600080fd5b505af1158015610b95573d6000803e3d6000fd5b505050506040513d6020811015610bab57600080fd5b810190808051906020019092919050505050610c0e565b3373ffffffffffffffffffffffffffffffffffffffff166108fc83600301549081150290604051600060405180830381858888f19350505050158015610c0c573d6000803e3d6000fd5b505b7fcbca3434730ae3817b50936d1dbbdf3a3a24a304e8d4239bd7601933f7c7687f338486604051808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001836bffffffffffffffffffffffff19166bffffffffffffffffffffffff191681526020018260001916600019168152602001935050505060405180910390a150505050565b6000806000808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000856bffffffffffffffffffffffff19166bffffffffffffffffffffffff191681526020019081526020016000209150816000015442111515610d3157600080fd5b8160010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141515610d8f57600080fd5b8160040160159054906101000a900460ff161515610dac57600080fd5b60008260040160156101000a81548160ff0219169083151502179055508160040160009054906101000a900460ff1615610eef578160040160019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1690508073ffffffffffffffffffffffffffffffffffffffff1663a9059cbb3384600301546040518363ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200182815260200192505050602060405180830381600087803b158015610eae57600080fd5b505af1158015610ec2573d6000803e3d6000fd5b505050506040513d6020811015610ed857600080fd5b810190808051906020019092919050505050610f3b565b3373ffffffffffffffffffffffffffffffffffffffff166108fc83600301549081150290604051600060405180830381858888f19350505050158015610f39573d6000803e3d6000fd5b505b7f156c8d8466f396c2a693c794d60f5e88107a49ab17056787ca821d1bac031a71338360020160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1686604051808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001826bffffffffffffffffffffffff19166bffffffffffffffffffffffff19168152602001935050505060405180910390a1505050505600a165627a7a723058200566fb41375fb659f8972697390783e7c4195745cf15b0a89e689ea38230f0f70029

   Swarm Source:
bzzr://0566fb41375fb659f8972697390783e7c4195745cf15b0a89e689ea38230f0f7

 

View All
Block Age transaction Difficulty GasUsed Reward
View All
Block Age UncleNumber Difficulty GasUsed Reward
Make sure to use the "Vote Down" button for any spammy posts, and the "Vote Up" for interesting conversations.