Skip to content

Commit c37022a

Browse files
authored
refactor(sdk-coin-ton): add support to use custom sub wallet id
2 parents 3b71a2a + 4441ab1 commit c37022a

File tree

5 files changed

+21
-3
lines changed

5 files changed

+21
-3
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
export const VESTING_CONTRACT_WALLET_ID = 268;
12
export const WALLET_ID = 698983191;
23
export const JETTON_TRANSFER_OPCODE = 0x0f8a7ea5;
34
export const WITHDRAW_OPCODE = '00001000';

modules/sdk-coin-ton/src/lib/iface.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export interface TxData {
1414
seqno: number;
1515
expirationTime: number;
1616
publicKey: string;
17+
sub_wallet_id: number;
1718
signature: string;
1819
bounceable: boolean;
1920
}

modules/sdk-coin-ton/src/lib/transaction.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Cell } from 'tonweb/dist/types/boc/cell';
55
import { BaseKey, BaseTransaction, Entry, Recipient, TransactionRecipient, TransactionType } from '@bitgo/sdk-core';
66
import { BaseCoin as CoinConfig } from '@bitgo/statics';
77
import { TransactionExplanation, TxData } from './iface';
8-
import { WITHDRAW_OPCODE, WALLET_ID, JETTON_TRANSFER_OPCODE } from './constants';
8+
import { WITHDRAW_OPCODE, WALLET_ID, JETTON_TRANSFER_OPCODE, VESTING_CONTRACT_WALLET_ID } from './constants';
99

1010
export class Transaction extends BaseTransaction {
1111
public recipient: Recipient;
@@ -19,6 +19,7 @@ export class Transaction extends BaseTransaction {
1919
sender: string;
2020
publicKey: string;
2121
isV3ContractMessage: boolean;
22+
sub_wallet_id: number;
2223
protected unsignedMessage: string;
2324
protected finalMessage: string;
2425

@@ -52,6 +53,7 @@ export class Transaction extends BaseTransaction {
5253
amount: this.recipient.amount,
5354
withdrawAmount: this.withdrawAmount,
5455
seqno: this.seqno,
56+
sub_wallet_id: this.sub_wallet_id,
5557
expirationTime: this.expireTime,
5658
publicKey: this.publicKey,
5759
signature: this._signatures[0],
@@ -72,7 +74,14 @@ export class Transaction extends BaseTransaction {
7274
}
7375

7476
async build(): Promise<void> {
75-
const signingMessage = this.createSigningMessage(WALLET_ID, this.seqno, this.expireTime);
77+
if (!this.sub_wallet_id) {
78+
if (this.isV3ContractMessage) {
79+
this.sub_wallet_id = VESTING_CONTRACT_WALLET_ID;
80+
} else {
81+
this.sub_wallet_id = WALLET_ID;
82+
}
83+
}
84+
const signingMessage = this.createSigningMessage(this.sub_wallet_id, this.seqno, this.expireTime);
7685
const sendMode = 3; // default sendMode
7786
signingMessage.bits.writeUint8(sendMode);
7887
const outMsg = this.createOutMsg(this.recipient.address, this.recipient.amount, this.message);
@@ -189,6 +198,7 @@ export class Transaction extends BaseTransaction {
189198
this.message = parsed.payload;
190199
this._signatures.push(parsed.signature);
191200
this.bounceable = parsed.bounce;
201+
this.sub_wallet_id = parsed.walletId;
192202
} catch (e) {
193203
throw new Error('invalid raw transaction');
194204
}
@@ -263,7 +273,7 @@ export class Transaction extends BaseTransaction {
263273
// signing message
264274

265275
const walletId = slice.loadUint(32).toNumber();
266-
if (walletId !== WALLET_ID) throw new Error('invalid walletId');
276+
if (walletId !== WALLET_ID && walletId !== VESTING_CONTRACT_WALLET_ID) throw new Error('invalid walletId');
267277

268278
const expireAt = slice.loadUint(32).toNumber();
269279

modules/sdk-coin-ton/src/lib/transactionBuilder.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,4 +184,8 @@ export abstract class TransactionBuilder extends BaseTransactionBuilder {
184184
this.transaction.isV3ContractMessage = bool;
185185
return this;
186186
}
187+
subWalletId(id: number): TransactionBuilder {
188+
this.transaction.sub_wallet_id = id;
189+
return this;
190+
}
187191
}

modules/sdk-coin-ton/test/unit/transferBuilder.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import TonWeb from 'tonweb';
33
import { TransactionType } from '@bitgo/sdk-core';
44
import { coins } from '@bitgo/statics';
55
import { TransactionBuilderFactory, KeyPair } from '../../src';
6+
import { WALLET_ID } from '../../src/lib/constants';
67
import * as testData from '../resources/ton';
78
import * as utils from '../../src/lib/utils';
89

@@ -258,5 +259,6 @@ describe('Ton Transfer Builder', () => {
258259
jsonTx.seqno.should.equal(3);
259260
jsonTx.expirationTime.should.equal(1761215512);
260261
jsonTx.bounceable.should.equal(true);
262+
jsonTx.sub_wallet_id.should.equal(WALLET_ID);
261263
});
262264
});

0 commit comments

Comments
 (0)