bchain

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2018 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package bchain is a generated protocol buffer package.

It is generated from these files:

tx.proto

It has these top-level messages:

ProtoTransaction

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrBlockNotFound is returned when block is not found
	// either unknown hash or too high height
	// can be returned from GetBlockHash, GetBlockHeader, GetBlock
	ErrBlockNotFound = errors.New("Block not found")
	// ErrAddressMissing is returned if address is not specified
	// for example To address in ethereum can be missing in case of contract transaction
	ErrAddressMissing = errors.New("Address missing")
	// ErrTxidMissing is returned if txid is not specified
	// for example coinbase transactions in Bitcoin
	ErrTxidMissing = errors.New("Txid missing")
)

errors with specific meaning returned by blockchain rpc

Functions

This section is empty.

Types

type Address

type Address interface {
	String() string
	AreEqual(addr string) bool
	InSlice(addrs []string) bool
}

func NewBaseAddress

func NewBaseAddress(addr string) (Address, error)

type AddressFactoryFunc

type AddressFactoryFunc func(string) (Address, error)

type BaseParser

type BaseParser struct {
	AddressFactory       AddressFactoryFunc
	BlockAddressesToKeep int
}

BaseParser implements data parsing/handling functionality base for all other parsers

func (*BaseParser) AddressToOutputScript

func (p *BaseParser) AddressToOutputScript(address string) ([]byte, error)

AddressToOutputScript converts address to ScriptPubKey - currently not implemented

func (*BaseParser) IsUTXOChain

func (p *BaseParser) IsUTXOChain() bool

IsUTXOChain returns true if the block chain is UTXO type, otherwise false

func (*BaseParser) KeepBlockAddresses

func (p *BaseParser) KeepBlockAddresses() int

KeepBlockAddresses returns number of blocks which are to be kept in blockaddresses column

func (*BaseParser) OutputScriptToAddresses

func (p *BaseParser) OutputScriptToAddresses(script []byte) ([]string, error)

OutputScriptToAddresses converts ScriptPubKey to addresses - currently not implemented

func (*BaseParser) PackBlockHash

func (p *BaseParser) PackBlockHash(hash string) ([]byte, error)

PackBlockHash packs block hash to byte array

func (*BaseParser) PackTx

func (p *BaseParser) PackTx(tx *Tx, height uint32, blockTime int64) ([]byte, error)

PackTx packs transaction to byte array using protobuf

func (*BaseParser) PackTxid

func (p *BaseParser) PackTxid(txid string) ([]byte, error)

PackTxid packs txid to byte array

func (*BaseParser) PackedTxidLen

func (p *BaseParser) PackedTxidLen() int

PackedTxidLen returns length in bytes of packed txid

func (*BaseParser) ParseBlock

func (p *BaseParser) ParseBlock(b []byte) (*Block, error)

ParseBlock parses raw block to our Block struct - currently not implemented

func (*BaseParser) ParseTx

func (p *BaseParser) ParseTx(b []byte) (*Tx, error)

ParseTx parses byte array containing transaction and returns Tx struct - currently not implemented

func (*BaseParser) ParseTxFromJson

func (p *BaseParser) ParseTxFromJson(msg json.RawMessage) (*Tx, error)

ParseTxFromJson parses JSON message containing transaction and returs Tx struct

func (*BaseParser) UnpackBlockHash

func (p *BaseParser) UnpackBlockHash(buf []byte) (string, error)

UnpackBlockHash unpacks byte array to block hash

func (*BaseParser) UnpackTx

func (p *BaseParser) UnpackTx(buf []byte) (*Tx, uint32, error)

UnpackTx unpacks transaction from protobuf byte array

func (*BaseParser) UnpackTxid

func (p *BaseParser) UnpackTxid(buf []byte) (string, error)

UnpackTxid unpacks byte array to txid

type Block

type Block struct {
	BlockHeader
	Txs []Tx `json:"tx"`
}

type BlockChain

