Documentation ¶
Index ¶
- Constants
- func BytesToBigUint(b []byte) sdk.Uint
- func BytesToUint(b []byte) uint
- func CalculateDifficulty(target sdk.Uint) sdk.Uint
- func DecodeIfHex(s string) []byte
- func DetermineInputLength(input []byte) (uint64, error)
- func DetermineOutputLength(output []byte) (uint64, error)
- func DetermineVarIntDataLength(flag uint8) uint8
- func EncodeP2PKH(pkh []byte) (string, error)
- func EncodeP2SH(sh []byte) (string, error)
- func EncodeP2WPKH(pkh []byte) (string, error)
- func EncodeP2WSH(sh Hash256Digest) (string, error)
- func ExtractDifficulty(header RawHeader) sdk.Uint
- func ExtractHash(output []byte) ([]byte, error)
- func ExtractInputAtIndex(vin []byte, index uint) ([]byte, error)
- func ExtractOpReturnData(output []byte) ([]byte, error)
- func ExtractOutpoint(input []byte) []byte
- func ExtractOutputAtIndex(vout []byte, index uint) ([]byte, error)
- func ExtractOutputScriptLen(output []byte) uint
- func ExtractScriptSig(input []byte) ([]byte, error)
- func ExtractScriptSigLen(input []byte) (uint64, uint64, error)
- func ExtractSequenceLELegacy(input []byte) ([]byte, error)
- func ExtractSequenceLEWitness(input []byte) []byte
- func ExtractSequenceLegacy(input []byte) (uint32, error)
- func ExtractSequenceWitness(input []byte) uint32
- func ExtractTarget(header RawHeader) sdk.Uint
- func ExtractTimestamp(header RawHeader) uint
- func ExtractTimestampLE(header RawHeader) []byte
- func ExtractTxIndex(input []byte) uint
- func ExtractTxIndexLE(input []byte) []byte
- func ExtractValue(output []byte) uint
- func ExtractValueLE(output []byte) []byte
- func IsLegacyInput(input []byte) bool
- func LastBytes(in []byte, num int) []byte
- func ParseVarInt(b []byte) (uint64, uint64, error)
- func Prove(txid Hash256Digest, merkleRoot Hash256Digest, intermediateNodes []byte, ...) bool
- func RetargetAlgorithm(previousTarget sdk.Uint, firstTimestamp uint, secondTimestamp uint) sdk.Uint
- func ReverseEndianness(b []byte) []byte
- func Strip0xPrefix(s string) string
- func ValidateHeaderChain(headers []byte) (sdk.Uint, error)
- func ValidateHeaderPrevHash(header RawHeader, prevHeaderDigest Hash256Digest) bool
- func ValidateHeaderWork(digest Hash256Digest, target sdk.Uint) bool
- func ValidateVin(vin []byte) bool
- func ValidateVout(vout []byte) bool
- func VerifyHash256Merkle(proof []byte, index uint) bool
- type BitcoinHeader
- type Hash160Digest
- type Hash256Digest
- func CalculateTxID(version, vin, vout, locktime []byte) Hash256Digest
- func ExtractInputTxIDLE(input []byte) Hash256Digest
- func ExtractMerkleRootLE(header RawHeader) Hash256Digest
- func ExtractPrevBlockHashLE(header RawHeader) Hash256Digest
- func Hash256(in []byte) Hash256Digest
- func Hash256MerkleStep(a []byte, b []byte) Hash256Digest
- func NewHash256Digest(b []byte) (Hash256Digest, error)
- func ReverseHash256Endianness(h Hash256Digest) Hash256Digest
- type HexBytes
- type RawHeader
- type SPVProof
Constants ¶
const ZeroBytesError = "Attempting to encode empty bytestring. " +
"Hint: your payload may not be properly initialized"
ZeroBytesError is the error returned when attempting to encode an empty bytestring
Variables ¶
This section is empty.
Functions ¶
func BytesToBigUint ¶
BytesToBigUint converts a bytestring of up to 32 bytes to a cosmos sdk uint
func BytesToUint ¶
BytesToUint converts 1, 2, 3, or 4-byte numbers to uints
func CalculateDifficulty ¶
CalculateDifficulty calculates difficulty from the difficulty 1 target and current target Difficulty 1 is 0x1d00ffff on mainnet and testnet Difficulty 1 is a 256 bit number encoded as a 3-byte mantissa and 1 byte exponent
func DecodeIfHex ¶ added in v1.1.0
DecodeIfHex decodes a hex string into a byte array
func DetermineInputLength ¶
DetermineInputLength gets the length of an input by parsing the scriptSigLength
func DetermineOutputLength ¶
DetermineOutputLength returns the length of an output
func DetermineVarIntDataLength ¶
DetermineVarIntDataLength extracts the payload length of a Bitcoin VarInt
func EncodeP2PKH ¶ added in v1.1.0
EncodeP2PKH turns a pubkey hash into an address
func EncodeP2SH ¶ added in v1.1.0
EncodeP2SH turns a scripthash into an address
func EncodeP2WPKH ¶ added in v1.1.0
EncodeP2WPKH turns a pubkey hash into an address
func EncodeP2WSH ¶ added in v1.1.0
func EncodeP2WSH(sh Hash256Digest) (string, error)
EncodeP2WSH turns a scripthash into an address
func ExtractDifficulty ¶
ExtractDifficulty calculates the difficulty of a header
func ExtractHash ¶
ExtractHash extracts the hash from the output script Returns the hash committed to by the pk_script
func ExtractInputAtIndex ¶
ExtractInputAtIndex parses the input vector and returns the vin at a specified index
func ExtractOpReturnData ¶
ExtractOpReturnData returns the value from the output in a tx Value is an 8byte little endian number
func ExtractOutpoint ¶
ExtractOutpoint returns the outpoint from the in input in a tx The outpoint is a 32 bit tx id with 4 byte index
func ExtractOutputAtIndex ¶
ExtractOutputAtIndex returns the output at a given index in the TxIns vector
func ExtractOutputScriptLen ¶
ExtractOutputScriptLen extracts the output script length
func ExtractScriptSig ¶
ExtractScriptSig extracts the VarInt-prepended scriptSig from the input in a tx
func ExtractScriptSigLen ¶
ExtractScriptSigLen determines the length of a scriptSig in an input
func ExtractSequenceLELegacy ¶
ExtractSequenceLELegacy returns the LE sequence in from a tx input The sequence is a 4 byte little-endian number.
func ExtractSequenceLEWitness ¶
ExtractSequenceLEWitness extracts the LE sequence bytes from a witness input
func ExtractSequenceLegacy ¶
ExtractSequenceLegacy returns the integer sequence in from a tx input
func ExtractSequenceWitness ¶
ExtractSequenceWitness extracts the sequence integer from a witness input
func ExtractTarget ¶
ExtractTarget returns the target from a given block hedaer
func ExtractTimestamp ¶
ExtractTimestamp returns the timestamp from a block header as a uint Time is not 100% reliable
func ExtractTimestampLE ¶
ExtractTimestampLE returns the timestamp from a block header It returns the timestamp as a little endian []byte Time is not 100% reliable
func ExtractTxIndex ¶
ExtractTxIndex extracts the tx input index from the input in a tx
func ExtractTxIndexLE ¶
ExtractTxIndexLE extracts the LE tx input index from the input in a tx Returns the tx index as a little endian []byte
func ExtractValue ¶
ExtractValue extracts the value from the output in a tx
func ExtractValueLE ¶
ExtractValueLE extracts the value in from the output in a tx Returns a little endian []byte of the output value
func IsLegacyInput ¶
IsLegacyInput determines whether an input is legacy
func ParseVarInt ¶ added in v1.3.0
ParseVarInt parses the length and value of a VarInt payload
func Prove ¶
func Prove(txid Hash256Digest, merkleRoot Hash256Digest, intermediateNodes []byte, index uint) bool
Prove checks the validity of a merkle proof
func RetargetAlgorithm ¶
func RetargetAlgorithm( previousTarget sdk.Uint, firstTimestamp uint, secondTimestamp uint) sdk.Uint
RetargetAlgorithm performs Bitcoin consensus retargets
func ReverseEndianness ¶
ReverseEndianness takes in a byte slice and returns a reversed endian byte slice.
func Strip0xPrefix ¶ added in v1.4.0
Strip0xPrefix removes the 0x prefix from a hex string
func ValidateHeaderChain ¶
ValidateHeaderChain checks validity of header chain
func ValidateHeaderPrevHash ¶
func ValidateHeaderPrevHash(header RawHeader, prevHeaderDigest Hash256Digest) bool
ValidateHeaderPrevHash checks validity of header chain
func ValidateHeaderWork ¶
func ValidateHeaderWork(digest Hash256Digest, target sdk.Uint) bool
ValidateHeaderWork checks validity of header work
func ValidateVin ¶
ValidateVin checks that the vin passed up is properly formatted
func ValidateVout ¶
ValidateVout checks that the vin passed up is properly formatted
func VerifyHash256Merkle ¶
VerifyHash256Merkle checks a merkle inclusion proof's validity. Note that `index` is not a reliable indicator of location within a block.
Types ¶
type BitcoinHeader ¶ added in v1.1.0
type BitcoinHeader struct { Raw RawHeader `json:"raw"` Hash Hash256Digest `json:"hash"` Height uint32 `json:"height"` PrevHash Hash256Digest `json:"prevhash"` MerkleRoot Hash256Digest `json:"merkle_root"` }
BitcoinHeader is a parsed Bitcoin header, values are LE
func HeaderFromHex ¶ added in v1.2.0
func HeaderFromHex(s string, height uint32) (BitcoinHeader, error)
HeaderFromHex buidls a BitcoinHeader from a hex string and height
func HeaderFromRaw ¶ added in v1.2.0
func HeaderFromRaw(raw RawHeader, height uint32) BitcoinHeader
HeaderFromRaw builds a BitcoinHeader from a raw bytestring and height
func (BitcoinHeader) Validate ¶ added in v1.1.0
func (b BitcoinHeader) Validate() (bool, error)
Validate checks validity of all the elements in a BitcoinHeader
type Hash160Digest ¶ added in v1.2.0
type Hash160Digest [20]byte
Hash160Digest is a 20-byte ripemd160+sha2 hash
func Hash160 ¶
func Hash160(in []byte) Hash160Digest
Hash160 takes a byte slice and returns a hashed byte slice.
func NewHash160Digest ¶ added in v1.2.0
func NewHash160Digest(b []byte) (Hash160Digest, error)
NewHash160Digest instantiates a Hash160Digest from a byte slice
func (Hash160Digest) MarshalJSON ¶ added in v1.4.0
func (h Hash160Digest) MarshalJSON() ([]byte, error)
MarshalJSON marashalls 32 byte digests as 0x-prepended hex
func (*Hash160Digest) UnmarshalJSON ¶ added in v1.4.0
func (h *Hash160Digest) UnmarshalJSON(b []byte) error
UnmarshalJSON unmarshalls 32 byte digests
type Hash256Digest ¶ added in v1.1.0
type Hash256Digest [32]byte
Hash256Digest is a 32-byte double-sha2 hash
func CalculateTxID ¶
func CalculateTxID(version, vin, vout, locktime []byte) Hash256Digest
CalculateTxID hashes transaction to get txid
func ExtractInputTxIDLE ¶
func ExtractInputTxIDLE(input []byte) Hash256Digest
ExtractInputTxIDLE returns the LE tx input index from the input in a tx
func ExtractMerkleRootLE ¶
func ExtractMerkleRootLE(header RawHeader) Hash256Digest
ExtractMerkleRootLE returns the transaction merkle root from a given block header The returned merkle root is little-endian
func ExtractPrevBlockHashLE ¶
func ExtractPrevBlockHashLE(header RawHeader) Hash256Digest
ExtractPrevBlockHashLE returns the previous block's hash from a block header Returns the hash as a little endian []byte
func Hash256 ¶
func Hash256(in []byte) Hash256Digest
Hash256 implements bitcoin's hash256 (double sha2)
func Hash256MerkleStep ¶ added in v1.4.0
func Hash256MerkleStep(a []byte, b []byte) Hash256Digest
Hash256MerkleStep concatenates and hashes two inputs for merkle proving
func NewHash256Digest ¶ added in v1.2.0
func NewHash256Digest(b []byte) (Hash256Digest, error)
NewHash256Digest instantiates a Hash256Digest from a byte slice
func ReverseHash256Endianness ¶ added in v1.2.0
func ReverseHash256Endianness(h Hash256Digest) Hash256Digest
ReverseHash256Endianness returns a new digest with opposite byteorder
func (Hash256Digest) MarshalJSON ¶ added in v1.1.0
func (h Hash256Digest) MarshalJSON() ([]byte, error)
MarshalJSON marashalls 32 byte digests as 0x-prepended hex
func (*Hash256Digest) UnmarshalJSON ¶ added in v1.1.0
func (h *Hash256Digest) UnmarshalJSON(b []byte) error
UnmarshalJSON unmarshalls 32 byte digests
type HexBytes ¶ added in v1.1.0
type HexBytes []byte
HexBytes is a type alias to make JSON hex ser/deser easier
func (HexBytes) MarshalJSON ¶ added in v1.1.0
MarshalJSON marashalls bytestrings as 0x-prepended hex
func (*HexBytes) UnmarshalJSON ¶ added in v1.1.0
UnmarshalJSON unmarshalls 32 byte digests
type RawHeader ¶ added in v1.1.0
type RawHeader [80]byte
RawHeader is an 80-byte raw header
func NewRawHeader ¶ added in v1.2.0
NewRawHeader instantiates a RawHeader from a byte slice
func (RawHeader) MarshalJSON ¶ added in v1.1.0
MarshalJSON marashalls 32 byte digests as 0x-prepended hex
func (*RawHeader) UnmarshalJSON ¶ added in v1.1.0
UnmarshalJSON unmarshalls 32 byte digests
type SPVProof ¶ added in v1.1.0
type SPVProof struct { Version HexBytes `json:"version"` Vin HexBytes `json:"vin"` Vout HexBytes `json:"vout"` Locktime HexBytes `json:"locktime"` TxID Hash256Digest `json:"tx_id"` Index uint32 `json:"index"` ConfirmingHeader BitcoinHeader `json:"confirming_header"` IntermediateNodes HexBytes `json:"intermediate_nodes"` }
SPVProof is the base struct for an SPV proof