jsonblock

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateOpenTransactionIndexerFiles

func CreateOpenTransactionIndexerFiles(folderName string) transactionindexing.ITransactionIndexer

func HardCodedJsonBlock

func HardCodedJsonBlock(height int64) string

func HardCodedJsonBlockCount

func HardCodedJsonBlockCount() int64

func HashOfString

func HashOfString(in string) indexedhashes.Sha256

func PostJsonArrayIndicesIntoElements added in v0.0.12

func PostJsonArrayIndicesIntoElements(block *JsonBlockEssential)

func PostJsonCalculateSatoshis added in v0.0.12

func PostJsonCalculateSatoshis(block *JsonBlockEssential)

func PostJsonEncodeAddressHashes added in v0.0.12

func PostJsonEncodeAddressHashes(block *JsonBlockEssential) error

func PostJsonEncodeAddressHashes2 added in v0.0.12

func PostJsonEncodeAddressHashes2(block *JsonBlockHashes) error

func PostJsonEncodeSha256s added in v0.0.12

func PostJsonEncodeSha256s(block *JsonBlockEssential) error

func PostJsonEncodeSha256s2 added in v0.0.12

func PostJsonEncodeSha256s2(block *JsonBlockHashes) error

func PostJsonGatherNonEssentialInts added in v0.0.12

func PostJsonGatherNonEssentialInts(block *JsonBlockEssential)

func PostJsonRemoveCoinbaseTxis added in v0.0.12

func PostJsonRemoveCoinbaseTxis(block *JsonBlockEssential)

func TestGenesisHandle_helper

func TestGenesisHandle_helper(blockchain chainreadinterface.IBlockChain, t *testing.T)

func TestInvalidHandle_helper

func TestInvalidHandle_helper(blockchain chainreadinterface.IBlockChain, t *testing.T)

func TestJustFiveCoinbaseBlocks_helper

func TestJustFiveCoinbaseBlocks_helper(blockchain chainreadinterface.IBlockChain, t *testing.T)

Types

type AddressHandle

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

func (*AddressHandle) Hash

func (ah *AddressHandle) Hash() indexedhashes.Sha256

Functions in jsonblock.AddressHandle to implement chainreadinterface.IAddressHandle

func (*AddressHandle) HashSpecified

func (ah *AddressHandle) HashSpecified() bool

func (*AddressHandle) Height

func (ah *AddressHandle) Height() int64

func (*AddressHandle) HeightSpecified

func (ah *AddressHandle) HeightSpecified() bool

func (*AddressHandle) NthTxo

func (*AddressHandle) TxoCount

func (ah *AddressHandle) TxoCount() (int64, error)

type BlockHandle

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

func (*BlockHandle) Hash

func (bh *BlockHandle) Hash() (indexedhashes.Sha256, error)

func (*BlockHandle) HashSpecified

func (bh *BlockHandle) HashSpecified() bool

func (*BlockHandle) Height

func (bh *BlockHandle) Height() int64

func (*BlockHandle) HeightSpecified

func (bh *BlockHandle) HeightSpecified() bool

func (*BlockHandle) IsBlockHandle

func (bh *BlockHandle) IsBlockHandle()

func (*BlockHandle) IsInvalid

func (bh *BlockHandle) IsInvalid() bool

type HardCodedBlockFetcher

type HardCodedBlockFetcher struct {
}

func (*HardCodedBlockFetcher) CountBlocks

func (fbf *HardCodedBlockFetcher) CountBlocks() (int64, error)

func (*HardCodedBlockFetcher) FetchBlockJsonBytes

func (fbf *HardCodedBlockFetcher) FetchBlockJsonBytes(height int64) ([]byte, error)

type HashesBlockChain added in v0.0.12

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

HashesBlockChain - Just the hashes (block, transaction, address) One block is in memory at any one time

func CreateHashesBlockChain added in v0.0.12

func CreateHashesBlockChain(fetcher IBlockJsonFetcher) *HashesBlockChain

func (*HashesBlockChain) SwitchBlock added in v0.0.12

func (hbc *HashesBlockChain) SwitchBlock(blockHeightRequested int64) (*JsonBlockHashes, error)

type IBlockJsonFetcher

type IBlockJsonFetcher interface {
	CountBlocks() (int64, error)
	FetchBlockJsonBytes(height int64) ([]byte, error)
}

