Skip to content

Commit e40c55c

Browse files
committed
feat: new CreateTransferCell and CreateBurnCell in Tep74Jettons (to create cells instead of messages)
1 parent 9070ddf commit e40c55c

File tree

1 file changed

+64
-16
lines changed

1 file changed

+64
-16
lines changed

TonLibDotNet/Recipes/Tep74Jettons.cs

Lines changed: 64 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -137,23 +137,21 @@ public async Task<string> GetWalletAddress(ITonClient tonClient, string jettonMi
137137
}
138138

139139
/// <summary>
140-
/// Creates message that will transfer jettons from source to destination.
140+
/// Creates body cell that should be used to transfer jettons from source to destination.
141141
/// </summary>
142-
/// <param name="sourceJettonAddress">Jetton wallet address to send coins from (use <see cref="GetWalletAddress">GetWalletAddress</see> if needed).</param>
143142
/// <param name="queryId">Arbitrary request number.</param>
144143
/// <param name="amount">Amount of transferred jettons <b>in elementary units</b>.</param>
145144
/// <param name="destination">Address of the new owner of the jettons (user main-wallet address, not his jetton address).</param>
146145
/// <param name="responseDestination">Address where to send a response with confirmation of a successful transfer and the rest of the incoming message Toncoins.</param>
147146
/// <param name="customPayload">Optional custom data (which is used by either sender or receiver jetton wallet for inner logic).</param>
148147
/// <param name="forwardTonAmount">The amount of nanotons to be sent to the destination address.</param>
149148
/// <param name="forwardPayload">Optional custom data that should be sent to the destination address.</param>
150-
/// <returns>Constructed and ready-to-be-sent Message (by editor/owner of <paramref name="sourceJettonAddress"/>).</returns>
149+
/// <returns>Constructed Cell (body of message to send).</returns>
151150
/// <remarks>
152151
/// <para>Your Jetton wallet address must already be deployed and active, and contain enough jettons to send.</para>
153152
/// </remarks>
154153
/// <seealso href="https://github.com/ton-blockchain/TEPs/blob/master/text/0074-jettons-standard.md#1-transfer">Transfer message in TEP</seealso>
155-
public Message CreateTransferMessage(
156-
string sourceJettonAddress,
154+
public Cell CreateTransferCell(
157155
ulong queryId,
158156
BigInteger amount,
159157
string destination,
@@ -162,7 +160,7 @@ public Message CreateTransferMessage(
162160
decimal forwardTonAmount,
163161
Cell? forwardPayload)
164162
{
165-
var body = new CellBuilder()
163+
return new CellBuilder()
166164
.StoreUInt(OPTransfer)
167165
.StoreULong(queryId)
168166
.StoreCoins(amount)
@@ -171,48 +169,98 @@ public Message CreateTransferMessage(
171169
.StoreDict(customPayload)
172170
.StoreCoins(TonUtils.Coins.ToNano(forwardTonAmount))
173171
.StoreDict(forwardPayload)
174-
;
172+
.Build();
173+
}
174+
175+
/// <summary>
176+
/// Creates message that will transfer jettons from source to destination.
177+
/// </summary>
178+
/// <param name="sourceJettonAddress">Jetton wallet address to send coins from (use <see cref="GetWalletAddress">GetWalletAddress</see> if needed).</param>
179+
/// <param name="queryId">Arbitrary request number.</param>
180+
/// <param name="amount">Amount of transferred jettons <b>in elementary units</b>.</param>
181+
/// <param name="destination">Address of the new owner of the jettons (user main-wallet address, not his jetton address).</param>
182+
/// <param name="responseDestination">Address where to send a response with confirmation of a successful transfer and the rest of the incoming message Toncoins.</param>
183+
/// <param name="customPayload">Optional custom data (which is used by either sender or receiver jetton wallet for inner logic).</param>
184+
/// <param name="forwardTonAmount">The amount of nanotons to be sent to the destination address.</param>
185+
/// <param name="forwardPayload">Optional custom data that should be sent to the destination address.</param>
186+
/// <returns>Constructed and ready-to-be-sent Message (by editor/owner of <paramref name="sourceJettonAddress"/>).</returns>
187+
/// <remarks>
188+
/// <para>Your Jetton wallet address must already be deployed and active, and contain enough jettons to send.</para>
189+
/// </remarks>
190+
/// <seealso href="https://github.com/ton-blockchain/TEPs/blob/master/text/0074-jettons-standard.md#1-transfer">Transfer message in TEP</seealso>
191+
public Message CreateTransferMessage(
192+
string sourceJettonAddress,
193+
ulong queryId,
194+
BigInteger amount,
195+
string destination,
196+
string responseDestination,
197+
Cell? customPayload,
198+
decimal forwardTonAmount,
199+
Cell? forwardPayload)
200+
{
201+
var body = CreateTransferCell(queryId, amount, destination, responseDestination, customPayload, forwardTonAmount, forwardPayload);
175202

176203
return new Message(new AccountAddress(sourceJettonAddress))
177204
{
178205
Amount = TonUtils.Coins.ToNano(DefaultAmount),
179-
Data = new DataRaw(new Boc(body.Build()).SerializeToBase64(), string.Empty),
206+
Data = new DataRaw(new Boc(body).SerializeToBase64(), string.Empty),
180207
SendMode = DefaultSendMode,
181208
};
182209
}
183210

184211
/// <summary>
185-
/// Creates message that will burn specified amount of jettons.
212+
/// Creates body cell that should be used to burn specified amount of jettons.
186213
/// </summary>
187-
/// <param name="sourceJettonAddress">Jetton wallet address to send coins from (use <see cref="GetWalletAddress">GetWalletAddress</see> if needed).</param>
188214
/// <param name="queryId">Arbitrary request number.</param>
189215
/// <param name="amount">Amount of jettons to burn <b>in elementary units</b>.</param>
190216
/// <param name="responseDestination">Address where to send a response with confirmation of a successful transfer and the rest of the incoming message Toncoins.</param>
191217
/// <param name="customPayload">Optional custom data (which is used by either sender or receiver jetton wallet for inner logic).</param>
192-
/// <returns>Constructed and ready-to-be-sent Message (by editor/owner of <paramref name="sourceJettonAddress"/>).</returns>
218+
/// <returns>Constructed Cell (body of message to send).</returns>
193219
/// <remarks>
194220
/// <para>Your Jetton wallet address must already be deployed and active, and contain enough jettons to send.</para>
195221
/// </remarks>
196222
/// <seealso href="https://github.com/ton-blockchain/TEPs/blob/master/text/0074-jettons-standard.md#2-burn">Burn message in TEP</seealso>
197-
public Message CreateBurnMessage(
198-
string sourceJettonAddress,
223+
public Cell CreateBurnCell(
199224
ulong queryId,
200225
BigInteger amount,
201226
string responseDestination,
202227
Cell? customPayload)
203228
{
204-
var body = new CellBuilder()
229+
return new CellBuilder()
205230
.StoreUInt(OPBurn)
206231
.StoreULong(queryId)
207232
.StoreCoins(amount)
208233
.StoreAddressIntStd(responseDestination)
209234
.StoreDict(customPayload)
210-
;
235+
.Build();
236+
}
237+
238+
/// <summary>
239+
/// Creates message that will burn specified amount of jettons.
240+
/// </summary>
241+
/// <param name="sourceJettonAddress">Jetton wallet address to send coins from (use <see cref="GetWalletAddress">GetWalletAddress</see> if needed).</param>
242+
/// <param name="queryId">Arbitrary request number.</param>
243+
/// <param name="amount">Amount of jettons to burn <b>in elementary units</b>.</param>
244+
/// <param name="responseDestination">Address where to send a response with confirmation of a successful transfer and the rest of the incoming message Toncoins.</param>
245+
/// <param name="customPayload">Optional custom data (which is used by either sender or receiver jetton wallet for inner logic).</param>
246+
/// <returns>Constructed and ready-to-be-sent Message (by editor/owner of <paramref name="sourceJettonAddress"/>).</returns>
247+
/// <remarks>
248+
/// <para>Your Jetton wallet address must already be deployed and active, and contain enough jettons to send.</para>
249+
/// </remarks>
250+
/// <seealso href="https://github.com/ton-blockchain/TEPs/blob/master/text/0074-jettons-standard.md#2-burn">Burn message in TEP</seealso>
251+
public Message CreateBurnMessage(
252+
string sourceJettonAddress,
253+
ulong queryId,
254+
BigInteger amount,
255+
string responseDestination,
256+
Cell? customPayload)
257+
{
258+
var body = CreateBurnCell(queryId, amount, responseDestination, customPayload);
211259

212260
return new Message(new AccountAddress(sourceJettonAddress))
213261
{
214262
Amount = TonUtils.Coins.ToNano(DefaultAmount),
215-
Data = new DataRaw(new Boc(body.Build()).SerializeToBase64(), string.Empty),
263+
Data = new DataRaw(new Boc(body).SerializeToBase64(), string.Empty),
216264
SendMode = DefaultSendMode,
217265
};
218266
}

0 commit comments

Comments
 (0)