type BlockChain interface {
	// life-cycle methods
	Initialize() error
	Shutdown(ctx context.Context) error
	// chain info
	IsTestnet() bool
	GetNetworkName() string
	GetSubversion() string
	GetCoinName() string
	// requests
	GetBlockChainInfo() (string, error)
	GetBestBlockHash() (string, error)
	GetBestBlockHeight() (uint32, error)
	GetBlockHash(height uint32) (string, error)
	GetBlockHeader(hash string) (*BlockHeader, error)
	GetBlock(hash string, height uint32) (*Block, error)
	GetMempool() ([]string, error)
	GetTransaction(txid string) (*Tx, error)
	GetTransactionForMempool(txid string) (*Tx, error)
	EstimateSmartFee(blocks int, conservative bool) (float64, error)
	EstimateFee(blocks int) (float64, error)
	SendRawTransaction(tx string) (string, error)
	// mempool
	ResyncMempool(onNewTxAddr OnNewTxAddrFunc) (int, error)
	GetMempoolTransactions(address string) ([]string, error)
	GetMempoolEntry(txid string) (*MempoolEntry, error)
	// parser
	GetChainParser() BlockChainParser
}

BlockChain defines common interface to block chain daemon

type BlockChainParser

type BlockChainParser interface {
	// self description
	// UTXO chains need "inputs" column in db, that map transactions to transactions that spend them
	// non UTXO chains have mapping of address to input and output transactions directly in "outputs" column in db
	IsUTXOChain() bool
	// KeepBlockAddresses returns number of blocks which are to be kept in blockaddresses column
	// and used in case of fork
	// if 0 the blockaddresses column is not used at all (usually non UTXO chains)
	KeepBlockAddresses() int
	// address id conversions
	GetAddrIDFromVout(output *Vout) ([]byte, error)
	GetAddrIDFromAddress(address string) ([]byte, error)
	// address to output script conversions
	AddressToOutputScript(address string) ([]byte, error)
	OutputScriptToAddresses(script []byte) ([]string, error)
	// transactions
	PackedTxidLen() int
	PackTxid(txid string) ([]byte, error)
	UnpackTxid(buf []byte) (string, error)
	ParseTx(b []byte) (*Tx, error)
	ParseTxFromJson(json.RawMessage) (*Tx, error)
	PackTx(tx *Tx, height uint32, blockTime int64) ([]byte, error)
	UnpackTx(buf []byte) (*Tx, uint32, error)
	// blocks
	PackBlockHash(hash string) ([]byte, error)
	UnpackBlockHash(buf []byte) (string, error)
	ParseBlock(b []byte) (*Block, error)
}

BlockChainParser defines common interface to parsing and conversions of block chain data

type BlockHeader

type BlockHeader struct {
	Hash          string `json:"hash"`
	Prev          string `json:"previousblockhash"`
	Next          string `json:"nextblockhash"`
	Height        uint32 `json:"height"`
	Confirmations int    `json:"confirmations"`
}

type MQ

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

MQ is message queue listener handle

func NewMQ

func NewMQ(binding string, callback func(NotificationType)) (*MQ, error)

NewMQ creates new Bitcoind ZeroMQ listener callback function receives messages

func (*MQ) Shutdown

func (mq *MQ) Shutdown(ctx context.Context) error

Shutdown stops listening to the ZeroMQ and closes the connection

type MempoolEntry

type MempoolEntry struct {
	Size            uint32   `json:"size"`
	Fee             float64  `json:"fee"`
	ModifiedFee     float64  `json:"modifiedfee"`
	Time            float64  `json:"time"`
	Height          uint32   `json:"height"`
	DescendantCount uint32   `json:"descendantcount"`
	DescendantSize  uint32   `json:"descendantsize"`
	DescendantFees  uint32   `json:"descendantfees"`
	AncestorCount   uint32   `json:"ancestorcount"`
	AncestorSize    uint32   `json:"ancestorsize"`
	AncestorFees    uint32   `json:"ancestorfees"`
	Depends         []string `json:"depends"`
}

type NonUTXOMempool

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

NonUTXOMempool is mempool handle of non UTXO chains

func NewNonUTXOMempool

func NewNonUTXOMempool(chain BlockChain) *NonUTXOMempool

NewNonUTXOMempool creates new mempool handler.

func (*NonUTXOMempool) GetTransactions

func (m *NonUTXOMempool) GetTransactions(address string) ([]string, error)

GetTransactions returns slice of mempool transactions for given address

