Documentation ¶
Index ¶
- Constants
- Variables
- func GetFileRecordByDate(db *leveldb.DB, t string) (uint64, error)
- func GetRecordByHash(db *leveldb.DB, h string) ([]byte, error)
- func GetRecordByHeight(db *leveldb.DB, h uint64) ([]byte, error)
- func Hash160ToAddress(pk []byte, version byte) []byte
- func MkWitAddr(s []byte) (string, error)
- func OpenDB(f string) (*leveldb.DB, error)
- func Pk2Address(s []byte) ([]string, string, error)
- func ReadBlockRecord(data []byte, r string) (uint64, error)
- func ReadFileRecord(data []byte, r string) (uint64, error)
- func ReadVarint(buf *bytes.Reader) (uint64, int, error)
- func SSig2Addr(in *Inputs) error
- func SSigToPk(s []byte, ssize uint64) ([]byte, error)
- func ValidPkSize(size int, s byte) bool
- type Block
- type BlockHeader
- type Inputs
- type Outputs
- type SParams
- type TransacData
Constants ¶
const ( OP_DUP = 0x76 // duplicates the top stack item OP_HASH160 = 0xa9 // SHA-256 and RIPEMD-160 hashed input OP_EQUALVERIFY = 0x88 // inputs equality + verify result OP_CHECKSIG = 0xac // valid signature for this hash and public key OP_1 = 0x51 // 1 / True OP_3 = 0x53 // 3 OP_CHECKMULTISIG = 0xae // compares signatures OP_EQUAL = 0x87 // checks inputs equality OP_RETURN = 0x6a // no-op, invalid transaction OP_PUSHDATA1 = 0x4c // next byte contains the number of bytes to push )
Variables ¶
Functions ¶
func GetRecordByHash ¶
GetRecordByHash returns the block record corresponding to a database and hash given as parameters
func GetRecordByHeight ¶
GetRecordByHeight returns the block record corresponding to a database and block height given as parameters
func Hash160ToAddress ¶
Hash160ToAddress converts a Hash160 to an actual address Adapted from https://strm.sh/post/bitcoin-address-generation/
func Pk2Address ¶
Pk2Address converts public key from lock / scriptPubKey to plain address
func ReadBlockRecord ¶
ReadBlockRecord returns the value of record `r` in Block Index Record LevelDB value `data`
func ReadFileRecord ¶
ReadFileRecord returns the value of record `r` in File Information Record LevelDB value `data`
func ReadVarint ¶
ReadVarint returns a VarInt value and the varint size https://learnmeabitcoin.com/guide/varint https://bitcoin.org/en/developer-reference#compactsize-unsigned-integers This is not the same varint as in base 128 varint
func ValidPkSize ¶
ValidPkSize Determines if this is a valid public key size, uncompressed or compressed
Types ¶
type Block ¶
type Block struct { Magic uint32 `json:"magic"` Size uint32 `json:"size"` Header BlockHeader `json:"header"` TxCount uint64 `json:"txcount"` Transac []TransacData `json:"transacdata"` BlockHash string `json:"blockhash,omitempty"` }
Block holds the full block structure
func LoadBlocks ¶
LoadBlocks reads the blkXXXXX.dat file and returns structured data. It can optionally compute and load txid for each transaction, and every address involved in inputs and outputs. Those two options are enabled by setting txid and addrs to true.
func (*Block) ReadInputs ¶
ReadInputs reads and returns `incount` number of inputs
func (*Block) ReadOutputs ¶
ReadOutputs read and returns `outcount` number of outputs
func (*Block) ReadTransactions ¶
ReadTransactions loops through transactions and loads them This function receives a byte slice beginning with TxCount, then the raw transaction
type BlockHeader ¶
type BlockHeader struct { Version uint32 `json:"version"` PrevHash string `json:"prevhash"` MerkleRoot string `json:"merkleroot"` TimeStamp uint32 `json:"timestamp"` Target uint32 `json::"target"` Nonce uint32 `json:"nonce"` }
BlockHeader stores block's headers
type Inputs ¶
type Inputs struct { PrevTxid string `json:"prevtxid"` // Previous (output) TXID PrevOut uint32 `json:"prevout"` // Previous output number SSigSize uint64 `json:"ssigsize"` SSig []byte `json:"ssig"` Sequence uint32 `json:"sequence"` Address []string `json:"address,omitempty"` Coinbase bool `json:"coinbase"` Height uint32 `json:"height,omitempty"` Witness [][]byte `json:"witness,omitempty"` Raw []byte `json:"raw,omitempty"` LockType string `json:"locktype,omitempty"` }
Inputs / spending structure https://learnmeabitcoin.com/guide/input Plus custom fields (Coinbase, Height, Raw and LockType)
type Outputs ¶
type Outputs struct { Value uint64 `json:"value"` SPubKeySize uint64 `json:"spubkeysize"` SPubKey []byte `json:"spubkey"` Address string `json:"address,omitempty"` LockType string `json:"locktype,omitempty"` Raw []byte `json:"raw,omitempty"` }
Outputs https://learnmeabitcoin.com/guide/output Plus custom fields (LockType and Raw)
type SParams ¶
type SParams struct { NBlocks uint32 `json:"nblocks"` // number of blocks to load, 0 for all StartBlock uint32 `json:"startblock"` // block number to start loading at StartHash uint64 `json:"starthash"` // block hash to start reading at P2WPrefix string `json:"p2wprefix"` // SegWit address prefix LoadAddr bool `json:"loadaddr"` // load (output) addresses LoadInAddr bool `json:"loadinaddr"` // load / guess input addresses LoadTxid bool `json:"loadtxid"` // compute and load TXIDs LoadBlockHash bool `json:"loadblockhash"` // compute and load current block hash LoadRaw bool `json:"loadraw"` // load in and out raw data TransacFunc interface{} `json:"transacfunc"` // optional transactions helper function TFuncParam string `json:"tfuncparam"` // optional parameter for transaction callback BlockFunc interface{} `json:"blockfunc"` // optional block load helper function BFuncParam string `json:"bfuncparam"` // optional parameter for block callback }
SParams holds block loading parameters
type TransacData ¶
type TransacData struct { Version uint32 `json:"version"` InCount uint64 `json:"incount"` Ins []Inputs `json:"inputs"` OutCount uint64 `json:"outcount"` Outs []Outputs `json:"outputs"` LockTime uint32 `json:"locktime"` Raw []byte `json:"raw,omitempty"` Txid string `json:"txid,omitempty"` SegWit bool `json:"segwit"` WTxid string `json:"wtxid,omitempty"` }
TransacData holds the transaction data https://learnmeabitcoin.com/guide/transaction-data