I am developing a Dapp in which users can buy and sell stamps. I have two different smart contract with the following struct each (plus setter/getter functions):
//Stamp.sol
struct Stamp {
bytes32 id; //id generated by keccak
bytes32 name; //name of the stamp
uint cost; //cost in wei of buying the stamp
address owner; //owner of the stamp
}
//Envelope.sol
struct Envelope {
bytes32 id; //id generated by keccak
string color; //color of the envelope
uint cost; //cost in wei of buying the envelope
address owner; //owner of the envelope
}
A user can buy a stamp/envelope or sell a stamp/envelope that she owns.
I assume that each user stores her stamps/envelopes on a DB and in my frontend I read the DB and I create a new struct of the corresponding object in the contract. This means that a stamp owner can be different from an envelope owner.
The users can view the available stamps/envelopes but they have to buy a pair (stamp/envelope) of the available items each time.
In order to handle the payment, my idea is to have a different contract that handles the payments, which has a function execPayment
with the following arguments:
1) ID of the bought stamp
2) ID of the bought envelope
3) Address of the Envelope.sol
4) Address of the Stamp.sol
So when I call the execPayment
method, the contract will retrieve the relevant information for each item based on the ID and find the cost and the owner, and then transfer the amount to the right address.
What is the best/efficient way to design the contract for payments?
I also don't know how to transfer the money from the seller since there is one buyer but 2 (possibly different) sellers who get different amount of money.
value
property of solidity for transferring funds to the contract so the user can see in metamask before signing the transaction how much ether she'll pay. Or you mean sth else?