Skip to content

Instantly share code, notes, and snippets.

@libertylocked
Last active October 17, 2017 07:16
Show Gist options
  • Save libertylocked/6391e741bf6cbd29cf527890fdddbcc3 to your computer and use it in GitHub Desktop.
Save libertylocked/6391e741bf6cbd29cf527890fdddbcc3 to your computer and use it in GitHub Desktop.
pragma solidity 0.4.15;
contract RemittanceManager {
struct Remittance {
address funder;
address collector;
uint amount;
bytes32 combinedPassword;
}
address owner;
mapping(uint => Remittance) public remittances; // key is the remittance ID
uint public count = 0;
function RemittanceManager() {
owner = msg.sender;
}
// creates a remittance
// combinedPassword is sha3(sha3(clearPassword), collector)
// returns the ID of the remittance
function create(address collector, bytes32 combinedPassword) payable returns (uint id) {
require(msg.value > 0);
id = count;
remittances[id] = Remittance(msg.sender, collector, msg.value, combinedPassword);
count++;
}
// collects a remittance
// hashedPassword is sha3(clearPassword)
function collect(uint id, bytes32 hashedPassword) {
Remittance storage remit = remittances[id];
require(remit.amount > 0); // the remittance with the ID must exist
require(remit.collector == msg.sender);
require(remit.combinedPassword == sha3(hashedPassword, msg.sender));
uint amountToSend = remit.amount;
remit.amount = 0;
msg.sender.transfer(amountToSend);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment