kaspad/infrastructure/network/rpc/handle_get_raw_mempool.go
stasatdaglabs d14809694f
[NOD-1223] Reorganize directory structure (#874)
* [NOD-1223] Delete unused files/packages.

* [NOD-1223] Move signal and limits to the os package.

* [NOD-1223] Put database and dbaccess into the db package.

* [NOD-1223] Fold the logs package into the logger package.

* [NOD-1223] Rename domainmessage to appmessage.

* [NOD-1223] Rename to/from DomainMessage to AppMessage.

* [NOD-1223] Move appmessage to the app packge.

* [NOD-1223] Move protocol to the app packge.

* [NOD-1223] Move the network package to the infrastructure packge.

* [NOD-1223] Rename cmd to executables.

* [NOD-1223] Fix go.doc in the logger package.
2020-08-18 10:26:39 +03:00

59 lines
1.6 KiB
Go

package rpc
import (
"github.com/kaspanet/kaspad/infrastructure/network/rpc/model"
"github.com/kaspanet/kaspad/util"
)
// handleGetRawMempool implements the getRawMempool command.
func handleGetRawMempool(s *Server, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) {
c := cmd.(*model.GetRawMempoolCmd)
mp := s.txMempool
if c.Verbose != nil && *c.Verbose {
return rawMempoolVerbose(s), nil
}
// The response is simply an array of the transaction hashes if the
// verbose flag is not set.
descs := mp.TxDescs()
hashStrings := make([]string, len(descs))
for i := range hashStrings {
hashStrings[i] = descs[i].Tx.ID().String()
}
return hashStrings, nil
}
// rawMempoolVerbose returns all of the entries in the mempool as a fully
// populated jsonrpc result.
func rawMempoolVerbose(s *Server) map[string]*model.GetRawMempoolVerboseResult {
descs := s.txMempool.TxDescs()
result := make(map[string]*model.GetRawMempoolVerboseResult, len(descs))
for _, desc := range descs {
// Calculate the current priority based on the inputs to
// the transaction. Use zero if one or more of the
// input transactions can't be found for some reason.
tx := desc.Tx
mpd := &model.GetRawMempoolVerboseResult{
Size: int32(tx.MsgTx().SerializeSize()),
Fee: util.Amount(desc.Fee).ToKAS(),
Time: desc.Added.UnixMilliseconds(),
Depends: make([]string, 0),
}
for _, txIn := range tx.MsgTx().TxIn {
txID := &txIn.PreviousOutpoint.TxID
if s.txMempool.HaveTransaction(txID) {
mpd.Depends = append(mpd.Depends,
txID.String())
}
}
result[tx.ID().String()] = mpd
}
return result
}