util

package
v0.0.0-...-77c8a84 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2020 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DarwinDataDir string = "/Library/Application Support/Bitcoin/"
View Source
var ForestDirPath string = filepath.Join(".", "utree/forestdata")
View Source
var ForestFilePath string = filepath.Join(ForestDirPath, "forestfile.dat")

forestdata file paths

View Source
var ForestLastSyncedBlockHeightFilePath string = filepath.Join(ForestDirPath,
	"forestlastsyncedheight.dat")
View Source
var LastIndexOffsetHeightFilePath string = filepath.Join(OffsetDirPath,
	"lastindexoffsetheightfile")
View Source
var LastPOffsetFilePath string = filepath.Join(ProofDirPath, "lastproofoffset.dat")

For resuming purposes. Stores the last index that genproofs left at

View Source
var LinuxDataDir string = "/.bitcoin/"

Bitcoin Core DATADIR

View Source
var MiscForestFilePath string = filepath.Join(ForestDirPath, "miscforestfile.dat")
View Source
var OffsetDirPath string = filepath.Join(".", "utree/offsetdata")

Directory paths

View Source
var OffsetFilePath string = filepath.Join(OffsetDirPath, "offsetfile")

offsetdata file paths

View Source
var PFilePath string = filepath.Join(ProofDirPath, "proof.dat")

proofdata file paths

Where the proofs for txs are stored

View Source
var POffsetFilePath string = filepath.Join(ProofDirPath, "proofoffset.dat")

Where the index for a proof for a block is stored

View Source
var PollardFilePath string = "pollardFile"

File paths

View Source
var ProofDirPath string = filepath.Join(".", "utree/proofdata")
View Source
var WinDataDir string = "\\AppData\\Roaming\\Bitcoin"

Functions

func BlockToAddLeaves

func BlockToAddLeaves(blk wire.MsgBlock,
	remember []bool, skiplist []uint32,
	height int32) (leaves []accumulator.Leaf)

BlockToAdds turns all the new utxos in a msgblock into leafTxos uses remember slice up to number of txos, but doesn't check that it's the right length. Similar with skiplist, doesn't check it.

func CheckMagicByte

func CheckMagicByte(bytesgiven []byte) bool

CheckMagicByte checks for the Bitcoin magic bytes. returns false if it didn't read the Bitcoin magic bytes. Checks only for testnet3 and mainnet

func DedupeBlock

func DedupeBlock(blk *wire.MsgBlock) (inskip []uint32, outskip []uint32)

DedupeBlock takes a bitcoin block, and returns two int slices: the indexes of inputs, and idexes of outputs which can be removed. These are indexes within the block as a whole, even the coinbase tx. So the coinbase tx in & output numbers affect the skip lists even though the coinbase ins/outs can never be deduped. it's simpler that way.

func GetBitcoinDataDir

func GetBitcoinDataDir() (dir string)

GetBitcoinDataDir grabs the user's Bitcoin DataDir. Doesn't support Windows or BSDs

func GetHomeDir

func GetHomeDir() string

GetHomeDir grabs the current user's home directory

func GetUDataBytesFromFile

func GetUDataBytesFromFile(height int32) (b []byte, err error)

GetUDataBytesFromFile reads the proof data from proof.dat and proofoffset.dat and gives the proof & utxo data back. Don't ask for block 0, there is no proof of that.

func HasAccess

func HasAccess(fileName string) bool

HasAccess reports whether we have access to the named file. Returns true if HasAccess, false if it doesn't. Does NOT tell us if the file exists or not. File might exist but may not be available to us

func IsUnspendable

func IsUnspendable(o *wire.TxOut) bool

IsUnspendable determines whether a tx is spendable or not. returns true if spendable, false if unspendable.

func MakePaths

func MakePaths()

MakePaths makes the necessary paths for all files

func PopPrefixLen16

func PopPrefixLen16(b []byte) ([]byte, []byte, error)

func PrefixLen16

func PrefixLen16(b []byte) []byte

PrefixLen16 puts a 2 byte length prefix in front of a byte slice

func UblockNetworkReader

func UblockNetworkReader(
	blockChan chan UBlock, remoteServer string,
	curHeight, lookahead int32)

UblockNetworkReader gets Ublocks from the remote host and puts em in the channel. It'll try to fill the channel buffer.

Types

type Hash

type Hash [32]byte

func GenHashForNet

