Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding batch timestamp to the public tx API #1740

Merged
merged 3 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions go/common/query_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type BlockListingResponse struct {
type PublicTransaction struct {
TransactionHash TxHash
BatchHeight *big.Int
BatchTimestamp uint64
Finality FinalityType
}

Expand Down
11 changes: 9 additions & 2 deletions go/enclave/storage/enclavedb/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const (

isCanonQuery = "select is_canonical from block where hash=?"

queryTxList = "select tx.full_hash, batch.height from exec_tx join batch on batch.sequence=exec_tx.batch join tx on tx.hash=exec_tx.tx where batch.is_canonical=true"
queryTxList = "select tx.full_hash, batch.height, batch.header from exec_tx join batch on batch.sequence=exec_tx.batch join tx on tx.hash=exec_tx.tx where batch.is_canonical=true"
queryTxCountList = "select count(1) from exec_tx join batch on batch.sequence=exec_tx.batch where batch.is_canonical=true"
)

Expand Down Expand Up @@ -509,14 +509,21 @@ func selectPublicTxsBySender(db *sql.DB, query string, args ...any) ([]common.Pu
for rows.Next() {
var txHash []byte
var batchHeight uint64
err := rows.Scan(&txHash, &batchHeight)
var batchHeader string
err := rows.Scan(&txHash, &batchHeight, &batchHeader)
if err != nil {
return nil, err
}

h := new(common.BatchHeader)
if err := rlp.DecodeBytes([]byte(batchHeader), h); err != nil {
return nil, fmt.Errorf("could not decode batch header. Cause: %w", err)
}

publicTxs = append(publicTxs, common.PublicTransaction{
TransactionHash: gethcommon.BytesToHash(txHash),
BatchHeight: big.NewInt(0).SetUint64(batchHeight),
BatchTimestamp: h.Time,
Finality: common.BatchFinal,
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ export function RecentTransactions({ transactions }: { transactions: any }) {
#{transaction?.BatchHeight}
</p>
</div>
<div className="ml-4 space-y-1">
<p className="text-sm font-medium leading-none">
{transaction?.BatchTimestamp}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it work to use {formatTimeAgo(batch?.timestamp)} here, like @Jennievon did in recent-batches.tsx? To get the 'x mins ago' formatting.

</p>
</div>
<div className="ml-auto font-medium">
<TruncatedAddress address={transaction?.TransactionHash} />
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,24 @@ export const columns: ColumnDef<Transaction>[] = [
enableHiding: false,
},

{
accessorKey: "BatchTimestamp",
header: ({ column }) => (
<DataTableColumnHeader column={column} title="BatchTimestamp" />
),
cell: ({ row }) => {
return (
<div className="flex space-x-2">
<span className="max-w-[500px] truncate">
{row.getValue("BatchTimestamp")}
</span>
</div>
);
},
enableSorting: false,
enableHiding: false,
},
otherview marked this conversation as resolved.
Show resolved Hide resolved

{
accessorKey: "TransactionHash",
header: ({ column }) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export type Transaction = {
Id: string;
label: string;
BatchHeight: number;
BatchTimestamp: number;
Finality: string;
TransactionHash: string;
};
Expand Down
Loading