Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. pragma solidity ^0.5.6;
  2.  
  3. contract Contract {
  4.  
  5. struct transaction{
  6. address buyerAddr;
  7. address sellerAddr;
  8. uint priceOfItem;
  9. }
  10.  
  11. mapping (address => uint) userBalances;
  12.  
  13. mapping (address => transaction) transactions;
  14.  
  15. function settlePayment(address transactionAddr) public {
  16. address buyerAddr = transactions[transactionAddr].buyerAddr;
  17. address sellerAddr = transactions[transactionAddr].sellerAddr;
  18. uint itemPrice = transactions[transactionAddr].priceOfItem;
  19.  
  20. userBalances[buyerAddr] = userBalances[buyerAddr] - itemPrice;
  21. userBalances[sellerAddr] = userBalances[sellerAddr] + itemPrice;
  22. }
  23.  
  24. function buyItem(address buyerAddr, address sellerAddr, uint itemPrice) public {
  25. address transactionAddr = msg.sender;
  26.  
  27. transactions[transactionAddr] =
  28. transaction(
  29. {
  30. buyerAddr : buyerAddr,
  31. sellerAddr : sellerAddr,
  32. priceOfItem : itemPrice
  33. });
  34. }
  35.  
  36. function deposit(uint amount) public {
  37. address user = msg.sender;
  38. userBalances[user] += amount;
  39. }
  40.  
  41. function register() public {
  42. address user = msg.sender;
  43. userBalances[user] = 500;
  44. }
  45.  
  46. function unregister() public {
  47. address user = msg.sender;
  48. delete userBalances[user];
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement