[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.

clientStructs[msg.sender].returned=> sorry I did not get what it returns and what’s the goal of this variable. @Rob Hitchens – alper Apr 14 '17 at 05:50payMeBack(). In the example, the "client" has deposited 10 and taken 9 back. They would be allowed to withdraw 1 more because received - returned = owed, 10-9=1.uint netOwed = clientStructs[msg.sender].received - clientStructs[msg.sender].returned;The screen cap doesn't show the order of events. TheclientStructs()function was called after 10 sent and 9 taken back. – Rob Hitchens Apr 14 '17 at 06:08clientStructs[msg.sender].receivedsince we do payback? as:clientStructs[msg.sender].received - amountToWithdraw@Rob Hitchens – alper May 02 '17 at 10:16clientStructs[msg.sender].returned += amountToWithdraw;a few lines earlier. We leave the received alone as a running total of all funds taken it. We have another overall total of sent back. The difference isnetOwed. I think it's tracking everything. Not the only way to do it. It's a matter of personal taste. Important thing to be careful about is avoiding overflow/underflow. – Rob Hitchens May 02 '17 at 14:55