Skip to content

Commit

Permalink
Merge pull request #304 from oasisprotocol/mitjat/runtime-tx-timestamp
Browse files Browse the repository at this point in the history
/runtime/transactions: Populate the timestamp
  • Loading branch information
mitjat committed Feb 3, 2023
2 parents 87af007 + 5dbb9fc commit 6d3c08e
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 16 deletions.
4 changes: 2 additions & 2 deletions analyzer/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,8 @@ func (qf QueryFactory) RuntimeRelatedTransactionInsertQuery() string {

func (qf QueryFactory) RuntimeTransactionInsertQuery() string {
return fmt.Sprintf(`
INSERT INTO %[1]s.runtime_transactions (runtime, round, tx_index, tx_hash, tx_eth_hash, raw, result_raw)
VALUES ('%[2]s', $1, $2, $3, $4, $5, $6)`, qf.chainID, qf.runtime)
INSERT INTO %[1]s.runtime_transactions (runtime, round, tx_index, tx_hash, tx_eth_hash, timestamp, raw, result_raw)
VALUES ('%[2]s', $1, $2, $3, $4, $5, $6, $7)`, qf.chainID, qf.runtime)
}

func (qf QueryFactory) RuntimeEventInsertQuery() string {
Expand Down
5 changes: 4 additions & 1 deletion analyzer/runtime/incoming.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/hex"
"fmt"
"math/big"
"time"

ethCommon "github.com/ethereum/go-ethereum/common"
"github.com/oasisprotocol/oasis-core/go/common/cbor"
Expand Down Expand Up @@ -78,6 +79,7 @@ type TokenChangeKey struct {

type BlockData struct {
Hash string
Timestamp time.Time
NumTransactions int
GasUsed uint64
Size int
Expand Down Expand Up @@ -227,6 +229,7 @@ func registerTokenDecrease(tokenChanges map[TokenChangeKey]*big.Int, contractAdd
func extractRound(b *block.Block, txrs []*sdkClient.TransactionWithResults, logger *log.Logger) (*BlockData, error) {
var blockData BlockData
blockData.Hash = b.Header.EncodedHash().String()
blockData.Timestamp = time.Unix(int64(b.Header.Timestamp), 0 /* nanos */)
blockData.NumTransactions = len(txrs)
blockData.TransactionData = make([]*BlockTransactionData, 0, len(txrs))
blockData.EventData = []*EventData{}
Expand Down Expand Up @@ -576,7 +579,7 @@ func emitRoundBatch(batch *storage.QueryBatch, qf *analyzer.QueryFactory, round
for addr := range transactionData.RelatedAccountAddresses {
batch.Queue(qf.RuntimeRelatedTransactionInsertQuery(), addr, round, transactionData.Index)
}
batch.Queue(qf.RuntimeTransactionInsertQuery(), round, transactionData.Index, transactionData.Hash, transactionData.EthHash, transactionData.Raw, transactionData.RawResult)
batch.Queue(qf.RuntimeTransactionInsertQuery(), round, transactionData.Index, transactionData.Hash, transactionData.EthHash, blockData.Timestamp, transactionData.Raw, transactionData.RawResult)
}
for _, eventData := range blockData.EventData {
eventRelatedAddresses := common.ExtractAddresses(eventData.RelatedAddresses)
Expand Down
24 changes: 12 additions & 12 deletions api/v1/logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,18 @@ func renderRuntimeTransaction(storageTransaction client.RuntimeTransaction) (api
return apiTypes.RuntimeTransaction{}, fmt.Errorf("body unmarshal: %w", err)
}
apiTransaction := apiTypes.RuntimeTransaction{
Round: storageTransaction.Round,
Index: storageTransaction.Index,
Hash: storageTransaction.Hash,
EthHash: storageTransaction.EthHash,
// TODO: Get timestamp from that round's block
Sender0: sender0,
Nonce0: tx.AuthInfo.SignerInfo[0].Nonce,
Fee: tx.AuthInfo.Fee.Amount.Amount.String(),
GasLimit: tx.AuthInfo.Fee.Gas,
Method: tx.Call.Method,
Body: body,
Success: cr.IsSuccess(),
Round: storageTransaction.Round,
Index: storageTransaction.Index,
Hash: storageTransaction.Hash,
EthHash: storageTransaction.EthHash,
Timestamp: storageTransaction.Timestamp,
Sender0: sender0,
Nonce0: tx.AuthInfo.SignerInfo[0].Nonce,
Fee: tx.AuthInfo.Fee.Amount.Amount.String(),
GasLimit: tx.AuthInfo.Fee.Gas,
Method: tx.Call.Method,
Body: body,
Success: cr.IsSuccess(),
}
if err = uncategorized.VisitCall(&tx.Call, &cr, &uncategorized.CallHandler{
AccountsTransfer: func(body *accounts.Transfer) error {
Expand Down
2 changes: 2 additions & 0 deletions storage/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1002,6 +1002,7 @@ func (c *StorageClient) RuntimeTransactions(ctx context.Context, p apiTypes.GetR
&t.Index,
&t.Hash,
&t.EthHash,
&t.Timestamp,
&t.Raw,
&t.ResultRaw,
); err != nil {
Expand Down Expand Up @@ -1029,6 +1030,7 @@ func (c *StorageClient) RuntimeTransaction(ctx context.Context, txHash string) (
&t.Index,
&t.Hash,
&t.EthHash,
&t.Timestamp,
&t.Raw,
&t.ResultRaw,
)
Expand Down
2 changes: 1 addition & 1 deletion storage/client/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ func (qf QueryFactory) RuntimeBlocksQuery() string {

func (qf QueryFactory) RuntimeTransactionsQuery() string {
return fmt.Sprintf(`
SELECT round, tx_index, tx_hash, tx_eth_hash, raw, result_raw
SELECT round, tx_index, tx_hash, tx_eth_hash, timestamp, raw, result_raw
FROM %[1]s.runtime_transactions
WHERE (runtime = '%[2]s') AND
($1::bigint IS NULL OR round = $1::bigint) AND
Expand Down
3 changes: 3 additions & 0 deletions storage/client/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
package client

import (
"time"

api "github.com/oasisprotocol/oasis-indexer/api/v1/types"
)

Expand Down Expand Up @@ -117,6 +119,7 @@ type RuntimeTransaction struct {
Index int64
Hash string
EthHash *string
Timestamp time.Time
Raw []byte
ResultRaw []byte
}
Expand Down
1 change: 1 addition & 0 deletions storage/migrations/02_oasis_3_runtimes.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ CREATE TABLE oasis_3.runtime_transactions
tx_index UINT31 NOT NULL,
tx_hash HEX64 NOT NULL,
tx_eth_hash HEX64,
timestamp TIMESTAMP WITH TIME ZONE NOT NULL,
-- raw is cbor(UnverifiedTransaction). If you're unable to get a copy of the
-- transaction from the node itself, parse from here. Remove this if we
-- later store sufficiently detailed data in other columns or if we turn out
Expand Down

0 comments on commit 6d3c08e

Please sign in to comment.