[Q] When following transaction get called: Bank.pay({"from": eth.accounts[0], "value": 1});
, who retrieves the money, does the owner of the contract? (Sorry I get lost who actually gains the money). And later on how could that money transfer back to the sender on another function call(this could be viewed as a refund process)?
I would like to carry out following scenario, if possible.
- Client A sents some money (lets say 1 wei) to the contract's function, via Client_A calls following:
Bank.pay({"from": eth.accounts[0], "value": 1})
. - That money should be locked to be used by the gainer until
payMeBack()
is called. Basically owner of the money is not allowed to spend msg.value => 1 wei. - When Client_A calls following:
Bank.payMeBack()
: Contract's function will send back the money(imagine is refund process) to Client A, if condition passed. If condition fails, now lock on money should be removed and money is gained by the contract and owner of the money could spent it.
Example contract:
pragma solidity ^0.4.8;
contract Bank{
address client;
uint gainedWei;
function pay() payable {
client = msg.sender;
gainedWei = msg.value;
}
function payMeBack() {
if(<some condition check>)
//Some how it has to send back ether to client-A. We know the address we would like to send and the amount.
}
}
Thank you for your valuable time and help.