Skip to content

Commit 18e8e26

Browse files
chore(ton): export token transaction from sdk-coin-ton
TICKET: COIN-5952
1 parent 98a7631 commit 18e8e26

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import * as Interface from './iface';
33

44
export { KeyPair } from './keyPair';
55
export { Transaction } from './transaction';
6+
export { TokenTransaction } from './tokenTransaction';
7+
export { TokenTransferBuilder } from './tokenTransferBuilder';
68
export { TransactionBuilder } from './transactionBuilder';
79
export { TransferBuilder } from './transferBuilder';
810
export { TransactionBuilderFactory } from './transactionBuilderFactory';
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
const { Cell } = require('ton-core');
2+
3+
const base64Hash = 'te6cckECGAEAA7cAAuGIAEJsvDe+uRyHLApBMQWKSrH5ey1Ll2FuzL1ed3ehKlqAG+igSi8vq9BieDi2b6uTXzDiZ+fXM41v7/HeVzPtxoXJ1IEB7VLY5CJZzynIyeO9WxJcswtdLMTIK+HWZf5qkDimpoxf/////AAAAAAADgEXAgE0AhYBFP8A9KQT9LzyyAsDAgEgBBECAUgFCALm0AHQ0wMhcbCSXwTgItdJwSCSXwTgAtMfIYIQcGx1Z70ighBkc3RyvbCSXwXgA/pAMCD6RAHIygfL/8nQ7UTQgQFA1yH0BDBcgQEI9ApvoTGzkl8H4AXTP8glghBwbHVnupI4MOMNA4IQZHN0crqSXwbjDQYHAHgB+gD0BDD4J28iMFAKoSG+8uBQghBwbHVngx6xcIAYUATLBSbPFlj6Ahn0AMtpF8sfUmDLPyDJgED7AAYAilAEgQEI9Fkw7UTQgQFA1yDIAc8W9ADJ7VQBcrCOI4IQZHN0coMesXCAGFAFywVQA88WI/oCE8tqyx/LP8mAQPsAkl8D4gIBIAkQAgEgCg8CAVgLDAA9sp37UTQgQFA1yH0BDACyMoHy//J0AGBAQj0Cm+hMYAIBIA0OABmtznaiaEAga5Drhf/AABmvHfaiaEAQa5DrhY/AABG4yX7UTQ1wsfgAWb0kK29qJoQICga5D6AhhHDUCAhHpJN9KZEM5pA+n/mDeBKAG3gQFImHFZ8xhAT48oMI1xgg0x/TH9MfAvgju/Jk7UTQ0x/TH9P/9ATRUUO68qFRUbryogX5AVQQZPkQ8qP4ACSkyMsfUkDLH1Iwy/9SEPQAye1U+A8B0wchwACfbFGTINdKltMH1AL7AOgw4CHAAeMAIcAC4wABwAORMOMNA6TIyx8Syx/L/xITFBUAbtIH+gDU1CL5AAXIygcVy//J0Hd0gBjIywXLAiLPFlAF+gIUy2sSzMzJc/sAyEAUgQEI9FHypwIAcIEBCNcY+gDTP8hUIEeBAQj0UfKnghBub3RlcHSAGMjLBcsCUAbPFlAE+gIUy2oSyx/LP8lz+wACAGyBAQjXGPoA0z8wUiSBAQj0WfKnghBkc3RycHSAGMjLBcsCUAXPFlAD+gITy2rLHxLLP8lz+wAACvQAye1UAFEAAAAAKamjF6XNqrWPjAy4KJe4VbiiMV+6gGESIHL8rh4HkGQdn55nQAB4YgAaRefBOjTi/hwqDjO7I6nGj9WEAe3ls/rFuBEQvggr6A613oAAAAAAAAAAAAAAAAAAAAAAAB0ZXN0EfFkpA==';
4+
5+
/**
6+
* Traverses a Bag of Cells (BoC) graph to print details of every unique cell.
7+
* @param {string} base64BOC The raw transaction BoC as a base64 string.
8+
*/
9+
function inspectAllCells(base64BOC) {
10+
console.log("=== Inspecting All Unique Cells in BoC ===");
11+
12+
let rootCell;
13+
try {
14+
const rawBuffer = Buffer.from(base64BOC, 'base64');
15+
// Deserialize and get the root cell
16+
rootCell = Cell.fromBoc(rawBuffer)[0];
17+
} catch (e) {
18+
console.error("❌ Error deserializing BoC:", e.message);
19+
return;
20+
}
21+
22+
const cellQueue = [rootCell];
23+
const visitedHashes = new Set();
24+
let index = 0;
25+
26+
while (cellQueue.length > 0) {
27+
// Dequeue the next cell
28+
const cell = cellQueue.shift();
29+
const hash = cell.hash().toString('hex');
30+
31+
// Check if we've already processed this *unique* cell (due to graph structure)
32+
if (visitedHashes.has(hash)) {
33+
continue;
34+
}
35+
visitedHashes.add(hash);
36+
37+
// --- Extracted Cell Metadata ---
38+
const num_refs = cell.refs.length;
39+
const bit_length = cell.bits.length;
40+
// In the C code, this is calculated as: (bit_length / 2) + (bit_length & 1)
41+
const data_bytes = Math.ceil(bit_length / 8);
42+
43+
console.log(`\n--- Cell ${index++} ---`);
44+
console.log(`| Refs: ${num_refs}`);
45+
console.log(`| Bits: ${bit_length}`);
46+
console.log(`| Data Bytes: ${data_bytes} (approximation)`);
47+
console.log(`| Hash: ${hash.substring(0, 16)}...`);
48+
49+
// Peek at the first few bytes of the data slice
50+
try {
51+
// Create a slice to read the first 8 bytes (64 bits)
52+
const cellSlice = cell.beginParse();
53+
const first64BitsHex = cellSlice.loadBuffer(8).toString('hex');
54+
console.log(`| Data (64b): 0x${first64BitsHex}`);
55+
} catch (e) {
56+
console.log(`| Data (64b): (Too small to read 8 bytes)`);
57+
}
58+
59+
60+
// Enqueue the referenced cells to continue traversal
61+
cell.refs.forEach((refCell) => {
62+
const refHash = refCell.hash().toString('hex');
63+
if (!visitedHashes.has(refHash)) {
64+
cellQueue.push(refCell);
65+
}
66+
});
67+
}
68+
69+
console.log(`\n✅ Finished traversal. Total unique cells found: ${index}`);
70+
}
71+
72+
// Run the inspection
73+
inspectAllCells(base64Hash);

0 commit comments

Comments
 (0)