From eb953096f1dc5569b31da7be0b97aaf42c0fcbc3 Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 9 Jul 2018 22:35:30 +0300 Subject: [PATCH] Format code for better reading --- contracts/AtomicSwap.sol | 148 +++++++++++++++++++-------------------- 1 file changed, 71 insertions(+), 77 deletions(-) diff --git a/contracts/AtomicSwap.sol b/contracts/AtomicSwap.sol index dba6c85..b01f0a7 100644 --- a/contracts/AtomicSwap.sol +++ b/contracts/AtomicSwap.sol @@ -1,8 +1,12 @@ -pragma solidity ^0.4.15; +pragma solidity ^ 0.4 .15; contract AtomicSwap { - enum State { Empty, Initiator, Participant } + enum State { + Empty, + Initiator, + Participant + } struct Swap { uint initTimestamp; @@ -17,108 +21,98 @@ contract AtomicSwap { } mapping(bytes20 => Swap) public swaps; - - event Refunded(uint _refundTime); + + event Refunded(uint _refundTime); event Redeemed(uint _redeemTime); event Participated( - address _initiator, - address _participator, + address _initiator, + address _participator, bytes20 _hashedSecret, uint256 _value ); - event Initiated( - uint _initTimestamp, - uint _refundTime, - bytes20 _hashedSecret, - address _participant, - address _initiator, - uint256 _funds - ); + event Initiated( + uint _initTimestamp, + uint _refundTime, + bytes20 _hashedSecret, + address _participant, + address _initiator, + uint256 _funds + ); + + function AtomicSwap() {} + + modifier isRefundable(bytes20 _hashedSecret) { + require(block.timestamp > swaps[_hashedSecret].initTimestamp + swaps[_hashedSecret].refundTime); + require(swaps[_hashedSecret].emptied == false); + _; + } + + modifier isRedeemable(bytes20 _hashedSecret, bytes32 _secret) { + require(ripemd160(_secret) == _hashedSecret); + require(block.timestamp < swaps[_hashedSecret].initTimestamp + swaps[_hashedSecret].refundTime); + require(swaps[_hashedSecret].emptied == false); + _; + } - function AtomicSwap() {} - - modifier isRefundable(bytes20 _hashedSecret) { - require(block.timestamp > swaps[_hashedSecret].initTimestamp + swaps[_hashedSecret].refundTime); - require(swaps[_hashedSecret].emptied == false); - _; - } - - modifier isRedeemable(bytes20 _hashedSecret, bytes32 _secret) { - require(ripemd160(_secret) == _hashedSecret); - require(block.timestamp < swaps[_hashedSecret].initTimestamp + swaps[_hashedSecret].refundTime); - require(swaps[_hashedSecret].emptied == false); - _; - } - - modifier isInitiator(bytes20 _hashedSecret) { - require(msg.sender == swaps[_hashedSecret].initiator); - _; - } - - modifier isNotInitiated(bytes20 _hashedSecret) { - require(swaps[_hashedSecret].state == State.Empty); - _; - } + modifier isInitiator(bytes20 _hashedSecret) { + require(msg.sender == swaps[_hashedSecret].initiator); + _; + } + + modifier isNotInitiated(bytes20 _hashedSecret) { + require(swaps[_hashedSecret].state == State.Empty); + _; + } - function initiate (uint _refundTime,bytes20 _hashedSecret,address _participant) - payable - isNotInitiated(_hashedSecret) - { - swaps[_hashedSecret].refundTime = _refundTime; - swaps[_hashedSecret].initTimestamp = block.timestamp; - swaps[_hashedSecret].hashedSecret = _hashedSecret; - swaps[_hashedSecret].participant = _participant; - swaps[_hashedSecret].initiator = msg.sender; + function initiate(uint _refundTime, bytes20 _hashedSecret, address _participant) payable isNotInitiated(_hashedSecret) { + swaps[_hashedSecret].refundTime = _refundTime; + swaps[_hashedSecret].initTimestamp = block.timestamp; + swaps[_hashedSecret].hashedSecret = _hashedSecret; + swaps[_hashedSecret].participant = _participant; + swaps[_hashedSecret].initiator = msg.sender; swaps[_hashedSecret].state = State.Initiator; swaps[_hashedSecret].value = msg.value; - Initiated( - swaps[_hashedSecret].initTimestamp, - _refundTime, - _hashedSecret, - _participant, - msg.sender, - msg.value - ); - } + Initiated( + swaps[_hashedSecret].initTimestamp, + _refundTime, + _hashedSecret, + _participant, + msg.sender, + msg.value + ); + } - function participate(uint _refundTime, bytes20 _hashedSecret,address _initiator) - payable - isNotInitiated(_hashedSecret) - { + function participate(uint _refundTime, bytes20 _hashedSecret, address _initiator) payable isNotInitiated(_hashedSecret) { swaps[_hashedSecret].refundTime = _refundTime; - swaps[_hashedSecret].initTimestamp = block.timestamp; + swaps[_hashedSecret].initTimestamp = block.timestamp; swaps[_hashedSecret].participant = msg.sender; swaps[_hashedSecret].initiator = _initiator; swaps[_hashedSecret].value = msg.value; swaps[_hashedSecret].hashedSecret = _hashedSecret; swaps[_hashedSecret].state = State.Participant; - Participated(_initiator,msg.sender,_hashedSecret,msg.value); + Participated(_initiator, msg.sender, _hashedSecret, msg.value); } - - function redeem(bytes32 _secret, bytes20 _hashedSecret) - isRedeemable(_hashedSecret, _secret) - { - if(swaps[_hashedSecret].state == State.Participant){ + + function redeem(bytes32 _secret, bytes20 _hashedSecret) isRedeemable(_hashedSecret, _secret) { + if (swaps[_hashedSecret].state == State.Participant) { swaps[_hashedSecret].initiator.transfer(swaps[_hashedSecret].value); } - if(swaps[_hashedSecret].state == State.Initiator){ + if (swaps[_hashedSecret].state == State.Initiator) { swaps[_hashedSecret].participant.transfer(swaps[_hashedSecret].value); } swaps[_hashedSecret].emptied = true; Redeemed(block.timestamp); swaps[_hashedSecret].secret = _secret; - } + } - function refund(bytes20 _hashedSecret) - isRefundable(_hashedSecret) - { - if(swaps[_hashedSecret].state == State.Participant){ + function refund(bytes20 _hashedSecret) isRefundable(_hashedSecret) { + if (swaps[_hashedSecret].state == State.Participant) { swaps[_hashedSecret].participant.transfer(swaps[_hashedSecret].value); } - if(swaps[_hashedSecret].state == State.Initiator){ + if (swaps[_hashedSecret].state == State.Initiator) { swaps[_hashedSecret].initiator.transfer(swaps[_hashedSecret].value); } swaps[_hashedSecret].emptied = true; - Refunded(block.timestamp); - } -} \ No newline at end of file + Refunded(block.timestamp); + } +}