Skip to content

Commit 5155899

Browse files
committed
rename nft_mint arguments
1 parent ee33444 commit 5155899

9 files changed

Lines changed: 108 additions & 95 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ near view $NFT_CONTRACT_ID nft_metadata
9393
### Minting Token
9494

9595
```bash=
96-
near call $NFT_CONTRACT_ID nft_mint '{"token_id": "token-1", "metadata": {"title": "My Non Fungible Team Token", "description": "The Team Most Certainly Goes :)", "media": "https://bafybeiftczwrtyr3k7a2k4vutd3amkwsmaqyhrdzlhvpt33dyjivufqusq.ipfs.dweb.link/goteam-gif.gif"}, "receiver_id": "'$MAIN_ACCOUNT'"}' --accountId $MAIN_ACCOUNT --amount 0.1
96+
near call $NFT_CONTRACT_ID nft_mint '{"token_id": "token-1", "token_metadata": {"title": "My Non Fungible Team Token", "description": "The Team Most Certainly Goes :)", "media": "https://bafybeiftczwrtyr3k7a2k4vutd3amkwsmaqyhrdzlhvpt33dyjivufqusq.ipfs.dweb.link/goteam-gif.gif"}, "token_owner_id": "'$MAIN_ACCOUNT'"}' --accountId $MAIN_ACCOUNT --amount 0.1
9797
```
9898

9999
After you've minted the token go to wallet.testnet.near.org to `your-account.testnet` and look in the collections tab and check out your new sample NFT!

integration-tests/src/helpers.rs

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
use near_workspaces::{
2+
types::{AccountDetails, NearToken},
3+
Account, Contract,
4+
};
15
use serde_json::json;
2-
use near_workspaces::{types::{NearToken, AccountDetails}, Account, Contract};
36

