Skip to content

Commit f706753

Browse files
authored
feat: add query_id to sdk (#37)
1 parent 5def009 commit f706753

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

types/messages.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,16 @@ import { Address, beginCell, Builder, Cell, Slice } from '@ton/core';
22
import { GatewayOp } from './types';
33
import { evmAddressToSlice } from './utils';
44

5-
// op code, query id (0)
6-
function newIntent(op: GatewayOp): Builder {
7-
return beginCell().storeUint(op, 32).storeUint(0, 64);
5+
const uint64Min = 0n;
6+
const uint64Max = (1n << 64n) - 1n;
7+
8+
// operation code + query id
9+
function newIntent(op: GatewayOp, queryId: bigint = 0n): Builder {
10+
if (queryId < uint64Min || queryId > uint64Max) {
11+
throw new Error('Query ID must be between 0 and 2^64 - 1');
12+
}
13+
14+
return beginCell().storeUint(op, 32).storeUint(queryId, 64);
815
}
916

1017
/**
@@ -20,13 +27,13 @@ export function messageDonation(): Cell {
2027
* @param zevmRecipient - EVM recipient address
2128
* @returns Cell
2229
*/
23-
export function messageDeposit(zevmRecipient: string | bigint): Cell {
30+
export function messageDeposit(zevmRecipient: string | bigint, queryId: bigint = 0n): Cell {
2431
// accept bigInt or hex string
2532
if (typeof zevmRecipient === 'string') {
2633
zevmRecipient = BigInt(zevmRecipient);
2734
}
2835

29-
return newIntent(GatewayOp.Deposit)
36+
return newIntent(GatewayOp.Deposit, queryId)
3037
.storeUint(zevmRecipient, 160) // 20 bytes
3138
.endCell();
3239
}
@@ -37,13 +44,17 @@ export function messageDeposit(zevmRecipient: string | bigint): Cell {
3744
* @param callData - Call data
3845
* @returns Cell
3946
*/
40-
export function messageDepositAndCall(zevmRecipient: string | bigint, callData: Cell): Cell {
47+
export function messageDepositAndCall(
48+
zevmRecipient: string | bigint,
49+
callData: Cell,
50+
queryId: bigint = 0n,
51+
): Cell {
4152
// accept bigInt or hex string
4253
if (typeof zevmRecipient === 'string') {
4354
zevmRecipient = BigInt(zevmRecipient);
4455
}
4556

46-
return newIntent(GatewayOp.DepositAndCall)
57+
return newIntent(GatewayOp.DepositAndCall, queryId)
4758
.storeUint(zevmRecipient, 160) // 20 bytes
4859
.storeRef(callData)
4960
.endCell();

0 commit comments

Comments
 (0)