blkparser

package module
v0.0.0-...-b268482 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2015 License: MIT Imports: 9 Imported by: 2

README

Blkparser

Open source Bitcoin block chain parser written in Go.

You must handle block height and orphaned blocks if any yourself, and it doesn't perform any verification, it assumes stored blocks are valid.

Documentation

See the API reference.

## Installation

$ go get github.com/tsileo/blkparser

License

Copyright (c) 2014 Thomas Sileo

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeVariableLengthInteger

func DecodeVariableLengthInteger(raw []byte) (cnt int, cnt_size int)

Get the Tx count, decode the variable length integer https://en.bitcoin.it/wiki/Protocol_specification#Variable_length_integer

func GetShaString

func GetShaString(data []byte) (res string)

func HashString

func HashString(data []byte) (res string)

Types

type Block

type Block struct {
	Raw         []byte  `json:"-"`
	Hash        string  `json:"hash"`
	Height      uint    `json:"height"`
	Txs         []*Tx   `json:"tx,omitempty"`
	Version     uint32  `json:"ver"`
	MerkleRoot  string  `json:"mrkl_root"`
	BlockTime   uint32  `json:"time"`
	Bits        uint32  `json:"bits"`
	Nonce       uint32  `json:"nonce"`
	Size        uint32  `json:"size"`
	TxCnt       uint32  `json:"n_tx"`
	TotalBTC    uint64  `json:"total_out"`
	BlockReward float64 `json:"-"`
	Parent      string  `json:"prev_block"`
	Next        string  `json:"next_block"`
}

func NewBlock

func NewBlock(rawblock []byte) (block *Block, err error)

type Blockchain

type Blockchain struct {
	Path        string
	Magic       [4]byte
	CurrentFile *os.File
	CurrentId   uint32
}

func NewBlockchain

func NewBlockchain(path string, magic [4]byte) (blockchain *Blockchain, err error)

func (*Blockchain) FetchNextBlock

func (blockchain *Blockchain) FetchNextBlock() (rawblock []byte, err error)

func (*Blockchain) NextBlock

func (blockchain *Blockchain) NextBlock() (block *Block, err error)

func (*Blockchain) SkipBlock

func (blockchain *Blockchain) SkipBlock() (err error)

func (*Blockchain) SkipTo

func (blockchain *Blockchain) SkipTo(blkId uint32, offset int64) (err error)

Convenience method to skip directly to the given blkfile / offset, you must take care of the height

type Tx

type Tx struct {
	Hash     string
	Size     uint32
	LockTime uint32
	Version  uint32
	TxInCnt  uint32
	TxOutCnt uint32
	TxIns    []*TxIn
	TxOuts   []*TxOut
}

func NewTx

func NewTx(rawtx []byte) (tx *Tx, offset int)

func ParseTxs

func ParseTxs(txsraw []byte) (txs []*Tx, err error)

type TxIn

type TxIn struct {
	InputHash string
	InputVout uint32
	ScriptSig []byte
	Sequence  uint32
}

func NewTxIn

func NewTxIn(txinraw []byte) (txin *TxIn, offset int)

type TxOut

type TxOut struct {
	Addr     string
	Value    uint64
	Pkscript []byte
}

func NewTxOut

func NewTxOut(txoutraw []byte) (txout *TxOut, offset int)

Jump to

Keyboard shortcuts

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