Skip to content

Commit

Permalink
Merge pull request #53 from garikbesson/main
Browse files Browse the repository at this point in the history
Update dependencies versions + style fixes
  • Loading branch information
gagdiez authored Feb 15, 2024
2 parents 16270e3 + fca226d commit 65ef6bc
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 85 deletions.
20 changes: 10 additions & 10 deletions integration-tests/rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ publish = false
edition = "2018"

[dev-dependencies]
near-sdk = "4.0.0"
anyhow = "1.0"
borsh = "0.9"
maplit = "1.0"
near-sdk = "4.1.1"
anyhow = "1.0.79"
borsh = "1.3.1"
maplit = "1.0.2"
near-units = "0.2.0"
# arbitrary_precision enabled for u128 types that workspaces requires for Balance types
serde_json = { version = "1.0", features = ["arbitrary_precision"] }
tokio = { version = "1.18.1", features = ["full"] }
tracing = "0.1"
tracing-subscriber = { version = "0.3.11", features = ["env-filter"] }
workspaces = "0.3.1"
pkg-config = "0.3.1"
serde_json = { version = "1.0.113", features = ["arbitrary_precision"] }
tokio = { version = "1.36.0", features = ["full"] }
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
workspaces = "0.7.0"
pkg-config = "0.3.29"

[[example]]
name = "integration-tests"
Expand Down
5 changes: 4 additions & 1 deletion market-contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ edition = "2021"
crate-type = ["cdylib", "rlib"]

[dependencies]
near-sdk = "4.0.0"
near-sdk = "4.1.1"

[patch.crates-io]
parity-secp256k1 = { git = 'https://github.com/paritytech/rust-secp256k1.git' }

[profile.release]
codegen-units=1
Expand Down
7 changes: 5 additions & 2 deletions nft-contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ edition = "2021"
crate-type = ["cdylib", "rlib"]

[dependencies]
near-sdk = "4.0.0"
serde_json = "1.0"
near-sdk = "4.1.1"
serde_json = "1.0.113"

[patch.crates-io]
parity-secp256k1 = { git = 'https://github.com/paritytech/rust-secp256k1.git' }

