Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. The seller approves the contract address to act on their behalf.
  2. The token is listed as available for sale in the marketplace.
  3. Then, when the buyer wants to buy the token, the contract transfers the token from the seller to the buyer, and transfers the payment from buyer to seller.
  4.  
  5. struct Token {
  6. uint id;
  7. uint price;
  8. uint prevPrice;
  9. bool forSale;
  10. }
  11.  
  12.  
  13. function buyMarketplaceToken(uint _tokenId) public payable whenNotPaused() isForSale(_tokenId) {
  14. address ticketOwner = ownerOf(_tokenId);
  15. require(msg.value >= tokens[_tokenId].price, "It costs more!");
  16. ticketOwner.transfer(msg.value);
  17. safeTransferFrom(ticketOwner, msg.sender, _ticketId);
  18. clearApproval(this, _ticketId);
  19. tokens[_tokenId].forSale = false;
  20. }
  21.  
  22. function addTokenForSale(uint _tokenId, uint newPrice) public onlyOwner(_tokenId) whenNotPaused() {
  23. tokens[_tokenId].forSale = true;
  24. tokens[_tokenId].prevPrice = tokens[_tokenId].price;
  25. tokens[_tokenId].price = newPrice;
  26. approve(address(this), _tokenId);
  27. emit TokenOnSale(_tokenId, newPrice);
  28. }
  29.  
  30. function removeTokenForSale(uint _tokenId) public onlyOwner(_tokenId) whenNotPaused() {
  31. tokens[_tokenId].forSale = false;
  32. tokens[_tokenId].price = tokens[_tokenId].prevPrice;
  33. clearApproval(address(this), _tokenId);
  34. emit TokenOffSale(_tokenId, tokens[_tokenId].prevPrice);
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement