git.gammaspectra.live/P2Pool/consensus/v3@v3.8.0/monero/client/rpc/daemon/raw_endpoints.go (about) 1 package daemon 2 3 import ( 4 "context" 5 "fmt" 6 "git.gammaspectra.live/P2Pool/consensus/v3/types" 7 "git.gammaspectra.live/P2Pool/consensus/v3/utils" 8 ) 9 10 const ( 11 endpointGetHeight = "/get_height" 12 endpointGetLimit = "/get_limit" 13 endpointGetNetStats = "/get_net_stats" 14 endpointGetOuts = "/get_outs" 15 endpointGetPeerList = "/get_peer_list" 16 endpointGetPublicNodes = "/get_public_nodes" 17 endpointGetTransactionPool = "/get_transaction_pool" 18 endpointGetTransactionPoolStats = "/get_transaction_pool_stats" 19 endpointGetTransactions = "/get_transactions" 20 endpointMiningStatus = "/mining_status" 21 endpointSetLimit = "/set_limit" 22 endpointSetLogLevel = "/set_log_level" 23 endpointSetLogCategories = "/set_log_categories" 24 endpointStartMining = "/start_mining" 25 endpointStopMining = "/stop_mining" 26 ) 27 28 func (c *Client) StopMining( 29 ctx context.Context, 30 ) (*StopMiningResult, error) { 31 resp := &StopMiningResult{} 32 33 err := c.RawRequest(ctx, endpointStopMining, nil, resp) 34 if err != nil { 35 return nil, fmt.Errorf("raw request: %w", err) 36 } 37 38 return resp, nil 39 } 40 41 func (c *Client) GetLimit(ctx context.Context) (*GetLimitResult, error) { 42 resp := &GetLimitResult{} 43 44 err := c.RawRequest(ctx, endpointGetLimit, nil, resp) 45 if err != nil { 46 return nil, fmt.Errorf("raw request: %w", err) 47 } 48 49 return resp, nil 50 } 51 52 func (c *Client) SetLogCategories( 53 ctx context.Context, params SetLogCategoriesRequestParameters, 54 ) (*SetLogCategoriesResult, error) { 55 resp := &SetLogCategoriesResult{} 56 57 err := c.RawRequest(ctx, endpointSetLogCategories, params, resp) 58 if err != nil { 59 return nil, fmt.Errorf("raw request: %w", err) 60 } 61 62 return resp, nil 63 } 64 65 func (c *Client) SetLogLevel( 66 ctx context.Context, params SetLogLevelRequestParameters, 67 ) (*SetLogLevelResult, error) { 68 resp := &SetLogLevelResult{} 69 70 err := c.RawRequest(ctx, endpointSetLogLevel, params, resp) 71 if err != nil { 72 return nil, fmt.Errorf("raw request: %w", err) 73 } 74 75 return resp, nil 76 } 77 78 func (c *Client) SetLimit( 79 ctx context.Context, params SetLimitRequestParameters, 80 ) (*SetLimitResult, error) { 81 resp := &SetLimitResult{} 82 83 err := c.RawRequest(ctx, endpointSetLimit, params, resp) 84 if err != nil { 85 return nil, fmt.Errorf("raw request: %w", err) 86 } 87 88 return resp, nil 89 } 90 91 func (c *Client) StartMining( 92 ctx context.Context, params StartMiningRequestParameters, 93 ) (*StartMiningResult, error) { 94 resp := &StartMiningResult{} 95 96 err := c.RawRequest(ctx, endpointStartMining, params, resp) 97 if err != nil { 98 return nil, fmt.Errorf("raw request: %w", err) 99 } 100 101 return resp, nil 102 } 103 104 func (c *Client) MiningStatus( 105 ctx context.Context, 106 ) (*MiningStatusResult, error) { 107 resp := &MiningStatusResult{} 108 109 err := c.RawRequest(ctx, endpointMiningStatus, nil, resp) 110 if err != nil { 111 return nil, fmt.Errorf("raw request: %w", err) 112 } 113 114 return resp, nil 115 } 116 117 func (c *Client) GetTransactionPool( 118 ctx context.Context, 119 ) (*GetTransactionPoolResult, error) { 120 resp := &GetTransactionPoolResult{} 121 122 err := c.RawRequest(ctx, endpointGetTransactionPool, nil, resp) 123 if err != nil { 124 return nil, fmt.Errorf("raw request: %w", err) 125 } 126 127 return resp, nil 128 } 129 130 func (c *Client) GetTransactionPoolStats( 131 ctx context.Context, 132 ) (*GetTransactionPoolStatsResult, error) { 133 resp := &GetTransactionPoolStatsResult{} 134 135 err := c.RawRequest(ctx, endpointGetTransactionPoolStats, nil, resp) 136 if err != nil { 137 return nil, fmt.Errorf("raw request: %w", err) 138 } 139 140 return resp, nil 141 } 142 143 func (c *Client) GetPeerList( 144 ctx context.Context, 145 ) (*GetPeerListResult, error) { 146 resp := &GetPeerListResult{} 147 148 err := c.RawRequest(ctx, endpointGetPeerList, nil, resp) 149 if err != nil { 150 return nil, fmt.Errorf("raw request: %w", err) 151 } 152 153 return resp, nil 154 } 155 156 type GetPublicNodesRequestParameters struct { 157 Gray bool `json:"gray"` 158 White bool `json:"white"` 159 IncludeBlocked bool `json:"include_blocked"` 160 } 161 162 func (c *Client) GetPublicNodes( 163 ctx context.Context, params GetPublicNodesRequestParameters, 164 ) (*GetPublicNodesResult, error) { 165 resp := &GetPublicNodesResult{} 166 167 err := c.RawRequest(ctx, endpointGetPublicNodes, params, resp) 168 if err != nil { 169 return nil, fmt.Errorf("raw request: %w", err) 170 } 171 172 return resp, nil 173 } 174 175 func (c *Client) GetOuts( 176 ctx context.Context, outputs []uint, gettxid bool, 177 ) (*GetOutsResult, error) { 178 resp := &GetOutsResult{} 179 180 type output struct { 181 Index uint `json:"index"` 182 } 183 184 params := struct { 185 Outputs []output `json:"outputs"` 186 GetTxID bool `json:"get_txid,omitempty"` 187 }{GetTxID: gettxid} 188 189 for _, out := range outputs { 190 params.Outputs = append(params.Outputs, output{out}) 191 } 192 193 err := c.RawRequest(ctx, endpointGetOuts, params, resp) 194 if err != nil { 195 return nil, fmt.Errorf("raw request: %w", err) 196 } 197 198 return resp, nil 199 } 200 201 func (c *Client) GetHeight(ctx context.Context) (*GetHeightResult, error) { 202 resp := &GetHeightResult{} 203 204 err := c.RawRequest(ctx, endpointGetHeight, nil, resp) 205 if err != nil { 206 return nil, fmt.Errorf("raw request: %w", err) 207 } 208 209 return resp, nil 210 } 211 212 func (c *Client) GetNetStats(ctx context.Context) (*GetNetStatsResult, error) { 213 resp := &GetNetStatsResult{} 214 215 err := c.RawRequest(ctx, endpointGetNetStats, nil, resp) 216 if err != nil { 217 return nil, fmt.Errorf("raw request: %w", err) 218 } 219 220 return resp, nil 221 } 222 223 func (r *GetTransactionsResult) GetTransactions() ([]*TransactionJSON, error) { 224 txns := make([]*TransactionJSON, len(r.Txs)) 225 226 for idx, txn := range r.Txs { 227 if len(txn.AsJSON) == 0 { 228 return nil, fmt.Errorf("txn w/ empty `.as_json`: %s", 229 txn.TxHash) 230 } 231 232 t := &TransactionJSON{} 233 err := utils.UnmarshalJSON([]byte(txn.AsJSON), t) 234 if err != nil { 235 return nil, fmt.Errorf("unmarshal txn '%s': %w", 236 txn.TxHash, err) 237 } 238 239 txns[idx] = t 240 } 241 242 return txns, nil 243 } 244 245 func (c *Client) GetTransactions( 246 ctx context.Context, txns []types.Hash, 247 ) (*GetTransactionsResult, error) { 248 resp := &GetTransactionsResult{} 249 params := map[string]interface{}{ 250 "txs_hashes": txns, 251 "decode_as_json": true, 252 } 253 254 err := c.RawRequest(ctx, endpointGetTransactions, params, resp) 255 if err != nil { 256 return nil, fmt.Errorf("raw request: %w", err) 257 } 258 259 return resp, nil 260 }