diff --git a/clients/js-legacy/src/actions.ts b/clients/js-legacy/src/actions.ts index 710435a..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 * @@ -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])); + } + }); });