Added SubmitBlock RPC method

This commit is contained in:
DataHoarder 2023-03-05 01:35:45 +01:00
parent 16f8644e01
commit f6a7735b8c
Signed by: DataHoarder
SSH key fingerprint: SHA256:OLTRf6Fl87G52SiR7sWLGNzlJt4WOX+tfI2yxo0z7xk
2 changed files with 24 additions and 0 deletions

View file

@ -2,6 +2,7 @@ package daemon
import (
"context"
"encoding/hex"
"encoding/json"
"fmt"
)
@ -29,6 +30,7 @@ const (
methodRelayTx = "relay_tx"
methodSetBans = "set_bans"
methodSyncInfo = "sync_info"
methodSubmitBlock = "submit_block"
)
// GetAlternateChains displays alternative chains seen by the node.
@ -244,6 +246,22 @@ func (c *Client) GetMinerData(ctx context.Context) (*GetMinerDataResult, error)
return resp, nil
}
func (c *Client) SubmitBlock(ctx context.Context, blobs ...[]byte) (*SubmitBlockResult, error) {
resp := &SubmitBlockResult{}
params := make([]string, 0, len(blobs))
for _, blob := range blobs {
params = append(params, hex.EncodeToString(blob))
}
err := c.JSONRPC(ctx, methodSubmitBlock, params, resp)
if err != nil {
return nil, fmt.Errorf("jsonrpc: %w", err)
}
return resp, nil
}
func (c *Client) GetConnections(
ctx context.Context,
) (*GetConnectionsResult, error) {

View file

@ -290,6 +290,12 @@ type GetMinerDataResult struct {
} `json:"tx_backlog"`
}
// SubmitBlockResult is the result of a call to the SubmitBlock RPC
// method.
type SubmitBlockResult struct {
Status string `json:"status"`
}
type Peer struct {
Host string `json:"host"`
ID uint64 `json:"id"`