@@ -11,9 +11,9 @@ const GAS_FOR_NFT_ON_TRANSFER = 35_000_000_000_000;
11
11
export function internalNftToken ( {
12
12
contract,
13
13
tokenId
14
- } :{
15
- contract : Contract ,
16
- tokenId : string
14
+ } :{
15
+ contract : Contract ,
16
+ tokenId : string
17
17
} ) {
18
18
let token = contract . tokensById . get ( tokenId ) as Token ;
19
19
//if there wasn't a token ID in the tokens_by_id collection, we return None
@@ -24,7 +24,7 @@ export function internalNftToken({
24
24
//if there is some token ID in the tokens_by_id collection
25
25
//we'll get the metadata for that token
26
26
let metadata = contract . tokenMetadataById . get ( tokenId ) as TokenMetadata ;
27
-
27
+
28
28
//we return the JsonToken
29
29
let jsonToken = new JsonToken ( {
30
30
tokenId : tokenId ,
@@ -36,21 +36,21 @@ export function internalNftToken({
36
36
return jsonToken ;
37
37
}
38
38
39
- //implementation of the nft_transfer method. This transfers the NFT from the current owner to the receiver.
39
+ //implementation of the nft_transfer method. This transfers the NFT from the current owner to the receiver.
40
40
export function internalNftTransfer ( {
41
41
contract,
42
42
receiverId,
43
43
tokenId,
44
44
approvalId,
45
45
memo,
46
46
} :{
47
- contract : Contract ,
48
- receiverId : string ,
49
- tokenId : string ,
47
+ contract : Contract ,
48
+ receiverId : string ,
49
+ tokenId : string ,
50
50
approvalId : number
51
51
memo : string
52
52
} ) {
53
- //assert that the user attached exactly 1 yoctoNEAR. This is for security and so that the user will be redirected to the NEAR wallet.
53
+ //assert that the user attached exactly 1 yoctoNEAR. This is for security and so that the user will be redirected to the NEAR wallet.
54
54
assertOneYocto ( ) ;
55
55
//get the sender to transfer the token from the sender to the receiver
56
56
let senderId = near . predecessorAccountId ( ) ;
@@ -82,13 +82,13 @@ export function internalNftTransferCall({
82
82
msg
83
83
} :{
84
84
contract : Contract ,
85
- receiverId : string ,
86
- tokenId : string ,
85
+ receiverId : string ,
86
+ tokenId : string ,
87
87
approvalId : number ,
88
88
memo : string ,
89
- msg : string
89
+ msg : string
90
90
} ) {
91
- //assert that the user attached exactly 1 yocto for security reasons.
91
+ //assert that the user attached exactly 1 yocto for security reasons.
92
92
assertOneYocto ( ) ;
93
93
//get the sender to transfer the token from the sender to the receiver
94
94
let senderId = near . predecessorAccountId ( ) ;
@@ -106,30 +106,30 @@ export function internalNftTransferCall({
106
106
// Initiating receiver's call and the callback
107
107
const promise = near . promiseBatchCreate ( receiverId ) ;
108
108
near . promiseBatchActionFunctionCall (
109
- promise ,
110
- "nft_on_transfer" ,
111
- bytes ( JSON . stringify ( {
109
+ promise ,
110
+ "nft_on_transfer" ,
111
+ bytes ( JSON . stringify ( {
112
112
sender_id : senderId ,
113
113
previous_owner_id : previousToken . owner_id ,
114
114
token_id : tokenId ,
115
115
msg
116
- } ) ) ,
117
- 0 , // no deposit
116
+ } ) ) ,
117
+ 0 , // no deposit
118
118
GAS_FOR_NFT_ON_TRANSFER
119
119
) ;
120
120
121
121
// We then resolve the promise and call nft_resolve_transfer on our own contract
122
122
near . promiseThen (
123
- promise ,
124
- near . currentAccountId ( ) ,
125
- "nft_resolve_transfer" ,
123
+ promise ,
124
+ near . currentAccountId ( ) ,
125
+ "nft_resolve_transfer" ,
126
126
bytes ( JSON . stringify ( {
127
127
owner_id : previousToken . owner_id ,
128
128
receiver_id : receiverId ,
129
129
token_id : tokenId ,
130
130
approved_account_ids : previousToken . approved_account_ids
131
- } ) ) ,
132
- 0 , // no deposit
131
+ } ) ) ,
132
+ 0 , // no deposit
133
133
GAS_FOR_RESOLVE_TRANSFER
134
134
) ;
135
135
return near . promiseReturn ( promise ) ;
@@ -152,7 +152,7 @@ export function internalResolveTransfer({
152
152
receiverId : string ,
153
153
tokenId : string ,
154
154
approvedAccountIds : { [ key : string ] : number } ,
155
- memo : string
155
+ memo : string
156
156
} ) {
157
157
assert ( near . currentAccountId ( ) === near . predecessorAccountId ( ) , "Only the contract itself can call this method" ) ;
158
158
// Whether receiver wants to return token back to the sender, based on `nft_on_transfer`
@@ -162,8 +162,8 @@ export function internalResolveTransfer({
162
162
//As per the standard, the nft_on_transfer should return whether we should return the token to it's owner or not
163
163
//if we need don't need to return the token, we simply return true meaning everything went fine
164
164
if ( result === 'false' ) {
165
- /*
166
- since we've already transferred the token and nft_on_transfer returned false, we don't have to
165
+ /*
166
+ since we've already transferred the token and nft_on_transfer returned false, we don't have to
167
167
revert the original transfer and thus we can just return true since nothing went wrong.
168
168
*/
169
169
//we refund the owner for releasing the storage used up by the approved account IDs
@@ -193,7 +193,7 @@ export function internalResolveTransfer({
193
193
//we add the token to the original owner
194
194
internalAddTokenToOwner ( contract , ownerId , tokenId ) ;
195
195
196
- //we change the token struct's owner to be the original owner
196
+ //we change the token struct's owner to be the original owner
197
197
token . owner_id = ownerId
198
198
199
199
//we refund the receiver any approved account IDs that they may have set on the token
@@ -235,7 +235,7 @@ export function internalResolveTransfer({
235
235
}
236
236
237
237
// Log the serialized json.
238
- near . log ( JSON . stringify ( nftTransferLog ) ) ;
238
+ near . log ( `EVENT_JSON: ${ JSON . stringify ( nftTransferLog ) } ` ) ;
239
239
240
240
//return false
241
241
return false
0 commit comments