func GenHashForNet(p chaincfg.Params) (*Hash, error)

For a given BitcoinNet, yields the genesis hash If the BitcoinNet is not supported, an error is returned.

func HashFromString

func HashFromString(s string) Hash

HashFromString hashes the given string with sha256

type LeafData

type LeafData struct {
	BlockHash [32]byte
	Outpoint  wire.OutPoint
	Height    int32
	Coinbase  bool
	Amt       int64
	PkScript  []byte
}

LeafData is all the data that goes into a leaf in the utreexo accumulator

func LeafDataFromBytes

func LeafDataFromBytes(b []byte) (LeafData, error)

func LeafDataFromCompactBytes

func LeafDataFromCompactBytes(b []byte) (LeafData, error)

LeafDataFromCompactBytes doesn't fill in blockhash, outpoint, and in most cases PkScript, so something else has to fill those in later.

func LeafDataFromTxo

func LeafDataFromTxo(txo wire.TxOut) (LeafData, error)

func (*LeafData) LeafHash

func (l *LeafData) LeafHash() [32]byte

LeafHash turns a LeafData into a LeafHash

func (*LeafData) ToBytes

func (l *LeafData) ToBytes() []byte

ToBytes turns LeafData into bytes

func (*LeafData) ToCompactBytes

func (l *LeafData) ToCompactBytes() []byte

ToCompactBytes turns a LeafData into bytes (compact, for sending in blockProof) - don't hash this, it doesn't commit to everything

func (*LeafData) ToString

func (l *LeafData) ToString() (s string)

ToString turns a LeafData into bytes

type PatriciaProof

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

PatriciaProof is a potential replacement structure for UData in the trie - Bolton

type ProofAndHeight

type ProofAndHeight struct {
	Proof  []byte
	Height int32
}

type UBlock

type UBlock struct {
	Block     wire.MsgBlock
	ExtraData UData
	Height    int32
}

UBlock is a regular block, with Udata stuck on

func (*UBlock) CheckBlock

func (ub *UBlock) CheckBlock(outskip []uint32, p *chaincfg.Params) bool

CheckBlock does all internal block checks for a UBlock right now checks the signatures

func (*UBlock) Deserialize

func (ub *UBlock) Deserialize(r io.Reader) (err error)

network serialization for UBlocks (regular block with udata) Firstjust a wire.MsgBlock with the regular serialization. Then there's 4 bytes is (big endian) length of the udata. So basically a block then udata, that's it. Looks like "height" doesn't get sent over this way, but maybe that's OK.

func (*UBlock) FromBytes

func (ub *UBlock) FromBytes(argbytes []byte) (err error)

func (*UBlock) ProofsProveBlock

func (ub *UBlock) ProofsProveBlock(inputSkipList []uint32) bool

ProofsProveBlock checks the consistency of a UBlock. Does the proof prove all the inputs in the block?

func (*UBlock) Serialize

func (ub *UBlock) Serialize(w io.Writer) (err error)

We don't actually call serialize since from the server side we don't serialize, we just glom stuff together from the disk and send it over.

type UData

type UData struct {
	AccProof accumulator.BatchProof
	UtxoData []LeafData
	LeafTTLs []uint32
}

func UDataFromBytes

func UDataFromBytes(b []byte) (ud UData, err error)

UDataFromBytes deserializes into UData from bytes.

func UDataFromCompactBytes

func UDataFromCompactBytes(b []byte) (UData, error)

func (*UData) ToBytes

func (ud *UData) ToBytes() []byte

ToBytes serializes UData into bytes. There's a bunch of variable length things (the batchProof.hashes, and the LeafDatas) so we prefix lengths for those. Ordering is: batch proof length (4 bytes) batch proof Bunch of LeafDatas, prefixed with 2-byte lengths leaf ttls 4 bytes each

func (*UData) ToCompactBytes

func (ud *UData) ToCompactBytes() (b []byte)

func (*UData) ToUtxoView

func (ud *UData) ToUtxoView() *blockchain.UtxoViewpoint

ToUtxoView converts a UData into a btcd blockchain.UtxoViewpoint all the data is there, just a bit different format. Note that this needs blockchain.NewUtxoEntry() in btcd

func (*UData) Verify

func (ud *UData) Verify(nl uint64, h uint8) bool

Verify checks the consistency of uData: that the utxos are proven in the batchproof

Jump to

Keyboard shortcuts

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