Merge branch 'master' of https://github.com/harmony-one/harmony into txhistory_fulltx

pull/1687/head
flicker-harmony 5 years ago
commit 690b2f0be5
  1. 6
      api/service/explorer/storage.go
  2. 21
      api/service/explorer/structs.go
  3. 2
      internal/hmyapi/blockchain.go
  4. 17
      internal/hmyapi/transactionpool.go
  5. 32
      internal/hmyapi/types.go

@ -112,10 +112,6 @@ func (storage *Storage) Dump(block *types.Block, height uint64) {
// Store txs
for _, tx := range block.Transactions() {
if tx.To() == nil {
continue
}
explorerTransaction := GetTransaction(tx, block)
storage.UpdateTXStorage(batch, explorerTransaction, tx)
storage.UpdateAddress(batch, explorerTransaction, tx)
@ -158,7 +154,9 @@ func (storage *Storage) UpdateTXStorage(batch ethdb.Batch, explorerTransaction *
// TODO: deprecate this logic
func (storage *Storage) UpdateAddress(batch ethdb.Batch, explorerTransaction *Transaction, tx *types.Transaction) {
explorerTransaction.Type = Received
if explorerTransaction.To != "" {
storage.UpdateAddressStorage(batch, explorerTransaction.To, explorerTransaction, tx)
}
explorerTransaction.Type = Sent
storage.UpdateAddressStorage(batch, explorerTransaction.From, explorerTransaction, tx)
}

@ -5,10 +5,8 @@ import (
"math/big"
"strconv"
"github.com/ethereum/go-ethereum/common"
"github.com/harmony-one/harmony/core/types"
common2 "github.com/harmony-one/harmony/internal/common"
"github.com/harmony-one/harmony/internal/common"
"github.com/harmony-one/harmony/internal/utils"
)
@ -114,20 +112,27 @@ func NewBlock(block *types.Block, height int) *Block {
// GetTransaction ...
func GetTransaction(tx *types.Transaction, addressBlock *types.Block) *Transaction {
if tx.To() == nil {
return nil
}
msg, err := tx.AsMessage(types.NewEIP155Signer(tx.ChainID()))
if err != nil {
utils.Logger().Error().Err(err).Msg("Error when parsing tx into message")
}
gasFee := big.NewInt(0)
gasFee = gasFee.Mul(tx.GasPrice(), new(big.Int).SetUint64(tx.Gas()))
to := ""
if msg.To() != nil {
if to, err = common.AddressToBech32(*msg.To()); err != nil {
return nil
}
}
from := ""
if from, err = common.AddressToBech32(msg.From()); err != nil {
return nil
}
return &Transaction{
ID: tx.Hash().Hex(),
Timestamp: strconv.Itoa(int(addressBlock.Time().Int64() * 1000)),
From: common2.MustAddressToBech32(common.HexToAddress(msg.From().Hex())),
To: common2.MustAddressToBech32(common.HexToAddress(msg.To().Hex())),
From: from,
To: to,
Value: msg.Value(),
Bytes: strconv.Itoa(int(tx.Size())),
Data: hex.EncodeToString(tx.Data()),

@ -58,7 +58,7 @@ func (s *PublicBlockChainAPI) GetBlockByNumber(ctx context.Context, blockNr rpc.
func (s *PublicBlockChainAPI) GetBlockByHash(ctx context.Context, blockHash common.Hash, fullTx bool) (map[string]interface{}, error) {
block, err := s.b.GetBlock(ctx, blockHash)
if block != nil {
return RPCMarshalBlock(block, false, false)
return RPCMarshalBlock(block, true, fullTx)
}
return nil, err
}

@ -201,15 +201,11 @@ func (s *PublicTransactionPoolAPI) GetTransactionReceipt(ctx context.Context, ha
if tx.Protected() {
signer = types.NewEIP155Signer(tx.ChainID())
}
from, _ := types.Sender(signer, tx)
fields := map[string]interface{}{
"blockHash": blockHash,
"blockNumber": hexutil.Uint64(blockNumber),
"transactionHash": hash,
"transactionIndex": hexutil.Uint64(index),
"from": from,
"to": tx.To(),
"shardID": tx.ShardID(),
"gasUsed": hexutil.Uint64(receipt.GasUsed),
"cumulativeGasUsed": hexutil.Uint64(receipt.CumulativeGasUsed),
@ -217,7 +213,18 @@ func (s *PublicTransactionPoolAPI) GetTransactionReceipt(ctx context.Context, ha
"logs": receipt.Logs,
"logsBloom": receipt.Bloom,
}
from, _ := types.Sender(signer, tx)
fields["from"] = from
if tx.To() != nil {
fields["to"], err = internal_common.AddressToBech32(*tx.To())
if err != nil {
return nil, err
}
fields["from"], err = internal_common.AddressToBech32(from)
if err != nil {
return nil, err
}
}
// Assign receipt status or post state.
if len(receipt.PostState) > 0 {
fields["root"] = hexutil.Bytes(receipt.PostState)

@ -3,6 +3,7 @@ package hmyapi
import (
"encoding/hex"
"math/big"
"strings"
"time"
"github.com/ethereum/go-ethereum/common"
@ -10,7 +11,7 @@ import (
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/harmony-one/harmony/block"
"github.com/harmony-one/harmony/core/types"
common2 "github.com/harmony-one/harmony/internal/common"
internal_common "github.com/harmony-one/harmony/internal/common"
)
// RPCTransaction represents a transaction that will serialize to the RPC representation of a transaction
@ -78,7 +79,7 @@ func newHeaderInformation(header *block.Header) *HeaderInformation {
sig := header.LastCommitSignature()
result.LastCommitSig = hex.EncodeToString(sig[:])
bechAddr, err := common2.AddressToBech32(header.Coinbase())
bechAddr, err := internal_common.AddressToBech32(header.Coinbase())
if err != nil {
bechAddr = header.Coinbase().Hex()
}
@ -101,13 +102,15 @@ func newRPCCXReceipt(cx *types.CXReceipt, blockHash common.Hash, blockNumber uin
result.BlockNumber = (*hexutil.Big)(new(big.Int).SetUint64(blockNumber))
}
fromAddr, err := common2.AddressToBech32(cx.From)
fromAddr, err := internal_common.AddressToBech32(cx.From)
if err != nil {
fromAddr = cx.From.Hex()
return nil
}
toAddr := ""
if cx.To != nil {
if toAddr, err = internal_common.AddressToBech32(*cx.To); err != nil {
return nil
}
toAddr, err := common2.AddressToBech32(*cx.To)
if err != nil {
toAddr = (*cx.To).Hex()
}
result.From = fromAddr
result.To = toAddr
@ -144,15 +147,20 @@ func newRPCTransaction(tx *types.Transaction, blockHash common.Hash, blockNumber
result.TransactionIndex = hexutil.Uint(index)
}
fromAddr, err := common2.AddressToBech32(from)
fromAddr, err := internal_common.AddressToBech32(from)
if err != nil {
fromAddr = from.Hex()
return nil
}
toAddr, err := common2.AddressToBech32(*tx.To())
if err != nil {
toAddr = (*tx.To()).Hex()
toAddr := ""
if tx.To() != nil {
if toAddr, err = internal_common.AddressToBech32(*tx.To()); err != nil {
return nil
}
result.From = fromAddr
} else {
result.From = strings.ToLower(from.Hex())
}
result.To = toAddr
return result

Loading…
Cancel
Save