11import " ./constants" ;
22import " ./messages" ;
33
4- inline fun sendMsg (toAddress : Address , amount : Int , op : Int , queryId : Int , payload : Builder , sendMode : Int ) {
5- let msgBody = beginCell ().storeUint (op , 32 ).storeUint (queryId , 64 );
6-
7- if (payload .bits () != 0 ) {
8- msgBody = msgBody .storeBuilder (payload );
9- }
10-
11- message (MessageParameters {
12- bounce : false ,
13- to : toAddress ,
14- value : amount ,
15- body : msgBody .endCell (),
16- mode : sendMode ,
17- });
18- }
19-
204struct NFTItemInit {
215 owner : Address ;
226 content : Cell ;
@@ -28,7 +12,22 @@ contract NFTItem(
2812 collectionAddress : Address ,
2913 itemIndex : Int as uint64 ,
3014) {
31- receive () {} // to ignore empty messages
15+ receive () {} // ignore empty messages
16+
17+ receive (msg : GetStaticData ) {
18+ throwUnless (NotInit , self .owner != null );
19+
20+ sendMsg (
21+ sender (),
22+ 0 ,
23+ ReportStaticData ,
24+ msg .queryId ,
25+ beginCell ()
26+ .storeUint (self .itemIndex , 256 )
27+ .storeAddress (self .collectionAddress ),
28+ SendRemainingValue ,
29+ ); // implementation detail
30+ }
3231
3332 receive (msg : Slice ) {
3433 // Check if owner == null, which means the contract hasn't been initialized yet
@@ -52,35 +51,47 @@ contract NFTItem(
5251 throwUnless (IncorrectForwardPayload , msg .forwardPayload .bits () >= 1 );
5352 forceBasechain (msg .newOwner );
5453
55- let fwdFees : Int = context ().readForwardFee ();
54+ let fwdFees = context ().readForwardFee ();
5655
57- let restAmount : Int = myBalance () - minTonsForStorage ;
56+ let restAmount = myBalance () - minTonsForStorage ;
5857 if (msg .forwardAmount > 0 ) {
59- restAmount -= ( msg .forwardAmount + fwdFees ) ;
58+ restAmount -= msg .forwardAmount + fwdFees ;
6059 }
6160
6261 // when we load addr_none$00 in tact we got null
63- let needResponse : Bool = ( msg .responseDestination != null ) ;
62+ let needResponse = msg .responseDestination != null ;
6463 if (needResponse ) {
6564 restAmount -= fwdFees ;
6665 }
6766
6867 throwUnless (InvalidFees , restAmount >= 0 );
6968
7069 if (msg .forwardAmount > 0 ) {
71- sendMsg (msg .newOwner , msg .forwardAmount , OwnershipAssigned , msg .queryId , beginCell ().storeAddress (self .owner !! ).storeSlice (msg .forwardPayload ), SendPayFwdFeesSeparately );
70+ sendMsg (
71+ msg .newOwner ,
72+ msg .forwardAmount ,
73+ OwnershipAssigned ,
74+ msg .queryId ,
75+ beginCell ()
76+ .storeAddress (self .owner !! )
77+ .storeSlice (msg .forwardPayload ),
78+ SendPayFwdFeesSeparately ,
79+ );
7280 }
81+
7382 if (needResponse ) {
7483 forceBasechain (msg .responseDestination !! );
75- sendMsg (msg .responseDestination !! , restAmount , Excesses , msg .queryId , beginCell (), SendPayFwdFeesSeparately );
84+ sendMsg (
85+ msg .responseDestination !! ,
86+ restAmount ,
87+ Excesses ,
88+ msg .queryId ,
89+ beginCell (),
90+ SendPayFwdFeesSeparately ,
91+ );
7692 }
77- self .owner = msg .newOwner ;
78- }
79-
80- receive (msg : GetStaticData ) {
81- throwUnless (NotInit , self .owner != null );
8293
83- sendMsg ( sender (), 0 , ReportStaticData , msg . queryId , beginCell (). storeUint ( self .itemIndex , 256 ). storeAddress ( self . collectionAddress ), SendRemainingValue ); // implementation detail
94+ self .owner = msg . newOwner ;
8495 }
8596
8697 get fun get_nft_data (): NFTData {
@@ -93,3 +104,17 @@ contract NFTItem(
93104 };
94105 }
95106}
107+
108+ inline fun sendMsg (toAddress : Address , amount : Int , op : Int , queryId : Int , payload : Builder , sendMode : Int ) {
109+ message (MessageParameters {
110+ bounce : false ,
111+ to : toAddress ,
112+ value : amount ,
113+ body : beginCell ()
114+ .storeUint (op , 32 )
115+ .storeUint (queryId , 64 )
116+ .storeBuilder (payload )
117+ .endCell (),
118+ mode : sendMode ,
119+ });
120+ }
0 commit comments