anza-xyz / anza-xyz/kit

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

Open
#1,140 2 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
TypeScript
Stars
695
Forks
210
Avg merge
21h 33m
Merged PRs (30d)
90

Description

## 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

```ts
/*
* {
* 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)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.