electrum

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2019 License: Apache-2.0, MIT Imports: 12 Imported by: 0

README

This code was imported from github.com/mbyczkowski/go-electrum, a fork of github.com/qshuai/go-electrum, a fork of github.com/d4l3k/go-electrum.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotImplemented = errors.New("not implemented")
	ErrNodeConnected  = errors.New("node already connected")
	ErrNodeShutdown   = errors.New("node has shutdown")
	ErrIdMismatch     = errors.New("response id mismatch")
	ErrUnknown        = errors.New("unknown error")
	ErrNetwork        = errors.New("network error")
	ErrAPI            = errors.New("received API error")
)
View Source
var DebugMode bool

Functions

func NodeIdent

func NodeIdent(addr, port string) string

Types

type Balance

type Balance struct {
	// Address field is unnecessary for Electrumx server protocol,
	// but is required for user of this library.
	Address string `json:"address"`

	Confirmed   cashutil.Amount `json:"confirmed"`
	Unconfirmed cashutil.Amount `json:"unconfirmed"`
}

type Block

type Block struct {
	Count uint   `json:"count"`
	Hex   string `json:"hex"`
	Max   uint   `json:"max"`
}

type BlockchainHeader

type BlockchainHeader struct {
	Nonce         uint32 `json:"nonce"`
	PrevBlockHash string `json:"prev_block_hash"`
	Timestamp     int64  `json:"timestamp"`
	MerkleRoot    string `json:"merkle_root"`
	BlockHeight   int32  `json:"block_height"`
	UtxoRoot      string `json:"utxo_root"`
	Version       int32  `json:"version"`
	Bits          int64  `json:"bits"`
}

type ErrorResponse

type ErrorResponse struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

type Feature

type Feature struct {
	Prunning string `json:"prunning"`
	Protocol string `json:"protocol_max"`
	Genesis  string `json:"genesis_hash"`
}

type GetTransaction

type GetTransaction struct {
	Hex           string `json:"hex"`
	Txid          string `json:"txid"`
	Version       int32  `json:"version"`
	Locktime      uint32 `json:"locktime"`
	Vin           []Vin  `json:"vin"`
	Vout          []Vout `json:"vout"`
	BlockHash     string `json:"blockhash"`
	Confirmations int32  `json:"confirmations"`
	Time          int64  `json:"time"`
	Blocktime     int64  `json:"blocktime"`
}
type Header struct {
	Height uint32 `json:"height"`
	Hex    string `json:"hex"`
}

type Node

type Node struct {
	// Ident is a an identifier of the form 127.0.0.1|s1234 or ::1|t5432.
	Ident   string
	Network Network
	// contains filtered or unexported fields
}

func NewNode

func NewNode(addr, port string, network Network) (*Node, error)

func (*Node) BlockchainAddressGetHistory

func (n *Node) BlockchainAddressGetHistory(address string) ([]*Transaction, error)

BlockchainAddressGetHistory returns the history of an address.

version 1.1 and version 1.2 only https://electrumx.readthedocs.io/en/latest/protocol-methods.html#blockchain-scripthash-get_history

func (*Node) BlockchainBlockHeaders

func (n *Node) BlockchainBlockHeaders(height uint32, count uint) (Block, error)

BlockchainBlockHeaders returns a block header (160 hex).

func (*Node) BlockchainHeadersSubscribe

func (n *Node) BlockchainHeadersSubscribe() (*Header, error)

Subscribe to receive block headers when a new block is found.

Note: there's no way to unsubscribe, and the rest of this code doesn't know how to deal with notifications. It is advisable to only call this method once and disconnect/reconnect after getting the block height.

https://electrumx.readthedocs.io/en/latest/protocol-methods.html#blockchain-headers-subscribe

func (*Node) BlockchainTransactionGet

func (n *Node) BlockchainTransactionGet(txid string) (string, error)

BlockchainTransactionGet returns a raw transaction.

https://electrumx.readthedocs.io/en/latest/protocol-methods.html#blockchain-transaction-get

func (*Node) Disconnect

func (n *Node) Disconnect() error

func (*Node) ServerFeatures

func (n *Node) ServerFeatures() (*Feature, error)

ServerFeatures returns the server features dictionary. method: "server.features"

version 1.1 https://electrumx.readthedocs.io/en/latest/protocol-methods.html#server-features

func (*Node) ServerPeersSubscribe

func (n *Node) ServerPeersSubscribe() ([]Peer, error)

ServerPeersSubscribe requests peers from a server.

https://electrumx.readthedocs.io/en/latest/protocol-methods.html#server-peers-subscribe

func (*Node) ServerVersion

func (n *Node) ServerVersion(ver string) error

ServerVersion allows negotiating a min protocol version. This is required, as various methods appeared (or were removed) in various versions.

version 1.1 https://electrumx.readthedocs.io/en/latest/protocol-methods.html#server-version

type Peer

type Peer struct {
	IP       string
	Host     string
	Version  string
	Features []string
}

type RequestMessage

type RequestMessage struct {
	Id     uint64        `json:"id"`
	Method string        `json:"method"`
	Params []interface{} `json:"params"`
}

type ResponseMessage

type ResponseMessage struct {
	Id      uint64         `json:"id"`
	JsonRpc string         `json:"jsonrpc"`
	Result  interface{}    `json:"result"`
	Error   *ErrorResponse `json:"error"`
}

type ScriptPubKeyResult

type ScriptPubKeyResult struct {
	Asm       string   `json:"asm"`
	Hex       string   `json:"hex,omitempty"`
	ReqSigs   int32    `json:"reqSigs,omitempty"`
	Type      string   `json:"type"`
	Addresses []string `json:"addresses,omitempty"`
}

ScriptPubKeyResult models the scriptPubKey data of a tx script. It is defined separately since it is used by multiple commands.

type ScriptSig

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

ScriptSig models a signature script. It is defined separately since it only applies to non-coinbase. Therefore the field in the Vin structure needs to be a pointer.

type TCPTransport

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

func (*TCPTransport) SendMessage

func (t *TCPTransport) SendMessage(request RequestMessage) (*ResponseMessage, error)

func (*TCPTransport) Shutdown

func (t *TCPTransport) Shutdown() error

type Transaction

type Transaction struct {
	Hash   string `json:"tx_hash"`
	Height uint32 `json:"height"`
	Value  int64  `json:"value"`
	Pos    uint32 `json:"tx_pos"`
}

type Transport

type Transport interface {
	SendMessage(RequestMessage) (*ResponseMessage, error)
	Shutdown() error
}

func NewSSLTransport

func NewSSLTransport(addr string) (Transport, error)

func NewTCPTransport

func NewTCPTransport(addr string) (Transport, error)

type Vin

type Vin struct {
	Coinbase  string     `json:"coinbase"`
	Txid      string     `json:"txid"`
	Vout      uint32     `json:"vout"`
	ScriptSig *ScriptSig `json:"scriptSig"`
	Sequence  uint32     `json:"sequence"`
}

Vin models parts of the tx data.

func (*Vin) IsCoinBase

func (v *Vin) IsCoinBase() bool

IsCoinBase returns a bool to show if a Vin is a Coinbase one or not.

type Vout

type Vout struct {
	Value        float64            `json:"value"`
	N            uint32             `json:"n"`
	ScriptPubKey ScriptPubKeyResult `json:"scriptPubKey"`
}

Vout models parts of the tx data.

Jump to

Keyboard shortcuts

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