kaspad/rpc/handle_get_raw_mempool.go
stasatdaglabs 3d45c8de50
[NOD-1130] Integrate RPC with the new architecture (#807)
* [NOD-1130] Delete rpcadapters.go.

* [NOD-1130] Delete p2p. Move rpc to top level.

* [NOD-1130] Remove DAGParams from rpcserverConfig.

* [NOD-1130] Remove rpcserverPeer, rpcserverConnManager, rpcserverSyncManager, and rpcserverConfig.

* [NOD-1130] Remove wallet RPC commands.

* [NOD-1130] Remove wallet RPC commands.

* [NOD-1130] Remove connmgr and peer.

* [NOD-1130] Move rpcmodel into rpc.

* [NOD-1130] Implement ConnectionCount.

* [NOD-1130] Remove ping and node RPC commands.

* [NOD-1130] Dummify handleGetNetTotals.

* [NOD-1130] Add NetConnection to Peer.

* [NOD-1130] Fix merge errors.

* [NOD-1130] Implement Peers.

* [NOD-1130] Fix HandleGetConnectedPeerInfo.

* [NOD-1130] Fix SendRawTransaction.

* [NOD-1130] Rename addManualNode to connect and removeManualNode to disconnect.

* [NOD-1130] Add a stub for AddBlock.

* [NOD-1130] Fix tests.

* [NOD-1130] Replace half-baked contents of RemoveConnection with a stub.

* [NOD-1130] Fix merge errors.

* [NOD-1130] Make golint happy.

* [NOD-1130] Get rid of something weird.

* [NOD-1130] Rename minerClient back to client.

* [NOD-1130] Add a few fields to GetConnectedPeerInfoResult.

* [NOD-1130] Rename oneTry to isPermanent.

* [NOD-1130] Implement ConnectionCount in NetAdapter.

* [NOD-1130] Move RawMempoolVerbose out of mempool.

* [NOD-1130] Move isSynced into the mining package.

* [NOD-1130] Fix a compilation error.

* [NOD-1130] Make golint happy.

* [NOD-1130] Fix merge errors.
2020-07-22 10:26:39 +03:00

59 lines
1.6 KiB
Go

package rpc
import (
"github.com/kaspanet/kaspad/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
}