IBlockJsonFetcher describes an object that serves each block as json bytes

type ITransIndicesPath

type ITransIndicesPath interface {
	BlockHeight() int64
	NthTransInBlock() int64
}

type ITransLocatorByHash

type ITransLocatorByHash interface {
	GetTransIndicesPathByHash(sha256 indexedhashes.Sha256) (ITransIndicesPath, error)
}

ITransLocatorByHash describes an object that obtains a transaction's Indices Path (block/trans) based on hash

type JsonBlockEssential

type JsonBlockEssential struct {
	J_height int                  `json:"height"`
	J_hash   string               `json:"hash"`
	J_tx     []JsonTransEssential `json:"tx"`

	// Non essential integers
	// Changes here should be reflected in postJsonGatherNonEssentialInts()
	J_version      int64   `json:"version"`
	J_time         int64   `json:"time"`
	J_mediantime   int64   `json:"mediantime"`
	J_nonce        int64   `json:"nonce"`
	J_difficulty   float64 `json:"difficulty"`
	J_strippedsize int64   `json:"strippedsize"`
	J_size         int64   `json:"size"`
	J_weight       int64   `json:"weight"`
	// contains filtered or unexported fields
}

func ParseJsonBlock added in v0.0.12

func ParseJsonBlock(jsonBytes []byte) (*JsonBlockEssential, error)

func (*JsonBlockEssential) BlockHash added in v0.0.12

func (jb *JsonBlockEssential) BlockHash() indexedhashes.Sha256

func (*JsonBlockEssential) Hash

func (*JsonBlockEssential) HashSpecified

func (b *JsonBlockEssential) HashSpecified() bool

func (*JsonBlockEssential) Height

func (b *JsonBlockEssential) Height() int64

func (*JsonBlockEssential) HeightSpecified

func (b *JsonBlockEssential) HeightSpecified() bool

func (*JsonBlockEssential) IsBlockHandle

func (b *JsonBlockEssential) IsBlockHandle()

func (*JsonBlockEssential) IsInvalid

func (b *JsonBlockEssential) IsInvalid() bool

func (*JsonBlockEssential) NonEssentialInts

func (b *JsonBlockEssential) NonEssentialInts() (*map[string]int64, error)

func (*JsonBlockEssential) NthTransaction

func (*JsonBlockEssential) TransactionCount

func (b *JsonBlockEssential) TransactionCount() (int64, error)

type JsonBlockHashes added in v0.0.12

type JsonBlockHashes struct {
	J_height int               `json:"height"`
	J_hash   string            `json:"hash"`
	J_tx     []JsonTransHashes `json:"tx"`
	// contains filtered or unexported fields
}

func ParseJsonBlockHashes added in v0.0.12

func ParseJsonBlockHashes(jsonBytes []byte) (*JsonBlockHashes, error)

func (*JsonBlockHashes) BlockHash added in v0.0.12

func (jb *JsonBlockHashes) BlockHash() indexedhashes.Sha256

type JsonScriptPubKeyEssential added in v0.0.12

type JsonScriptPubKeyEssential struct {
	J_hex     string `json:"hex"`
	J_address string `json:"address"`
	J_type    string `json:"type"`
	// contains filtered or unexported fields
}

type JsonScriptPubKeyEssential2 added in v0.0.12

type JsonScriptPubKeyEssential2 struct {
	J_hex     string `json:"hex"`
	J_address string `json:"address"`
	J_type    string `json:"type"`
	// contains filtered or unexported fields
}

type JsonTransEssential added in v0.0.12

type JsonTransEssential struct {
	J_txid string             `json:"txid"`
	J_vin  []JsonTxiEssential `json:"vin"`
	J_vout []JsonTxoEssential `json:"vout"`

	// Non essential integers
	J_version  int64 `json:"version"`
	J_size     int64 `json:"size"`
	J_vsize    int64 `json:"vsize"`
	J_weight   int64 `json:"weight"`
	J_locktime int64 `json:"locktime"`
	// contains filtered or unexported fields
}

func (*JsonTransEssential) Hash added in v0.0.12

func (*JsonTransEssential) HashSpecified added in v0.0.12

func (t *JsonTransEssential) HashSpecified() bool

func (*JsonTransEssential) Height added in v0.0.12

func (t *JsonTransEssential) Height() int64