[profile.release]
codegen-units=1
Expand Down
23 changes: 11 additions & 12 deletions nft-contract/src/approval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub trait NonFungibleTokenCore {
fn nft_approve(&mut self, token_id: TokenId, account_id: AccountId, msg: Option<String>);

//check if the passed in account has access to approve the token ID
fn nft_is_approved(
fn nft_is_approved(
&self,
token_id: TokenId,
approved_account_id: AccountId,
Expand Down Expand Up @@ -34,7 +34,6 @@ trait NonFungibleTokenApprovalsReceiver {

#[near_bindgen]
impl NonFungibleTokenCore for Contract {

//allow a specific account ID to approve a token on your behalf
#[payable]
fn nft_approve(&mut self, token_id: TokenId, account_id: AccountId, msg: Option<String>) {
Expand Down Expand Up @@ -96,7 +95,7 @@ impl NonFungibleTokenCore for Contract {
}

//check if the passed in account has access to approve the token ID
fn nft_is_approved(
fn nft_is_approved(
&self,
token_id: TokenId,
approved_account_id: AccountId,
Expand All @@ -106,22 +105,22 @@ impl NonFungibleTokenCore for Contract {
let token = self.tokens_by_id.get(&token_id).expect("No token");

//get the approval number for the passed in account ID
let approval = token.approved_account_ids.get(&approved_account_id);
let approval = token.approved_account_ids.get(&approved_account_id);

//if there was some approval ID found for the account ID
if let Some(approval) = approval {
//if a specific approval_id was passed into the function
if let Some(approval_id) = approval_id {
if let Some(approval_id) = approval_id {
//return if the approval ID passed in matches the actual approval ID for the account
approval_id == *approval
approval_id == *approval
//if there was no approval_id passed into the function, we simply return true
} else {
true
}
} else {
true
}
//if there was no approval ID found for the account ID, we simply return false
} else {
false
}
} else {
false
}
}

//revoke a specific account from transferring the token on your behalf
Expand Down
43 changes: 20 additions & 23 deletions nft-contract/src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ pub(crate) fn bytes_for_approved_account_id(account_id: &AccountId) -> u64 {
pub(crate) fn refund_approved_account_ids_iter<'a, I>(
account_id: AccountId,
approved_account_ids: I, //the approved account IDs must be passed in as an iterator
) -> Promise
where
I: Iterator<Item = &'a AccountId>,
{
) -> Promise where I: Iterator<Item = &'a AccountId> {
//get the storage total by going through and summing all the bytes for each approved account IDs
let storage_released: u64 = approved_account_ids.map(bytes_for_approved_account_id).sum();
//transfer the account the storage that is released
Expand Down Expand Up @@ -151,29 +148,29 @@ impl Contract {
let token = self.tokens_by_id.get(token_id).expect("No token");

//if the sender doesn't equal the owner, we check if the sender is in the approval list
if sender_id != &token.owner_id {
//if the token's approved account IDs doesn't contain the sender, we panic
if !token.approved_account_ids.contains_key(sender_id) {
env::panic_str("Unauthorized");
}

// If they included an approval_id, check if the sender's actual approval_id is the same as the one included
if let Some(enforced_approval_id) = approval_id {
if sender_id != &token.owner_id {
//if the token's approved account IDs doesn't contain the sender, we panic
if !token.approved_account_ids.contains_key(sender_id) {
env::panic_str("Unauthorized");
}

// If they included an approval_id, check if the sender's actual approval_id is the same as the one included
if let Some(enforced_approval_id) = approval_id {
//get the actual approval ID
let actual_approval_id = token
.approved_account_ids
.get(sender_id)
//if the sender isn't in the map, we panic
.expect("Sender is not approved account");
let actual_approval_id = token
.approved_account_ids
.get(sender_id)
//if the sender isn't in the map, we panic
.expect("Sender is not approved account");

//make sure that the actual approval ID is the same as the one provided
assert_eq!(
actual_approval_id, &enforced_approval_id,
"The actual approval_id {} is different from the given approval_id {}",
actual_approval_id, enforced_approval_id,
);
}
}
actual_approval_id, &enforced_approval_id,
"The actual approval_id {} is different from the given approval_id {}",
actual_approval_id, enforced_approval_id,
);
}
}

//we make sure that the sender isn't sending the token to themselves
assert_ne!(
Expand Down
5 changes: 2 additions & 3 deletions nft-contract/src/nft_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ pub trait NonFungibleTokenCore {
memo: Option<String>,
);

/// Transfers an NFT to a receiver and calls the
/// function `nft_on_transfer` on their contract.
// Transfers an NFT to a receiver and calls the
// function `nft_on_transfer` on their contract.
fn nft_transfer_call(
&mut self,
receiver_id: AccountId,
Expand Down Expand Up @@ -67,7 +67,6 @@ trait NonFungibleTokenResolver {

#[near_bindgen]
impl NonFungibleTokenCore for Contract {

//implementation of the nft_transfer method. This transfers the NFT from the current owner to the receiver.
#[payable]
fn nft_transfer(
Expand Down
63 changes: 31 additions & 32 deletions nft-contract/src/royalty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,46 +18,45 @@ pub trait NonFungibleTokenCore {

#[near_bindgen]
impl NonFungibleTokenCore for Contract {

//calculates the payout for a token given the passed in balance. This is a view method
fn nft_payout(&self, token_id: TokenId, balance: U128, max_len_payout: u32) -> Payout {
//get the token object
let token = self.tokens_by_id.get(&token_id).expect("No token");
let token = self.tokens_by_id.get(&token_id).expect("No token");

//get the owner of the token
let owner_id = token.owner_id;
//keep track of the total perpetual royalties
let mut total_perpetual = 0;
//get the u128 version of the passed in balance (which was U128 before)
let balance_u128 = u128::from(balance);
//keep track of the payout object to send back
//keep track of the payout object to send back
let mut payout_object = Payout {
payout: HashMap::new()
};
//get the royalty object from token
let royalty = token.royalty;
let royalty = token.royalty;

//make sure we're not paying out to too many people (GAS limits this)
assert!(royalty.len() as u32 <= max_len_payout, "Market cannot payout to that many receivers");
assert!(royalty.len() as u32 <= max_len_payout, "Market cannot payout to that many receivers");

//go through each key and value in the royalty object
for (k, v) in royalty.iter() {
//go through each key and value in the royalty object
for (k, v) in royalty.iter() {
//get the key
let key = k.clone();
let key = k.clone();

//only insert into the payout if the key isn't the token owner (we add their payout at the end)
if key != owner_id {
//
payout_object.payout.insert(key, royalty_to_payout(*v, balance_u128));
total_perpetual += *v;
}
}
if key != owner_id {
payout_object.payout.insert(key, royalty_to_payout(*v, balance_u128));
total_perpetual += *v;
}
}

// payout to previous owner who gets 100% - total perpetual royalties
payout_object.payout.insert(owner_id, royalty_to_payout(10000 - total_perpetual, balance_u128));
// payout to previous owner who gets 100% - total perpetual royalties
payout_object.payout.insert(owner_id, royalty_to_payout(10000 - total_perpetual, balance_u128));

//return the payout object
payout_object
}
payout_object
}

//transfers the token to the receiver ID and returns the payout object that should be payed given the passed in balance.
#[payable]
Expand Down Expand Up @@ -95,32 +94,32 @@ impl NonFungibleTokenCore for Contract {
let mut total_perpetual = 0;
//get the u128 version of the passed in balance (which was U128 before)
let balance_u128 = u128::from(balance);
//keep track of the payout object to send back
//keep track of the payout object to send back
let mut payout_object = Payout {
payout: HashMap::new()
};
//get the royalty object from token
let royalty = previous_token.royalty;
let royalty = previous_token.royalty;

//make sure we're not paying out to too many people (GAS limits this)
assert!(royalty.len() as u32 <= max_len_payout, "Market cannot payout to that many receivers");
assert!(royalty.len() as u32 <= max_len_payout, "Market cannot payout to that many receivers");

//go through each key and value in the royalty object
for (k, v) in royalty.iter() {
for (k, v) in royalty.iter() {
//get the key
let key = k.clone();
let key = k.clone();

//only insert into the payout if the key isn't the token owner (we add their payout at the end)
if key != owner_id {
//
payout_object.payout.insert(key, royalty_to_payout(*v, balance_u128));
total_perpetual += *v;
}
}
if key != owner_id {
payout_object.payout.insert(key, royalty_to_payout(*v, balance_u128));
total_perpetual += *v;
}
}

// payout to previous owner who gets 100% - total perpetual royalties
payout_object.payout.insert(owner_id, royalty_to_payout(10000 - total_perpetual, balance_u128));
// payout to previous owner who gets 100% - total perpetual royalties
payout_object.payout.insert(owner_id, royalty_to_payout(10000 - total_perpetual, balance_u128));

//return the payout object
payout_object
payout_object
}
}
7 changes: 5 additions & 2 deletions nft-series/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ edition = "2021"
crate-type = ["cdylib", "rlib"]

[dependencies]
near-sdk = "4.0.0"
serde_json = "1.0"
near-sdk = "4.1.1"
serde_json = "1.0.113"

[patch.crates-io]
parity-secp256k1 = { git = 'https://github.com/paritytech/rust-secp256k1.git' }

[profile.release]
codegen-units=1
Expand Down
Binary file modified out/main.wasm
Binary file not shown.
Binary file modified out/market.wasm
Binary file not shown.
Binary file modified out/series.wasm
Binary file not shown.

0 comments on commit 65ef6bc

Please sign in to comment.