Documentation
¶
Index ¶
- Constants
- Variables
- func AddressToElectrumScriptHash(addressStr string) (string, error)
- type Client
- func NewClient(ctx context.Context, urlStr string, tlsConfig *tls.Config) (*Client, error)
- func NewClientSSL(ctx context.Context, addr string, config *tls.Config) (*Client, error)
- func NewClientTCP(ctx context.Context, addr string) (*Client, error)
- func NewClientWebSocket(ctx context.Context, url string, config *tls.Config) (*Client, error)
- func (s *Client) BroadcastTransaction(ctx context.Context, rawTx string) (string, error)
- func (s *Client) GetBalance(ctx context.Context, scripthash string) (GetBalanceResult, error)
- func (s *Client) GetBlockHeader(ctx context.Context, height uint32, checkpointHeight ...uint32) (*GetBlockHeaderResult, error)
- func (s *Client) GetBlockHeaders(ctx context.Context, startHeight, count uint32, checkpointHeight ...uint32) (*GetBlockHeadersResult, error)
- func (s *Client) GetFee(ctx context.Context, target uint32) (float32, error)
- func (s *Client) GetFeeHistogram(ctx context.Context) (map[uint32]uint64, error)
- func (s *Client) GetHashFromPosition(ctx context.Context, height, position uint32) (string, error)
- func (s *Client) GetHistory(ctx context.Context, scripthash string) ([]*GetMempoolResult, error)
- func (s *Client) GetMempool(ctx context.Context, scripthash string) ([]*GetMempoolResult, error)
- func (s *Client) GetMerkleProof(ctx context.Context, txHash string, height uint32) (*GetMerkleProofResult, error)
- func (s *Client) GetMerkleProofFromPosition(ctx context.Context, height, position uint32) (*GetMerkleProofFromPosResult, error)
- func (s *Client) GetRawTransaction(ctx context.Context, txHash string) (string, error)
- func (s *Client) GetRelayFee(ctx context.Context) (float32, error)
- func (s *Client) GetTransaction(ctx context.Context, txHash string) (*GetTransactionResult, error)
- func (s *Client) IsShutdown() bool
- func (s *Client) ListUnspent(ctx context.Context, scripthash string) ([]*ListUnspentResult, error)
- func (s *Client) Ping(ctx context.Context) error
- func (s *Client) ServerAddPeer(ctx context.Context, features *ServerFeaturesResult) error
- func (s *Client) ServerBanner(ctx context.Context) (string, error)
- func (s *Client) ServerDonation(ctx context.Context) (string, error)
- func (s *Client) ServerFeatures(ctx context.Context) (*ServerFeaturesResult, error)
- func (s *Client) ServerPeers(ctx context.Context) (interface{}, error)
- func (s *Client) ServerVersion(ctx context.Context) (serverVer, protocolVer string, err error)
- func (s *Client) Shutdown()
- func (s *Client) SubscribeHeaders(ctx context.Context) (<-chan *SubscribeHeadersResult, error)
- func (s *Client) SubscribeHeadersSingle(ctx context.Context) (*SubscribeHeadersResult, error)
- func (s *Client) SubscribeMasternode(ctx context.Context, collateral string) (<-chan string, error)
- func (s *Client) SubscribeScripthash() (*ScripthashSubscription, <-chan *SubscribeNotif)
- type GetBalanceResp
- type GetBalanceResult
- type GetBlockHeaderResp
- type GetBlockHeaderResult
- type GetBlockHeadersResp
- type GetBlockHeadersResult
- type GetFeeResp
- type GetMempoolResp
- type GetMempoolResult
- type GetMerkleProofFromPosResp
- type GetMerkleProofFromPosResult
- type GetMerkleProofResp
- type GetMerkleProofResult
- type GetTransactionResp
- type GetTransactionResult
- type ListUnspentResp
- type ListUnspentResult
- type ScriptPubkey
- type ScriptSig
- type ScripthashSubscription
- func (sub *ScripthashSubscription) Add(ctx context.Context, scripthash string, address ...string) error
- func (sub *ScripthashSubscription) GetAddress(scripthash string) (string, error)
- func (sub *ScripthashSubscription) GetChannel() <-chan *SubscribeNotif
- func (sub *ScripthashSubscription) GetScripthash(address string) (string, error)
- func (sub *ScripthashSubscription) Remove(scripthash string) error
- func (sub *ScripthashSubscription) RemoveAddress(address string) error
- func (sub *ScripthashSubscription) Resubscribe(ctx context.Context) error
- type ServerFeaturesResp
- type ServerFeaturesResult
- type ServerVersionResp
- type SubscribeHeadersNotif
- type SubscribeHeadersResp
- type SubscribeHeadersResult
- type SubscribeNotif
- type TCPTransport
- type Transport
- type Vin
- type Vout
- type WebSocketTransport
Constants ¶
const ( // ClientVersion identifies the client version/name to the remote server ClientVersion = "go-electrum1.1" // ProtocolVersion identifies the support protocol version to the remote server ProtocolVersion = "1.4" )
Variables ¶
var ( // DebugMode provides debug output on communications with the remote server if enabled. DebugMode bool // ErrServerConnected throws an error if remote server is already connected. ErrServerConnected = errors.New("server is already connected") // ErrServerShutdown throws an error if remote server has shutdown. ErrServerShutdown = errors.New("server has shutdown") // ErrTimeout throws an error if request has timed out ErrTimeout = errors.New("request timeout") // ErrNotImplemented throws an error if this RPC call has not been implemented yet. ErrNotImplemented = errors.New("RPC call is not implemented") // ErrDeprecated throws an error if this RPC call is deprecated. ErrDeprecated = errors.New("RPC call has been deprecated") )
var ( // ErrCheckpointHeight is thrown if the checkpoint height is smaller than the block height. ErrCheckpointHeight = errors.New("checkpoint height must be greater than or equal to block height") )
Functions ¶
func AddressToElectrumScriptHash ¶
AddressToElectrumScriptHash converts valid bitcoin address to electrum scriptHash sha256 encoded, reversed and encoded in hex https://electrumx.readthedocs.io/en/latest/protocol-basics.html#script-hashes
Types ¶
type Client ¶
type Client struct { Error chan error // contains filtered or unexported fields }
Client stores information about the remote server.
func NewClient ¶
NewClient initializes a new client for remote server and connects to it using a transport protocol resolved from the URL's protocol scheme. A remote server URL should be provided in the `scheme://hostname:port` format (e.g. `tcp://electrum.io:50001`).
func NewClientSSL ¶
NewClientSSL initialize a new client for remote server and connects to the remote server using SSL
func NewClientTCP ¶
NewClientTCP initialize a new client for remote server and connects to the remote server using TCP
func NewClientWebSocket ¶
NewClientWebSocket initialize a new client for remote server and connects to the remote server using WebSocket.
func (*Client) BroadcastTransaction ¶
BroadcastTransaction sends a raw transaction to the remote server to be broadcasted on the server network. https://electrumx.readthedocs.io/en/latest/protocol-methods.html#blockchain-transaction-broadcast
func (*Client) GetBalance ¶
GetBalance returns the confirmed and unconfirmed balance for a scripthash. https://electrumx.readthedocs.io/en/latest/protocol-methods.html#blockchain-scripthash-get-balance
func (*Client) GetBlockHeader ¶
func (s *Client) GetBlockHeader(ctx context.Context, height uint32, checkpointHeight ...uint32) (*GetBlockHeaderResult, error)
GetBlockHeader returns the block header at a specific height. https://electrumx.readthedocs.io/en/latest/protocol-methods.html#blockchain-block-header
func (*Client) GetBlockHeaders ¶
func (s *Client) GetBlockHeaders(ctx context.Context, startHeight, count uint32, checkpointHeight ...uint32) (*GetBlockHeadersResult, error)
GetBlockHeaders return a concatenated chunk of block headers. https://electrumx.readthedocs.io/en/latest/protocol-methods.html#blockchain-block-headers
func (*Client) GetFee ¶
GetFee returns the estimated transaction fee per kilobytes for a transaction to be confirmed within a target number of blocks. https://electrumx.readthedocs.io/en/latest/protocol-methods.html#blockchain-estimatefee
func (*Client) GetFeeHistogram ¶
GetFeeHistogram returns a histogram of the fee rates paid by transactions in the memory pool, weighted by transacation size. https://electrumx.readthedocs.io/en/latest/protocol-methods.html#mempool-get-fee-histogram
func (*Client) GetHashFromPosition ¶
GetHashFromPosition returns the transaction hash for a specific position in a block. https://electrumx.readthedocs.io/en/latest/protocol-methods.html#blockchain-transaction-id-from-pos
func (*Client) GetHistory ¶
GetHistory returns the confirmed and unconfirmed history for a scripthash.
func (*Client) GetMempool ¶
GetMempool returns the unconfirmed transacations of a scripthash.
func (*Client) GetMerkleProof ¶
func (s *Client) GetMerkleProof(ctx context.Context, txHash string, height uint32) (*GetMerkleProofResult, error)
GetMerkleProof returns the merkle proof for a confirmed transaction. https://electrumx.readthedocs.io/en/latest/protocol-methods.html#blockchain-transaction-get-merkle
func (*Client) GetMerkleProofFromPosition ¶
func (s *Client) GetMerkleProofFromPosition(ctx context.Context, height, position uint32) (*GetMerkleProofFromPosResult, error)
GetMerkleProofFromPosition returns the merkle proof for a specific position in a block. https://electrumx.readthedocs.io/en/latest/protocol-methods.html#blockchain-transaction-id-from-pos
func (*Client) GetRawTransaction ¶
GetRawTransaction gets a raw encoded transaction. https://electrumx.readthedocs.io/en/latest/protocol-methods.html#blockchain-transaction-get
func (*Client) GetRelayFee ¶
GetRelayFee returns the minimum fee a transaction must pay to be accepted into the remote server memory pool. https://electrumx.readthedocs.io/en/latest/protocol-methods.html#blockchain-relayfee
func (*Client) GetTransaction ¶
GetTransaction gets the detailed information for a transaction. https://electrumx.readthedocs.io/en/latest/protocol-methods.html#blockchain-transaction-get
func (*Client) IsShutdown ¶
func (*Client) ListUnspent ¶
ListUnspent returns an ordered list of UTXOs for a scripthash.
func (*Client) Ping ¶
Ping send a ping to the target server to ensure it is responding and keeping the session alive. https://electrumx.readthedocs.io/en/latest/protocol-methods.html#server-ping
func (*Client) ServerAddPeer ¶
func (s *Client) ServerAddPeer(ctx context.Context, features *ServerFeaturesResult) error
ServerAddPeer adds your new server into the remote server own peers list. This should not be used if you are a client. https://electrumx.readthedocs.io/en/latest/protocol-methods.html#server-add-peer
func (*Client) ServerBanner ¶
ServerBanner returns the banner for this remote server. https://electrumx.readthedocs.io/en/latest/protocol-methods.html#server-banner
func (*Client) ServerDonation ¶
ServerDonation returns the donation address for this remote server https://electrumx.readthedocs.io/en/latest/protocol-methods.html#server-donation-address
func (*Client) ServerFeatures ¶
func (s *Client) ServerFeatures(ctx context.Context) (*ServerFeaturesResult, error)
ServerFeatures returns a list of features and services supported by the remote server. https://electrumx.readthedocs.io/en/latest/protocol-methods.html#server-features
func (*Client) ServerPeers ¶
ServerPeers returns a list of peers this remote server is aware of. https://electrumx.readthedocs.io/en/latest/protocol-methods.html#server-peers-subscribe
func (*Client) ServerVersion ¶
ServerVersion identify the client to the server, and negotiate the protocol version. This call must be sent first, or the server will default to an older protocol version. https://electrumx.readthedocs.io/en/latest/protocol-methods.html#server-version
func (*Client) SubscribeHeaders ¶
func (s *Client) SubscribeHeaders(ctx context.Context) (<-chan *SubscribeHeadersResult, error)
SubscribeHeaders subscribes to receive block headers notifications when new blocks are found.
BEWARE: This function can lead to a memory leak if the caller stops pulling from the returned channel. See the SubscribeHeadersSingle method for a safer alternative.
https://electrumx.readthedocs.io/en/latest/protocol-methods.html#blockchain-headers-subscribe
func (*Client) SubscribeHeadersSingle ¶
func (s *Client) SubscribeHeadersSingle(ctx context.Context) ( *SubscribeHeadersResult, error, )
SubscribeHeadersSingle subscribes to receive the header of the current blockchain tip. Unlike SubscribeHeaders, this method only returns the tip and does not listen for new block headers.
Worth noting that this action still creates a new subscription in the Electrum server. The protocol does neither support a single-shot request for the current blockchain tip nor subscription cancellation. Although this limitation causes a slight resource overhead on the client, it does not cause a memory leak like the SubscribeHeaders method which spawns a goroutine that may hang on the channel if the caller is no longer pulling from it.
https://electrumx.readthedocs.io/en/latest/protocol-methods.html#blockchain-headers-subscribe
func (*Client) SubscribeMasternode ¶
SubscribeMasternode subscribes to receive notifications when a masternode status changes. https://electrumx.readthedocs.io/en/latest/protocol-methods.html#blockchain-headers-subscribe
func (*Client) SubscribeScripthash ¶
func (s *Client) SubscribeScripthash() (*ScripthashSubscription, <-chan *SubscribeNotif)
SubscribeScripthash ...
type GetBalanceResp ¶
type GetBalanceResp struct {
Result GetBalanceResult `json:"result"`
}
GetBalanceResp represents the response to GetBalance().
type GetBalanceResult ¶
type GetBalanceResult struct { Confirmed float64 `json:"confirmed"` Unconfirmed float64 `json:"unconfirmed"` }
GetBalanceResult represents the content of the result field in the response to GetBalance().
type GetBlockHeaderResp ¶
type GetBlockHeaderResp struct {
Result *GetBlockHeaderResult `json:"result"`
}
GetBlockHeaderResp represents the response to GetBlockHeader().
type GetBlockHeaderResult ¶
type GetBlockHeaderResult struct { Branch []string `json:"branch"` Header string `json:"header"` Root string `json:"root"` }
GetBlockHeaderResult represents the content of the result field in the response to GetBlockHeader().
type GetBlockHeadersResp ¶
type GetBlockHeadersResp struct {
Result *GetBlockHeadersResult `json:"result"`
}
GetBlockHeadersResp represents the response to GetBlockHeaders().
type GetBlockHeadersResult ¶
type GetBlockHeadersResult struct { Count uint32 `json:"count"` Headers string `json:"hex"` Max uint32 `json:"max"` Branch []string `json:"branch,omitempty"` Root string `json:"root,omitempty"` }
GetBlockHeadersResult represents the content of the result field in the response to GetBlockHeaders().
type GetFeeResp ¶
type GetFeeResp struct {
Result float32 `json:"result"`
}
GetFeeResp represents the response to GetFee().
type GetMempoolResp ¶
type GetMempoolResp struct {
Result []*GetMempoolResult `json:"result"`
}
GetMempoolResp represents the response to GetHistory() and GetMempool().
type GetMempoolResult ¶
type GetMempoolResult struct { Hash string `json:"tx_hash"` Height int32 `json:"height"` Fee uint32 `json:"fee,omitempty"` }
GetMempoolResult represents the content of the result field in the response to GetHistory() and GetMempool().
type GetMerkleProofFromPosResp ¶
type GetMerkleProofFromPosResp struct {
Result *GetMerkleProofFromPosResult `json:"result"`
}
GetMerkleProofFromPosResp represents the response to GetMerkleProofFromPosition().
type GetMerkleProofFromPosResult ¶
type GetMerkleProofFromPosResult struct { Hash string `json:"tx_hash"` Merkle []string `json:"merkle"` }
GetMerkleProofFromPosResult represents the content of the result field in the response to GetMerkleProofFromPosition().
type GetMerkleProofResp ¶
type GetMerkleProofResp struct {
Result *GetMerkleProofResult `json:"result"`
}
GetMerkleProofResp represents the response to GetMerkleProof().
type GetMerkleProofResult ¶
type GetMerkleProofResult struct { Merkle []string `json:"merkle"` Height uint32 `json:"block_height"` Position uint32 `json:"pos"` }
GetMerkleProofResult represents the content of the result field in the response to GetMerkleProof().
type GetTransactionResp ¶
type GetTransactionResp struct {
Result *GetTransactionResult `json:"result"`
}
GetTransactionResp represents the response to GetTransaction().
type GetTransactionResult ¶
type GetTransactionResult struct { Blockhash string `json:"blockhash"` Blocktime uint64 `json:"blocktime"` Confirmations int32 `json:"confirmations"` Hash string `json:"hash"` Hex string `json:"hex"` Locktime uint32 `json:"locktime"` Size uint32 `json:"size"` Time uint64 `json:"time"` Txid string `json:"txid"` Version uint32 `json:"version"` Vin []Vin `json:"vin"` Vout []Vout `json:"vout"` Merkle GetMerkleProofResult `json:"merkle,omitempty"` // For protocol v1.5 and up. }
GetTransactionResult represents the content of the result field in the response to GetTransaction().
type ListUnspentResp ¶
type ListUnspentResp struct {
Result []*ListUnspentResult `json:"result"`
}
ListUnspentResp represents the response to ListUnspent()
type ListUnspentResult ¶
type ListUnspentResult struct { Height uint32 `json:"height"` Position uint32 `json:"tx_pos"` Hash string `json:"tx_hash"` Value uint64 `json:"value"` }
ListUnspentResult represents the content of the result field in the response to ListUnspent()
type ScriptPubkey ¶
type ScriptPubkey struct { Addresses []string `json:"addresses,omitempty"` Asm string `json:"asm"` Hex string `json:"hex,omitempty"` ReqSigs uint32 `json:"reqsigs,omitempty"` Type string `json:"type"` }
ScriptPubkey represents the script of that transaction output.
type ScripthashSubscription ¶
type ScripthashSubscription struct {
// contains filtered or unexported fields
}
ScripthashSubscription ...
func (*ScripthashSubscription) Add ¶
func (sub *ScripthashSubscription) Add(ctx context.Context, scripthash string, address ...string) error
Add ...
func (*ScripthashSubscription) GetAddress ¶
func (sub *ScripthashSubscription) GetAddress(scripthash string) (string, error)
GetAddress ...
func (*ScripthashSubscription) GetChannel ¶
func (sub *ScripthashSubscription) GetChannel() <-chan *SubscribeNotif
GetChannel ...
func (*ScripthashSubscription) GetScripthash ¶
func (sub *ScripthashSubscription) GetScripthash(address string) (string, error)
GetScripthash ...
func (*ScripthashSubscription) Remove ¶
func (sub *ScripthashSubscription) Remove(scripthash string) error
Remove ...
func (*ScripthashSubscription) RemoveAddress ¶
func (sub *ScripthashSubscription) RemoveAddress(address string) error
RemoveAddress ...
func (*ScripthashSubscription) Resubscribe ¶
func (sub *ScripthashSubscription) Resubscribe(ctx context.Context) error
Resubscribe ...
type ServerFeaturesResp ¶
type ServerFeaturesResp struct {
Result *ServerFeaturesResult `json:"result"`
}
ServerFeaturesResp represent the response to GetFeatures().
type ServerFeaturesResult ¶
type ServerFeaturesResult struct { GenesisHash string `json:"genesis_hash"` Hosts map[string]host `json:"hosts"` ProtocolMax string `json:"protocol_max"` ProtocolMin string `json:"protocol_min"` Pruning bool `json:"pruning,omitempty"` ServerVersion string `json:"server_version"` HashFunction string `json:"hash_function"` }
ServerFeaturesResult represent the data sent or receive in RPC call "server.features" and "server.add_peer".
type ServerVersionResp ¶
type ServerVersionResp struct {
Result [2]string `json:"result"`
}
ServerVersionResp represent the response to ServerVersion().
type SubscribeHeadersNotif ¶
type SubscribeHeadersNotif struct {
Params []*SubscribeHeadersResult `json:"params"`
}
SubscribeHeadersNotif represent the notification to SubscribeHeaders().
type SubscribeHeadersResp ¶
type SubscribeHeadersResp struct {
Result *SubscribeHeadersResult `json:"result"`
}
SubscribeHeadersResp represent the response to SubscribeHeaders().
type SubscribeHeadersResult ¶
type SubscribeHeadersResult struct { Height int32 `json:"height,omitempty"` Hex string `json:"hex"` }
SubscribeHeadersResult represents the content of the result field in the response to SubscribeHeaders().
type SubscribeNotif ¶
type SubscribeNotif struct {
Params [2]string `json:"params"`
}
SubscribeNotif represent the notification to SubscribeScripthash() and SubscribeMasternode().
type TCPTransport ¶
type TCPTransport struct {
// contains filtered or unexported fields
}
TCPTransport store information about the TCP transport.
func NewSSLTransport ¶
NewSSLTransport opens a new SSL connection to the remote server.
func NewTCPTransport ¶
func NewTCPTransport(ctx context.Context, addr string) (*TCPTransport, error)
NewTCPTransport opens a new TCP connection to the remote server.
func (*TCPTransport) Close ¶
func (t *TCPTransport) Close() error
func (*TCPTransport) Errors ¶
func (t *TCPTransport) Errors() <-chan error
Errors returns chan to TCP transport errors.
func (*TCPTransport) Responses ¶
func (t *TCPTransport) Responses() <-chan []byte
Responses returns chan to TCP transport responses.
func (*TCPTransport) SendMessage ¶
func (t *TCPTransport) SendMessage(body []byte) error
SendMessage sends a message to the remote server through the TCP transport.
type Transport ¶
type Transport interface { SendMessage([]byte) error Responses() <-chan []byte Errors() <-chan error Close() error }
Transport provides interface to server transport.
type Vin ¶
type Vin struct { Coinbase string `json:"coinbase"` ScriptSig *ScriptSig `json:"scriptsig"` Sequence uint32 `json:"sequence"` TxID string `json:"txid"` Vout uint32 `json:"vout"` }
Vin represents the input side of a transaction.
type Vout ¶
type Vout struct { N uint32 `json:"n"` ScriptPubkey ScriptPubkey `json:"scriptpubkey"` Value float64 `json:"value"` }
Vout represents the output side of a transaction.
type WebSocketTransport ¶
type WebSocketTransport struct {
// contains filtered or unexported fields
}
func NewWebSocketTransport ¶
func NewWebSocketTransport( ctx context.Context, url string, tlsConfig *tls.Config, ) (*WebSocketTransport, error)
NewWebSocketTransport initializes new WebSocket transport.
func (*WebSocketTransport) Close ¶
func (t *WebSocketTransport) Close() error
Close closes WebSocket transport.
func (*WebSocketTransport) Errors ¶
func (t *WebSocketTransport) Errors() <-chan error
Errors returns chan to WebSocket transport errors.
func (*WebSocketTransport) Responses ¶
func (t *WebSocketTransport) Responses() <-chan []byte
Responses returns chan to WebSocket transport responses.
func (*WebSocketTransport) SendMessage ¶
func (t *WebSocketTransport) SendMessage(body []byte) error
SendMessage sends a message to the remote server through the WebSocket transport.