Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4.0.0 SDK Updates #32

Merged
merged 1 commit into from
Jun 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
805 changes: 706 additions & 99 deletions market-contract/Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion market-contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2021"
crate-type = ["cdylib", "rlib"]

[dependencies]
near-sdk = "=4.0.0-pre.4"
near-sdk = "4.0.0"

[profile.release]
codegen-units=1
Expand Down
5 changes: 1 addition & 4 deletions market-contract/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,9 @@ mod sale;
mod sale_views;

//GAS constants to attach to calls
const GAS_FOR_ROYALTIES: Gas = Gas(115_000_000_000_000);
const GAS_FOR_RESOLVE_PURCHASE: Gas = Gas(115_000_000_000_000);
const GAS_FOR_NFT_TRANSFER: Gas = Gas(15_000_000_000_000);

//constant used to attach 0 NEAR to a call
const NO_DEPOSIT: Balance = 0;

//the minimum storage to have a sale on the contract.
const STORAGE_PER_SALE: u128 = 1000 * STORAGE_PRICE_PER_BYTE;

Expand Down
35 changes: 19 additions & 16 deletions market-contract/src/sale.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,30 +113,33 @@ impl Contract {

//initiate a cross contract call to the nft contract. This will transfer the token to the buyer and return
//a payout object used for the market to distribute funds to the appropriate accounts.
ext_contract::nft_transfer_payout(
buyer_id.clone(), //purchaser (person to transfer the NFT to)
token_id, //token ID to transfer
sale.approval_id, //market contract's approval ID in order to transfer the token on behalf of the owner
ext_contract::ext(nft_contract_id)
// Attach 1 yoctoNEAR with static GAS equal to the GAS for nft transfer. Also attach an unused GAS weight of 1 by default.
.with_attached_deposit(1)
.with_static_gas(GAS_FOR_NFT_TRANSFER)
.nft_transfer_payout(
buyer_id.clone(), //purchaser (person to transfer the NFT to)
token_id, //token ID to transfer
sale.approval_id, //market contract's approval ID in order to transfer the token on behalf of the owner
"payout from market".to_string(), //memo (to include some context)
/*
the price that the token was purchased for. This will be used in conjunction with the royalty percentages
for the token in order to determine how much money should go to which account.
*/
price,
10, //the maximum amount of accounts the market can payout at once (this is limited by GAS)
nft_contract_id, //contract to initiate the cross contract call to
1, //yoctoNEAR to attach to the call
GAS_FOR_NFT_TRANSFER, //GAS to attach to the call
)
10, //the maximum amount of accounts the market can payout at once (this is limited by GAS)
)
//after the transfer payout has been initiated, we resolve the promise by calling our own resolve_purchase function.
//resolve purchase will take the payout object returned from the nft_transfer_payout and actually pay the accounts
.then(ext_self::resolve_purchase(
buyer_id, //the buyer and price are passed in incase something goes wrong and we need to refund the buyer
price,
env::current_account_id(), //we are invoking this function on the current contract
NO_DEPOSIT, //don't attach any deposit
GAS_FOR_ROYALTIES, //GAS attached to the call to payout royalties
))
.then(
// No attached deposit with static GAS equal to the GAS for resolving the purchase. Also attach an unused GAS weight of 1 by default.
Self::ext(env::current_account_id())
.with_static_gas(GAS_FOR_RESOLVE_PURCHASE)
.resolve_purchase(
buyer_id, //the buyer and price are passed in incase something goes wrong and we need to refund the buyer
price,
)
)
}

/*
Expand Down
Loading