Skip to content

Commit

Permalink
Merge pull request #65 from garikbesson/migrate-and-reorganize
Browse files Browse the repository at this point in the history
Fixed U/u types
  • Loading branch information
gagdiez authored May 2, 2024
2 parents 55d64e7 + 7294991 commit 84a5d40
Show file tree
Hide file tree
Showing 33 changed files with 130 additions and 130 deletions.
4 changes: 2 additions & 2 deletions integration-tests/src/helpers.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use serde_json::json;
use near_workspaces::{types::{NearToken, AccountDetails}, Account, Contract};

pub const DEFAULT_DEPOSIT: u128 = 10000000000000000000000 as u128;
pub const DEFAULT_DEPOSIT: u128 = 10000000000000000000000;
pub const ONE_YOCTO_NEAR: NearToken = NearToken::from_yoctonear(1);

pub async fn mint_nft(
Expand Down Expand Up @@ -70,7 +70,7 @@ pub async fn place_nft_for_sale(
market_contract: &Contract,
nft_contract: &Contract,
token_id: &str,
approval_id: u128,
approval_id: u32,
price: &NearToken,
) -> Result<(), Box<dyn std::error::Error>> {
let request_payload = json!({
Expand Down
4 changes: 2 additions & 2 deletions market-contract/src/external.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ trait ExtContract {
&mut self,
receiver_id: AccountId, //purchaser (person to transfer the NFT to)
token_id: TokenId, //token ID to transfer
approval_id: u64, //market contract's approval ID in order to transfer the token on behalf of the owner
approval_id: u32, //market contract's approval ID in order to transfer the token on behalf of the owner
memo: String, //memo (to include some context)
/*
the price that the token was purchased for. This will be used in conjunction with the royalty percentages
Expand All @@ -25,6 +25,6 @@ trait ExtContract {
&self,
token_id: TokenId,
approved_account_id: AccountId,
approval_id: u64,
approval_id: u32,
);
}
4 changes: 2 additions & 2 deletions market-contract/src/nft_callbacks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ trait NonFungibleTokenApprovalsReceiver {
&mut self,
token_id: TokenId,
owner_id: AccountId,
approval_id: u64,
approval_id: u32,
msg: String,
);
}
Expand All @@ -24,7 +24,7 @@ impl NonFungibleTokenApprovalsReceiver for Contract {
&mut self,
token_id: TokenId,
owner_id: AccountId,
approval_id: u64,
approval_id: u32,
msg: String,
) {
/*
Expand Down
6 changes: 3 additions & 3 deletions market-contract/src/sale.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub struct Sale {
//owner of the sale
pub owner_id: AccountId,
//market contract's approval ID to transfer the token on behalf of the owner
pub approval_id: u64,
pub approval_id: u32,
//nft contract where the token was minted
pub nft_contract_id: String,
//actual token ID for sale
Expand All @@ -35,7 +35,7 @@ impl Contract {
&mut self,
nft_contract_id: AccountId,
token_id: TokenId,
approval_id: u64,
approval_id: u32,
sale_conditions: SalePriceInYoctoNear,
) {
let owner_id = env::predecessor_account_id();
Expand Down Expand Up @@ -267,7 +267,7 @@ impl Contract {
owner_id: AccountId,
nft_contract_id: AccountId,
token_id: TokenId,
approval_id: u64,
approval_id: u32,
sale_conditions: SalePriceInYoctoNear,
#[callback_result] nft_token_result: Result<JsonToken, PromiseError>,
#[callback_result] nft_is_approved_result: Result<bool, PromiseError>,
Expand Down
12 changes: 6 additions & 6 deletions market-contract/src/sale_views.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ impl Contract {
pub fn get_sales_by_owner_id(
&self,
account_id: AccountId,
from_index: Option<u128>,
limit: Option<u64>,
from_index: Option<U128>,
limit: Option<u32>,
) -> Vec<Sale> {
//get the set of token IDs for sale for the given account ID
let by_owner_id = self.by_owner_id.get(&account_id);
Expand All @@ -48,7 +48,7 @@ impl Contract {
let keys = sales.as_vector();

//where to start pagination - if we have a from_index, we'll use that - otherwise start from 0 index
let start = from_index.unwrap_or(0);
let start = u128::from(from_index.unwrap_or(U128(0)));

//iterate through the keys vector
keys.iter()
Expand Down Expand Up @@ -82,8 +82,8 @@ impl Contract {
pub fn get_sales_by_nft_contract_id(
&self,
nft_contract_id: AccountId,
from_index: Option<u128>,
limit: Option<u64>,
from_index: Option<U128>,
limit: Option<u32>,
) -> Vec<Sale> {
//get the set of token IDs for sale for the given contract ID
let by_nft_contract_id = self.by_nft_contract_id.get(&nft_contract_id);
Expand All @@ -99,7 +99,7 @@ impl Contract {
let keys = sales.as_vector();

//where to start pagination - if we have a from_index, we'll use that - otherwise start from 0 index
let start = from_index.unwrap_or(0);
let start = u128::from(from_index.unwrap_or(U128(0)));

//iterate through the keys vector
keys.iter()
Expand Down
8 changes: 4 additions & 4 deletions nft-contract-approval/src/approval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub trait NonFungibleTokenCore {
&self,
token_id: TokenId,
approved_account_id: AccountId,
approval_id: Option<u64>,
approval_id: Option<u32>,
) -> bool;

//revoke a specific account from transferring the token on your behalf
Expand All @@ -27,7 +27,7 @@ trait NonFungibleTokenApprovalsReceiver {
&mut self,
token_id: TokenId,
owner_id: AccountId,
approval_id: u64,
approval_id: u32,
msg: String,
);
}
Expand All @@ -54,7 +54,7 @@ impl NonFungibleTokenCore for Contract {
);

//get the next approval ID if we need a new approval
let approval_id: u64 = token.next_approval_id;
let approval_id: u32 = token.next_approval_id;

//check if the account has been approved already for this token
let is_new_approval = token
Expand Down Expand Up @@ -99,7 +99,7 @@ impl NonFungibleTokenCore for Contract {
&self,
token_id: TokenId,
approved_account_id: AccountId,
approval_id: Option<u64>,
approval_id: Option<u32>,
) -> bool {
//get the token object from the token_id
let token = self.tokens_by_id.get(&token_id).expect("No token");
Expand Down
10 changes: 5 additions & 5 deletions nft-contract-approval/src/enumeration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ impl Contract {
}

//Query for nft tokens on the contract regardless of the owner using pagination
pub fn nft_tokens(&self, from_index: Option<u128>, limit: Option<u64>) -> Vec<JsonToken> {
pub fn nft_tokens(&self, from_index: Option<U128>, limit: Option<u32>) -> Vec<JsonToken> {
//where to start pagination - if we have a from_index, we'll use that - otherwise start from 0 index
let start = from_index.unwrap_or(0);
let start = u128::from(from_index.unwrap_or(U128(0)));

//iterate through each token using an iterator
self.token_metadata_by_id.keys()
Expand Down Expand Up @@ -46,8 +46,8 @@ impl Contract {
pub fn nft_tokens_for_owner(
&self,
account_id: AccountId,
from_index: Option<u128>,
limit: Option<u64>,
from_index: Option<U128>,
limit: Option<u32>,
) -> Vec<JsonToken> {
//get the set of tokens for the passed in owner
let tokens_for_owner_set = self.tokens_per_owner.get(&account_id);
Expand All @@ -60,7 +60,7 @@ impl Contract {
};

//where to start pagination - if we have a from_index, we'll use that - otherwise start from 0 index
let start = from_index.unwrap_or(0);
let start = u128::from(from_index.unwrap_or(U128(0)));

//iterate through the keys vector
tokens.iter()
Expand Down
4 changes: 2 additions & 2 deletions nft-contract-approval/src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub(crate) fn refund_approved_account_ids_iter<'a, I>(
//refund a map of approved account IDs and send the funds to the passed in account ID
pub(crate) fn refund_approved_account_ids(
account_id: AccountId,
approved_account_ids: &HashMap<AccountId, u64>,
approved_account_ids: &HashMap<AccountId, u32>,
) -> Promise {
//call the refund_approved_account_ids_iter with the approved account IDs as keys
refund_approved_account_ids_iter(account_id, approved_account_ids.keys())
Expand Down Expand Up @@ -134,7 +134,7 @@ impl Contract {
receiver_id: &AccountId,
token_id: &TokenId,
//we introduce an approval ID so that people with that approval ID can transfer the token
approval_id: Option<u64>,
approval_id: Option<u32>,
memo: Option<String>,
) -> Token {
//get the token object by passing in the token_id
Expand Down
6 changes: 3 additions & 3 deletions nft-contract-approval/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ pub struct Token {
//owner of the token
pub owner_id: AccountId,
//list of approved account IDs that have access to transfer the token. This maps an account ID to an approval ID
pub approved_account_ids: HashMap<AccountId, u64>,
pub approved_account_ids: HashMap<AccountId, u32>,
//the next approval ID to give out.
pub next_approval_id: u64,
pub next_approval_id: u32,
}

//The Json token is what will be returned from view calls.
Expand All @@ -60,7 +60,7 @@ pub struct JsonToken {
//token metadata
pub metadata: TokenMetadata,
//list of approved account IDs that have access to transfer the token. This maps an account ID to an approval ID
pub approved_account_ids: HashMap<AccountId, u64>,
pub approved_account_ids: HashMap<AccountId, u32>,
}

pub trait NonFungibleTokenMetadata {
Expand Down
12 changes: 6 additions & 6 deletions nft-contract-approval/src/nft_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub trait NonFungibleTokenCore {
receiver_id: AccountId,
token_id: TokenId,
//we introduce an approval ID so that people with that approval ID can transfer the token
approval_id: Option<u64>,
approval_id: Option<u32>,
memo: Option<String>,
);

Expand All @@ -22,7 +22,7 @@ pub trait NonFungibleTokenCore {
receiver_id: AccountId,
token_id: TokenId,
//we introduce an approval ID so that people with that approval ID can transfer the token
approval_id: Option<u64>,
approval_id: Option<u32>,
memo: Option<String>,
msg: String,
) -> PromiseOrValue<bool>;
Expand Down Expand Up @@ -59,7 +59,7 @@ trait NonFungibleTokenResolver {
receiver_id: AccountId,
token_id: TokenId,
//we introduce the approval map so we can keep track of what the approvals were before the transfer
approved_account_ids: HashMap<AccountId, u64>,
approved_account_ids: HashMap<AccountId, u32>,
//we introduce a memo for logging the transfer event
memo: Option<String>,
) -> bool;
Expand All @@ -74,7 +74,7 @@ impl NonFungibleTokenCore for Contract {
receiver_id: AccountId,
token_id: TokenId,
//we introduce an approval ID so that people with that approval ID can transfer the token
approval_id: Option<u64>,
approval_id: Option<u32>,
memo: Option<String>,
) {
//assert that the user attached exactly 1 yoctoNEAR. This is for security and so that the user will be redirected to the NEAR wallet.
Expand Down Expand Up @@ -105,7 +105,7 @@ impl NonFungibleTokenCore for Contract {
receiver_id: AccountId,
token_id: TokenId,
//we introduce an approval ID so that people with that approval ID can transfer the token
approval_id: Option<u64>,
approval_id: Option<u32>,
memo: Option<String>,
msg: String,
) -> PromiseOrValue<bool> {
Expand Down Expand Up @@ -189,7 +189,7 @@ impl NonFungibleTokenResolver for Contract {
receiver_id: AccountId,
token_id: TokenId,
//we introduce the approval map so we can keep track of what the approvals were before the transfer
approved_account_ids: HashMap<AccountId, u64>,
approved_account_ids: HashMap<AccountId, u32>,
//we introduce a memo for logging the transfer event
memo: Option<String>,
) -> bool {
Expand Down
4 changes: 2 additions & 2 deletions nft-contract-approval/src/royalty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub trait NonFungibleTokenCore {
&mut self,
receiver_id: AccountId,
token_id: TokenId,
approval_id: u64,
approval_id: u32,
memo: Option<String>,
balance: U128,
max_len_payout: u32,
Expand All @@ -33,7 +33,7 @@ impl NonFungibleTokenCore for Contract {
&mut self,
receiver_id: AccountId,
token_id: TokenId,
approval_id: u64,
approval_id: u32,
memo: Option<String>,
balance: U128,
max_len_payout: u32,
Expand Down
6 changes: 3 additions & 3 deletions nft-contract-basic/src/approval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub trait NonFungibleTokenCore {
&self,
token_id: TokenId,
approved_account_id: AccountId,
approval_id: Option<u64>,
approval_id: Option<u32>,
) -> bool;

//revoke a specific account from transferring the token on your behalf
Expand All @@ -27,7 +27,7 @@ trait NonFungibleTokenApprovalsReceiver {
&mut self,
token_id: TokenId,
owner_id: AccountId,
approval_id: u64,
approval_id: u32,
msg: String,
);
}
Expand All @@ -47,7 +47,7 @@ impl NonFungibleTokenCore for Contract {
&self,
token_id: TokenId,
approved_account_id: AccountId,
approval_id: Option<u64>,
approval_id: Option<u32>,
) -> bool {
/*
FILL THIS IN
Expand Down
10 changes: 5 additions & 5 deletions nft-contract-basic/src/enumeration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ impl Contract {
}

//Query for nft tokens on the contract regardless of the owner using pagination
pub fn nft_tokens(&self, from_index: Option<u128>, limit: Option<u64>) -> Vec<JsonToken> {
pub fn nft_tokens(&self, from_index: Option<U128>, limit: Option<u32>) -> Vec<JsonToken> {
//where to start pagination - if we have a from_index, we'll use that - otherwise start from 0 index
let start = from_index.unwrap_or(0);
let start = u128::from(from_index.unwrap_or(U128(0)));

//iterate through each token using an iterator
self.token_metadata_by_id.keys()
Expand Down Expand Up @@ -46,8 +46,8 @@ impl Contract {
pub fn nft_tokens_for_owner(
&self,
account_id: AccountId,
from_index: Option<u128>,
limit: Option<u64>,
from_index: Option<U128>,
limit: Option<u32>,
) -> Vec<JsonToken> {
//get the set of tokens for the passed in owner
let tokens_for_owner_set = self.tokens_per_owner.get(&account_id);
Expand All @@ -60,7 +60,7 @@ impl Contract {
};

//where to start pagination - if we have a from_index, we'll use that - otherwise start from 0 index
let start = from_index.unwrap_or(0);
let start = u128::from(from_index.unwrap_or(U128(0)));

//iterate through the keys vector
tokens.iter()
Expand Down
4 changes: 2 additions & 2 deletions nft-contract-basic/src/royalty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub trait NonFungibleTokenCore {
&mut self,
receiver_id: AccountId,
token_id: TokenId,
approval_id: u64,
approval_id: u32,
memo: Option<String>,
balance: U128,
max_len_payout: u32,
Expand All @@ -33,7 +33,7 @@ impl NonFungibleTokenCore for Contract {
&mut self,
receiver_id: AccountId,
token_id: TokenId,
approval_id: u64,
approval_id: u32,
memo: Option<String>,
balance: U128,
max_len_payout: u32,
Expand Down
Loading

0 comments on commit 84a5d40

Please sign in to comment.