UserStats.sol 941 B

123456789101112131415161718192021222324252627282930313233
  1. // SPDX-License-Identifier: Apache-2.0
  2. @program_id("GLXybr8w3egyd8HpnHJEy6vQUoXyD3uGzjoUcAnmjQwx")
  3. contract UserStats {
  4. string private name;
  5. uint16 private level;
  6. uint8 private bump;
  7. // The constructor initializes the PDA hash table for a user.
  8. @payer(wallet)
  9. @seed("user-stats")
  10. @space(250)
  11. constructor(@seed address user_key, @bump uint8 _bump, string _name, uint16 _level) {
  12. name = _name;
  13. level = _level;
  14. bump = _bump;
  15. }
  16. // Change the name saved in the data account
  17. function change_user_name(string new_name) external {
  18. name = new_name;
  19. }
  20. // Change the level saved in the data account
  21. function change_level(uint16 new_level) external {
  22. level = new_level;
  23. }
  24. // Read the information from the data account
  25. function return_stats() external view returns (string memory, uint16, uint8) {
  26. return (name, level, bump);
  27. }
  28. }