func (*NonUTXOMempool) Resync

func (m *NonUTXOMempool) Resync(onNewTxAddr OnNewTxAddrFunc) (int, error)

Resync gets mempool transactions and maps outputs to transactions. Resync is not reentrant, it should be called from a single thread. Read operations (GetTransactions) are safe.

type NotificationType

type NotificationType int

NotificationType is type of notification

const (
	// NotificationUnknown is unknown
	NotificationUnknown NotificationType = iota
	// NotificationNewBlock message is sent when there is a new block to be imported
	NotificationNewBlock NotificationType = iota
	// NotificationNewTx message is sent when there is a new mempool transaction
	NotificationNewTx NotificationType = iota
)

type OnNewBlockFunc

type OnNewBlockFunc func(hash string, height uint32)

OnNewBlockFunc is used to send notification about a new block

type OnNewTxAddrFunc

type OnNewTxAddrFunc func(txid string, addr string, isOutput bool)

OnNewTxAddrFunc is used to send notification about a new transaction/address

type ProtoTransaction

type ProtoTransaction struct {
	Txid      []byte                       `protobuf:"bytes,1,opt,name=Txid,proto3" json:"Txid,omitempty"`
	Hex       []byte                       `protobuf:"bytes,2,opt,name=Hex,proto3" json:"Hex,omitempty"`
	Blocktime uint64                       `protobuf:"varint,3,opt,name=Blocktime" json:"Blocktime,omitempty"`
	Locktime  uint32                       `protobuf:"varint,4,opt,name=Locktime" json:"Locktime,omitempty"`
	Height    uint32                       `protobuf:"varint,5,opt,name=Height" json:"Height,omitempty"`
	Vin       []*ProtoTransaction_VinType  `protobuf:"bytes,6,rep,name=Vin" json:"Vin,omitempty"`
	Vout      []*ProtoTransaction_VoutType `protobuf:"bytes,7,rep,name=Vout" json:"Vout,omitempty"`
}

func (*ProtoTransaction) Descriptor

func (*ProtoTransaction) Descriptor() ([]byte, []int)

func (*ProtoTransaction) GetBlocktime

func (m *ProtoTransaction) GetBlocktime() uint64

func (*ProtoTransaction) GetHeight

func (m *ProtoTransaction) GetHeight() uint32

func (*ProtoTransaction) GetHex

func (m *ProtoTransaction) GetHex() []byte

func (*ProtoTransaction) GetLocktime

func (m *ProtoTransaction) GetLocktime() uint32

func (*ProtoTransaction) GetTxid

func (m *ProtoTransaction) GetTxid() []byte

func (*ProtoTransaction) GetVin

func (*ProtoTransaction) GetVout

func (*ProtoTransaction) ProtoMessage

func (*ProtoTransaction) ProtoMessage()

func (*ProtoTransaction) Reset

func (m *ProtoTransaction) Reset()

func (*ProtoTransaction) String

func (m *ProtoTransaction) String() string

type ProtoTransaction_VinType

type ProtoTransaction_VinType struct {
	Coinbase     string   `protobuf:"bytes,1,opt,name=Coinbase" json:"Coinbase,omitempty"`
	Txid         []byte   `protobuf:"bytes,2,opt,name=Txid,proto3" json:"Txid,omitempty"`
	Vout         uint32   `protobuf:"varint,3,opt,name=Vout" json:"Vout,omitempty"`
	ScriptSigHex []byte   `protobuf:"bytes,4,opt,name=ScriptSigHex,proto3" json:"ScriptSigHex,omitempty"`
	Sequence     uint32   `protobuf:"varint,5,opt,name=Sequence" json:"Sequence,omitempty"`
	Addresses    []string `protobuf:"bytes,6,rep,name=Addresses" json:"Addresses,omitempty"`
}

func (*ProtoTransaction_VinType) Descriptor

func (*ProtoTransaction_VinType) Descriptor() ([]byte, []int)

func (*ProtoTransaction_VinType) GetAddresses

func (m *ProtoTransaction_VinType) GetAddresses() []string

func (*ProtoTransaction_VinType) GetCoinbase

func (m *ProtoTransaction_VinType) GetCoinbase() string

