Skip to content

Add codec for TransactionMeta to enable more efficient data transfer and storage. #1140

@joefitter

Description

@joefitter

Motivation

When requesting a base64 tx via RPC, the transaction is encoded as base64, however meta is provided in a fully-inflated format. The issue with this is any service that wishes to cache the result of getTransaction needs to implement JSON.stringify and JSON.parse replace functions to handle BigInts etc, and the size of the stored result is v large.

Also when parsing using plain JSON the branded types (Lamports, Address etc) are lost.

Example use case

/*
 *  {
 *    transaction: Base64EncodedDataResponse,
 *    meta: Base64EncodedDataResponse
 *  }
 */
const result = await client.rpc.getTransaction(txSignature, { encoding: "base64", encodeMeta: true }).send();
await env.CACHE.put(txSignature, JSON.stringify(result));

const { transaction, meta } = JSON.parse(await env.CACHE.get(txSignature));
const encodedMeta = getBase64Encoder().encode(meta)
const decodedMeta = getTransactionMetaDecoder().decode(encodedMeta);

// decodedMeta has the same data structure as would have been received by `rpc.getTransaction(sig, { encoding: 'json' })`

Details

A transactionMetaCodec would need to be added to encode and decode transaction meta from an array of bytes.

The functionality should be opt-in so as to not break existing implementations (encodeMeta flag or similar)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions