Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pragma solidity >=0.5.0 <0.6.0;
- interface Token {
- function approve(address _spender, uint256 _value) external returns (bool success);
- function allowance(address _owner, address _spender) external view returns (uint256 remaining);
- function transferFrom(address _from, address _to, uint256 _value) external returns (bool success);
- }
- interface PaymentChannel {}
- contract PaymentChannelERC20 is PaymentChannel {
- constructor(Token _token, address _recipient, uint256 _duration) public {}
- }
- contract PaymentChannelETH is PaymentChannel {
- constructor(address payable _recipient, uint256 _duration) public payable {}
- }
- contract ChannelFactory {
- function newChannel(address payable _recipient, uint256 _duration) external payable returns(PaymentChannel _channel){
- _channel = (new PaymentChannelETH).value(msg.value)(_recipient, _duration);
- }
- function newChannel(Token _token, address _recipient, uint256 _duration) external returns(PaymentChannel _channel) {
- _channel = new PaymentChannelERC20(_token, _recipient, _duration);
- _token.transferFrom(msg.sender, address(_channel), _token.allowance(msg.sender, address(this)));
- }
- }
- contract Account {
- function openChannel(ChannelFactory _factory, Token _token, address payable _recipient, uint256 _duration, uint256 _amount) external {
- _token.approve(address(_factory), _amount);
- _factory.newChannel(_token, _recipient, _duration);
- }
- function openChannel(ChannelFactory _factory, address payable _recipient, uint256 _duration, uint256 _amount) external {
- _factory.newChannel.value(_amount)(_recipient, _duration);
- }
- }
Add Comment
Please, Sign In to add comment