Guest User

Untitled

a guest
Dec 9th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. pragma solidity >=0.5.0 <0.6.0;
  2.  
  3. interface Token {
  4. function approve(address _spender, uint256 _value) external returns (bool success);
  5. function allowance(address _owner, address _spender) external view returns (uint256 remaining);
  6. function transferFrom(address _from, address _to, uint256 _value) external returns (bool success);
  7. }
  8.  
  9. interface PaymentChannel {}
  10.  
  11. contract PaymentChannelERC20 is PaymentChannel {
  12. constructor(Token _token, address _recipient, uint256 _duration) public {}
  13. }
  14.  
  15. contract PaymentChannelETH is PaymentChannel {
  16. constructor(address payable _recipient, uint256 _duration) public payable {}
  17. }
  18.  
  19. contract ChannelFactory {
  20. function newChannel(address payable _recipient, uint256 _duration) external payable returns(PaymentChannel _channel){
  21. _channel = (new PaymentChannelETH).value(msg.value)(_recipient, _duration);
  22. }
  23. function newChannel(Token _token, address _recipient, uint256 _duration) external returns(PaymentChannel _channel) {
  24. _channel = new PaymentChannelERC20(_token, _recipient, _duration);
  25. _token.transferFrom(msg.sender, address(_channel), _token.allowance(msg.sender, address(this)));
  26. }
  27. }
  28.  
  29. contract Account {
  30. function openChannel(ChannelFactory _factory, Token _token, address payable _recipient, uint256 _duration, uint256 _amount) external {
  31. _token.approve(address(_factory), _amount);
  32. _factory.newChannel(_token, _recipient, _duration);
  33. }
  34. function openChannel(ChannelFactory _factory, address payable _recipient, uint256 _duration, uint256 _amount) external {
  35. _factory.newChannel.value(_amount)(_recipient, _duration);
  36. }
  37. }
Add Comment
Please, Sign In to add comment