From 11bb6c64343a625d70bd8e23ed416fd0aacdf5cd Mon Sep 17 00:00:00 2001 From: gangov <6922910+gangov@users.noreply.github.com> Date: Wed, 4 Dec 2024 22:24:27 +0200 Subject: [PATCH] updates auction --- contracts/auctions/src/contract.rs | 15 ++++++++------- contracts/auctions/src/storage.rs | 11 +++++++---- contracts/auctions/src/test/setup.rs | 28 ++++++++++++++++++++-------- 3 files changed, 35 insertions(+), 19 deletions(-) diff --git a/contracts/auctions/src/contract.rs b/contracts/auctions/src/contract.rs index 03fbce3..8403372 100644 --- a/contracts/auctions/src/contract.rs +++ b/contracts/auctions/src/contract.rs @@ -4,10 +4,11 @@ use crate::{ collection, error::ContractError, storage::{ - generate_auction_id, get_admin, get_auction_by_id, get_auction_token, get_auctions, - get_auctions_by_seller_id, get_highest_bid, is_initialized, save_admin, save_auction_by_id, - save_auction_by_seller, save_auction_token, set_highest_bid, set_initialized, update_admin, - validate_input_params, Auction, AuctionStatus, HighestBid, ItemInfo, + generate_auction_id, get_admin_old, get_auction_by_id, get_auction_token, get_auctions, + get_auctions_by_seller_id, get_highest_bid, is_initialized, save_admin_old, + save_auction_by_id, save_auction_by_seller, save_auction_token, set_highest_bid, + set_initialized, update_admin, validate_input_params, Auction, AuctionStatus, HighestBid, + ItemInfo, }, token, }; @@ -30,7 +31,7 @@ impl MarketplaceContract { return Err(ContractError::AlreadyInitialized); } - save_admin(&env, &admin); + save_admin_old(&env, &admin); save_auction_token(&env, auction_token); set_initialized(&env); @@ -424,7 +425,7 @@ impl MarketplaceContract { #[allow(dead_code)] pub fn update_admin(env: Env, new_admin: Address) -> Result
{ - let old_admin = get_admin(&env)?; + let old_admin = get_admin_old(&env)?; old_admin.require_auth(); env.events() @@ -437,7 +438,7 @@ impl MarketplaceContract { #[allow(dead_code)] pub fn upgrade(env: Env, new_wasm_hash: BytesN<32>) -> Result<(), ContractError> { - let admin: Address = get_admin(&env)?; + let admin: Address = get_admin_old(&env)?; admin.require_auth(); env.deployer().update_current_contract_wasm(new_wasm_hash); diff --git a/contracts/auctions/src/storage.rs b/contracts/auctions/src/storage.rs index e633510..8aef45b 100644 --- a/contracts/auctions/src/storage.rs +++ b/contracts/auctions/src/storage.rs @@ -1,4 +1,6 @@ -use soroban_sdk::{contracttype, log, panic_with_error, vec, Address, Env, Vec}; +use soroban_sdk::{ + contracttype, log, panic_with_error, symbol_short, vec, Address, Env, Symbol, Vec, +}; use crate::error::ContractError; @@ -11,6 +13,7 @@ pub const LIFETIME_THRESHOLD: u32 = BUMP_AMOUNT - DAY_IN_LEDGERS; // since we start counting from 1, default would be 1 as well pub const DEFAULT_INDEX: u64 = 1; pub const DEFAULT_LIMIT: u64 = 10; +pub const ADMIN: Symbol = symbol_short!("ADMIN"); #[contracttype] #[derive(Clone)] @@ -198,14 +201,14 @@ pub fn set_initialized(env: &Env) { .set(&DataKey::IsInitialized, &true); } -pub fn save_admin(env: &Env, admin: &Address) { +pub fn save_admin_old(env: &Env, admin: &Address) { env.storage().persistent().set(&DataKey::Admin, &admin); env.storage() .persistent() .extend_ttl(&DataKey::Admin, LIFETIME_THRESHOLD, BUMP_AMOUNT); } -pub fn get_admin(env: &Env) -> Result { +pub fn get_admin_old(env: &Env) -> Result { let admin = env .storage() .persistent() @@ -237,7 +240,7 @@ pub fn get_highest_bid(env: &Env, auction_id: u64) -> Result