func (*ProtoTransaction_VinType) GetScriptSigHex

func (m *ProtoTransaction_VinType) GetScriptSigHex() []byte

func (*ProtoTransaction_VinType) GetSequence

func (m *ProtoTransaction_VinType) GetSequence() uint32

func (*ProtoTransaction_VinType) GetTxid

func (m *ProtoTransaction_VinType) GetTxid() []byte

func (*ProtoTransaction_VinType) GetVout

func (m *ProtoTransaction_VinType) GetVout() uint32

func (*ProtoTransaction_VinType) ProtoMessage

func (*ProtoTransaction_VinType) ProtoMessage()

func (*ProtoTransaction_VinType) Reset

func (m *ProtoTransaction_VinType) Reset()

func (*ProtoTransaction_VinType) String

func (m *ProtoTransaction_VinType) String() string

type ProtoTransaction_VoutType

type ProtoTransaction_VoutType struct {
	Value           float64  `protobuf:"fixed64,1,opt,name=Value" json:"Value,omitempty"`
	N               uint32   `protobuf:"varint,2,opt,name=N" json:"N,omitempty"`
	ScriptPubKeyHex []byte   `protobuf:"bytes,3,opt,name=ScriptPubKeyHex,proto3" json:"ScriptPubKeyHex,omitempty"`
	Addresses       []string `protobuf:"bytes,4,rep,name=Addresses" json:"Addresses,omitempty"`
}

func (*ProtoTransaction_VoutType) Descriptor

func (*ProtoTransaction_VoutType) Descriptor() ([]byte, []int)

func (*ProtoTransaction_VoutType) GetAddresses

func (m *ProtoTransaction_VoutType) GetAddresses() []string

func (*ProtoTransaction_VoutType) GetN

func (*ProtoTransaction_VoutType) GetScriptPubKeyHex

func (m *ProtoTransaction_VoutType) GetScriptPubKeyHex() []byte

func (*ProtoTransaction_VoutType) GetValue

func (m *ProtoTransaction_VoutType) GetValue() float64

func (*ProtoTransaction_VoutType) ProtoMessage

func (*ProtoTransaction_VoutType) ProtoMessage()

func (*ProtoTransaction_VoutType) Reset

func (m *ProtoTransaction_VoutType) Reset()

func (*ProtoTransaction_VoutType) String

func (m *ProtoTransaction_VoutType) String() string

type RPCError

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

func (*RPCError) Error

func (e *RPCError) Error() string

type ScriptPubKey

type ScriptPubKey struct {
	// Asm       string   `json:"asm"`
	Hex string `json:"hex,omitempty"`
	// Type      string   `json:"type"`
	Addresses []string `json:"addresses"`
}

type ScriptSig

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

type ThinBlock

type ThinBlock struct {
	BlockHeader
	Txids []string `json:"tx"`
}

type Tx

type Tx 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,omitempty"`
	Confirmations uint32 `json:"confirmations,omitempty"`
	Time          int64  `json:"time,omitempty"`
	Blocktime     int64  `json:"blocktime,omitempty"`
}

Tx is blockchain transaction unnecessary fields are commented out to avoid overhead

type UTXOMempool

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

UTXOMempool is mempool handle.

func NewUTXOMempool

func NewUTXOMempool(chain BlockChain, workers int, subworkers int) *UTXOMempool

NewUTXOMempool creates new mempool handler. For now there is no cleanup of sync routines, the expectation is that the mempool is created only once per process

func (*UTXOMempool) GetTransactions

func (m *UTXOMempool) GetTransactions(address string) ([]string, error)

GetTransactions returns slice of mempool transactions for given address

func (*UTXOMempool) Resync

func (m *UTXOMempool) Resync(onNewTxAddr OnNewTxAddrFunc) (int, error)

Resync gets mempool transactions and maps outputs to transactions. Resync is not reentrant, it should be called from a single thread. Read operations (GetTransactions) are safe.

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"`
	Addresses []string  `json:"addresses"`
}

type Vout

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

Directories

Path Synopsis
bch
btc
btg
eth
Package eth is a generated protocol buffer package.
Package eth is a generated protocol buffer package.
zec

Jump to

Keyboard shortcuts

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