pkg: unexport methods; cmd: common factory

- there's no reason why we should be exporting those method names, so
  let's unexport them

- with a common factory for creating a deadlined context and client, we
  have to care less about those details inside the commands themselves

Signed-off-by: Ciro S. Costa <utxobr@protonmail.com>
This commit is contained in:
Ciro S. Costa 2021-06-12 10:04:11 -04:00
parent 87e9058fc3
commit 42d84b912b
29 changed files with 174 additions and 235 deletions

View file

@ -1,25 +1,20 @@
package main
import (
"context"
"encoding/json"
"fmt"
"os"
"github.com/cirocosta/go-monero/pkg/rpc"
)
type GetAlternateChainsCommand struct{}
func (c *GetAlternateChainsCommand) Execute(_ []string) error {
ctx, cancel := context.WithTimeout(context.Background(), options.RequestTimeout)
ctx, cancel := options.Context()
defer cancel()
client, err := rpc.NewClient(options.Address,
rpc.WithHTTPClient(rpc.NewHTTPClient(options.Verbose)),
)
client, err := options.Client()
if err != nil {
return fmt.Errorf("new client for '%s': %w", options.Address, err)
return fmt.Errorf("client: %w", err)
}
resp, err := client.GetAlternateChains(ctx)

View file

@ -1,25 +1,20 @@
package main
import (
"context"
"encoding/json"
"fmt"
"os"
"github.com/cirocosta/go-monero/pkg/rpc"
)
type GetBansCommand struct{}
func (c *GetBansCommand) Execute(_ []string) error {
ctx, cancel := context.WithTimeout(context.Background(), options.RequestTimeout)
ctx, cancel := options.Context()
defer cancel()
client, err := rpc.NewClient(options.Address,
rpc.WithHTTPClient(rpc.NewHTTPClient(options.Verbose)),
)
client, err := options.Client()
if err != nil {
return fmt.Errorf("new client for '%s': %w", options.Address, err)
return fmt.Errorf("client: %w", err)
}
resp, err := client.GetBans(ctx)

View file

@ -1,12 +1,9 @@
package main
import (
"context"
"encoding/json"
"fmt"
"os"
"github.com/cirocosta/go-monero/pkg/rpc"
)
type GetBlockCommand struct {
@ -15,14 +12,12 @@ type GetBlockCommand struct {
}
func (c *GetBlockCommand) Execute(_ []string) error {
ctx, cancel := context.WithTimeout(context.Background(), options.RequestTimeout)
ctx, cancel := options.Context()
defer cancel()
client, err := rpc.NewClient(options.Address,
rpc.WithHTTPClient(rpc.NewHTTPClient(options.Verbose)),
)
client, err := options.Client()
if err != nil {
return fmt.Errorf("new client for '%s': %w", options.Address, err)
return fmt.Errorf("client: %w", err)
}
resp, err := client.GetBlock(ctx, c.Height)

View file

@ -1,25 +1,20 @@
package main
import (
"context"
"encoding/json"
"fmt"
"os"
"github.com/cirocosta/go-monero/pkg/rpc"
)
type GetBlockCountCommand struct{}
func (c *GetBlockCountCommand) Execute(_ []string) error {
ctx, cancel := context.WithTimeout(context.Background(), options.RequestTimeout)
ctx, cancel := options.Context()
defer cancel()
client, err := rpc.NewClient(options.Address,
rpc.WithHTTPClient(rpc.NewHTTPClient(options.Verbose)),
)
client, err := options.Client()
if err != nil {
return fmt.Errorf("new client for '%s': %w", options.Address, err)
return fmt.Errorf("client: %w", err)
}
resp, err := client.GetBlockCount(ctx)

View file

@ -1,12 +1,9 @@
package main
import (
"context"
"encoding/json"
"fmt"
"os"
"github.com/cirocosta/go-monero/pkg/rpc"
)
type GetBlockTemplateCommand struct {
@ -15,14 +12,12 @@ type GetBlockTemplateCommand struct {
}
func (c *GetBlockTemplateCommand) Execute(_ []string) error {
ctx, cancel := context.WithTimeout(context.Background(), options.RequestTimeout)
ctx, cancel := options.Context()
defer cancel()
client, err := rpc.NewClient(options.Address,
rpc.WithHTTPClient(rpc.NewHTTPClient(options.Verbose)),
)
client, err := options.Client()
if err != nil {
return fmt.Errorf("new client for '%s': %w", options.Address, err)
return fmt.Errorf("client: %w", err)
}
resp, err := client.GetBlockTemplate(ctx, c.WalletAddress, c.ReserveSize)

View file

@ -1,12 +1,9 @@
package main
import (
"context"
"encoding/json"
"fmt"
"os"
"github.com/cirocosta/go-monero/pkg/rpc"
)
type GetCoinbaseTxSumCommand struct {
@ -15,14 +12,12 @@ type GetCoinbaseTxSumCommand struct {
}
func (c *GetCoinbaseTxSumCommand) Execute(_ []string) error {
ctx, cancel := context.WithTimeout(context.Background(), options.RequestTimeout)
ctx, cancel := options.Context()
defer cancel()
client, err := rpc.NewClient(options.Address,
rpc.WithHTTPClient(rpc.NewHTTPClient(options.Verbose)),
)
client, err := options.Client()
if err != nil {
return fmt.Errorf("new client for '%s': %w", options.Address, err)
return fmt.Errorf("client: %w", err)
}
resp, err := client.GetCoinbaseTxSum(ctx, c.Height, c.Count)

View file

@ -1,25 +1,20 @@
package main
import (
"context"
"encoding/json"
"fmt"
"os"
"github.com/cirocosta/go-monero/pkg/rpc"
)
type GetConnectionsCommand struct{}
func (c *GetConnectionsCommand) Execute(_ []string) error {
ctx, cancel := context.WithTimeout(context.Background(), options.RequestTimeout)
ctx, cancel := options.Context()
defer cancel()
client, err := rpc.NewClient(options.Address,
rpc.WithHTTPClient(rpc.NewHTTPClient(options.Verbose)),
)
client, err := options.Client()
if err != nil {
return fmt.Errorf("new client for '%s': %w", options.Address, err)
return fmt.Errorf("client: %w", err)
}
resp, err := client.GetConnections(ctx)

View file

@ -1,12 +1,9 @@
package main
import (
"context"
"encoding/json"
"fmt"
"os"
"github.com/cirocosta/go-monero/pkg/rpc"
)
type GetFeeEstimateCommand struct {
@ -14,14 +11,12 @@ type GetFeeEstimateCommand struct {
}
func (c *GetFeeEstimateCommand) Execute(_ []string) error {
ctx, cancel := context.WithTimeout(context.Background(), options.RequestTimeout)
ctx, cancel := options.Context()
defer cancel()
client, err := rpc.NewClient(options.Address,
rpc.WithHTTPClient(rpc.NewHTTPClient(options.Verbose)),
)
client, err := options.Client()
if err != nil {
return fmt.Errorf("new client for '%s': %w", options.Address, err)
return fmt.Errorf("client: %w", err)
}
resp, err := client.GetFeeEstimate(ctx, c.GraceBlocks)

View file

@ -1,25 +1,20 @@
package main
import (
"context"
"encoding/json"
"fmt"
"os"
"github.com/cirocosta/go-monero/pkg/rpc"
)
type GetHeightCommand struct{}
func (c *GetHeightCommand) Execute(_ []string) error {
ctx, cancel := context.WithTimeout(context.Background(), options.RequestTimeout)
ctx, cancel := options.Context()
defer cancel()
client, err := rpc.NewClient(options.Address,
rpc.WithHTTPClient(rpc.NewHTTPClient(options.Verbose)),
)
client, err := options.Client()
if err != nil {
return fmt.Errorf("new client for '%s': %w", options.Address, err)
return fmt.Errorf("client: %w", err)
}
resp, err := client.GetHeight(ctx)

View file

@ -1,25 +1,20 @@
package main
import (
"context"
"encoding/json"
"fmt"
"os"
"github.com/cirocosta/go-monero/pkg/rpc"
)
type GetInfoCommand struct{}
func (c *GetInfoCommand) Execute(_ []string) error {
ctx, cancel := context.WithTimeout(context.Background(), options.RequestTimeout)
ctx, cancel := options.Context()
defer cancel()
client, err := rpc.NewClient(options.Address,
rpc.WithHTTPClient(rpc.NewHTTPClient(options.Verbose)),
)
client, err := options.Client()
if err != nil {
return fmt.Errorf("new client for '%s': %w", options.Address, err)
return fmt.Errorf("client: %w", err)
}
resp, err := client.GetInfo(ctx)

View file

@ -1,26 +1,21 @@
package main
import (
"context"
"encoding/json"
"fmt"
"os"
"github.com/cirocosta/go-monero/pkg/rpc"
)
type GetLastBlockHeaderCommand struct {
}
func (c *GetLastBlockHeaderCommand) Execute(_ []string) error {
ctx, cancel := context.WithTimeout(context.Background(), options.RequestTimeout)
ctx, cancel := options.Context()
defer cancel()
client, err := rpc.NewClient(options.Address,
rpc.WithHTTPClient(rpc.NewHTTPClient(options.Verbose)),
)
client, err := options.Client()
if err != nil {
return fmt.Errorf("new client for '%s': %w", options.Address, err)
return fmt.Errorf("client: %w", err)
}
resp, err := client.GetLastBlockHeader(ctx)

View file

@ -1,25 +1,20 @@
package main
import (
"context"
"encoding/json"
"fmt"
"os"
"github.com/cirocosta/go-monero/pkg/rpc"
)
type GetNetStatsCommand struct{}
func (c *GetNetStatsCommand) Execute(_ []string) error {
ctx, cancel := context.WithTimeout(context.Background(), options.RequestTimeout)
ctx, cancel := options.Context()
defer cancel()
client, err := rpc.NewClient(options.Address,
rpc.WithHTTPClient(rpc.NewHTTPClient(options.Verbose)),
)
client, err := options.Client()
if err != nil {
return fmt.Errorf("new client for '%s': %w", options.Address, err)
return fmt.Errorf("client: %w", err)
}
resp, err := client.GetNetStats(ctx)

View file

@ -1,25 +1,20 @@
package main
import (
"context"
"encoding/json"
"fmt"
"os"
"github.com/cirocosta/go-monero/pkg/rpc"
)
type GetPeerListCommand struct{}
func (c *GetPeerListCommand) Execute(_ []string) error {
ctx, cancel := context.WithTimeout(context.Background(), options.RequestTimeout)
ctx, cancel := options.Context()
defer cancel()
client, err := rpc.NewClient(options.Address,
rpc.WithHTTPClient(rpc.NewHTTPClient(options.Verbose)),
)
client, err := options.Client()
if err != nil {
return fmt.Errorf("new client for '%s': %w", options.Address, err)
return fmt.Errorf("client: %w", err)
}
resp, err := client.GetPeerList(ctx)

View file

@ -1,25 +1,20 @@
package main
import (
"context"
"encoding/json"
"fmt"
"os"
"github.com/cirocosta/go-monero/pkg/rpc"
)
type GetTransactionPoolCommand struct{}
func (c *GetTransactionPoolCommand) Execute(_ []string) error {
ctx, cancel := context.WithTimeout(context.Background(), options.RequestTimeout)
ctx, cancel := options.Context()
defer cancel()
client, err := rpc.NewClient(options.Address,
rpc.WithHTTPClient(rpc.NewHTTPClient(options.Verbose)),
)
client, err := options.Client()
if err != nil {
return fmt.Errorf("new client for '%s': %w", options.Address, err)
return fmt.Errorf("client: %w", err)
}
resp, err := client.GetTransactionPool(ctx)

View file

@ -1,26 +1,21 @@
package main
import (
"context"
"encoding/json"
"fmt"
"os"
"github.com/cirocosta/go-monero/pkg/rpc"
)
type GetTransactionPoolStatsCommand struct {
}
func (c *GetTransactionPoolStatsCommand) Execute(_ []string) error {
ctx, cancel := context.WithTimeout(context.Background(), options.RequestTimeout)
ctx, cancel := options.Context()
defer cancel()
client, err := rpc.NewClient(options.Address,
rpc.WithHTTPClient(rpc.NewHTTPClient(options.Verbose)),
)
client, err := options.Client()
if err != nil {
return fmt.Errorf("new client for '%s': %w", options.Address, err)
return fmt.Errorf("client: %w", err)
}
resp, err := client.GetTransactionPoolStats(ctx)

View file

@ -1,12 +1,9 @@
package main
import (
"context"
"encoding/json"
"fmt"
"os"
"github.com/cirocosta/go-monero/pkg/rpc"
)
type GetTransactionsCommand struct {
@ -15,14 +12,12 @@ type GetTransactionsCommand struct {
}
func (c *GetTransactionsCommand) Execute(_ []string) error {
ctx, cancel := context.WithTimeout(context.Background(), options.RequestTimeout)
ctx, cancel := options.Context()
defer cancel()
client, err := rpc.NewClient(options.Address,
rpc.WithHTTPClient(rpc.NewHTTPClient(options.Verbose)),
)
client, err := options.Client()
if err != nil {
return fmt.Errorf("new client for '%s': %w", options.Address, err)
return fmt.Errorf("client: %w", err)
}
resp, err := client.GetTransactions(ctx, c.Txns)

View file

@ -1,25 +1,20 @@
package main
import (
"context"
"encoding/json"
"fmt"
"os"
"github.com/cirocosta/go-monero/pkg/rpc"
)
type HardForkInfoCommand struct{}
func (c *HardForkInfoCommand) Execute(_ []string) error {
ctx, cancel := context.WithTimeout(context.Background(), options.RequestTimeout)
ctx, cancel := options.Context()
defer cancel()
client, err := rpc.NewClient(options.Address,
rpc.WithHTTPClient(rpc.NewHTTPClient(options.Verbose)),
)
client, err := options.Client()
if err != nil {
return fmt.Errorf("new client for '%s': %w", options.Address, err)
return fmt.Errorf("client: %w", err)
}
resp, err := client.HardForkInfo(ctx)

View file

@ -2,27 +2,21 @@ package main
import (
"os"
"time"
"github.com/jessevdk/go-flags"
log "github.com/sirupsen/logrus"
)
// configure global logging
//
func init() {
log.SetOutput(os.Stdout)
log.SetLevel(log.InfoLevel)
}
var options RPCOptions
var parser = flags.NewParser(&options, flags.Default)
type Options struct {
Verbose bool `short:"v" env:"MONEROD_VERBOSE" long:"verbose" description:"dump http requests and responses to stderr"`
Address string `short:"a" env:"MONEROD_ADDRESS" default:"http://xps.utxo.com.br" long:"address" description:"RPC server address" required:"true"`
RequestTimeout time.Duration `short:"t" env:"MONEROD_TIMEOUT" long:"timeout" description:"request timeout" default:"10s"`
}
var options Options
func main() {
if _, err := parser.Parse(); err != nil {
switch flagsErr := err.(type) {

View file

@ -1,12 +1,9 @@
package main
import (
"context"
"encoding/json"
"fmt"
"os"
"github.com/cirocosta/go-monero/pkg/rpc"
)
type OnGetBlockHashCommand struct {
@ -14,14 +11,12 @@ type OnGetBlockHashCommand struct {
}
func (c *OnGetBlockHashCommand) Execute(_ []string) error {
ctx, cancel := context.WithTimeout(context.Background(), options.RequestTimeout)
ctx, cancel := options.Context()
defer cancel()
client, err := rpc.NewClient(options.Address,
rpc.WithHTTPClient(rpc.NewHTTPClient(options.Verbose)),
)
client, err := options.Client()
if err != nil {
return fmt.Errorf("new client for '%s': %w", options.Address, err)
return fmt.Errorf("client: %w", err)
}
resp, err := client.OnGetBlockHash(ctx, c.Height)

View file

@ -1,12 +1,9 @@
package main
import (
"context"
"encoding/json"
"fmt"
"os"
"github.com/cirocosta/go-monero/pkg/rpc"
)
type RelayTxCommand struct {
@ -14,14 +11,12 @@ type RelayTxCommand struct {
}
func (c *RelayTxCommand) Execute(_ []string) error {
ctx, cancel := context.WithTimeout(context.Background(), options.RequestTimeout)
ctx, cancel := options.Context()
defer cancel()
client, err := rpc.NewClient(options.Address,
rpc.WithHTTPClient(rpc.NewHTTPClient(options.Verbose)),
)
client, err := options.Client()
if err != nil {
return fmt.Errorf("new client for '%s': %w", options.Address, err)
return fmt.Errorf("client: %w", err)
}
resp, err := client.RelayTx(ctx, c.Txns)

View file

@ -1,25 +1,20 @@
package main
import (
"context"
"encoding/json"
"fmt"
"os"
"github.com/cirocosta/go-monero/pkg/rpc"
)
type RPCAccessTrackingCommand struct{}
func (c *RPCAccessTrackingCommand) Execute(_ []string) error {
ctx, cancel := context.WithTimeout(context.Background(), options.RequestTimeout)
ctx, cancel := options.Context()
defer cancel()
client, err := rpc.NewClient(options.Address,
rpc.WithHTTPClient(rpc.NewHTTPClient(options.Verbose)),
)
client, err := options.Client()
if err != nil {
return fmt.Errorf("new client for '%s': %w", options.Address, err)
return fmt.Errorf("client: %w", err)
}
resp, err := client.RPCAccessTracking(ctx)

36
cmd/monero/rpc_options.go Normal file
View file

@ -0,0 +1,36 @@
package main
import (
"context"
"fmt"
"time"
mhttp "github.com/cirocosta/go-monero/pkg/http"
"github.com/cirocosta/go-monero/pkg/rpc"
)
// global RPC configuration available for all commands.
//
type RPCOptions struct {
Verbose bool `short:"v" env:"MONEROD_VERBOSE" long:"verbose" description:"dump http requests and responses to stderr"`
RequestTimeout time.Duration `short:"t" env:"MONEROD_TIMEOUT" long:"timeout" description:"request timeout" default:"10s"`
Address string `short:"a" env:"MONEROD_ADDRESS" long:"address" description:"address of the node to target" default:"http://localhost:18081"`
}
// Context generates a new `context.Context` already honouring the deadline
// specified in the options.
//
func (o RPCOptions) Context() (context.Context, context.CancelFunc) {
return context.WithTimeout(context.Background(), o.RequestTimeout)
}
// Client instantiates a new RPC client based on the options filled.
//
func (o RPCOptions) Client() (*rpc.Client, error) {
client, err := rpc.NewClient(o.Address, rpc.WithHTTPClient(mhttp.NewHTTPClient(o.Verbose)))
if err != nil {
return nil, fmt.Errorf("new client for '%s': %w", o.Address, err)
}
return client, nil
}

View file

@ -1,25 +1,20 @@
package main
import (
"context"
"encoding/json"
"fmt"
"os"
"github.com/cirocosta/go-monero/pkg/rpc"
)
type SyncInfoCommand struct{}
func (c *SyncInfoCommand) Execute(_ []string) error {
ctx, cancel := context.WithTimeout(context.Background(), options.RequestTimeout)
ctx, cancel := options.Context()
defer cancel()
client, err := rpc.NewClient(options.Address,
rpc.WithHTTPClient(rpc.NewHTTPClient(options.Verbose)),
)
client, err := options.Client()
if err != nil {
return fmt.Errorf("new client for '%s': %w", options.Address, err)
return fmt.Errorf("client: %w", err)
}
resp, err := client.SyncInfo(ctx)

4
go.sum
View file

@ -9,6 +9,7 @@ github.com/sclevine/spec v1.4.0 h1:z/Q9idDcay5m5irkZ28M7PtQM4aOISzOpj4bUPkDee8=
github.com/sclevine/spec v1.4.0/go.mod h1:LvpgJaFyvQzRvc1kaDs0bulYwzC70PbiYjC4QnFHkOM=
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
@ -21,8 +22,11 @@ golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7 h1:iGu644GcxtEcrInvDsQRCwJjtCIOlT2V7IRt6ah2Whw=
golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e h1:FDhOuMEY4JVRztM/gsbk+IKUQ8kj74bxZrgw87eMMVc=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

19
pkg/http/client.go Normal file
View file

@ -0,0 +1,19 @@
package http
import (
"net/http"
"time"
)
func NewHTTPClient(verbose bool) *http.Client {
client := &http.Client{
Timeout: 15 * time.Second,
}
if verbose {
client.Transport = NewDumpTransport(http.DefaultTransport)
}
return client
}

View file

@ -1,4 +1,4 @@
package rpc
package http
import (
"fmt"

View file

@ -8,7 +8,8 @@ import (
"io"
"net/http"
"net/url"
"time"
mhttp "github.com/cirocosta/go-monero/pkg/http"
)
const (
@ -54,19 +55,6 @@ func WithHTTPClient(v *http.Client) func(o *ClientOptions) {
}
}
func NewHTTPClient(verbose bool) *http.Client {
client := &http.Client{
Timeout: 15 * time.Second,
}
if verbose {
client.Transport = NewDumpTransport(http.DefaultTransport)
}
return client
}
// NewClient instantiates a new Client that is able to communicate with
// monerod's RPC endpoints.
//
@ -75,7 +63,7 @@ func NewHTTPClient(verbose bool) *http.Client {
//
func NewClient(address string, opts ...ClientOption) (*Client, error) {
options := &ClientOptions{
HTTPClient: NewHTTPClient(false),
HTTPClient: mhttp.NewHTTPClient(false),
}
for _, opt := range opts {

3
pkg/rpc/export_test.go Normal file
View file

@ -0,0 +1,3 @@
package rpc
var EndpointJsonRPC = endpointJsonRPC

View file

@ -7,28 +7,28 @@ import (
)
const (
MethodGetAlternateChains = "get_alternate_chains"
MethodGetBans = "get_bans"
MethodGetBlock = "get_block"
MethodGetBlockCount = "get_block_count"
MethodGetBlockTemplate = "get_block_template"
MethodGetCoinbaseTxSum = "get_coinbase_tx_sum"
MethodGetConnections = "get_connections"
MethodGetFeeEstimate = "get_fee_estimate"
MethodGetInfo = "get_info"
MethodGetLastBlockHeader = "get_last_block_header"
MethodHardForkInfo = "hard_fork_info"
MethodOnGetBlockHash = "on_get_block_hash"
MethodSyncInfo = "sync_info"
MethodRPCAccessTracking = "rpc_access_tracking"
MethodRelayTx = "relay_tx"
methodGetAlternateChains = "get_alternate_chains"
methodGetBans = "get_bans"
methodGetBlock = "get_block"
methodGetBlockCount = "get_block_count"
methodGetBlockTemplate = "get_block_template"
methodGetCoinbaseTxSum = "get_coinbase_tx_sum"
methodGetConnections = "get_connections"
methodGetFeeEstimate = "get_fee_estimate"
methodGetInfo = "get_info"
methodGetLastBlockHeader = "get_last_block_header"
methodHardForkInfo = "hard_fork_info"
methodOnGetBlockHash = "on_get_block_hash"
methodSyncInfo = "sync_info"
methodRPCAccessTracking = "rpc_access_tracking"
methodRelayTx = "relay_tx"
EndpointGetHeight = "/get_height"
EndpointGetPeerList = "/get_peer_list"
EndpointGetTransactionPool = "/get_transaction_pool"
EndpointGetTransactionPoolStats = "/get_transaction_pool_stats"
EndpointGetTransactions = "/get_transactions"
EndpointGetNetStats = "/get_net_stats"
endpointGetHeight = "/get_height"
endpointGetPeerList = "/get_peer_list"
endpointGetTransactionPool = "/get_transaction_pool"
endpointGetTransactionPoolStats = "/get_transaction_pool_stats"
endpointGetTransactions = "/get_transactions"
endpointGetNetStats = "/get_net_stats"
)
type RPCAccessTrackingResult struct {
@ -45,7 +45,7 @@ type RPCAccessTrackingResult struct {
func (c *Client) RPCAccessTracking(ctx context.Context) (*RPCAccessTrackingResult, error) {
var resp = &RPCAccessTrackingResult{}
if err := c.JsonRPC(ctx, MethodRPCAccessTracking, nil, resp); err != nil {
if err := c.JsonRPC(ctx, methodRPCAccessTracking, nil, resp); err != nil {
return nil, fmt.Errorf("get: %w", err)
}
@ -70,7 +70,7 @@ type HardForkInfoResult struct {
func (c *Client) HardForkInfo(ctx context.Context) (*HardForkInfoResult, error) {
var resp = &HardForkInfoResult{}
if err := c.JsonRPC(ctx, MethodHardForkInfo, nil, resp); err != nil {
if err := c.JsonRPC(ctx, methodHardForkInfo, nil, resp); err != nil {
return nil, fmt.Errorf("get: %w", err)
}
@ -90,7 +90,7 @@ type GetBansResult struct {
func (c *Client) GetBans(ctx context.Context) (*GetBansResult, error) {
var resp = &GetBansResult{}
if err := c.JsonRPC(ctx, MethodGetBans, nil, resp); err != nil {
if err := c.JsonRPC(ctx, methodGetBans, nil, resp); err != nil {
return nil, fmt.Errorf("get: %w", err)
}
@ -115,7 +115,7 @@ type GetAlternateChainsResult struct {
func (c *Client) GetAlternateChains(ctx context.Context) (*GetAlternateChainsResult, error) {
var resp = &GetAlternateChainsResult{}
if err := c.JsonRPC(ctx, MethodGetAlternateChains, nil, resp); err != nil {
if err := c.JsonRPC(ctx, methodGetAlternateChains, nil, resp); err != nil {
return nil, fmt.Errorf("get: %w", err)
}
@ -130,7 +130,7 @@ type GetBlockCountResult struct {
func (c *Client) GetBlockCount(ctx context.Context) (*GetBlockCountResult, error) {
var resp = &GetBlockCountResult{}
if err := c.JsonRPC(ctx, MethodGetBlockCount, nil, resp); err != nil {
if err := c.JsonRPC(ctx, methodGetBlockCount, nil, resp); err != nil {
return nil, fmt.Errorf("get: %w", err)
}
@ -143,7 +143,7 @@ func (c *Client) OnGetBlockHash(ctx context.Context, height uint64) (string, err
params = []uint64{height}
)
if err := c.JsonRPC(ctx, MethodOnGetBlockHash, params, &resp); err != nil {
if err := c.JsonRPC(ctx, methodOnGetBlockHash, params, &resp); err != nil {
return "", fmt.Errorf("get: %w", err)
}
@ -165,7 +165,7 @@ func (c *Client) RelayTx(ctx context.Context, txns []string) (*RelayTxResult, er
}
)
if err := c.JsonRPC(ctx, MethodRelayTx, params, resp); err != nil {
if err := c.JsonRPC(ctx, methodRelayTx, params, resp); err != nil {
return nil, fmt.Errorf("get: %w", err)
}
@ -193,7 +193,7 @@ func (c *Client) GetBlockTemplate(ctx context.Context, walletAddress string, res
}
)
if err := c.JsonRPC(ctx, MethodGetBlockTemplate, params, resp); err != nil {
if err := c.JsonRPC(ctx, methodGetBlockTemplate, params, resp); err != nil {
return nil, fmt.Errorf("get: %w", err)
}
@ -230,7 +230,7 @@ type GetConnectionsResult struct {
func (c *Client) GetConnections(ctx context.Context) (*GetConnectionsResult, error) {
var resp = &GetConnectionsResult{}
if err := c.JsonRPC(ctx, MethodGetConnections, nil, resp); err != nil {
if err := c.JsonRPC(ctx, methodGetConnections, nil, resp); err != nil {
return nil, fmt.Errorf("get: %w", err)
}
@ -272,7 +272,7 @@ type GetInfoResult struct {
func (c *Client) GetInfo(ctx context.Context) (*GetInfoResult, error) {
var resp = &GetInfoResult{}
if err := c.JsonRPC(ctx, MethodGetInfo, nil, resp); err != nil {
if err := c.JsonRPC(ctx, methodGetInfo, nil, resp); err != nil {
return nil, fmt.Errorf("get: %w", err)
}
@ -309,7 +309,7 @@ type GetLastBlockHeaderResult struct {
func (c *Client) GetLastBlockHeader(ctx context.Context) (*GetLastBlockHeaderResult, error) {
var resp = &GetLastBlockHeaderResult{}
if err := c.JsonRPC(ctx, MethodGetLastBlockHeader, nil, resp); err != nil {
if err := c.JsonRPC(ctx, methodGetLastBlockHeader, nil, resp); err != nil {
return nil, fmt.Errorf("get: %w", err)
}
@ -338,7 +338,7 @@ func (c *Client) GetCoinbaseTxSum(ctx context.Context, height, count uint64) (*G
}
)
if err := c.JsonRPC(ctx, MethodGetCoinbaseTxSum, params, resp); err != nil {
if err := c.JsonRPC(ctx, methodGetCoinbaseTxSum, params, resp); err != nil {
return nil, fmt.Errorf("get: %w", err)
}
@ -425,7 +425,7 @@ func (c *Client) GetBlock(ctx context.Context, height uint64) (*GetBlockResult,
}
)
if err := c.JsonRPC(ctx, MethodGetBlock, params, resp); err != nil {
if err := c.JsonRPC(ctx, methodGetBlock, params, resp); err != nil {
return nil, fmt.Errorf("get: %w", err)
}
@ -449,7 +449,7 @@ func (c *Client) GetFeeEstimate(ctx context.Context, graceBlocks uint64) (*GetFe
}
)
if err := c.JsonRPC(ctx, MethodGetFeeEstimate, params, resp); err != nil {
if err := c.JsonRPC(ctx, methodGetFeeEstimate, params, resp); err != nil {
return nil, fmt.Errorf("get: %w", err)
}
@ -499,7 +499,7 @@ type SyncInfoResult struct {
func (c *Client) SyncInfo(ctx context.Context) (*SyncInfoResult, error) {
var resp = new(SyncInfoResult)
if err := c.JsonRPC(ctx, MethodSyncInfo, nil, resp); err != nil {
if err := c.JsonRPC(ctx, methodSyncInfo, nil, resp); err != nil {
return nil, fmt.Errorf("get: %w", err)
}
@ -538,7 +538,7 @@ type GetTransactionPoolResult struct {
func (c *Client) GetTransactionPool(ctx context.Context) (*GetTransactionPoolResult, error) {
var resp = &GetTransactionPoolResult{}
if err := c.Other(ctx, EndpointGetTransactionPool, nil, resp); err != nil {
if err := c.Other(ctx, endpointGetTransactionPool, nil, resp); err != nil {
return nil, fmt.Errorf("other: %w", err)
}
@ -575,7 +575,7 @@ func (c *Client) GetTransactionPoolStats(ctx context.Context) (*GetTransactionPo
resp = new(GetTransactionPoolStatsResult)
)
if err := c.Other(ctx, EndpointGetTransactionPoolStats, nil, resp); err != nil {
if err := c.Other(ctx, endpointGetTransactionPoolStats, nil, resp); err != nil {
return nil, fmt.Errorf("other: %w", err)
}
@ -606,7 +606,7 @@ type GetPeerListResult struct {
func (c *Client) GetPeerList(ctx context.Context) (*GetPeerListResult, error) {
var resp = &GetPeerListResult{}
if err := c.Other(ctx, EndpointGetPeerList, nil, resp); err != nil {
if err := c.Other(ctx, endpointGetPeerList, nil, resp); err != nil {
return nil, fmt.Errorf("other: %w", err)
}
@ -705,7 +705,7 @@ type GetTransactionsResultJSONTxn struct {
func (c *Client) GetTransactions(ctx context.Context, txns []string) (*GetTransactionsResult, error) {
var resp = &GetTransactionsResult{}
if err := c.Other(ctx, EndpointGetTransactions, map[string]interface{}{
if err := c.Other(ctx, endpointGetTransactions, map[string]interface{}{
"txs_hashes": txns,
"decode_as_json": true,
}, resp); err != nil {
@ -725,7 +725,7 @@ type GetHeightResult struct {
func (c *Client) GetHeight(ctx context.Context) (*GetHeightResult, error) {
var resp = &GetHeightResult{}
if err := c.Other(ctx, EndpointGetHeight, nil, resp); err != nil {
if err := c.Other(ctx, endpointGetHeight, nil, resp); err != nil {
return nil, fmt.Errorf("other: %w", err)
}
@ -745,7 +745,7 @@ type GetNetStatsResult struct {
func (c *Client) GetNetStats(ctx context.Context) (*GetNetStatsResult, error) {
var resp = &GetNetStatsResult{}
if err := c.Other(ctx, EndpointGetNetStats, nil, resp); err != nil {
if err := c.Other(ctx, endpointGetNetStats, nil, resp); err != nil {
return nil, fmt.Errorf("other: %w", err)
}