Skip to content

Commit

Permalink
feat: setting price to null for not for sale
Browse files Browse the repository at this point in the history
  • Loading branch information
emarai committed Sep 2, 2021
1 parent ac68fa1 commit d86e631
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ env NEAR_ENV=local near call --keyPath ~/.near/localnet/validator_key.json --acc
env NEAR_ENV=local near call --keyPath ~/.near/localnet/validator_key.json --accountId alice.test.near comic.test.near nft_set_series_price '{"token_series_id":"1", "price": "2000000000000000000000000"}' --depositYocto 1
```

### NFT set series not for sale (Creator only)
```
env NEAR_ENV=local near call --keyPath ~/.near/localnet/validator_key.json --accountId alice.test.near comic.test.near nft_set_series_price '{"token_series_id":"1"}' --depositYocto 1
```

### NFT burn
```
env NEAR_ENV=local near call --keyPath ~/.near/localnet/validator_key.json --accountId comic.test.near comic.test.near nft_burn '{"token_id":"1:1"}' --depositYocto 1
Expand Down
21 changes: 17 additions & 4 deletions paras-nft-contract/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ impl Contract {
}

#[payable]
pub fn nft_set_series_price(&mut self, token_series_id: TokenSeriesId, price: U128) -> U128 {
pub fn nft_set_series_price(&mut self, token_series_id: TokenSeriesId, price: Option<U128>) -> Option<U128> {
assert_one_yocto();

let mut token_series = self.token_series_by_id.get(&token_series_id).expect("Token series not exist");
Expand All @@ -422,7 +422,12 @@ impl Contract {
"Paras: Creator only"
);

token_series.price = Some(price.into());
if price.is_none() {
token_series.price = None;
} else {
token_series.price = Some(price.unwrap().0);
}

self.token_series_by_id.insert(&token_series_id, &token_series);
env::log(
json!({
Expand All @@ -435,7 +440,7 @@ impl Contract {
.to_string()
.as_bytes(),
);
return token_series.price.unwrap().into();
return price;
}

#[payable]
Expand Down Expand Up @@ -1174,7 +1179,15 @@ mod tests {
let mut royalty: HashMap<AccountId, u32> = HashMap::new();
royalty.insert(accounts(1).to_string(), 1000);

create_series(&mut contract, &royalty, None, None);
create_series(&mut contract, &royalty, Some(U128::from(1 * 10u128.pow(24))), None);

testing_env!(context
.predecessor_account_id(accounts(1))
.attached_deposit(1)
.build()
);

contract.nft_set_series_price("1".to_string(), None);

testing_env!(context
.predecessor_account_id(accounts(2))
Expand Down

0 comments on commit d86e631

Please sign in to comment.