Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pragma solidity ^0.5.6;
- contract Contract {
- struct transaction{
- address buyerAddr;
- address sellerAddr;
- uint priceOfItem;
- }
- mapping (address => uint) userBalances;
- mapping (address => transaction) transactions;
- function settlePayment(address transactionAddr) public {
- address buyerAddr = transactions[transactionAddr].buyerAddr;
- address sellerAddr = transactions[transactionAddr].sellerAddr;
- uint itemPrice = transactions[transactionAddr].priceOfItem;
- userBalances[buyerAddr] = userBalances[buyerAddr] - itemPrice;
- userBalances[sellerAddr] = userBalances[sellerAddr] + itemPrice;
- }
- function buyItem(address buyerAddr, address sellerAddr, uint itemPrice) public {
- address transactionAddr = msg.sender;
- transactions[transactionAddr] =
- transaction(
- {
- buyerAddr : buyerAddr,
- sellerAddr : sellerAddr,
- priceOfItem : itemPrice
- });
- }
- function deposit(uint amount) public {
- address user = msg.sender;
- userBalances[user] += amount;
- }
- function register() public {
- address user = msg.sender;
- userBalances[user] = 500;
- }
- function unregister() public {
- address user = msg.sender;
- delete userBalances[user];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement