electrum

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 12, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ClientVersion identifies the client version/name to the remote server
	ClientVersion = "go-electrum1.0"

	// ProtocolVersion identifies the support protocol version to the remote server
	ProtocolVersion = "1.4"
)

Variables

View Source
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")
)
View Source
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

This section is empty.

Types

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"`
	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:"address,omitempty"`
	AddressSlice []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 ScriptSig

type ScriptSig struct {
	Asm string `json:"asm"`
	Hex string `json:"hex"`
}

ScriptSig represents the signature script for that transaction input.

type ScripthashSubscription

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

ScripthashSubscription ...

func (*ScripthashSubscription) Add

func (sub *ScripthashSubscription) Add(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() error

Resubscribe ...

type Server

type Server struct {
	Error chan error
	// contains filtered or unexported fields
}

Server stores information about the remote server.

func NewServer

func NewServer(opts *ServerOptions) *Server

NewServer initialize a new remote server.

func (*Server) BroadcastTransaction

func (s *Server) BroadcastTransaction(rawTx string) (string, error)

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 (*Server) ConnectSSL

func (s *Server) ConnectSSL(addr string, config *tls.Config) error

ConnectSSL connects to the remote server using SSL.

func (*Server) ConnectTCP

func (s *Server) ConnectTCP(addr string) error

ConnectTCP connects to the remote server using TCP.

func (*Server) GetBalance

func (s *Server) GetBalance(scripthash string) (GetBalanceResult, error)

GetBalance returns the confirmed and unconfirmed balance for a scripthash. https://electrumx.readthedocs.io/en/latest/protocol-methods.html#blockchain-scripthash-get-balance

func (*Server) GetBlockHeader

func (s *Server) GetBlockHeader(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 (*Server) GetBlockHeaders

func (s *Server) GetBlockHeaders(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 (*Server) GetFee

func (s *Server) GetFee(target uint32) (float32, error)

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 (*Server) GetFeeHistogram

func (s *Server) GetFeeHistogram() (map[uint32]uint64, error)

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 (*Server) GetHashFromPosition

func (s *Server) GetHashFromPosition(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 (*Server) GetHistory

func (s *Server) GetHistory(scripthash string) ([]*GetMempoolResult, error)

GetHistory returns the confirmed and unconfirmed history for a scripthash.

func (*Server) GetMempool

func (s *Server) GetMempool(scripthash string) ([]*GetMempoolResult, error)

GetMempool returns the unconfirmed transacations of a scripthash.

func (*Server) GetMerkleProof

func (s *Server) GetMerkleProof(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 (*Server) GetMerkleProofFromPosition

func (s *Server) GetMerkleProofFromPosition(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 (*Server) GetRawTransaction

func (s *Server) GetRawTransaction(txHash string) (string, error)

GetRawTransaction gets a raw encoded transaction. https://electrumx.readthedocs.io/en/latest/protocol-methods.html#blockchain-transaction-get

func (*Server) GetRelayFee

func (s *Server) GetRelayFee() (float32, error)

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 (*Server) GetTransaction

func (s *Server) GetTransaction(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 (*Server) IsShutdown

func (s *Server) IsShutdown() bool

func (*Server) ListUnspent

func (s *Server) ListUnspent(scripthash string) ([]*ListUnspentResult, error)

ListUnspent returns an ordered list of UTXOs for a scripthash.

func (*Server) Ping

func (s *Server) Ping() error

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 (*Server) ServerAddPeer

func (s *Server) ServerAddPeer(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 (*Server) ServerBanner

func (s *Server) ServerBanner() (string, error)

ServerBanner returns the banner for this remote server. https://electrumx.readthedocs.io/en/latest/protocol-methods.html#server-banner

func (*Server) ServerDonation

func (s *Server) ServerDonation() (string, error)

ServerDonation returns the donation address for this remote server https://electrumx.readthedocs.io/en/latest/protocol-methods.html#server-donation-address

func (*Server) ServerFeatures

func (s *Server) ServerFeatures() (*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 (*Server) ServerPeers

func (s *Server) ServerPeers() (interface{}, error)

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 (*Server) ServerVersion

func (s *Server) ServerVersion() (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 (*Server) Shutdown

func (s *Server) Shutdown()

func (*Server) SubscribeHeaders

func (s *Server) SubscribeHeaders() (<-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 (*Server) SubscribeMasternode

func (s *Server) SubscribeMasternode(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 (*Server) SubscribeScripthash

func (s *Server) SubscribeScripthash() (*ScripthashSubscription, <-chan *SubscribeNotif)

SubscribeScripthash ...

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 ServerOptions

type ServerOptions struct {
	ConnTimeout time.Duration
	ReqTimeout  time.Duration
}

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 informations about the TCP transport.

func NewSSLTransport

func NewSSLTransport(addr string, config *tls.Config, timeout time.Duration) (*TCPTransport, error)

NewSSLTransport opens a new SSL connection to the remote server.

func NewTCPTransport

func NewTCPTransport(addr string, timeout time.Duration) (*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.

Jump to

Keyboard shortcuts

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