diff --git a/integration-tests/rs/Cargo.toml b/integration-tests/rs/Cargo.toml index 71f5426..c588ca5 100644 --- a/integration-tests/rs/Cargo.toml +++ b/integration-tests/rs/Cargo.toml @@ -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" diff --git a/market-contract/Cargo.toml b/market-contract/Cargo.toml index 953eba2..27d85ca 100644 --- a/market-contract/Cargo.toml +++ b/market-contract/Cargo.toml @@ -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 diff --git a/nft-contract/Cargo.toml b/nft-contract/Cargo.toml index 9484b1f..17c1958 100644 --- a/nft-contract/Cargo.toml +++ b/nft-contract/Cargo.toml @@ -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 diff --git a/nft-contract/src/approval.rs b/nft-contract/src/approval.rs index a58d8a1..51faa94 100644 --- a/nft-contract/src/approval.rs +++ b/nft-contract/src/approval.rs @@ -6,7 +6,7 @@ pub trait NonFungibleTokenCore { fn nft_approve(&mut self, token_id: TokenId, account_id: AccountId, msg: Option); //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, @@ -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) { @@ -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, @@ -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 diff --git a/nft-contract/src/internal.rs b/nft-contract/src/internal.rs index 465fa5d..8a02f6b 100644 --- a/nft-contract/src/internal.rs +++ b/nft-contract/src/internal.rs @@ -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, -{ +) -> Promise where I: Iterator { //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 @@ -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!( diff --git a/nft-contract/src/nft_core.rs b/nft-contract/src/nft_core.rs index 9927d39..e628e54 100644 --- a/nft-contract/src/nft_core.rs +++ b/nft-contract/src/nft_core.rs @@ -15,8 +15,8 @@ pub trait NonFungibleTokenCore { memo: Option, ); -/// 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, @@ -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( diff --git a/nft-contract/src/royalty.rs b/nft-contract/src/royalty.rs index 08e5ad2..bde91f6 100644 --- a/nft-contract/src/royalty.rs +++ b/nft-contract/src/royalty.rs @@ -18,11 +18,10 @@ 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; @@ -30,34 +29,34 @@ 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 = 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] @@ -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 } } \ No newline at end of file diff --git a/nft-series/Cargo.toml b/nft-series/Cargo.toml index 9484b1f..17c1958 100644 --- a/nft-series/Cargo.toml +++ b/nft-series/Cargo.toml @@ -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 diff --git a/out/main.wasm b/out/main.wasm index 12dde4b..459543d 100755 Binary files a/out/main.wasm and b/out/main.wasm differ diff --git a/out/market.wasm b/out/market.wasm index 889ef0b..4fe8538 100755 Binary files a/out/market.wasm and b/out/market.wasm differ diff --git a/out/series.wasm b/out/series.wasm index 707a3ff..9b31f36 100755 Binary files a/out/series.wasm and b/out/series.wasm differ