Documentation ¶
Index ¶
Constants ¶
const ( // Flags which combined can turn into full utxo modes FlagTxoPubKeyHash TxoMode = 0x01 FlagTxoScript TxoMode = 0x02 FlagTxoWitness TxoMode = 0x04 FlagTxoCompressed TxoMode = 0x08 FlagTxoUncompressed TxoMode = 0x10 // fully specified tx output modes // raw pubkey outputs (old school) TxoP2PKUncomp = FlagTxoUncompressed TxoP2PKComp = FlagTxoCompressed // pub key hash outputs, standard p2pkh (common) TxoP2PKHUncomp = FlagTxoPubKeyHash | FlagTxoUncompressed TxoP2PKHComp = FlagTxoCompressed | FlagTxoPubKeyHash // script hash TxoP2SHUncomp = FlagTxoScript | FlagTxoUncompressed TxoP2SHComp = FlagTxoScript | FlagTxoCompressed // witness p2wpkh modes TxoP2WPKHUncomp = FlagTxoWitness | FlagTxoPubKeyHash | FlagTxoUncompressed TxoP2WPKHComp = FlagTxoWitness | FlagTxoPubKeyHash | FlagTxoCompressed // witness script hash TxoP2WSHUncomp = FlagTxoWitness | FlagTxoScript | FlagTxoUncompressed TxoP2WSHComp = FlagTxoWitness | FlagTxoScript | FlagTxoCompressed // unknown TxoUnknownMode = 0x80 )
Constants defining txo modes
Variables ¶
This section is empty.
Functions ¶
func PrivKeyAddBytes ¶
func PrivKeyAddBytes(k *koblitz.PrivateKey, b []byte)
PrivKeyAddBytes adds bytes to a private key. NOTE that this modifies the key in place, overwriting it!!!!1 If k is nil, does nothing and doesn't error (k stays nil)
Types ¶
type KeyGen ¶
type KeyGen struct { Depth uint8 `json:"depth"` // how many levels of the path to use. 0 means privkey as-is Step [5]uint32 `json:"steps"` // bip 32 / 44 path numbers PrivKey [32]byte `json:"privkey"` // private key }
KeyGen describes how to get to the key from the master / seed. it can be used with bip44 or other custom schemes (up to 5 levels deep) Depth must be 0 to 5 inclusive. Child indexes of 0 are OK, so we can't just terminate at the first 0.
func KeyGenFromBytes ¶
KeyGenFromBytes turns a 53 byte array into a key derivation path. Always works (note a depth > 5 path is invalid, but this just deserializes & doesn't check)
func (*KeyGen) DerivePrivateKey ¶
func (kg *KeyGen) DerivePrivateKey( m *hdkeychain.ExtendedKey) (*koblitz.PrivateKey, error)
DerivePrivateKey returns the private key for a utxo based on a master key
type KeyGenSortableSlice ¶
type KeyGenSortableSlice []*KeyGen
KeyGenSortableSlice is a sortable slice of keygens. Shorter and lower numbers first.
func (KeyGenSortableSlice) Len ¶
func (s KeyGenSortableSlice) Len() int
func (KeyGenSortableSlice) Less ¶
func (s KeyGenSortableSlice) Less(i, j int) bool
func (KeyGenSortableSlice) Swap ¶
func (s KeyGenSortableSlice) Swap(i, j int)
type PorTxo ¶
type PorTxo struct { // got rid of NetID. If you want to specify different networks / coins, // use KeyGen.Step[1], that's what it's for. // Heck, set KeyGen.Depth to 0 and still use Step[1] as the network / coin... // NetID byte // indicates what network / coin utxo is in Op wire.OutPoint `json:"outpoint"` // unique outpoint Value int64 `json:"val"` // higher is better Height int32 `json:"height"` // block height of utxo (not needed? nice to know?) Seq uint32 `json:"seq"` // used for relative timelock Mode TxoMode `json:"mode"` // what kind of output KeyGen `json:"keygen"` PkScript []byte `json:"privkeyscript"` // if empty, try to generate based on mode and priv key PreSigStack [][]byte `json:"stack"` // items to push before the sig }
PorTxo specify a utxo, and all the information needed to spend it.
The first 3 fields (Op, Amt, Mode) are required in all cases. If KeyGen.Depth != 0, that means no key path is supplied, and PrivKey is probably empty / ignored. Having both a KeyGen and a PrivKey is redunant. Having neither KeyGen nor PrivKey means there's no private key, and no indication of how to get it; in that case get the private key from somewhere else.
If BOTH KeyGen AND PrivKey are filled in, add em up! Add the two private keys, modulo the curve order.
PkScript can also be left empty depending on the mode. Basically only script-hash modes need it, as the previous pkscript can be generated
PreSigStack are data pushes that happen before the signature is pushed.
I was thinking of putting PostSigStack as well but I think it makes more sense to always have the data before the sig, since there's pretty much only CHECKSIGVERIFY now and you might as well put the sig check last.
Also makes sense that with a MAST or pay-to-script-merkle-root type of structure, you'd want a bunch stuff before the sig.
func ExtractFromTx ¶
ExtractFromTx returns a portxo from a tx and index. It fills in what it can, but the keygen, sequence, and height can't be determined from just this and need to be put in separately.
func PorTxoFromBytes ¶
func (*PorTxo) EstSize ¶
EstSize returns an estimated vsize in bytes for using this portxo as an input. Might not be perfectly accurate. Also maybe should switch from vsize to weight..? everything is vsize right now though.
type TxoSliceByAmt ¶
type TxoSliceByAmt []*PorTxo
txoSliceByAmt is a sortable txo slice. Sorts by value, and puts unconfirmed last. Also has sum functions for calculating balances
func (TxoSliceByAmt) Len ¶
func (s TxoSliceByAmt) Len() int
func (TxoSliceByAmt) Less ¶
func (s TxoSliceByAmt) Less(i, j int) bool
height 0 means you are lesser
func (TxoSliceByAmt) Sum ¶
func (s TxoSliceByAmt) Sum() int64
func (TxoSliceByAmt) SumWitness ¶
func (s TxoSliceByAmt) SumWitness(currentHeight int32) int64
func (TxoSliceByAmt) Swap ¶
func (s TxoSliceByAmt) Swap(i, j int)
type TxoSliceByBip69 ¶
type TxoSliceByBip69 []*PorTxo
txoSliceByBip69 is a sortable txo slice - same algo as txsort / BIP69
func (TxoSliceByBip69) Len ¶
func (s TxoSliceByBip69) Len() int
Sort utxos just like txins -- Len, Less, Swap
func (TxoSliceByBip69) Less ¶
func (s TxoSliceByBip69) Less(i, j int) bool
outpoint sort; First input hash (reversed / rpc-style), then index.
func (TxoSliceByBip69) Swap ¶
func (s TxoSliceByBip69) Swap(i, j int)