47
pub const DEFAULT_DEPOSIT: u128 = 10000000000000000000000;
58
pub const ONE_YOCTO_NEAR: NearToken = NearToken::from_yoctonear(1);
@@ -8,23 +11,24 @@ pub async fn mint_nft(
811
user: &Account,
912
nft_contract: &Contract,
1013
token_id: &str,
11-
) -> Result<(), Box<dyn std::error::Error>> {
14+
) -> Result<(), Box<dyn std::error::Error>> {
1215
let request_payload = json!({
1316
"token_id": token_id,
14-
"receiver_id": user.id(),
15-
"metadata": {
17+
"token_owner_id": user.id(),
18+
"token_metadata": {
1619
"title": "Grumpy Cat",
1720
"description": "Not amused.",
1821
"media": "https://www.adamsdrafting.com/wp-content/uploads/2018/06/More-Grumpy-Cat.jpg"
1922
},
2023
});
2124

22-
let _ = user.call(nft_contract.id(), "nft_mint")
25+
let _ = user
26+
.call(nft_contract.id(), "nft_mint")
2327
.args_json(request_payload)
2428
.deposit(NearToken::from_yoctonear(DEFAULT_DEPOSIT))
2529
.transact()
2630
.await;
27-
31+
2832
Ok(())
2933
}
3034

@@ -34,13 +38,14 @@ pub async fn approve_nft(
3438
nft_contract: &Contract,
3539
token_id: &str,
3640
) -> Result<(), Box<dyn std::error::Error>> {
37-
let request_payload = json!({
41+
let request_payload = json!({
3842
"token_id": token_id,
3943
"account_id": market_contract.id(),
4044
"msg": serde_json::Value::Null,
4145
});
4246

43-
let _ = user.call(nft_contract.id(), "nft_approve")
47+
let _ = user
48+
.call(nft_contract.id(), "nft_approve")
4449
.args_json(request_payload)
4550
.deposit(NearToken::from_yoctonear(DEFAULT_DEPOSIT))
4651
.transact()
@@ -55,8 +60,9 @@ pub async fn pay_for_storage(
5560
amount: NearToken,
5661
) -> Result<(), Box<dyn std::error::Error>> {
5762
let request_payload = json!({});
58-
59-
let _ = user.call(market_contract.id(), "storage_deposit")
63+
64+
let _ = user
65+
.call(market_contract.id(), "storage_deposit")
6066
.args_json(request_payload)
6167
.deposit(amount)
6268
.transact()
@@ -79,7 +85,8 @@ pub async fn place_nft_for_sale(
7985
"approval_id": approval_id,
8086
"sale_conditions": NearToken::as_yoctonear(price).to_string(),
8187
});
82-
let _ = user.call(market_contract.id(), "list_nft_for_sale")
88+
let _ = user
89+
.call(market_contract.id(), "list_nft_for_sale")
8390
.args_json(request_payload)
8491
.max_gas()
8592
.deposit(NearToken::from_yoctonear(DEFAULT_DEPOSIT))
@@ -89,10 +96,11 @@ pub async fn place_nft_for_sale(
8996
Ok(())
9097
}
9198

92-
pub async fn get_user_balance(
93-
user: &Account,
94-
) -> NearToken {
95-
let details: AccountDetails = user.view_account().await.expect("Account has to have some balance");
99+
pub async fn get_user_balance(user: &Account) -> NearToken {
100+
let details: AccountDetails = user
101+
.view_account()
102+
.await
103+
.expect("Account has to have some balance");
96104
details.balance
97105
}
98106

@@ -101,14 +109,15 @@ pub async fn purchase_listed_nft(
101109
market_contract: &Contract,
102110
nft_contract: &Contract,
103111
token_id: &str,
104-
offer_price: NearToken
112+
offer_price: NearToken,
105113
) -> Result<(), Box<dyn std::error::Error>> {
106-
let request_payload = json!({
114+
let request_payload = json!({
107115
"token_id": token_id,
108116
"nft_contract_id": nft_contract.id(),
109117
});
110118

111-
let _ = bidder.call(market_contract.id(), "offer")
119+
let _ = bidder
120+
.call(market_contract.id(), "offer")
112121
.args_json(request_payload)
113122
.max_gas()
114123
.deposit(offer_price)
@@ -124,19 +133,20 @@ pub async fn transfer_nft(
124133
nft_contract: &Contract,
125134
token_id: &str,
126135
) -> Result<(), Box<dyn std::error::Error>> {
127-
let request_payload = json!({
136+
let request_payload = json!({
128137
"token_id": token_id,
129138
"receiver_id": receiver.id(),
130139
"approval_id": 1 as u64,
131140
});
132141

133-
let _ = sender.call(nft_contract.id(), "nft_transfer")
142+
let _ = sender
143+
.call(nft_contract.id(), "nft_transfer")
134144
.args_json(request_payload)
135145
.max_gas()
136146
.deposit(ONE_YOCTO_NEAR)
137147
.transact()
138148
.await;
139-
149+
140150
Ok(())
141151
}
142152

@@ -155,10 +165,7 @@ pub async fn get_nft_token_info(
155165
Ok(token_info)
156166
}
157167

158-
pub fn round_to_near_dp(
159-
amount: u128,
160-
sf: u128,
161-
) -> String {
162-
let near_amount = amount as f64 / 1_000_000_000_000_000_000_000_000.0; // yocto in 1 NEAR
168+
pub fn round_to_near_dp(amount: u128, sf: u128) -> String {
169+
let near_amount = amount as f64 / 1_000_000_000_000_000_000_000_000.0; // yocto in 1 NEAR
163170
return format!("{:.1$}", near_amount, sf as usize);
164-
}
171+
}

integration-tests/src/tests.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ async fn test_nft_mint_call(
9999
) -> Result<(), Box<dyn std::error::Error>> {
100100
let request_payload = json!({
101101
"token_id": "1",
102-
"receiver_id": user.id(),
103-
"metadata": {
102+
"token_owner_id": user.id(),
103+
"token_metadata": {
104104
"title": "LEEROYYYMMMJENKINSSS",
105105
"description": "Alright time's up, let's do this.",
106106
"media": "https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Ftse3.mm.bing.net%2Fth%3Fid%3DOIP.Fhp4lHufCdTzTeGCAblOdgHaF7%26pid%3DApi&f=1"
@@ -392,8 +392,8 @@ async fn test_reselling_and_royalties(
392392
// mint with royalties
393393
let request_payload = json!({
394394
"token_id": token_id,
395-
"receiver_id": user.id(),
396-
"metadata": {
395+
"token_owner_id": user.id(),
396+
"token_metadata": {
397397
"title": "Grumpy Cat",
398398
"description": "Not amused.",
399399
"media": "https://www.adamsdrafting.com/wp-content/uploads/2018/06/More-Grumpy-Cat.jpg"
@@ -555,8 +555,8 @@ async fn test_royalties_exceeding_100_percents(
555555
// mint with royalties
556556
let request_payload = json!({
557557
"token_id": token_id,
558-
"receiver_id": user.id(),
559-
"metadata": {
558+
"token_owner_id": user.id(),
559+
"token_metadata": {
560560
"title": "Grumpy Cat",
561561
"description": "Not amused.",
562562
"media": "https://www.adamsdrafting.com/wp-content/uploads/2018/06/More-Grumpy-Cat.jpg"

nft-contract-approval/src/mint.rs

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,49 +6,52 @@ impl Contract {
66
pub fn nft_mint(
77
&mut self,
88
token_id: TokenId,
9-
metadata: TokenMetadata,
10-
receiver_id: AccountId,
9+
token_owner_id: AccountId,
10+
token_metadata: TokenMetadata,
1111
//we add an optional parameter for perpetual royalties
1212
perpetual_royalties: Option<HashMap<AccountId, u32>>,
1313
) {
1414
//measure the initial storage being used on the contract
1515
let initial_storage_usage = env::storage_usage();
16-
16+
1717
// create a royalty map to store in the token
1818
let mut royalty = HashMap::new();
19-
20-
// if perpetual royalties were passed into the function:
19+
20+
// if perpetual royalties were passed into the function:
2121
if let Some(perpetual_royalties) = perpetual_royalties {
2222
//make sure that the length of the perpetual royalties is below 7 since we won't have enough GAS to pay out that many people
23-
assert!(perpetual_royalties.len() < 7, "Cannot add more than 6 perpetual royalty amounts");
24-
23+
assert!(
24+
perpetual_royalties.len() < 7,
25+
"Cannot add more than 6 perpetual royalty amounts"
26+
);
27+
2528
//iterate through the perpetual royalties and insert the account and amount in the royalty map
2629
for (account, amount) in perpetual_royalties {
2730
royalty.insert(account, amount);
2831
}
2932
}
30-
31-
//specify the token struct that contains the owner ID
33+
34+
//specify the token struct that contains the owner ID
3235
let token = Token {
33-
owner_id: receiver_id,
36+
owner_id: token_owner_id,
3437
//we set the approved account IDs to the default value (an empty map)
3538
approved_account_ids: Default::default(),
3639
//the next approval ID is set to 0
3740
next_approval_id: 0,
3841
};
39-
42+
4043
//insert the token ID and token struct and make sure that the token doesn't exist
4144
assert!(
4245
self.tokens_by_id.insert(&token_id, &token).is_none(),
4346
"Token already exists"
4447
);
45-
48+
4649
//insert the token ID and metadata
47-
self.token_metadata_by_id.insert(&token_id, &metadata);
48-
50+
self.token_metadata_by_id.insert(&token_id, &token_metadata);
51+
4952
//call the internal method for adding the token to the owner
5053
self.internal_add_token_to_owner(&token.owner_id, &token_id);
51-
54+
5255
// Construct the mint log as per the events standard.
5356
let nft_mint_log: EventLog = EventLog {
5457
// Standard name ("nep171").
@@ -65,14 +68,14 @@ impl Contract {
6568
memo: None,
6669
}]),
6770
};
68-
71+
6972
// Log the serialized json.
7073
env::log_str(&nft_mint_log.to_string());
71-
74+
7275
//calculate the required storage which was the used - initial
7376
let required_storage_in_bytes = env::storage_usage() - initial_storage_usage;
74-
77+
7578
//refund any excess storage if the user attached too much. Panic if they didn't attach enough to cover the required.
7679
refund_deposit(required_storage_in_bytes.into());
7780
}
78-
}
81+
}

nft-contract-basic/src/mint.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,34 @@ impl Contract {
66
pub fn nft_mint(
77
&mut self,
88
token_id: TokenId,
9-
metadata: TokenMetadata,
10-
receiver_id: AccountId,
9+
token_owner_id: AccountId,
10+
token_metadata: TokenMetadata,
1111
) {
1212
//measure the initial storage being used on the contract
1313
let initial_storage_usage = env::storage_usage();
14-
15-
//specify the token struct that contains the owner ID
14+
15+
//specify the token struct that contains the owner ID
1616
let token = Token {
1717
//set the owner ID equal to the receiver ID passed into the function
18-
owner_id: receiver_id,
18+
owner_id: token_owner_id,
1919
};
20-
20+
2121
//insert the token ID and token struct and make sure that the token doesn't exist
2222
assert!(
2323
self.tokens_by_id.insert(&token_id, &token).is_none(),
2424
"Token already exists"
2525
);
26-
26+
2727
//insert the token ID and metadata
28-
self.token_metadata_by_id.insert(&token_id, &metadata);
29-
28+
self.token_metadata_by_id.insert(&token_id, &token_metadata);
29+
3030
//call the internal method for adding the token to the owner
3131
self.internal_add_token_to_owner(&token.owner_id, &token_id);
32-
32+
3333
//calculate the required storage which was the used - initial
3434
let required_storage_in_bytes = env::storage_usage() - initial_storage_usage;
35-
35+
3636
//refund any excess storage if the user attached too much. Panic if they didn't attach enough to cover the required.
3737
refund_deposit(required_storage_in_bytes.into());
3838
}
39-
}
39+
}

nft-contract-events/src/mint.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,30 @@ impl Contract {
66
pub fn nft_mint(
77
&mut self,
88
token_id: TokenId,
9-
metadata: TokenMetadata,
10-
receiver_id: AccountId,
9+
token_owner_id: AccountId,
10+
token_metadata: TokenMetadata,
1111
) {
1212
//measure the initial storage being used on the contract
1313
let initial_storage_usage = env::storage_usage();
14-
15-
//specify the token struct that contains the owner ID
14+
15+
//specify the token struct that contains the owner ID
1616
let token = Token {
1717
//set the owner ID equal to the receiver ID passed into the function
18-
owner_id: receiver_id,
18+
owner_id: token_owner_id,
1919
};
20-
20+
2121
//insert the token ID and token struct and make sure that the token doesn't exist
2222
assert!(
2323
self.tokens_by_id.insert(&token_id, &token).is_none(),
2424
"Token already exists"
2525
);
26-
26+
2727
//insert the token ID and metadata
28-
self.token_metadata_by_id.insert(&token_id, &metadata);
29-
28+
self.token_metadata_by_id.insert(&token_id, &token_metadata);
29+
3030
//call the internal method for adding the token to the owner
3131
self.internal_add_token_to_owner(&token.owner_id, &token_id);
32-
32+
3333
// Construct the mint log as per the events standard.
3434
let nft_mint_log: EventLog = EventLog {
3535
// Standard name ("nep171").
@@ -46,14 +46,14 @@ impl Contract {
4646
memo: None,
4747
}]),
4848
};
49-
49+
5050
// Log the serialized json.
5151
env::log_str(&nft_mint_log.to_string());
52-
52+
5353
//calculate the required storage which was the used - initial
5454
let required_storage_in_bytes = env::storage_usage() - initial_storage_usage;
55-
55+
5656
//refund any excess storage if the user attached too much. Panic if they didn't attach enough to cover the required.
5757
refund_deposit(required_storage_in_bytes.into());
5858
}
59-
}
59+
}

0 commit comments

Comments
 (0)