Skip to content

Commit

Permalink
summary field on transaction info idb table
Browse files Browse the repository at this point in the history
  • Loading branch information
TalDerei committed Feb 21, 2025
1 parent d3fb1f8 commit 8291e28
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/protobuf/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"gen:ibc": "buf generate buf.build/cosmos/ibc:7ab44ae956a0488ea04e04511efa5f70",
"gen:ics23": "buf generate buf.build/cosmos/ics23:55085f7c710a45f58fa09947208eb70b",
"gen:noble": "buf generate buf.build/noble-assets/forwarding:5a8609a6772d417584a9c60cd8b80881",
"gen:penumbra": "buf generate buf.build/penumbra-zone/penumbra:ae2300bce202a7d429727f1340e7412d3b9f810c",
"gen:penumbra": "buf generate buf.build/penumbra-zone/penumbra:f6682d4ef839bb06e2da4fae487eb9d565ea04d6",
"lint": "eslint src",
"lint:fix": "eslint src --fix",
"lint:strict": "tsc --noEmit && eslint src --max-warnings 0",
Expand Down
14 changes: 9 additions & 5 deletions packages/services/src/view-service/transaction-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
import { fvkCtx } from '../ctx/full-viewing-key.js';
import {
TransactionPerspective,
TransactionSummary,
TransactionView,
} from '@penumbra-zone/protobuf/penumbra/core/transaction/v1/transaction_pb';

Expand All @@ -27,11 +28,13 @@ export const transactionInfo: Impl['transactionInfo'] = async function* (_req, c
const tx_info = await indexedDb.getTransactionInfo(txRecord.id);
let perspective: TransactionPerspective;
let view: TransactionView;
let summary: TransactionSummary;

// If TxP + TxV already exist in database, then simply yield them.
if (tx_info) {
// If TxP + TxV + summary already exist in database, then simply yield them.
if (tx_info && tx_info.summary) {
perspective = tx_info.perspective;
view = tx_info.view;
summary = tx_info.summary;
// Otherwise, generate the TxP + TxV from the transaction in wasm
// and store them.
} else {
Expand All @@ -41,10 +44,10 @@ export const transactionInfo: Impl['transactionInfo'] = async function* (_req, c
indexedDb.constants(),
);

let tx_summary = await generateTransactionSummary(txv);
console.log('tx_summary: ', tx_summary);
// Generate and save transaction info summary from the TxV.
summary = await generateTransactionSummary(txv);
await indexedDb.saveTransactionInfo(txRecord.id, txp, txv, summary);

await indexedDb.saveTransactionInfo(txRecord.id, txp, txv);
perspective = txp;
view = txv;
}
Expand All @@ -56,6 +59,7 @@ export const transactionInfo: Impl['transactionInfo'] = async function* (_req, c
transaction: txRecord.transaction,
perspective,
view,
summary,
}),
};
}
Expand Down
14 changes: 13 additions & 1 deletion packages/storage/src/indexed-db/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { ValidatorInfo } from '@penumbra-zone/protobuf/penumbra/core/component/s
import {
Transaction,
TransactionPerspective,
TransactionSummary,
TransactionView,
} from '@penumbra-zone/protobuf/penumbra/core/transaction/v1/transaction_pb';
import { bech32mAssetId } from '@penumbra-zone/bech32m/passet';
Expand Down Expand Up @@ -369,14 +370,23 @@ export class IndexedDb implements IndexedDbInterface {
async getTransactionInfo(
id: TransactionId,
): Promise<
{ id: TransactionId; perspective: TransactionPerspective; view: TransactionView } | undefined
| {
id: TransactionId;
perspective: TransactionPerspective;
view: TransactionView;
summary: TransactionSummary | undefined;
}
| undefined
> {
const existingData = await this.db.get('TRANSACTION_INFO', uint8ArrayToBase64(id.inner));
if (existingData) {
return {
id: TransactionId.fromJson(existingData.id, { typeRegistry }),
perspective: TransactionPerspective.fromJson(existingData.perspective, { typeRegistry }),
view: TransactionView.fromJson(existingData.view, { typeRegistry }),
summary: existingData.summary
? TransactionSummary.fromJson(existingData.summary, { typeRegistry })
: undefined,
};
} else {
return undefined;
Expand All @@ -387,12 +397,14 @@ export class IndexedDb implements IndexedDbInterface {
id: TransactionId,
txp: TransactionPerspective,
txv: TransactionView,
summary: TransactionSummary,
): Promise<void> {
assertTransactionId(id);
const value = {
id: id.toJson({ typeRegistry }) as Jsonified<TransactionId>,
perspective: txp.toJson({ typeRegistry }) as Jsonified<TransactionPerspective>,
view: txv.toJson({ typeRegistry }) as Jsonified<TransactionView>,
summary: summary.toJson({ typeRegistry }) as Jsonified<TransactionSummary>,
};
await this.u.update({
table: 'TRANSACTION_INFO',
Expand Down
11 changes: 10 additions & 1 deletion packages/types/src/indexed-db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { AddressIndex, IdentityKey } from '@penumbra-zone/protobuf/penumbra/core
import {
Transaction,
TransactionPerspective,
TransactionSummary,
TransactionView,
} from '@penumbra-zone/protobuf/penumbra/core/transaction/v1/transaction_pb';
import { TransactionId } from '@penumbra-zone/protobuf/penumbra/core/txhash/v1/txhash_pb';
Expand Down Expand Up @@ -168,12 +169,19 @@ export interface IndexedDbInterface {
id: TransactionId,
txp: TransactionPerspective,
txv: TransactionView,
summary: TransactionSummary,
): Promise<void>;

getTransactionInfo(
id: TransactionId,
): Promise<
{ id: TransactionId; perspective: TransactionPerspective; view: TransactionView } | undefined
| {
id: TransactionId;
perspective: TransactionPerspective;
view: TransactionView;
summary: TransactionSummary | undefined;
}
| undefined
>;

getPosition(positionId: PositionId): Promise<Position | undefined>;
Expand Down Expand Up @@ -241,6 +249,7 @@ export interface PenumbraDb extends DBSchema {
id: Jsonified<TransactionId>;
perspective: Jsonified<TransactionPerspective>;
view: Jsonified<TransactionView>;
summary: Jsonified<TransactionSummary>;
};
};
REGISTRY_VERSION: {
Expand Down

0 comments on commit 8291e28

Please sign in to comment.