Skip to content

Commit b4dff8a

Browse files
refactor: inlined logs preparation into encodeReceiptToHex (#4892)
Signed-off-by: Bartosz Solka <bartosz.solka@blockydevs.com>
1 parent d5f1615 commit b4dff8a

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

packages/relay/src/lib/factories/transactionReceiptFactory.ts

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,17 @@ class TransactionReceiptFactory {
183183
? new Uint8Array(0)
184184
: hexToBytes(prepend0x(BigInt(cumulativeGasUsed).toString(16))); // canonical RLP encoding (no leading zeros)
185185

186+
const receiptLogsParam = receipt.logs.map((log) => [
187+
hexToBytes(log.address),
188+
log.topics.map((t) => hexToBytes(t)),
189+
hexToBytes(log.data),
190+
]);
191+
186192
const encodedList = RLP.encode([
187193
receiptRootOrStatus,
188194
cumulativeGasUsedBytes,
189195
hexToBytes(receipt.logsBloom),
190-
this.encodeLogsForReceipt(receipt.logs),
196+
receiptLogsParam,
191197
]);
192198

193199
if (txType === 0) {
@@ -196,19 +202,6 @@ class TransactionReceiptFactory {
196202
const withPrefix = concatBytes(intToBytes(txType), encodedList);
197203
return prepend0x(toHexString(withPrefix));
198204
}
199-
200-
/**
201-
* Converts receipt logs into the RLP encoded log structure.
202-
*
203-
* Each log becomes a 3-tuple [address, topics[], data] per the Yellow Paper
204-
* (address and data as bytes; topics as array of 32-byte topic hashes).
205-
*
206-
* @param logs - The logs array from the transaction receipt (see {@link Log}).
207-
* @returns Array of [address, topics, data] as Uint8Arrays for RLP encoding.
208-
*/
209-
private static encodeLogsForReceipt(logs: Log[]): [Uint8Array, Uint8Array[], Uint8Array][] {
210-
return logs.map((log) => [hexToBytes(log.address), log.topics.map((t) => hexToBytes(t)), hexToBytes(log.data)]);
211-
}
212205
}
213206

214207
export { ISyntheticTransactionReceiptParams, IRegularTransactionReceiptParams, TransactionReceiptFactory };

0 commit comments

Comments
 (0)