func (*JsonTransEssential) HeightSpecified added in v0.0.12

func (t *JsonTransEssential) HeightSpecified() bool

func (*JsonTransEssential) IndicesPath added in v0.0.12

func (t *JsonTransEssential) IndicesPath() (int64, int64)

func (*JsonTransEssential) IndicesPathSpecified added in v0.0.12

func (t *JsonTransEssential) IndicesPathSpecified() bool

func (*JsonTransEssential) IsInvalid added in v0.0.12

func (t *JsonTransEssential) IsInvalid() bool

func (*JsonTransEssential) IsTransHandle added in v0.0.12

func (t *JsonTransEssential) IsTransHandle()

func (*JsonTransEssential) NonEssentialInts added in v0.0.12

func (t *JsonTransEssential) NonEssentialInts() (*map[string]int64, error)

func (*JsonTransEssential) NthTxi added in v0.0.12

func (*JsonTransEssential) NthTxo added in v0.0.12

func (*JsonTransEssential) TransHash added in v0.0.12

func (jt *JsonTransEssential) TransHash() indexedhashes.Sha256

func (*JsonTransEssential) TxiCount added in v0.0.12

func (t *JsonTransEssential) TxiCount() (int64, error)

func (*JsonTransEssential) TxoCount added in v0.0.12

func (t *JsonTransEssential) TxoCount() (int64, error)

type JsonTransHashes added in v0.0.12

type JsonTransHashes struct {
	J_txid string          `json:"txid"`
	J_vout []JsonTxoHashes `json:"vout"` // We're not interested in vins as they don't define any hashes
	// contains filtered or unexported fields
}

func (*JsonTransHashes) TransHash added in v0.0.12

func (jt *JsonTransHashes) TransHash() indexedhashes.Sha256

type JsonTxiEssential added in v0.0.12

type JsonTxiEssential struct {
	J_txid string `json:"txid"`
	J_vout int    `json:"vout"`
	// contains filtered or unexported fields
}

func (*JsonTxiEssential) IndicesPath added in v0.0.12

func (txi *JsonTxiEssential) IndicesPath() (int64, int64, int64)

func (*JsonTxiEssential) IndicesPathSpecified added in v0.0.12

func (txi *JsonTxiEssential) IndicesPathSpecified() bool

func (*JsonTxiEssential) ParentIndex added in v0.0.12

func (txi *JsonTxiEssential) ParentIndex() int64

func (*JsonTxiEssential) ParentSpecified added in v0.0.12

func (txi *JsonTxiEssential) ParentSpecified() bool

func (*JsonTxiEssential) ParentTrans added in v0.0.12

func (*JsonTxiEssential) SourceTxo added in v0.0.12

func (*JsonTxiEssential) TxiHeight added in v0.0.12

func (txi *JsonTxiEssential) TxiHeight() int64

func (*JsonTxiEssential) TxiHeightSpecified added in v0.0.12

func (txi *JsonTxiEssential) TxiHeightSpecified() bool

type JsonTxoEssential added in v0.0.12

type JsonTxoEssential struct {
	J_value        float64                   `json:"value"`
	J_scriptPubKey JsonScriptPubKeyEssential `json:"scriptPubKey"`
	// contains filtered or unexported fields
}

func (*JsonTxoEssential) Address added in v0.0.12

func (*JsonTxoEssential) IndicesPath added in v0.0.12

func (txo *JsonTxoEssential) IndicesPath() (int64, int64, int64)

func (*JsonTxoEssential) IndicesPathSpecified added in v0.0.12

func (txo *JsonTxoEssential) IndicesPathSpecified() bool

func (*JsonTxoEssential) ParentIndex added in v0.0.12

func (txo *JsonTxoEssential) ParentIndex() int64

func (*JsonTxoEssential) ParentSpecified added in v0.0.12

func (txo *JsonTxoEssential) ParentSpecified() bool

func (*JsonTxoEssential) ParentTrans added in v0.0.12

func (*JsonTxoEssential) Satoshis added in v0.0.12

func (txo *JsonTxoEssential) Satoshis() (int64, error)

func (*JsonTxoEssential) TxoHeight added in v0.0.12

func (txo *JsonTxoEssential) TxoHeight() int64

func (*JsonTxoEssential) TxoHeightSpecified added in v0.0.12

