From 01c76abacd2592a8d9e96cea196383c1f16fe47b Mon Sep 17 00:00:00 2001 From: flicker-harmony Date: Thu, 12 Dec 2019 11:38:59 +0300 Subject: [PATCH 1/3] Add timestamp to transactions json --- internal/hmyapi/types.go | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/internal/hmyapi/types.go b/internal/hmyapi/types.go index d81b7034b..6b258998a 100644 --- a/internal/hmyapi/types.go +++ b/internal/hmyapi/types.go @@ -23,6 +23,7 @@ type RPCTransaction struct { BlockHash common.Hash `json:"blockHash"` BlockNumber *hexutil.Big `json:"blockNumber"` From string `json:"from"` + Timestamp hexutil.Uint64 `json:"timestamp"` Gas hexutil.Uint64 `json:"gas"` GasPrice *hexutil.Big `json:"gasPrice"` Hash common.Hash `json:"hash"` @@ -43,6 +44,7 @@ type RPCStakingTransaction struct { BlockHash common.Hash `json:"blockHash"` BlockNumber *hexutil.Big `json:"blockNumber"` From string `json:"from"` + Timestamp hexutil.Uint64 `json:"timestamp"` Gas hexutil.Uint64 `json:"gas"` GasPrice *hexutil.Big `json:"gasPrice"` Hash common.Hash `json:"hash"` @@ -192,7 +194,7 @@ func newRPCValidator(validator *types2.Validator) *RPCValidator { // newRPCTransaction returns a transaction that will serialize to the RPC // representation, with the given location metadata set (if available). -func newRPCTransaction(tx *types.Transaction, blockHash common.Hash, blockNumber uint64, index uint64) *RPCTransaction { +func newRPCTransaction(tx *types.Transaction, blockHash common.Hash, blockNumber uint64, timestamp uint64, uinindex uint64) *RPCTransaction { var signer types.Signer = types.FrontierSigner{} if tx.Protected() { signer = types.NewEIP155Signer(tx.ChainID()) @@ -208,6 +210,7 @@ func newRPCTransaction(tx *types.Transaction, blockHash common.Hash, blockNumber Value: (*hexutil.Big)(tx.Value()), ShardID: tx.ShardID(), ToShardID: tx.ToShardID(), + Timestamp: hexutil.Uint64(timestamp), V: (*hexutil.Big)(v), R: (*hexutil.Big)(r), S: (*hexutil.Big)(s), @@ -239,7 +242,7 @@ func newRPCTransaction(tx *types.Transaction, blockHash common.Hash, blockNumber // newRPCStakingTransaction returns a transaction that will serialize to the RPC // representation, with the given location metadata set (if available). -func newRPCStakingTransaction(tx *types2.StakingTransaction, blockHash common.Hash, blockNumber uint64, index uint64) *RPCStakingTransaction { +func newRPCStakingTransaction(tx *types2.StakingTransaction, blockHash common.Hash, blockNumber uint64, timestamp uint64, index uint64) *RPCStakingTransaction { from, _ := tx.SenderAddress() v, r, s := tx.RawSignatureValues() @@ -302,15 +305,16 @@ func newRPCStakingTransaction(tx *types2.StakingTransaction, blockHash common.Ha } result := &RPCStakingTransaction{ - Gas: hexutil.Uint64(tx.Gas()), - GasPrice: (*hexutil.Big)(tx.Price()), - Hash: tx.Hash(), - Nonce: hexutil.Uint64(tx.Nonce()), - V: (*hexutil.Big)(v), - R: (*hexutil.Big)(r), - S: (*hexutil.Big)(s), - Type: stakingTxType, - Msg: fields, + Gas: hexutil.Uint64(tx.Gas()), + GasPrice: (*hexutil.Big)(tx.Price()), + Hash: tx.Hash(), + Nonce: hexutil.Uint64(tx.Nonce()), + Timestamp: hexutil.Uint64(timestamp), + V: (*hexutil.Big)(v), + R: (*hexutil.Big)(r), + S: (*hexutil.Big)(s), + Type: stakingTxType, + Msg: fields, } if blockHash != (common.Hash{}) { result.BlockHash = blockHash @@ -448,7 +452,7 @@ func newRPCTransactionFromBlockIndex(b *types.Block, index uint64) *RPCTransacti if index >= uint64(len(txs)) { return nil } - return newRPCTransaction(txs[index], b.Hash(), b.NumberU64(), index) + return newRPCTransaction(txs[index], b.Hash(), b.NumberU64(), b.Time().Uint64(), index) } // newRPCStakingTransactionFromBlockHash returns a transaction that will serialize to the RPC representation. @@ -467,7 +471,7 @@ func newRPCStakingTransactionFromBlockIndex(b *types.Block, index uint64) *RPCSt if index >= uint64(len(txs)) { return nil } - return newRPCStakingTransaction(txs[index], b.Hash(), b.NumberU64(), index) + return newRPCStakingTransaction(txs[index], b.Hash(), b.NumberU64(), b.Time().Uint64(), index) } // CallArgs represents the arguments for a call. From 4aad0e20a93d1ecadf0e4e4f72abd4d9dd02559a Mon Sep 17 00:00:00 2001 From: flicker-harmony Date: Thu, 12 Dec 2019 21:03:22 +0300 Subject: [PATCH 2/3] Fix travis --- internal/hmyapi/transactionpool.go | 12 ++++++++++-- internal/hmyapi/types.go | 4 ++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/internal/hmyapi/transactionpool.go b/internal/hmyapi/transactionpool.go index a30dcbd07..d81931c66 100644 --- a/internal/hmyapi/transactionpool.go +++ b/internal/hmyapi/transactionpool.go @@ -110,8 +110,12 @@ func (s *PublicTransactionPoolAPI) GetTransactionByBlockHashAndIndex(ctx context func (s *PublicTransactionPoolAPI) GetTransactionByHash(ctx context.Context, hash common.Hash) *RPCTransaction { // Try to return an already finalized transaction tx, blockHash, blockNumber, index := rawdb.ReadTransaction(s.b.ChainDb(), hash) + block, _ := s.b.GetBlock(ctx, blockHash) + if block != nil { + return nil + } if tx != nil { - return newRPCTransaction(tx, blockHash, blockNumber, index) + return newRPCTransaction(tx, blockHash, blockNumber, block.Time().Uint64(), index) } // No finalized transaction, try to retrieve it from the pool if tx = s.b.GetPoolTransaction(hash); tx != nil { @@ -125,8 +129,12 @@ func (s *PublicTransactionPoolAPI) GetTransactionByHash(ctx context.Context, has func (s *PublicTransactionPoolAPI) GetStakingTransactionByHash(ctx context.Context, hash common.Hash) *RPCStakingTransaction { // Try to return an already finalized transaction stx, blockHash, blockNumber, index := rawdb.ReadStakingTransaction(s.b.ChainDb(), hash) + block, _ := s.b.GetBlock(ctx, blockHash) + if block != nil { + return nil + } if stx != nil { - return newRPCStakingTransaction(stx, blockHash, blockNumber, index) + return newRPCStakingTransaction(stx, blockHash, blockNumber, block.Time().Uint64(), index) } return nil } diff --git a/internal/hmyapi/types.go b/internal/hmyapi/types.go index 6b258998a..61cf1c488 100644 --- a/internal/hmyapi/types.go +++ b/internal/hmyapi/types.go @@ -194,7 +194,7 @@ func newRPCValidator(validator *types2.Validator) *RPCValidator { // newRPCTransaction returns a transaction that will serialize to the RPC // representation, with the given location metadata set (if available). -func newRPCTransaction(tx *types.Transaction, blockHash common.Hash, blockNumber uint64, timestamp uint64, uinindex uint64) *RPCTransaction { +func newRPCTransaction(tx *types.Transaction, blockHash common.Hash, blockNumber uint64, timestamp uint64, index uint64) *RPCTransaction { var signer types.Signer = types.FrontierSigner{} if tx.Protected() { signer = types.NewEIP155Signer(tx.ChainID()) @@ -333,7 +333,7 @@ func newRPCStakingTransaction(tx *types2.StakingTransaction, blockHash common.Ha // newRPCPendingTransaction returns a pending transaction that will serialize to the RPC representation func newRPCPendingTransaction(tx *types.Transaction) *RPCTransaction { - return newRPCTransaction(tx, common.Hash{}, 0, 0) + return newRPCTransaction(tx, common.Hash{}, 0, 0, 0) } // RPCBlock represents a block that will serialize to the RPC representation of a block From a7b2617f10833b6495f71f66189a62479b3f98c3 Mon Sep 17 00:00:00 2001 From: flicker-harmony Date: Thu, 12 Dec 2019 21:41:21 +0300 Subject: [PATCH 3/3] Fix jenkins --- internal/hmyapi/transactionpool.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/hmyapi/transactionpool.go b/internal/hmyapi/transactionpool.go index d81931c66..f3a220f8c 100644 --- a/internal/hmyapi/transactionpool.go +++ b/internal/hmyapi/transactionpool.go @@ -111,7 +111,7 @@ func (s *PublicTransactionPoolAPI) GetTransactionByHash(ctx context.Context, has // Try to return an already finalized transaction tx, blockHash, blockNumber, index := rawdb.ReadTransaction(s.b.ChainDb(), hash) block, _ := s.b.GetBlock(ctx, blockHash) - if block != nil { + if block == nil { return nil } if tx != nil { @@ -130,7 +130,7 @@ func (s *PublicTransactionPoolAPI) GetStakingTransactionByHash(ctx context.Conte // Try to return an already finalized transaction stx, blockHash, blockNumber, index := rawdb.ReadStakingTransaction(s.b.ChainDb(), hash) block, _ := s.b.GetBlock(ctx, blockHash) - if block != nil { + if block == nil { return nil } if stx != nil {