github.com/lmittmann/w3@v0.20.0/module/txpool/status.go (about)

     1  package txpool
     2  
     3  import (
     4  	"encoding/json"
     5  
     6  	"github.com/ethereum/go-ethereum/common/hexutil"
     7  	"github.com/lmittmann/w3/internal/module"
     8  	"github.com/lmittmann/w3/w3types"
     9  )
    10  
    11  // Status requests the number of pending and queued transactions in the transaction pool.
    12  func Status() w3types.RPCCallerFactory[*StatusResponse] {
    13  	return module.NewFactory[*StatusResponse](
    14  		"txpool_status",
    15  		nil,
    16  	)
    17  }
    18  
    19  type StatusResponse struct {
    20  	Pending uint
    21  	Queued  uint
    22  }
    23  
    24  func (s *StatusResponse) UnmarshalJSON(data []byte) error {
    25  	type statusResponse struct {
    26  		Pending hexutil.Uint `json:"pending"`
    27  		Queued  hexutil.Uint `json:"queued"`
    28  	}
    29  
    30  	var dec statusResponse
    31  	if err := json.Unmarshal(data, &dec); err != nil {
    32  		return err
    33  	}
    34  	s.Pending = uint(dec.Pending)
    35  	s.Queued = uint(dec.Queued)
    36  	return nil
    37  }