electrum

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 21, 2024 License: MIT Imports: 13 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a high level API access to an Electrum protocol compatible server. See https://electrumx-spesmilo.readthedocs.io/en/latest/protocol-methods.html selecting the `supportedProtocolVersion` currently in use.

func Connect

func Connect(opts *Options) (*Client, error)

Connect connets to an Electrum server and negotiates the protocol in a blocking fashion immediately. If the connection could not be established or the server didn't respond with a valid server version response, an error is returned.

func (*Client) Close

func (c *Client) Close()

Close closes the connection and shuts down all pending requests. All pending requests will be resolved with an error.

func (*Client) EstimateFee

func (c *Client) EstimateFee(ctx context.Context, number int) (float64, error)

EstimateFee estimates the fee rate needed to be confirmed within the given number of blocks using the blockchain.estimatefee RPC method. The value returned is the fee rate in BTC/kB. If the fee rate could not be estimated, an error is returned.

func (*Client) GetMerkle

func (c *Client) GetMerkle(ctx context.Context, txHashHex string, height int) (*GetMerkleResult, error)

GetMerkle does the blockchain.transaction.get_merkle RPC call.

func (*Client) Headers

func (c *Client) Headers(ctx context.Context, startHeight int, count int) (*HeadersResult, error)

Headers does the blockchain.block.headers RPC call. It returns a slice of 80-byte headers, and the maximum number of headers the server will return in a single request.

func (*Client) HeadersSubscribe

func (c *Client) HeadersSubscribe(ctx context.Context, result func(header *types.Header, err error))

HeadersSubscribe does the blockchain.headers.subscribe RPC call. The callback is called once with the latest header and subsequently on each new header.

This function is non-blocking, the result is delivered asynchronously to the callback. The callback is called with an error if: - writing to the socket fails - there was a timeout in invoking the RPC call - the server responds with invalid data to the RPC call - the server sends invalid data in the `blockchain.headers.subscribe` notification.

func (*Client) RelayFee

func (c *Client) RelayFee(ctx context.Context) (float64, error)

RelayFee does the blockchain.relayfee RPC call. The value returned is the fee rate in BTC/kB.

func (*Client) ScriptHashGetHistory

func (c *Client) ScriptHashGetHistory(ctx context.Context, scriptHashHex string) (types.TxHistory, error)

ScriptHashGetHistory does the blockchain.scripthash.get_history RPC call.

func (*Client) ScriptHashSubscribe

func (c *Client) ScriptHashSubscribe(
	ctx context.Context,
	scriptHashHex string,
	result func(status string, err error))

func (*Client) ServerVersion

func (c *Client) ServerVersion() ServerVersion

ServerVersion returns the version as reported by the server.

func (*Client) SetOnError

func (c *Client) SetOnError(f func(error))

SetOnError defines a callback that is called when there is a JSON RPC error. See `jsonrpc.SetOnError`.

func (*Client) TransactionBroadcast

func (c *Client) TransactionBroadcast(ctx context.Context, rawTxHex string) (string, error)

TransactionBroadcast does the blockchain.transaction.broadcast RPC call.

func (*Client) TransactionGet

func (c *Client) TransactionGet(ctx context.Context, txHash string) ([]byte, error)

TransactionGet downloads a transaction using the blockchain.transaction.get RPC method. The response is the raw transaction.

func (*Client) VaultTransactionSubscribe

func (c *Client) VaultTransactionSubscribe(ctx context.Context,
	result func(vaultTxs []types.VaultTransaction, err error) error,
	params ...interface{})

func (*Client) VaultTransactionsGetFrom

func (c *Client) VaultTransactionsGetFrom(ctx context.Context, txHash string, length int) ([]map[string]interface{}, error)

type GetMerkleResult

type GetMerkleResult struct {
	Merkle      []string `json:"merkle"`
	Pos         int      `json:"pos"`
	BlockHeight int      `json:"block_height"`
}

GetMerkleResult is returned by `GetMerkle()`.

type HeadersResult

type HeadersResult struct {
	// Headers is a slice of 80-byte headers.
	Headers [][]byte
	// Max is the maximum number of headers the server will return in a single request.
	Max int
}

HeadersResult is returned by `Headers()`.

type Method

type Method string
const (
	VaultTransactionsSubscribe Method = "vault.transactions.subscribe"
	VaultTransactionsGet       Method = "vault.transactions.get"
)

func (Method) String

func (m Method) String() string

type Options

type Options struct {
	// SoftwareVersion reports to an electrum protocol compatible server
	// its name and a version so that server owners can identify what kind of
	// clients are connected.
	SoftwareVersion string
	// MethodTimeout is the duration after method calls time out. If 0, no timeout is applied.
	MethodTimeout time.Duration
	// PingInterval is the time between periodic ping requests to the Electrum server. 1m is the
	// default if not specified. If negative, pinging is disabled. This should be longer than
	// `MethodTimeout`.
	PingInterval time.Duration
	// Dial connects to the server and returns a connection object.
	Dial func() (net.Conn, error)
}

Options to initialize the Electrum client.

type ServerVersion

type ServerVersion struct {
	// contains filtered or unexported fields
}

ServerVersion is returned by the `server.version` RPC call.

func (ServerVersion) String

func (v ServerVersion) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL