bitcoin raw block

btcutil: Index | Examples | Files | Directories /btcsuite/btcutil" Package btcutil provides bitcoin-specific convenience functions and types.A Block defines a bitcoin block that provides easier and more efficient manipulation of raw wire protocol blocks.It also memoizes hashes for the block and its transactions on their first access so subsequent accesses don't have to repeat the relatively expensive hashing operations.A Tx defines a bitcoin transaction that provides more efficient manipulation of raw wire protocol transactions.It memoizes the hash for the transaction on its first access so subsequent accesses don't have to repeat the relatively expensive hashing operations.The Address interface provides an abstraction for a Bitcoin address.While the most common type is a pay-to-pubkey-hash, Bitcoin already supports others and may well support more in the future.This package currently provides implementations for the pay-to-pubkey, pay-to-pubkey-hash, and pay-to-script-hash address types.
address.go amount.go appdata.go block.go certgen.go const.go doc.go hash160.go net.go tx.go wif.go ❖const ( = 1e6 = 1e8 = 21e6 * SatoshiPerBitcoin ) BlockHeightUnknown is the value returned for a block height that is unknown.This is typically because the block has not been inserted into the main chain yet.TxIndexUnknown is the value returned for a transaction index that is unknown.This is typically because the transaction has not been inserted into a block yet.❖var ( = errors.New("checksum mismatch") = errors.New("unknown address type") = errors.New("address collision") )❖var = errors.New("malformed private key") ErrMalformedPrivateKey describes an error where a WIF-encoded private key cannot be decoded due to being improperly formatted.This may occur if the byte length is incorrect or an unexpected magic number was encountered.❖func AppDataDir(appName string, roaming bool) string AppDataDir returns an operating system specific directory to be used for storing application data for an application.
The appName parameter is the name of the application the data directory is being requested for.This function will prepend a period to the appName for POSIX style operating systems since that is standard practice.bitcoin casino minecraftAn empty appName or one with a single dot is treated as requesting the current directory so only "."bitcoin what is segwitFurther, the first character of appName will be made lowercase for POSIX style operating systems and uppercase for Mac and Windows since that is standard practice.bitcoin segwit whenThe roaming parameter only applies to Windows where it specifies the roaming application data profile (%APPDATA%) should be used instead of the local one (%LOCALAPPDATA%) that is used by default.ethereum kraken
Hash160 calculates the hash ripemd160(sha256(b)).❖func NewTLSCertPair(organization string, validUntil time.Time, extraHosts []string) (cert, key []byte, err error) NewTLSCertPair returns a new PEM-encoded x.509 certificate pair based on a 521-bit ECDSA private key.bitcoin seizedThe machine's local interface addresses and all variants of IPv4 and IPv6 localhost are included as valid IP addresses.litecoin value prediction 2014❖type Address interface { () string () string () []byte (*chaincfg.Params) bool } Address is an interface type for any type of destination a transaction output may spend to.bitcoin euro währungsrechnerThis includes pay-to-pubkey (P2PK), pay-to-pubkey-hash (P2PKH), and pay-to-script-hash (P2SH).kurs bitcoin live
Address is designed to be generic enough that other kinds of addresses may be added in the future without changing the decoding and encoding API.bitcoin price data excel❖func DecodeAddress(addr string, defaultNet *chaincfg.Params) (Address, error) DecodeAddress decodes the string encoding of an address and returns the Address if addr is a valid encoding for a known address type.The bitcoin network the address is associated with is extracted if possible.When the address does not encode the network, such as in the case of a raw public key, the address will be associated with the passed defaultNet.AddressPubKey is an Address for a pay-to-pubkey transaction.❖func NewAddressPubKey(serializedPubKey []byte, net *chaincfg.Params) (*AddressPubKey, error) NewAddressPubKey returns a new AddressPubKey which represents a pay-to-pubkey address.The serializedPubKey parameter must be a valid pubkey and can be uncompressed, compressed, or hybrid.
❖func (a *AddressPubKey) AddressPubKeyHash() *AddressPubKeyHash AddressPubKeyHash returns the pay-to-pubkey address converted to a pay-to-pubkey-hash address.Note that the public key format (uncompressed, compressed, etc) will change the resulting address.This is expected since pay-to-pubkey-hash is a hash of the serialized public key which obviously differs with the format.At the time of this writing, most Bitcoin addresses are pay-to-pubkey-hash constructed from the uncompressed public key.❖func (a *AddressPubKey) EncodeAddress() string EncodeAddress returns the string encoding of the public key as a pay-to-pubkey-hash.Part of the Address interface.❖func (a *AddressPubKey) Format() PubKeyFormat Format returns the format (uncompressed, compressed, etc) of the pay-to-pubkey address.❖func (a *AddressPubKey) IsForNet(net *chaincfg.Params) bool IsForNet returns whether or not the pay-to-pubkey address is associated with the passed bitcoin network.
❖func (a *AddressPubKey) PubKey() *btcec.PublicKey PubKey returns the underlying public key for the address.❖func (a *AddressPubKey) ScriptAddress() []byte ScriptAddress returns the bytes to be included in a txout script to pay to a public key.Setting the public key format will affect the output of this function accordingly.❖func (a *AddressPubKey) SetFormat(pkFormat PubKeyFormat) SetFormat sets the format (uncompressed, compressed, etc) of the pay-to-pubkey address.❖func (a *AddressPubKey) String() string String returns the hex-encoded human-readable string for the pay-to-pubkey address.This is not the same as calling EncodeAddress.AddressPubKeyHash is an Address for a pay-to-pubkey-hash (P2PKH) transaction.❖func NewAddressPubKeyHash(pkHash []byte, net *chaincfg.Params) (*AddressPubKeyHash, error) NewAddressPubKeyHash returns a new AddressPubKeyHash.pkHash mustbe 20 bytes.❖func (a *AddressPubKeyHash) EncodeAddress() string EncodeAddress returns the string encoding of a pay-to-pubkey-hash address.
❖func (a *AddressPubKeyHash) Hash160() *[ripemd160.Size]byte Hash160 returns the underlying array of the pubkey hash.This can be useful when an array is more appropiate than a slice (for example, when used as map keys).❖func (a *AddressPubKeyHash) IsForNet(net *chaincfg.Params) bool IsForNet returns whether or not the pay-to-pubkey-hash address is associated with the passed bitcoin network.❖func (a *AddressPubKeyHash) ScriptAddress() []byte ScriptAddress returns the bytes to be included in a txout script to pay to a pubkey hash.❖func (a *AddressPubKeyHash) String() string String returns a human-readable string for the pay-to-pubkey-hash address.This is equivalent to calling EncodeAddress, but is provided so the type can be used as a fmt.Stringer.AddressScriptHash is an Address for a pay-to-script-hash (P2SH) transaction.❖func NewAddressScriptHash(serializedScript []byte, net *chaincfg.Params) (*AddressScriptHash, error) NewAddressScriptHash returns a new AddressScriptHash.
❖func NewAddressScriptHashFromHash(scriptHash []byte, net *chaincfg.Params) (*AddressScriptHash, error) NewAddressScriptHashFromHash returns a new AddressScriptHash.scriptHash must be 20 bytes.❖func (a *AddressScriptHash) EncodeAddress() string EncodeAddress returns the string encoding of a pay-to-script-hash address.❖func (a *AddressScriptHash) Hash160() *[ripemd160.Size]byte Hash160 returns the underlying array of the script hash.❖func (a *AddressScriptHash) IsForNet(net *chaincfg.Params) bool IsForNet returns whether or not the pay-to-script-hash address is associated with the passed bitcoin network.❖func (a *AddressScriptHash) ScriptAddress() []byte ScriptAddress returns the bytes to be included in a txout script to pay to a script hash.❖func (a *AddressScriptHash) String() string String returns a human-readable string for the pay-to-script-hash address.Amount represents the base bitcoin monetary unit (colloquially referred to as a `Satoshi').
A single Amount is equal to 1e-8 of a bitcoin.Example Code: Output: Example (UnitConversions) Code: Output: ❖func NewAmount(f float64) (Amount, error) NewAmount creates an Amount from a floating point value representing some value in bitcoin.NewAmount errors if f is NaN or +-Infinity, but does not check that the amount is within the total amount of bitcoin producible as f may not refer to an amount at a single moment in time.NewAmount is for specifically for converting BTC to Satoshi.For creating a new Amount with an int64 value which denotes a quantity of Satoshi, do a simple type conversion from type int64 to Amount.//btcsuite/btcutil#example-Amount Example Code: Output: ❖func (a Amount) Format(u AmountUnit) string Format formats a monetary amount counted in bitcoin base units as a string for a given unit.The conversion will succeed for any unit, however, known units will be formated with an appended label describing the units with SI notation, or "Satoshi" for the base unit.
❖func (a Amount) MulF64(f float64) Amount MulF64 multiplies an Amount by a floating point value.While this is not an operation that must typically be done by a full node or wallet, it is useful for services that build on top of bitcoin (for example, calculating a fee by multiplying by a percentage).❖func (a Amount) String() string String is the equivalent of calling Format with AmountBTC.❖func (a Amount) ToBTC() float64 ToBTC is the equivalent of calling ToUnit with AmountBTC.❖func (a Amount) ToUnit(u AmountUnit) float64 ToUnit converts a monetary amount counted in bitcoin base units to a floating point value representing an amount of bitcoin.AmountUnit describes a method of converting an Amount to something other than the base unit of a bitcoin.The value of the AmountUnit is the exponent component of the decadic multiple to convert from an amount in bitcoin to an amount counted in units.❖const ( AmountUnit = 6 AmountUnit = 3 AmountUnit = 0 AmountUnit = -3 AmountUnit = -6 AmountUnit = -8 ) These constants define various units used when describing a bitcoin monetary amount.
❖func (u AmountUnit) String() string String returns the unit as a string.For recognized units, the SI prefix is used, or "Satoshi" for the base unit.For all unrecognized units, "1eN BTC" is returned, where N is the AmountUnit.Block defines a bitcoin block that provides easier and more efficient manipulation of raw blocks.It also memoizes hashes for the block and its transactions on their first access so subsequent accesses don't have to repeat the relatively expensive hashing operations.NewBlock returns a new instance of a bitcoin block given an underlying wire.MsgBlock.❖func NewBlockFromBlockAndBytes(msgBlock *wire.MsgBlock, serializedBlock []byte) *Block NewBlockFromBlockAndBytes returns a new instance of a bitcoin block given an underlying wire.MsgBlock and the serialized bytes for it.❖func NewBlockFromBytes(serializedBlock []byte) (*Block, error) NewBlockFromBytes returns a new instance of a bitcoin block given the serialized bytes.
❖func NewBlockFromReader(r io.Reader) (*Block, error) NewBlockFromReader returns a new instance of a bitcoin block given a Reader to deserialize the block.❖func (b *Block) Bytes() ([]byte, error) Bytes returns the serialized bytes for the Block.This is equivalent to calling Serialize on the underlying wire.MsgBlock, however it caches the result so subsequent calls are more efficient.❖func (b *Block) Hash() *chainhash.Hash Hash returns the block identifier hash for the Block.This is equivalent to calling BlockHash on the underlying wire.MsgBlock, however it caches the result so subsequent calls are more efficient.❖func (b *Block) Height() int32 Height returns the saved height of the block in the block chain.This value will be BlockHeightUnknown if it hasn't already explicitly been set.❖func (b *Block) MsgBlock() *wire.MsgBlock MsgBlock returns the underlying wire.MsgBlock for the Block.❖func (b *Block) SetHeight(height int32) SetHeight sets the height of the block in the block chain.
❖func (b *Block) Transactions() []*Tx Transactions returns a slice of wrapped transactions (btcutil.Tx) for all transactions in the Block.This is nearly equivalent to accessing the raw transactions (wire.MsgTx) in the underlying wire.MsgBlock, however it instead provides easy access to wrapped versions (btcutil.Tx) of them.❖func (b *Block) Tx(txNum int) (*Tx, error) Tx returns a wrapped transaction (btcutil.Tx) for the transaction at the specified index in the Block.The supplied index is 0 based.That is to say, the first transaction in the block is txNum 0.This is nearly equivalent to accessing the raw transaction (wire.MsgTx) from the underlying wire.MsgBlock, however the wrapped transaction has some helpful properties such as caching the hash so subsequent calls are more efficient.❖func (b *Block) TxHash(txNum int) (*chainhash.Hash, error) TxHash returns the hash for the requested transaction number in the Block.That is to say, the first transaction in the block is txNum 0.
This is equivalent to calling TxHash on the underlying wire.MsgTx, however it caches the result so subsequent calls are more efficient.❖func (b *Block) TxLoc() ([]wire.TxLoc, error) TxLoc returns the offsets and lengths of each transaction in a raw block.It is used to allow fast indexing into transactions within the raw byte stream.OutOfRangeError describes an error due to accessing an element that is out of range.❖func (e OutOfRangeError) Error() string Error satisfies the error interface and prints human-readable errors.PubKeyFormat describes what format to use for a pay-to-pubkey address.❖const ( PubKeyFormat = iota ) Tx defines a bitcoin transaction that provides easier and more efficient manipulation of raw transactions.It also memoizes the hash for the transaction on its first access so subsequent accesses don't have to repeat the relatively expensive hashing operations.NewTx returns a new instance of a bitcoin transaction given an underlying wire.MsgTx.
❖func NewTxFromBytes(serializedTx []byte) (*Tx, error) NewTxFromBytes returns a new instance of a bitcoin transaction given the serialized bytes.❖func NewTxFromReader(r io.Reader) (*Tx, error) NewTxFromReader returns a new instance of a bitcoin transaction given a Reader to deserialize the transaction.❖func (t *Tx) Hash() *chainhash.Hash Hash returns the hash of the transaction.This is equivalent to calling TxHash on the underlying wire.MsgTx, however it caches the result so subsequent calls are more efficient.❖func (t *Tx) Index() int Index returns the saved index of the transaction within a block.This value will be TxIndexUnknown if it hasn't already explicitly been set.❖func (t *Tx) MsgTx() *wire.MsgTx MsgTx returns the underlying wire.MsgTx for the transaction.❖func (t *Tx) SetIndex(index int) SetIndex sets the index of the transaction in within a block.❖type WIF struct { *btcec.PrivateKey bool } WIF contains the individual components described by the Wallet Import Format (WIF).
A WIF string is typically used to represent a private key and its associated address in a way that may be easily copied and imported into or exported from wallet software.WIF strings may be decoded into this structure by calling DecodeWIF or created with a user-provided private key by calling NewWIF.❖func DecodeWIF(wif string) (*WIF, error) DecodeWIF creates a new WIF structure by decoding the string encoding of the import format.The WIF string must be a base58-encoded string of the following byte sequence: If the base58-decoded byte sequence does not match this, DecodeWIF will return a non-nil error.ErrMalformedPrivateKey is returned when the WIF is of an impossible length or the expected compressed pubkey magic number does not equal the expected value of 0x01.ErrChecksumMismatch is returned if the expected WIF checksum does not match the calculated checksum.❖func NewWIF(privKey *btcec.PrivateKey, net *chaincfg.Params, compress bool) (*WIF, error) NewWIF creates a new WIF structure to export an address and its private key as a string encoded in the Wallet Import Format.