-
Notifications
You must be signed in to change notification settings - Fork 134
Closed
Labels
Beta-CampaignCampaign: Beta-CampaignCampaign: Beta-Campaigngood first issueGood for newcomersGood for newcomerssoroban-contract
Description
With the scaffold in place, the contract needs a one-time initialize entry point to store the admin address and payment token. We also need the two public query functions (admin, payment_token) so that front-ends and tests can read back the configured values.
Task
Building on the code from Issue #1, add the following public functions to the #[contractimpl] block:
-
pub fn initialize(env: Env, admin: Address, payment_token: Address) -> Result<(), Error>- Return
Error::AlreadyInitializedifDataKey::Adminalready exists in instance storage. - Call
admin.require_auth(). - Write
admintoDataKey::Adminandpayment_tokentoDataKey::PaymentTokenin instance storage. - Emit an event: topic =
(symbol_short!("init"),), data =(admin, payment_token).
- Return
-
pub fn admin(env: Env) -> Result<Address, Error>- Delegate to
Self::get_admin(&env).
- Delegate to
-
pub fn payment_token(env: Env) -> Result<Address, Error>- Delegate to
Self::get_payment_token(&env).
- Delegate to
Files to modify
contracts/workspace_booking/src/lib.rs
Acceptance criteria
-
cargo check -p workspace_bookingpasses. -
cargo clippy -p workspace_booking -- -D warningspasses. - Calling
initializetwice panics withError(Contract, #3)(AlreadyInitialized). -
admin()returns the address passed toinitialize. -
payment_token()returns the token address passed toinitialize. - The
initevent is emitted on successful initialization.
Technical notes
- Guard against double-initialization with
env.storage().instance().has(&DataKey::Admin). symbol_short!macros are limited to 9 characters.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Beta-CampaignCampaign: Beta-CampaignCampaign: Beta-Campaigngood first issueGood for newcomersGood for newcomerssoroban-contract