Skip to content

Commit

Permalink
lints and refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
gangov committed Sep 4, 2024
1 parent b65f282 commit 889b58c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
39 changes: 31 additions & 8 deletions contracts/collections/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,29 @@ impl Collections {
Ok(result)
}

// Returns true if `operator` is approved to manage `owner`'s tokens
#[allow(dead_code)]
pub fn is_approved_for_transfer(
env: Env,
owner: Address,
market_place: Address,
) -> Result<bool, ContractError> {
let data_key = DataKey::TransferApproval(TransferApprovalKey {
owner,
market_place,
});

let result = env.storage().persistent().get(&data_key).unwrap_or(false);

env.storage().persistent().has(&data_key).then(|| {
env.storage()
.persistent()
.extend_ttl(&data_key, LIFETIME_THRESHOLD, BUMP_AMOUNT)
});

Ok(result)
}

// Transfers `amount` tokens of token type `id` from `from` to `to`
#[allow(dead_code)]
pub fn safe_transfer_from(
Expand All @@ -195,14 +218,14 @@ impl Collections {
) -> Result<(), ContractError> {
let admin = get_admin(&env)?;

//if sender == admin
// || operator.as_ref().map_or(false, |op| sender == op.clone())
// || approved_for_transfer
// .as_ref()
// .map_or(false, |approved| sender == approved.clone())
//{
// sender.require_auth();
//}
let is_sender_operator =
Self::is_approved_for_all(env.clone(), admin.clone(), sender.clone())?;
let is_sender_market_place =
Self::is_approved_for_transfer(env.clone(), admin.clone(), sender.clone())?;

if sender == admin || is_sender_operator || is_sender_market_place {
sender.require_auth();
}

let sender_balance = get_balance_of(&env, &from, id)?;
let rcpt_balance = get_balance_of(&env, &to, id)?;
Expand Down
5 changes: 1 addition & 4 deletions contracts/collections/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,7 @@ pub mod utils {

use soroban_sdk::{log, Address, Env, Map};

use crate::{
error::ContractError,
ttl::{BALANCE_BUMP_AMOUNT, BUMP_AMOUNT, LIFETIME_THRESHOLD},
};
use crate::error::ContractError;

use super::{Balance, Config, DataKey, TokenId, ADMIN};

Expand Down

0 comments on commit 889b58c

Please sign in to comment.