Skip to content

Instantly share code, notes, and snippets.

@heikoheiko heikoheiko/raiden_iou.sol Secret
Created Jan 17, 2019

Embed
What would you like to do?
/*
Minimal IOU based off-chain payment system.
Assumption is, that there is a contract which manages user deposits.
deposit_contract trusts RaidenIOU contract and allows it to claim funds.
users can withdraw their (remaining) deposit form deposit_contract after a timeout.
*/
contract RaidenIOU {
address deposit_contract;
mapping bytes32 => uint public settled_sessions;
RaidenIOU(
address _deposit_contract)
public)
{
deposit_contract = _deposit_contract;
}
function available_funds(address _address) returns uint {
// call deposit contract and return deposit of _address
}
function active_deposit(address _address) returns uint {
// call deposit contract and returns True if the user didn't initiate
// withdrawl of deposit
}
/// in order to claim, recveiver needs to provide a signed message by sender
/// which contains amount, receiver, sender, expiration, sig
function claim(bytes signed_IOU) returns uint {
amount, receiver, sender, expiration = _decode(signed_IOU);
_key = concatenate(receiver, sender, expiration);
// must not be claimed before
require(_key not in settled_sessions);
// claim as much as possible
transferable = min(amount, available_funds(sender));
// register to avoid double claiming
settled_sessions[_key] = expiration;
// event SessionSettled(_key, expiration);
deposit_contract.please_transfer(transferable, sender, receiver);
return transferable;
}
/// func to cleanup storage once IOU expired
/// free gas for cleaner, alternatively allow only receiver to claim the free slot.
function cleanup(_key) {
require(settled_sessions[_key] <= block.timestamp);
settled_sessions[_key] = expiration;
}
function claim_multiple() {} // optional optimization
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.