Merge pull request #1618 from flicker-harmony/pr_balance_fix

Fix balance and add cross-shard txs
pull/1623/head
Rongjian Lan 5 years ago committed by GitHub
commit 59a8e6980b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      api/service/explorer/service.go
  2. 8
      api/service/explorer/structs.go
  3. 4
      node/contract.go

@ -695,7 +695,6 @@ func (s *Service) GetExplorerAddress(w http.ResponseWriter, r *http.Request) {
balance, err := s.GetAccountBalance(address) balance, err := s.GetAccountBalance(address)
if err == nil { if err == nil {
balanceAddr = balance balanceAddr = balance
data.Address.Balance = balance
} }
} }

@ -57,6 +57,9 @@ type Transaction struct {
Value *big.Int `json:"value"` Value *big.Int `json:"value"`
Bytes string `json:"bytes"` Bytes string `json:"bytes"`
Data string `json:"data"` Data string `json:"data"`
GasFee *big.Int `json:"gasFee"`
FromShard uint32 `json:"fromShard"`
ToShard uint32 `json:"toShard"`
Type string `json:"type"` Type string `json:"type"`
} }
@ -118,6 +121,8 @@ func GetTransaction(tx *types.Transaction, addressBlock *types.Block) *Transacti
if err != nil { if err != nil {
utils.Logger().Error().Err(err).Msg("Error when parsing tx into message") 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()))
return &Transaction{ return &Transaction{
ID: tx.Hash().Hex(), ID: tx.Hash().Hex(),
Timestamp: strconv.Itoa(int(addressBlock.Time().Int64() * 1000)), Timestamp: strconv.Itoa(int(addressBlock.Time().Int64() * 1000)),
@ -126,6 +131,9 @@ func GetTransaction(tx *types.Transaction, addressBlock *types.Block) *Transacti
Value: msg.Value(), Value: msg.Value(),
Bytes: strconv.Itoa(int(tx.Size())), Bytes: strconv.Itoa(int(tx.Size())),
Data: hex.EncodeToString(tx.Data()), Data: hex.EncodeToString(tx.Data()),
GasFee: gasFee,
FromShard: tx.ShardID(),
ToShard: tx.ToShardID(),
Type: "", Type: "",
} }
} }

@ -150,7 +150,9 @@ func (node *Node) GetBalanceOfAddress(address common.Address) (*big.Int, error)
utils.Logger().Error().Err(err).Msg("Failed to get chain state") utils.Logger().Error().Err(err).Msg("Failed to get chain state")
return nil, err return nil, err
} }
return state.GetBalance(address), nil balance := big.NewInt(0)
balance.SetBytes(state.GetBalance(address).Bytes())
return balance, nil
} }
// AddFaucetContractToPendingTransactions adds the faucet contract the genesis block. // AddFaucetContractToPendingTransactions adds the faucet contract the genesis block.

Loading…
Cancel
Save