Scenario:
I have users who will initiate booking for one product with x
price. This contract will create a wallet contract between that user and the product so that he can return/cancel the booking at any time and get the refund or succeed.
Code:
User talks via contract EthBooking
contract EthBooking {
function addBooking(uint listingId) public payable returns(uint bookingId) {
bookingId = BookingLibrary.book(ethDB, listingId, msg.sender, msg.value);
//Send money to the contract
return bookingId;
}
}
Booking Library code:
library BookingLibrary {
function book(address db, uint listingId, address sender, uint value)
internal returns (uint bookingId)
{
var cost = ListingLibrary.getCost(db,listingId);
//Create Contract wallet
EthWallet wallet = new EthWallet();
//Send money to the contract
wallet.receiveFunds.value(cost);
return bookingId;
}
EthWallet Code:
contract EthWallet is Mortal {
function ethWallet() {
}
function receiveFunds() payable {
}
function sendFunds(address receiver, uint amount) {
receiver.transfer(amount);
}
}
PROBLEM
The ethers sent is held in contract EthBooking
and is not transferred to EthWallet
as expected with code wallet.receiveFunds.value(cost);
.
Please guide me about if the chosen approach is right and also why the ethers are not transferred to the destination. PS: The code is shortened with removal of irrelevant parts to avoid confusion