Documentation ¶
Index ¶
- Constants
- Variables
- func AddressToElectrumScriptHash(addressStr string) (string, error)
- func GetTotalSentAndReceived(address string, history []*DetailedMempoolResult) (float64, float64)
- type Client
- func (s *Client) BroadcastTransaction(ctx context.Context, rawTx string) (string, error)
- func (s *Client) DetailHistory(ctx context.Context, address string, history []*GetMempoolResult) ([]*DetailedMempoolResult, error)
- func (s *Client) DetailTransaction(ctx context.Context, tx *GetTransactionResult) (*DetailedTransaction, error)
- func (s *Client) GetBalance(ctx context.Context, scripthash string) (GetBalanceResult, error)
- func (s *Client) GetBlockHeader(ctx context.Context, height uint64, checkpointHeight ...uint64) (*GetBlockHeaderResult, error)
- func (s *Client) GetBlockHeaders(ctx context.Context, startHeight, count uint64, checkpointHeight ...uint64) (*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) GetTransactionOutput(ctx context.Context, txHash string, outputIndex uint32) (*Vout, 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, clientVersion, protocolVersion string) (serverVer, protocolVer string, err error)
- func (s *Client) Shutdown()
- func (s *Client) SubscribeHeaders(ctx context.Context) (<-chan *SubscribeHeadersResult, error)
- func (s *Client) SubscribeMasternode(ctx context.Context, collateral string) (<-chan string, error)
- func (s *Client) SubscribeScripthash() (*ScripthashSubscription, <-chan *SubscribeNotif)
- type ClientOption
- type DetailedMempoolResult
- type DetailedTransaction
- type DialerOption
- 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 Logger
- 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 TxCache
- type Vin
- type VinWithPrevout
- type Vout
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
func GetTotalSentAndReceived ¶ added in v0.0.8
func GetTotalSentAndReceived( address string, history []*DetailedMempoolResult, ) (float64, float64)
GetTotalSentAndReceived returns the total sent and received for a scripthash.
Types ¶
type Client ¶
type Client struct { Error chan error // contains filtered or unexported fields }
Client stores information about the remote server.
func NewClientSSL ¶
func NewClientSSL( ctx context.Context, addr string, config *tls.Config, options ...ClientOption, ) (*Client, error)
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 (*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) DetailHistory ¶ added in v0.0.7
func (s *Client) DetailHistory( ctx context.Context, address string, history []*GetMempoolResult, ) ([]*DetailedMempoolResult, error)
Details history of a scripthash by adding Prevout and Incoming fields.
func (*Client) DetailTransaction ¶ added in v0.0.7
func (s *Client) DetailTransaction( ctx context.Context, tx *GetTransactionResult, ) (*DetailedTransaction, error)
Details a transaction by adding Prevout to Vin.
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 uint64, checkpointHeight ...uint64, ) (*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 uint64, checkpointHeight ...uint64) (*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 ¶
func (s *Client) GetHashFromPosition( ctx context.Context, height, position uint32, ) (string, error)
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 ¶
func (s *Client) GetTransaction( ctx context.Context, txHash string, ) (*GetTransactionResult, error)
GetTransaction gets the detailed information for a transaction. https://electrumx.readthedocs.io/en/latest/protocol-methods.html#blockchain-transaction-get
func (*Client) GetTransactionOutput ¶ added in v0.0.7
func (s *Client) GetTransactionOutput( ctx context.Context, txHash string, outputIndex uint32, ) (*Vout, error)
GetTransactionOutput gets the Vout from a transaction.
func (*Client) IsShutdown ¶
func (*Client) ListUnspent ¶
func (s *Client) ListUnspent( ctx context.Context, scripthash string, ) ([]*ListUnspentResult, error)
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 ¶
func (s *Client) ServerVersion( ctx context.Context, clientVersion, protocolVersion string, ) (serverVer, protocolVer string, err error)
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. https://electrumx.readthedocs.io/en/latest/protocol-methods.html#blockchain-headers-subscribe
func (*Client) SubscribeMasternode ¶
func (s *Client) SubscribeMasternode( ctx context.Context, collateral string, ) (<-chan string, error)
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 ClientOption ¶ added in v0.0.7
type ClientOption func(*Client)
func WithLogger ¶ added in v0.0.7
func WithLogger(logger Logger) ClientOption
func WithTimeout ¶ added in v0.0.6
func WithTimeout(timeout time.Duration) ClientOption
type DetailedMempoolResult ¶ added in v0.0.7
type DetailedMempoolResult struct { *DetailedTransaction Height int64 `json:"height"` Fee uint32 `json:"fee,omitempty"` Incoming bool `json:"incoming,omitempty"` }
type DetailedTransaction ¶ added in v0.0.7
type DetailedTransaction struct { *GetTransactionResult Vin []VinWithPrevout `json:"vin"` InputsTotal float64 `json:"inputs_total"` OutputsTotal float64 `json:"outputs_total"` FeeInSat float64 `json:"fee_in_sat"` }
type DialerOption ¶ added in v0.0.6
DialerOption is a function that configures a TCPTransport.
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 int64 `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 uint64 `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 uint64 `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"` Address string `json:"address,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 int64 `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 ¶
func NewSSLTransport( ctx context.Context, addr string, config *tls.Config, options ...DialerOption, ) (*TCPTransport, error)
NewSSLTransport opens a new SSL connection to the remote server.
func NewTCPTransport ¶
func NewTCPTransport( ctx context.Context, addr string, options ...DialerOption, ) (*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 VinWithPrevout ¶ added in v0.0.7
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.