func (txo *JsonTxoEssential) TxoHeightSpecified() bool

type JsonTxoHashes added in v0.0.12

type JsonTxoHashes struct {
	J_scriptPubKey JsonScriptPubKeyEssential2 `json:"scriptPubKey"`
}

func (*JsonTxoHashes) AddrHash added in v0.0.12

func (jt *JsonTxoHashes) AddrHash() indexedhashes.Sha256

type OneBlockChain

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

OneBlockChain - We call it a one block chain, as one block is in memory at any point in time

func (*OneBlockChain) AddressInterface

func (*OneBlockChain) BlockInterface

func (*OneBlockChain) GenesisBlock

func (obc *OneBlockChain) GenesisBlock() chainreadinterface.IBlockHandle

func (*OneBlockChain) GenesisTransaction

func (obc *OneBlockChain) GenesisTransaction() (chainreadinterface.ITransHandle, error)

func (*OneBlockChain) InvalidBlock

func (obc *OneBlockChain) InvalidBlock() chainreadinterface.IBlockHandle

func (*OneBlockChain) InvalidTrans

func (obc *OneBlockChain) InvalidTrans() chainreadinterface.ITransHandle

func (*OneBlockChain) IsBlockTree

func (obc *OneBlockChain) IsBlockTree() bool

func (*OneBlockChain) LatestBlock

func (obc *OneBlockChain) LatestBlock() (chainreadinterface.IBlockHandle, error)

func (*OneBlockChain) LatestTransaction

func (obc *OneBlockChain) LatestTransaction() (chainreadinterface.ITransHandle, error)

func (*OneBlockChain) NextBlock

func (*OneBlockChain) NextTransaction

func (*OneBlockChain) ParentBlock

func (*OneBlockChain) PreviousTransaction

func (*OneBlockChain) TransInterface

func (*OneBlockChain) TxiInterface

func (*OneBlockChain) TxoInterface

type OneBlockHolder added in v0.0.12

type OneBlockHolder struct {
	InChan chan *JsonBlockEssential
	// contains filtered or unexported fields
}

OneBlockHolder provides an IBlockchain restricted to accessing blocks in sequence. GenesisBlock() must be called first, and only once. At this point OneBlockHolder takes a JsonBlockEssential* from its InChan and presumes it to be the genesis block. Subsequent calls to NextBlock must be in sequence, and causes another JsonBlockEssentials* to be taken from InChan. Out of sequence blocks will generate errors.

func CreateOneBlockHolder added in v0.0.12

func CreateOneBlockHolder(
	indexer transactionindexing.ITransactionIndexer,
) *OneBlockHolder

func (*OneBlockHolder) AddressInterface added in v0.0.12

func (*OneBlockHolder) BlockInterface added in v0.0.12

func (*OneBlockHolder) GenesisBlock added in v0.0.12

func (obh *OneBlockHolder) GenesisBlock() chainreadinterface.IBlockHandle

func (*OneBlockHolder) GenesisTransaction added in v0.0.12

func (obh *OneBlockHolder) GenesisTransaction() (chainreadinterface.ITransHandle, error)

func (*OneBlockHolder) InvalidBlock added in v0.0.12

func (obh *OneBlockHolder) InvalidBlock() chainreadinterface.IBlockHandle

func (*OneBlockHolder) InvalidTrans added in v0.0.12

func (obh *OneBlockHolder) InvalidTrans() chainreadinterface.ITransHandle

func (*OneBlockHolder) IsBlockTree added in v0.0.12

func (obh *OneBlockHolder) IsBlockTree() bool

func (*OneBlockHolder) LatestBlock added in v0.0.12

func (obh *OneBlockHolder) LatestBlock() (chainreadinterface.IBlockHandle, error)

func (*OneBlockHolder) LatestTransaction added in v0.0.12

func (obh *OneBlockHolder) LatestTransaction() (chainreadinterface.ITransHandle, error)

func (*OneBlockHolder) NextBlock added in v0.0.12

func (*OneBlockHolder) NextTransaction added in v0.0.12

func (*OneBlockHolder) ParentBlock added in v0.0.12

func (*OneBlockHolder) PostJsonGatherTransHashes added in v0.0.12

func (obh *OneBlockHolder) PostJsonGatherTransHashes(block *JsonBlockEssential) error

