Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions modules/sdk-coin-ton/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,19 @@ export class Utils implements BaseUtils {
const contractAddress = new TonWeb.Address('0:' + TonWeb.utils.bytesToHex(stateInitHash));
return contractAddress.toString(true, true, true);
}

/**
* Converts a TON address into a Base64 encoded BOC (Bag of Cells) string.
* This is required when passing an address as a 'slice' argument to `runGetMethod`.
* @param address - The TON address (friendly or raw)
* @returns Base64 string of the serialized address cell
*/
async getAddressBoc(address: string): Promise<string> {
const cell = new TonWeb.boc.Cell();
cell.bits.writeAddress(new TonWeb.Address(address));
const boc = await cell.toBoc(false);
return TonWeb.utils.bytesToBase64(boc);
}
}

const DUMMY_PRIVATE_KEY = '43e8594854cb53947c4a1a2fab926af11e123f6251dcd5bd0dfb100604186430'; // This dummy private key is used only for fee estimation
Expand Down
6 changes: 6 additions & 0 deletions modules/sdk-coin-ton/test/resources/ton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,9 @@ export const signedTonWhalesFullWithdrawalTransaction = {
'e9565e2211801ecf93f8955513786583367845f293f85430798f931395993829e3ce1b537d63203dddec00e00d6cba76e6def382f1c4ebbdb1737ff1c5f8cf0d',
bounceable: true,
};

export const getMemberStackFixture = {
friendlyAddress: 'EQBkD52LACNxGgaoAxm5Nhs0SN6gg8hNaceNYifev88Y7qoZ',
rawAddress: '0:640f9d8b0023711a06a80319b9361b3448dea083c84d69c78d6227debfcf18ee',
boc: 'te6cckEBAQEAJAAAQ4AMgfOxYARuI0DVAGM3JsNmiRvUEHkJrTjxrET71/njHdDqtWeh',
};
12 changes: 12 additions & 0 deletions modules/sdk-coin-ton/test/unit/ton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,18 @@ describe('TON:', function () {
});
});

describe('getAddressBoc', function () {
it('should return the correct BOC for a friendly address', async function () {
const result = await utils.getAddressBoc(testData.getMemberStackFixture.friendlyAddress);
result.should.equal(testData.getMemberStackFixture.boc);
});

it('should return the correct BOC for a raw address', async function () {
const result = await utils.getAddressBoc(testData.getMemberStackFixture.rawAddress);
result.should.equal(testData.getMemberStackFixture.boc);
});
});

describe('Ton recover - Non-BitGo and Unsigned Sweep Transactions', function () {
let sandbox: sinon.SinonSandbox;
beforeEach(() => {
Expand Down