Challenge: Build a Solana Account Struct
Apply what you've learned about Rust ownership, structs, and methods. You'll create a SolanaAccount struct that models an on-chain account with balance management.
Your Task
Complete the SolanaAccount struct and its methods, then implement create_and_withdraw which:
- Creates a new
SolanaAccountusingSolanaAccount::new(owner, initial_balance) - Attempts to withdraw
withdraw_amount - Returns a
Stringdescribing the result
Requirements:
new()creates an account that is not frozen by defaultwithdraw()returnsErr("Account is frozen")if the account is frozenwithdraw()returnsErr("Insufficient balance")ifamount > balancewithdraw()subtracts the amount and returnsOk(remaining_balance)create_and_withdrawformats the result as"OK:<remaining>"or"ERR:<message>"
Rust Concepts Used:
- Structs with
implblocks Result<T, E>return type- Pattern matching with
match - String formatting with
format!()