func (*OneBlockHolder) PostJsonUpdateTransReferences added in v0.0.12

func (obh *OneBlockHolder) PostJsonUpdateTransReferences(block *JsonBlockEssential) error

postJsonUpdateTransReferences() uses the accrued transaction hash map to locate the txos (by way of block/nthTrans/vindex path indices) corresponding to each txi.

func (*OneBlockHolder) PreviousTransaction added in v0.0.12

func (*OneBlockHolder) TransInterface added in v0.0.12

func (*OneBlockHolder) TxiInterface added in v0.0.12

func (*OneBlockHolder) TxoInterface added in v0.0.12

type OneBlockHolderHashes added in v0.0.12

type OneBlockHolderHashes struct {
	InChan chan *JsonBlockHashes
	// contains filtered or unexported fields
}

OneBlockHolder provides a HashesBlockchain restricted to accessing blocks in sequence. GenesisBlock() must be called first, and only once. At this point OneBlockHolder takes a JsonBlockEssential* from its InChan and presumes it to be the genesis block. Subsequent calls to NextBlock must be in sequence, and causes another JsonBlockEssentials* to be taken from InChan. Out of sequence blocks will generate errors.

func CreateOneBlockHolderHashes added in v0.0.12

func CreateOneBlockHolderHashes() *OneBlockHolderHashes

func (*OneBlockHolderHashes) GenesisBlock added in v0.0.12

func (obh *OneBlockHolderHashes) GenesisBlock() *JsonBlockHashes

func (*OneBlockHolderHashes) NextBlock added in v0.0.12

func (obh *OneBlockHolderHashes) NextBlock() (*JsonBlockHashes, error)

type TransHandle

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

func (*TransHandle) Hash

func (th *TransHandle) Hash() (indexedhashes.Sha256, error)

func (*TransHandle) HashSpecified

func (th *TransHandle) HashSpecified() bool

func (*TransHandle) Height

func (th *TransHandle) Height() int64

func (*TransHandle) HeightSpecified

func (th *TransHandle) HeightSpecified() bool

func (*TransHandle) IndicesPath

func (th *TransHandle) IndicesPath() (int64, int64)

func (*TransHandle) IndicesPathSpecified

func (th *TransHandle) IndicesPathSpecified() bool

func (*TransHandle) IsInvalid

func (th *TransHandle) IsInvalid() bool

func (*TransHandle) IsTransHandle

func (th *TransHandle) IsTransHandle()

type TxiHandle

type TxiHandle struct {
	TxxIndicesPath
}

func (*TxiHandle) IndicesPath

func (th *TxiHandle) IndicesPath() (int64, int64, int64)

func (*TxiHandle) IndicesPathSpecified

func (th *TxiHandle) IndicesPathSpecified() bool

func (*TxiHandle) ParentIndex

func (th *TxiHandle) ParentIndex() int64

func (*TxiHandle) ParentSpecified

func (th *TxiHandle) ParentSpecified() bool

func (*TxiHandle) ParentTrans

func (th *TxiHandle) ParentTrans() chainreadinterface.ITransHandle

func (*TxiHandle) TxiHeight

func (th *TxiHandle) TxiHeight() int64

func (*TxiHandle) TxiHeightSpecified

func (th *TxiHandle) TxiHeightSpecified() bool

type TxoHandle

type TxoHandle struct {
	TxxIndicesPath
}

func (*TxoHandle) IndicesPath

func (th *TxoHandle) IndicesPath() (int64, int64, int64)

func (*TxoHandle) IndicesPathSpecified

func (th *TxoHandle) IndicesPathSpecified() bool

func (*TxoHandle) ParentIndex

func (th *TxoHandle) ParentIndex() int64

func (*TxoHandle) ParentSpecified

func (th *TxoHandle) ParentSpecified() bool

func (*TxoHandle) ParentTrans

func (th *TxoHandle) ParentTrans() chainreadinterface.ITransHandle

func (*TxoHandle) TxoHeight

func (th *TxoHandle) TxoHeight() int64

func (*TxoHandle) TxoHeightSpecified

func (th *TxoHandle) TxoHeightSpecified() bool

type TxxIndicesPath

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

TxxIndicesPath specifies block height, nth transaction within block, and vin/vout index (vindex) It is used for TxiHandle and TxoHandle

Jump to

Keyboard shortcuts

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