Documentation ¶
Overview ¶
Package util provides bitcoin-specific convenience functions and types.
Block Overview ¶
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.
Tx Overview ¶
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.
Address Overview ¶
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. To decode/encode an address:
// NOTE: The default network is only used for address types which do not already contain that information. At this // time, that is only pay-to-pubkey addresses. addrString := "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962" + "e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d57" + "8a4c702b6bf11d5f" defaultNet := &chaincfg.MainNetParams addr, e := util.DecodeAddress(addrString, defaultNet) if e != nil { fmt.Println(e) return } fmt.Println(addr.EncodeAddress())
Index ¶
Constants ¶
const TxIndexUnknown = -1
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.
Variables ¶
var ErrMalformedPrivateKey = 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.
var F, E, W, I, D, T log.LevelPrinter = log.GetLogPrinterSet(subsystem)
Functions ¶
func GetActualPort ¶
func GetSecondsAhead ¶
GetSecondsAhead returns the difference in time, of the second ahead of the first
func NewTLSCertPair ¶
func NewTLSCertPair(organization string, validUntil time.Time, extraHosts []string) (cert, key []byte, e error)
NewTLSCertPair returns a new PEM-encoded x.509 certificate pair based on a 521-bit ECDSA private key. The machine's local interface addresses and all variants of IPv4 and IPv6 localhost are included as valid IP addresses.
Types ¶
type Tx ¶
type Tx struct {
// contains filtered or unexported fields
}
Tx defines a bitcoin transaction that provides easier and more efficient manipulation of raw transactions. It also memorizes the hash for the transaction on its first access so subsequent accesses don't have to repeat the relatively expensive hashing operations.
func NewTx ¶
NewTx returns a new instance of a bitcoin transaction given an underlying wire.MsgTx. See Tx.
func NewTxFromBytes ¶
NewTxFromBytes returns a new instance of a bitcoin transaction given the serialized bytes. See Tx.
func NewTxFromReader ¶
NewTxFromReader returns a new instance of a bitcoin transaction given a Reader to deserialize the transaction. See Tx.
func (*Tx) 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 (*Tx) Index ¶
Index returns the saved index of the transaction within a block. This value will be TxIndexUnknown if it hasn't already explicitly been set.
type WIF ¶
type WIF struct { // PrivKey is the private key being imported or exported. PrivKey *ec.PrivateKey // CompressPubKey specifies whether the address controlled by the imported or exported private key was created by // hashing a compressed (33-byte) serialized public key, rather than an uncompressed (65-byte) one. CompressPubKey bool // contains filtered or unexported fields }
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 ¶
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:
1 byte to identify the network, must be 0x80 for mainnet or 0xef for either testnet3 or the regression test network
32 bytes of a binary-encoded, big-endian, zero-padded private key
Optional 1 byte (equal to 0x01) if the address being imported or exported was created by taking the RIPEMD160 after SHA256 hash of a serialized compressed (33-byte) public key
4 bytes of checksum, must equal the first four bytes of the double SHA256 of every byte before the checksum in this 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 ¶
NewWIF creates a new WIF structure to export an address and its private key as a string encoded in the Wallet Import Format. The compress argument specifies whether the address intended to be imported or exported was created by serializing the public key compressed rather than uncompressed.
func (*WIF) IsForNet ¶
IsForNet returns whether or not the decoded WIF structure is associated with the passed bitcoin network.
func (*WIF) SerializePubKey ¶
SerializePubKey serializes the associated public key of the imported or exported private key in either a compressed or uncompressed format. The serialization format chosen depends on the value of w.CompressPubKey.