Skip to content

Feedback and some nits #6

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
build
node_modules
node_modules
neardev
5 changes: 1 addition & 4 deletions __tests__/test-template.ava.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ test.beforeEach(async t => {
const root = worker.rootAccount;

// Deploy the counter contract.
const counter = await root.createAndDeploy(
root.getSubAccount('counter').accountId,
'./build/contract.wasm'
);
const counter = await root.devDeploy('./build/contract.wasm');

// Init the contract
await counter.call(counter, 'init', {});
Expand Down
1 change: 0 additions & 1 deletion neardev/dev-account

This file was deleted.

1 change: 0 additions & 1 deletion neardev/dev-account.env

This file was deleted.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
"lodash-es": "^4.17.21"
},
"devDependencies": {
"typescript": "^4.7.4"
"typescript": "^4.7.4",
"ava": "^4.3.1",
"near-workspaces": "^3.1.0"
}
}
}
36 changes: 18 additions & 18 deletions src/nft-contract/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ export class Contract extends NearContract {
the owner_id.
*/
constructor({
owner_id,
owner_id,
metadata = {
spec: "nft-1.0.0",
name: "NFT Tutorial Contract",
symbol: "GOTEAM"
}
}
}) {
super()
this.owner_id = owner_id;
Expand All @@ -43,7 +43,7 @@ export class Contract extends NearContract {
}

default() {
return new Contract({owner_id: ''})
return new Contract({ owner_id: '' })
}

/*
Expand All @@ -57,26 +57,26 @@ export class Contract extends NearContract {
/*
CORE
*/
@view
//get the information for a specific token ID
@view
nft_token({ token_id }) {
return internalNftToken({ contract: this, tokenId: token_id });
}

@call
//implementation of the nft_transfer method. This transfers the NFT from the current owner to the receiver.
@call
nft_transfer({ receiver_id, token_id, approval_id, memo }) {
return internalNftTransfer({ contract: this, receiverId: receiver_id, tokenId: token_id, approvalId: approval_id, memo: memo });
}

@call
//implementation of the transfer call method. This will transfer the NFT and call a method on the receiver_id contract
@call
nft_transfer_call({ receiver_id, token_id, approval_id, memo, msg }) {
return internalNftTransferCall({ contract: this, receiverId: receiver_id, tokenId: token_id, approvalId: approval_id, memo: memo, msg: msg });
}

@call
//resolves the cross contract call when calling nft_on_transfer in the nft_transfer_call method
@call
//returns true if the token was successfully transferred to the receiver_id
nft_resolve_transfer({ authorized_id, owner_id, receiver_id, token_id, approved_account_ids, memo }) {
return internalResolveTransfer({ contract: this, authorizedId: authorized_id, ownerId: owner_id, receiverId: receiver_id, tokenId: token_id, approvedAccountIds: approved_account_ids, memo: memo });
Expand All @@ -85,77 +85,77 @@ export class Contract extends NearContract {
/*
APPROVALS
*/
@view
//check if the passed in account has access to approve the token ID
@view
nft_is_approved({ token_id, approved_account_id, approval_id }) {
return internalNftIsApproved({ contract: this, tokenId: token_id, approvedAccountId: approved_account_id, approvalId: approval_id });
}

@call
//approve an account ID to transfer a token on your behalf
@call
nft_approve({ token_id, account_id, msg }) {
return internalNftApprove({ contract: this, tokenId: token_id, accountId: account_id, msg: msg });
}

/*
ROYALTY
*/
@view
//calculates the payout for a token given the passed in balance. This is a view method
@view
nft_payout({ token_id, balance, max_len_payout }) {
return internalNftPayout({ contract: this, tokenId: token_id, balance: balance, maxLenPayout: max_len_payout });
}

@call
//transfers the token to the receiver ID and returns the payout object that should be payed given the passed in balance.
@call
nft_transfer_payout({ receiver_id, token_id, approval_id, memo, balance, max_len_payout }) {
return internalNftTransferPayout({ contract: this, receiverId: receiver_id, tokenId: token_id, approvalId: approval_id, memo: memo, balance: balance, maxLenPayout: max_len_payout });
}

@call
//approve an account ID to transfer a token on your behalf
@call
nft_revoke({ token_id, account_id }) {
return internalNftRevoke({ contract: this, tokenId: token_id, accountId: account_id });
}

@call
//approve an account ID to transfer a token on your behalf
@call
nft_revoke_all({ token_id }) {
return internalNftRevokeAll({ contract: this, tokenId: token_id });
}

/*
ENUMERATION
*/
@view
//Query for the total supply of NFTs on the contract
@view
nft_total_supply() {
return internalTotalSupply({ contract: this });
}

@view
//Query for nft tokens on the contract regardless of the owner using pagination
@view
nft_tokens({ from_index, limit }) {
return internalNftTokens({ contract: this, fromIndex: from_index, limit: limit });
}

@view
//get the total supply of NFTs for a given owner
@view
nft_tokens_for_owner({ account_id, from_index, limit }) {
return internalTokensForOwner({ contract: this, accountId: account_id, fromIndex: from_index, limit: limit });
}

@view
//Query for all the tokens for an owner
@view
nft_supply_for_owner({ account_id }) {
return internalSupplyForOwner({ contract: this, accountId: account_id });
}

/*
METADATA
*/
@view
//Query for all the tokens for an owner
@view
nft_metadata() {
return internalNftMetadata({ contract: this });
}
Expand Down
Loading