blockchainparser

package module
v0.0.0-...-990a888 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2017 License: MIT Imports: 9 Imported by: 2 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Bitcoin Blockchain Parser Library

This library provide methods to access and parse raw block files (blocks/blk####.dat), database files (blocks/index) and to some extend expose some of the RPC commands provided by bitcoind for Go language.

Authors

  • Faruq Rasid - Initial work - ruqqq

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Acknowledgments

  • TO BE UPDATED

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BitcoinDir

func BitcoinDir() string

func ParseBlockHeaderFromFile

func ParseBlockHeaderFromFile(blockFile *BlockFile, block *Block) error

Parse the header fields except the MagicId TODO: Currently won't return any error

func ParseBlockTransactionsFromFile

func ParseBlockTransactionsFromFile(blockFile *BlockFile, block *Block) error

func ReverseHex

func ReverseHex(b []byte) []byte

TODO: Maybe can optimize

func Varint

func Varint(n uint64) []byte

Types

type Block

type Block struct {
	BlockHeader      // actual pos below Length field
	MagicId          MagicId
	Length           uint32
	TransactionCount uint64 // txn_count
	Transactions     []Transaction
	StartPos         uint64 // not actually in blockchain data
}

func NewBlockFromFile

func NewBlockFromFile(blockchainDataDir string, magicHeader MagicId, num uint32, pos uint32) (*Block, error)

func ParseBlockFromFile

func ParseBlockFromFile(blockFile *BlockFile, magicHeader MagicId) (*Block, error)

type BlockFile

type BlockFile struct {
	FileNum uint32
	// contains filtered or unexported fields
}

func NewBlockFile

func NewBlockFile(blockchainDataDir string, fileNum uint32) (*BlockFile, error)

func (*BlockFile) Close

func (blockFile *BlockFile) Close()

func (*BlockFile) Peek

func (blockFile *BlockFile) Peek(length int) ([]byte, error)

func (*BlockFile) ReadByte

func (blockFile *BlockFile) ReadByte() byte

func (*BlockFile) ReadBytes

func (blockFile *BlockFile) ReadBytes(length uint64) []byte

func (*BlockFile) ReadInt32

func (blockFile *BlockFile) ReadInt32() int32

func (*BlockFile) ReadInt64

func (blockFile *BlockFile) ReadInt64() int64

func (*BlockFile) ReadUint16

func (blockFile *BlockFile) ReadUint16() uint16

func (*BlockFile) ReadUint32

func (blockFile *BlockFile) ReadUint32() uint32

func (*BlockFile) ReadUint64

func (blockFile *BlockFile) ReadUint64() uint64

func (*BlockFile) ReadVarint

func (blockFile *BlockFile) ReadVarint() uint64

func (*BlockFile) Seek

func (blockFile *BlockFile) Seek(offset int64, whence int) (int64, error)

func (*BlockFile) Size

func (blockFile *BlockFile) Size() (int64, error)

type BlockHeader

type BlockHeader struct {
	Version          int32
	HashPrev         Hash256
	HashMerkle       Hash256
	Timestamp        time.Time
	TargetDifficulty uint32 // bits
	Nonce            uint32
	// contains filtered or unexported fields
}

func (*BlockHeader) Hash

func (blockHeader *BlockHeader) Hash() Hash256

type Hash256

type Hash256 []byte

func DoubleSha256

func DoubleSha256(data []byte) Hash256

func (Hash256) String

func (hash Hash256) String() string

type MagicId

type MagicId uint32
const (
	//! Magic numbers to identify start of block
	BLOCK_MAGIC_ID_BITCOIN MagicId = 0xd9b4bef9
	BLOCK_MAGIC_ID_TESTNET MagicId = 0x0709110b
)

func (MagicId) String

func (magicId MagicId) String() string

type Script

type Script []byte

func (Script) String

func (script Script) String() string

type Transaction

type Transaction struct {
	Version  int32
	Locktime uint32
	Vin      []TxInput
	Vout     []TxOutput
	StartPos uint64 // not actually in blockchain data
	// contains filtered or unexported fields
}

func NewTxFromFile

func NewTxFromFile(blockchainDataDir string, magicHeader MagicId, num uint32, pos uint32, txPos uint32) (*Transaction, error)

func ParseBlockTransactionFromFile

func ParseBlockTransactionFromFile(blockFile *BlockFile) (*Transaction, error)

func (Transaction) HasWitness

func (tx Transaction) HasWitness() bool

func (Transaction) Txid

func (tx Transaction) Txid() Hash256

type TxInput

type TxInput struct {
	Hash          Hash256
	Index         uint32
	Script        Script
	Sequence      uint32
	ScriptWitness [][]byte
}

func (TxInput) Binary

func (in TxInput) Binary() []byte

func (TxInput) ScriptWitnessBinary

func (in TxInput) ScriptWitnessBinary() []byte

type TxOutput

type TxOutput struct {
	Value  int64
	Script Script
}

func (TxOutput) BTC

func (out TxOutput) BTC() float64

func (TxOutput) Binary

func (out TxOutput) Binary() []byte

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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