Merge pull request #1687 from flicker-harmony/pr_txhistory_fulltx

Add transactions history api with full tx info
pull/1690/head
flicker-harmony 5 years ago committed by GitHub
commit 49090cd242
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 21
      internal/hmyapi/transactionpool.go
  2. 3
      internal/hmyapi/util.go

@ -20,6 +20,7 @@ type TxHistoryArgs struct {
Address string `json:"address"`
Offset int `json:"offset"`
Page int `json:"page"`
FullTx bool `json:"fullTx"`
}
// PublicTransactionPoolAPI exposes methods for the RPC interface
@ -34,25 +35,35 @@ func NewPublicTransactionPoolAPI(b Backend, nonceLock *AddrLocker) *PublicTransa
}
// GetTransactionsHistory returns the list of transactions hashes that involve a particular address.
func (s *PublicTransactionPoolAPI) GetTransactionsHistory(ctx context.Context, args TxHistoryArgs) ([]common.Hash, error) {
func (s *PublicTransactionPoolAPI) GetTransactionsHistory(ctx context.Context, args TxHistoryArgs) (map[string]interface{}, error) {
address := args.Address
result := []common.Hash{}
if strings.HasPrefix(address, "one1") {
result, err := s.b.GetTransactionsHistory(address)
hashes, err := s.b.GetTransactionsHistory(address)
if err != nil {
return nil, err
}
return ReturnWithPagination(result, args), nil
result = ReturnWithPagination(hashes, args)
}
addr := internal_common.ParseAddr(address)
oneAddress, err := internal_common.AddressToBech32(addr)
if err != nil {
return nil, err
}
result, err := s.b.GetTransactionsHistory(oneAddress)
hashes, err := s.b.GetTransactionsHistory(oneAddress)
if err != nil {
return nil, err
}
return ReturnWithPagination(result, args), nil
result = ReturnWithPagination(hashes, args)
if !args.FullTx {
return map[string]interface{}{"transactions": result}, nil
}
txs := []*RPCTransaction{}
for _, hash := range result {
tx := s.GetTransactionByHash(ctx, hash)
txs = append(txs, tx)
}
return map[string]interface{}{"transactions": txs}, nil
}
// GetBlockTransactionCountByNumber returns the number of transactions in the block with the given block number.

@ -23,6 +23,9 @@ func ReturnWithPagination(hashes []common.Hash, args TxHistoryArgs) []common.Has
if args.Offset > 0 {
offset = args.Offset
}
if offset*page >= len(hashes) {
return make([]common.Hash, 0)
}
if offset*page+offset > len(hashes) {
return hashes[offset*page:]
}

Loading…
Cancel
Save