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
6 changes: 3 additions & 3 deletions clients/js-legacy/src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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
*
Expand All @@ -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);
Expand Down
19 changes: 19 additions & 0 deletions clients/js-legacy/test/longRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]));
}
});
});
Loading