Documentation ¶
Index ¶
- Constants
- Variables
- func CurrentCoinbase(timestamp time.Time, nonceSize int, addresses []MinerAddress) (cb1 []byte, cb2 []byte)
- func DigestFromBytes(digest *Digest, buffer []byte) error
- func Finalise()
- func Initialise()
- func MinerAddressFromBytes(m *MinerAddress, buffer []byte) error
- func MinerCheckIn(timestamp time.Time, ntime uint32, nonce uint32, extraNonce []byte, ...) (Digest, Packed, bool)
- func NewCoinbase(blockNumber uint64, timestamp time.Time, nonceSize int, ...) (cb1 []byte, cb2 []byte)
- func Number() uint64
- func Pack(blockNumber uint64, timestamp time.Time, difficulty *difficulty.Difficulty, ...) (Digest, Packed, bool)
- func PrintBlockTimes(fh io.Writer, beginBlockNumber uint64, endBlockNumber uint64)
- type Block
- type CoinbaseData
- type Digest
- func (digest Digest) BtcHex() string
- func (digest Digest) Cmp(difficulty *big.Int) int
- func (digest Digest) GoString() string
- func (digest Digest) MarshalJSON() ([]byte, error)
- func (digest Digest) MarshalText() ([]byte, error)
- func (digest Digest) MinerHex() string
- func (digest *Digest) Scan(state fmt.ScanState, verb rune) error
- func (digest Digest) String() string
- func (digest *Digest) UnmarshalJSON(s []byte) error
- func (digest *Digest) UnmarshalText(s []byte) error
- type Header
- type Mined
- type MinerAddress
- type Packed
- type PackedCoinbase
- type PackedHeader
Constants ¶
const DigestSize = 32
number of bytes in the digest
const (
ExpectedMinutes = 10 // number of minutes to mine a block
)
constants
const (
GenesisBlockNumber = uint64(1)
)
the starting block number
const (
OP_RETURN = byte(0x6a)
)
bitcoin operations
const (
Version = 2 // simulating block headers compatible with this Bitcoin version
)
constant values
Variables ¶
var LiveGenesisBlock = Packed([]byte{
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x88, 0x01, 0x89, 0x7b,
0x89, 0x71, 0x5a, 0x19, 0xbf, 0xbf, 0xb3, 0xd0,
0x71, 0x81, 0xd5, 0xc5, 0x7c, 0xc7, 0x61, 0xaf,
0xfd, 0xb8, 0x41, 0x06, 0x78, 0xd6, 0xac, 0xc6,
0xa0, 0xa9, 0x7e, 0x69, 0xb7, 0x9a, 0x80, 0x56,
0xff, 0xff, 0x00, 0x1d, 0x02, 0x40, 0xf1, 0xfd,
0x64, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff,
0xff, 0xff, 0xff, 0x11, 0x02, 0x01, 0x00, 0x04,
0xb7, 0x9a, 0x80, 0x56, 0x08, 0x42, 0x4d, 0x52,
0x4b, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x17, 0x6a, 0x00, 0x14, 0x44, 0x4f,
0x57, 0x4e, 0x20, 0x74, 0x68, 0x65, 0x20, 0x52,
0x41, 0x42, 0x42, 0x49, 0x54, 0x20, 0x68, 0x6f,
0x6c, 0x65, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
0x88, 0x01, 0x89, 0x7b, 0x89, 0x71, 0x5a, 0x19,
0xbf, 0xbf, 0xb3, 0xd0, 0x71, 0x81, 0xd5, 0xc5,
0x7c, 0xc7, 0x61, 0xaf, 0xfd, 0xb8, 0x41, 0x06,
0x78, 0xd6, 0xac, 0xc6, 0xa0, 0xa9, 0x7e, 0x69,
})
var LiveGenesisDigest = Digest([...]byte{
0x77, 0xa0, 0xf7, 0x2e, 0x22, 0xf6, 0xb9, 0x18,
0x61, 0x3d, 0x96, 0x3e, 0xe0, 0x97, 0xdc, 0x13,
0x43, 0x05, 0x6f, 0x70, 0x6a, 0x84, 0xb9, 0x9e,
0x30, 0x5f, 0x6b, 0x7e, 0x00, 0x00, 0x00, 0x00,
})
digest of the live genesis header 000000007e6b5f309eb9846a706f054313dc97e03e963d6118b9f6222ef7a077
var TestGenesisBlock = Packed([]byte{
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xaa, 0x5e, 0x56, 0xa6,
0xd8, 0x3f, 0xd0, 0xfd, 0xc7, 0x58, 0x3f, 0x33,
0xb1, 0x17, 0xb5, 0x4d, 0xfb, 0x30, 0x12, 0x1c,
0xa9, 0x2d, 0xcc, 0xf3, 0x34, 0xc3, 0x5b, 0x67,
0x8c, 0xdc, 0xe9, 0x3c, 0x4b, 0x42, 0x78, 0x54,
0xff, 0xff, 0x00, 0x1d, 0x3b, 0xa8, 0xcc, 0xae,
0x6d, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff,
0xff, 0xff, 0xff, 0x11, 0x02, 0x01, 0x00, 0x04,
0x4b, 0x42, 0x78, 0x54, 0x08, 0x42, 0x4d, 0x52,
0x4b, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x20, 0x6a, 0x00, 0x1d, 0x42, 0x69,
0x74, 0x6d, 0x61, 0x72, 0x6b, 0x20, 0x54, 0x65,
0x73, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x47, 0x65,
0x6e, 0x65, 0x73, 0x69, 0x73, 0x20, 0x42, 0x6c,
0x6f, 0x63, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x01,
0x00, 0xaa, 0x5e, 0x56, 0xa6, 0xd8, 0x3f, 0xd0,
0xfd, 0xc7, 0x58, 0x3f, 0x33, 0xb1, 0x17, 0xb5,
0x4d, 0xfb, 0x30, 0x12, 0x1c, 0xa9, 0x2d, 0xcc,
0xf3, 0x34, 0xc3, 0x5b, 0x67, 0x8c, 0xdc, 0xe9,
0x3c,
})
var TestGenesisDigest = Digest([...]byte{
0x20, 0xa0, 0x5d, 0x03, 0x00, 0xee, 0x7c, 0xf9,
0x5b, 0x57, 0xa3, 0x2e, 0x0b, 0xfd, 0x3e, 0x45,
0x21, 0xae, 0x16, 0x82, 0x29, 0x46, 0x19, 0x93,
0x5a, 0x72, 0x6b, 0x70, 0x00, 0x00, 0x00, 0x00,
})
digest of the test genesis header 00000000706b725a931946298216ae21453efd0b2ea3575bf97cee00035da020
Functions ¶
func CurrentCoinbase ¶
func CurrentCoinbase(timestamp time.Time, nonceSize int, addresses []MinerAddress) (cb1 []byte, cb2 []byte)
create a split coinbase transaction for the miner using the current block number
func DigestFromBytes ¶
convert and validate little endian binary byte slice to a digest
func MinerAddressFromBytes ¶
func MinerAddressFromBytes(m *MinerAddress, buffer []byte) error
convert and validate little endian binary byte slice to a MinerAddress
func MinerCheckIn ¶
func MinerCheckIn(timestamp time.Time, ntime uint32, nonce uint32, extraNonce []byte, addresses []MinerAddress, ids []Digest) (Digest, Packed, bool)
create the combined block assuming current state
binary format:
- packed header
- coinbase a. length (little endian int16) b. packed coinbase
- transaction count + 1 (to account for coinbase digest) (little endian int16) a. coinbase digest b. list of txids (digests)
- full merkle tree computed from 3
validate submitted data, and save the block
func NewCoinbase ¶
func NewCoinbase(blockNumber uint64, timestamp time.Time, nonceSize int, addresses []MinerAddress) (cb1 []byte, cb2 []byte)
create a split coinbase transaction for the miner
func Pack ¶
func Pack(blockNumber uint64, timestamp time.Time, difficulty *difficulty.Difficulty, ntime uint32, nonce uint32, extraNonce []byte, addresses []MinerAddress, ids []Digest) (Digest, Packed, bool)
create a packed block from various pieces
Types ¶
type Block ¶
type Block struct { Digest Digest Number uint64 Timestamp time.Time // the 64 bit timestamp from coinbase, _NOT_ block header ntime Addresses []MinerAddress Header Header Coinbase []byte TxIds []Digest }
type to hold the unpacked block
type CoinbaseData ¶
type CoinbaseData struct { BlockNumber uint64 Timestamp time.Time Addresses []MinerAddress }
type to hold some data unpacked from the coinbase
type Digest ¶
type Digest [DigestSize]byte
the type for a digest stored as little endian byte array represented as big endian hex value for print represented as little endian hex text for JSON encoding
func FullMerkleTree ¶
compute minimum merkle root from coinbase + minimum tree
structure is:
- coinbase digest
- N * transaction digests
- level 1..m digests
- merkle root digest
Note for an empty txIds array the result is just one element
i.e. merkle root == coinbase (Digest) only the genesis block is like this
func MinimumMerkleTree ¶
merkle hashing
build a minimised tree lacking a coinbase i.e. ids[0] is 2nd transaction (the one after the coinbase)
func (Digest) BtcHex ¶
convert a binary digest to BTC little endian word swapped hex string for use by miners
func (Digest) GoString ¶
convert a binary digest to big endian hex string for use by the fmt package (for %#v)
func (Digest) MarshalJSON ¶
convert a binary digest to little endian hex for JSON
func (Digest) MarshalText ¶
convert digest to little endian hex text
func (Digest) MinerHex ¶
convert a binary digest to hex string for use by the stratum miner
the stored version and the output string are both little endian
func (*Digest) Scan ¶
convert a big endian hex representation to a digest for use by the format package scan routines
func (Digest) String ¶
convert a binary digest to hex string for use by the fmt package (for %s)
the stored version is in little endian, but the output string is big endian
func (*Digest) UnmarshalJSON ¶
convert a little endian hex string to a digest for conversion from JSON
func (*Digest) UnmarshalText ¶
convert little endian hex text into a digest
type Header ¶
type Header struct { Version uint32 PreviousBlock Digest MerkleRoot Digest Time uint32 Bits difficulty.Difficulty Nonce uint32 }
the unpacked header structure the types here must match Bitcoin header types
func (*Header) Pack ¶
func (header *Header) Pack() PackedHeader
turn a record into an array of bytes
the byte ordering matches a Bitcoin header
type MinerAddress ¶
to hold miner address and its corresponding currency code
func (*MinerAddress) String ¶
func (m *MinerAddress) String() string
convert a miner address to a string for use as a map index
type Packed ¶
type Packed []byte // for general distribution
for packed block
type PackedCoinbase ¶
type PackedCoinbase []byte
the packed coinbase data
func NewFullCoinbase ¶
func NewFullCoinbase(blockNumber uint64, timestamp time.Time, nonce []byte, addresses []MinerAddress) (cb PackedCoinbase)
create a full coinbase transaction for the block
func (PackedCoinbase) Unpack ¶
func (coinbase PackedCoinbase) Unpack(coinbaseData *CoinbaseData) error
unpack some data from the coinbase
type PackedHeader ¶
type PackedHeader []byte
packed records are just a byte slice
func (PackedHeader) Unpack ¶
func (record PackedHeader) Unpack(header *Header) error
turn a byte slice into a record