From 109d28550b552a5cf55b7226a474bdf898d9864d Mon Sep 17 00:00:00 2001 From: Iamsohungrynow <261225237+Iamsohungrynow@users.noreply.github.com> Date: Sat, 7 Nov 2026 01:47:31 +0800 Subject: [PATCH 1/2] js-legacy: Size the record account for the offset in createInitializeWriteRecord --- clients/js-legacy/src/actions.ts | 2 +- clients/js-legacy/test/longRecord.ts | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/clients/js-legacy/src/actions.ts b/clients/js-legacy/src/actions.ts index 710435a..c62b2bf 100644 --- a/clients/js-legacy/src/actions.ts +++ b/clients/js-legacy/src/actions.ts @@ -115,7 +115,7 @@ export async function createInitializeWriteRecord( confirmOptions?: ConfirmOptions, programId = RECORD_PROGRAM_ID, ) { - const recordSize = buffer.length; + const recordSize = Number(offset) + buffer.length; const recordAccountSize = RECORD_META_DATA_SIZE + recordSize; const lamports = await connection.getMinimumBalanceForRentExemption(recordAccountSize); const firstChunkBuffer = buffer.subarray(0, RECORD_CHUNK_SIZE_PRE_INITIALIZE); diff --git a/clients/js-legacy/test/longRecord.ts b/clients/js-legacy/test/longRecord.ts index 66d7c19..da5142e 100644 --- a/clients/js-legacy/test/longRecord.ts +++ b/clients/js-legacy/test/longRecord.ts @@ -29,4 +29,23 @@ describe('long record data', () => { expect(recordAccountData.recordData).to.eql(recordData); } }); + + it('initialize and write at an offset', async () => { + const offsetRecordAccount = Keypair.generate(); + const offset = 10; + await createInitializeWriteRecord( + connection, + payer, + offsetRecordAccount, + recordAuthority, + BigInt(offset), + recordData, + ); + + const recordAccountData = await getRecordAccount(connection, offsetRecordAccount.publicKey); + expect(recordAccountData).to.not.equal(null); + if (recordAccountData !== null) { + expect(recordAccountData.recordData).to.eql(Buffer.concat([Buffer.alloc(offset), recordData])); + } + }); }); From 99a0c9a1364ea9a0f5b4070ad8c590103eb2bd9b Mon Sep 17 00:00:00 2001 From: Iamsohungrynow <261225237+Iamsohungrynow@users.noreply.github.com> Date: Sun, 8 Nov 2026 19:56:33 +0800 Subject: [PATCH 2/2] js-legacy: Rename the offset param in the JSDoc --- clients/js-legacy/src/actions.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clients/js-legacy/src/actions.ts b/clients/js-legacy/src/actions.ts index c62b2bf..26c43b8 100644 --- a/clients/js-legacy/src/actions.ts +++ b/clients/js-legacy/src/actions.ts @@ -57,7 +57,7 @@ export async function createRecord( * @param payer Payer of the transaction fees * @param record Record account address * @param authority Record account authority keypair - * @param recordSize Offset to store the record bytes + * @param offset Offset to store the record bytes * @param buffer Record bytes * @param confirmOptions Options for confirming the transaction * @@ -99,7 +99,7 @@ export async function writeRecord( * @param payer Payer of the transaction fees * @param record Record account signer * @param authority Record account authority keypair - * @param recordSize Offset to store the record bytes + * @param offset Offset to store the record bytes; the record is sized to `offset + buffer.length` * @param buffer Record bytes * @param confirmOptions Options for confirming the transaction *