Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pragma solidity ^0.5.4;
- contract Contract {
- struct item {
- string item_description;
- string item_status;
- uint item_price;
- string item_owner;
- address item_owner_address;
- }
- struct user {
- string username;
- string password;
- uint balance;
- string first_name;
- string last_name;
- }
- mapping (address => user) users;
- address[] public userTable;
- mapping (address => item) items;
- address[] public itemTable;
- //---------------------------------------------------
- //-----------------------Items-----------------------
- //---------------------------------------------------
- function getAllItems() public view returns(address[] memory) {
- return itemTable;
- }
- function getItemByAddress(address addr) public view returns (string memory ownerId, string memory descr, string memory status, uint price) {
- return(items[addr].item_owner, items[addr].item_description, items[addr].item_status, items[addr].item_price);
- }
- function sellItem(address addr, string memory ownerId, string memory descr, string memory status, uint price) public {
- item storage table = items[addr];
- table.item_owner = ownerId;
- table.item_description = descr;
- table.item_status = status;
- table.item_price = price;
- itemTable.push(addr) -1;
- }
- function buyItem(address itemAddr, address myAddr, address sellerAddr) public {
- users[myAddr].balance -= items[itemAddr].item_price;
- users[sellerAddr].balance += items[itemAddr].item_price;
- delete items[itemAddr];
- }
- //--------------------------------------------------
- //-----------------------User-----------------------
- //--------------------------------------------------
- function getAllUsers() public view returns(address[] memory) {
- return userTable;
- }
- function getBalance(address addr) public view returns (uint balance) {
- return users[addr].balance;
- }
- function getUserByAddress(address addr) public view returns (string memory username, string memory password, uint balance, string memory first_name, string memory last_name) {
- return(users[addr].username, users[addr].password, users[addr].balance, users[addr].first_name, users[addr].last_name);
- }
- function deposit(address addr, uint amount) public {
- users[addr].balance += amount;
- }
- function register(address addr, string memory username, string memory password, string memory first_name, string memory last_name) public {
- user storage table = users[addr];
- table.username = username;
- table.password = password;
- table.balance = 500;
- table.first_name = first_name;
- table.last_name = last_name;
- userTable.push(addr) -1;
- }
- function unregister(address addr) public {
- delete users[addr];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement