Documentation ¶
Index ¶
- Variables
- func EstFee(txins []*portxo.PorTxo, outputByteSize, spB int64) int64
- func GetWalletKeygen(idx, cointype uint32) portxo.KeyGen
- func NewPorTxo(tx *wire.MsgTx, idx uint32, height int32, kg portxo.KeyGen) (*portxo.PorTxo, error)
- func NewPorTxoBytesFromKGBytes(tx *wire.MsgTx, idx uint32, height int32, kgb []byte) ([]byte, error)
- func TxToString(tx *wire.MsgTx) string
- type FrozenTx
- type Stxo
- type Wallit
- func (w *Wallit) AddPorTxoAdr(kg portxo.KeyGen) error
- func (w *Wallit) AdrDump() ([][20]byte, error)
- func (w *Wallit) BuildAndSign(utxos []*portxo.PorTxo, txos []*wire.TxOut, nlt uint32) (*wire.MsgTx, error)
- func (w *Wallit) BuildDontSign(utxos []*portxo.PorTxo, txos []*wire.TxOut) (*wire.MsgTx, error)
- func (w *Wallit) CurrentHeight() int32
- func (w *Wallit) DirectSendTx(tx *wire.MsgTx) error
- func (w *Wallit) ExportHook() uspv.ChainHook
- func (w *Wallit) ExportUtxo(u *portxo.PorTxo)
- func (w *Wallit) Fee() int64
- func (w *Wallit) FindFreezeTx(txid *chainhash.Hash) (*FrozenTx, error)
- func (w *Wallit) GainUtxo(u portxo.PorTxo) error
- func (w *Wallit) GetAllUtxos() ([]*portxo.PorTxo, error)
- func (w *Wallit) GetDBSyncHeight() (int32, error)
- func (w *Wallit) GetPriv(k portxo.KeyGen) (*koblitz.PrivateKey, error)
- func (w *Wallit) GetPub(k portxo.KeyGen) *koblitz.PublicKey
- func (w *Wallit) GetUsePriv(kg portxo.KeyGen, use uint32) *koblitz.PrivateKey
- func (w *Wallit) GetUsePub(kg portxo.KeyGen, use uint32) [33]byte
- func (w *Wallit) GetWalletPrivkey(idx uint32) *koblitz.PrivateKey
- func (w *Wallit) GrabAll() error
- func (w *Wallit) HeightHandler(incomingHeight chan int32)
- func (w *Wallit) Ingest(tx *wire.MsgTx, height int32) (uint32, error)
- func (w *Wallit) IngestMany(txs []*wire.MsgTx, height int32) (uint32, error)
- func (w *Wallit) LetMeKnow() chan lnutil.OutPointEvent
- func (w *Wallit) LetMeKnowHeight() chan lnutil.HeightEvent
- func (w *Wallit) MaybeSend(txos []*wire.TxOut, ow bool) ([]*wire.OutPoint, error)
- func (w *Wallit) NahDontSend(txid *chainhash.Hash) error
- func (w *Wallit) NewAdr() ([20]byte, error)
- func (w *Wallit) NewAdr160() ([20]byte, error)
- func (w *Wallit) NewChangeOut(amt int64) (*wire.TxOut, error)
- func (w *Wallit) NewOutgoingTx(tx *wire.MsgTx) error
- func (w *Wallit) OpenDB(filename string) error
- func (w *Wallit) Params() *coinparam.Params
- func (w *Wallit) PathPrivkey(kg portxo.KeyGen) *koblitz.PrivateKey
- func (w *Wallit) PathPubHash160(kg portxo.KeyGen) [20]byte
- func (w *Wallit) PathPubkey(kg portxo.KeyGen) *koblitz.PublicKey
- func (w *Wallit) PickUtxos(amtWanted, outputByteSize, feePerByte int64, ow bool) (portxo.TxoSliceByBip69, int64, error)
- func (w *Wallit) PushTx(tx *wire.MsgTx) error
- func (w *Wallit) ReallySend(txid *chainhash.Hash) error
- func (w *Wallit) RegisterWatchOP(op wire.OutPoint) error
- func (w *Wallit) RollBack(rollHeight int32) error
- func (w *Wallit) SaveTx(tx *wire.MsgTx) error
- func (w *Wallit) SendOne(u portxo.PorTxo, outScript []byte) (*wire.MsgTx, error)
- func (w *Wallit) SetDBSyncHeight(n int32) error
- func (w *Wallit) SetFee(set int64) int64
- func (w *Wallit) SignMyInputs(tx *wire.MsgTx) error
- func (w *Wallit) StopWatchingThis(op wire.OutPoint) error
- func (w *Wallit) Sweep(outScript []byte, n uint32) ([]*chainhash.Hash, error)
- func (w *Wallit) TxHandler(incomingTxAndHeight chan lnutil.TxAndHeight)
- func (w *Wallit) UnregisterWatchOP(op wire.OutPoint) error
- func (w *Wallit) UtxoDump() ([]*portxo.PorTxo, error)
- func (w *Wallit) WatchThis(op wire.OutPoint) error
Constants ¶
This section is empty.
Variables ¶
var ( // storage of all utxos. top level is outpoints. BKToutpoint = []byte("DuffelBag") // storage of all addresses being watched. top level is pkscripts BKTadr = []byte("adr") BKTStxos = []byte("SpentTxs") // for bookkeeping / not sure BKTTxns = []byte("Txns") // all txs we care about, for replays BKTState = []byte("MiscState") // misc states of DB // BKTWatch = []byte("watch") // outpoints we're watching for someone else // these are in the state bucket KEYNumKeys = []byte("NumKeys") // number of p2pkh keys used KEYTipHeight = []byte("TipHeight") // height synced to )
const strings for db usage
Functions ¶
func EstFee ¶
EstFee gives a fee estimate based on an input / output set and a sat/Byte target. It guesses the final tx size based on: Txouts: 8 bytes + pkscript length Total guess on the p2wsh one, see if that's accurate
func GetWalletKeygen ¶
GetWalletKeygen returns the keygen for a standard wallet address
func NewPorTxoBytesFromKGBytes ¶
func NewPorTxoBytesFromKGBytes( tx *wire.MsgTx, idx uint32, height int32, kgb []byte) ([]byte, error)
NewPorTxoBytesFromKGBytes just calls NewPorTxo() and de/serializes quick shortcut for use in the ingest() function
func TxToString ¶
TxToString prints out some info about a transaction. for testing / debugging
Types ¶
type Stxo ¶
type Stxo struct { PorTxo portxo.PorTxo `json:"txo"` // when it used to be a utxo SpendHeight int32 `json:"height"` // height at which it met its demise SpendTxid chainhash.Hash `json:"txid"` // the tx that consumed it }
Stxo is a utxo that has moved on.
func StxoFromBytes ¶
StxoFromBytes turns bytes into a Stxo. it's a portxo with a spendHeight and spendTxid at the end.
type Wallit ¶
type Wallit struct { // could get rid of adr slice, it's just an in-ram cache... StateDB *bolt.DB // place to write all this down // Set of frozen utxos not to use... they point to the tx using em FreezeSet map[wire.OutPoint]*FrozenTx FreezeMutex sync.Mutex // OPEventChan sends events to the LN wallet. // Gets initialized and activates when called by qln OPEventChan chan lnutil.OutPointEvent // HeightEventChan sends block height changes to the LN wallet. // Gets initialized and activates when called by qln HeightEventChan chan lnutil.HeightEvent // Params live here... Param *coinparam.Params // network parameters (testnet3, segnet, etc) // Hook is the connection to a blockchain. // imports the uspv interface. Could put that somewhere else. // like an interfaces library, ... lnutil? Hook uspv.ChainHook // current fee per byte FeeRate int64 // contains filtered or unexported fields }
The Wallit is lit's main wallet struct. It's got the root key, the dbs, and contains the SPVhooks into the network.
func (*Wallit) AddPorTxoAdr ¶
AddPorTxoAdr adds an externally sourced address to the db. Looks at the keygen to derive hash160.
func (*Wallit) AdrDump ¶
AdrDump returns all the addresses in the wallit. currently returns 20 byte arrays, which can then be converted somewhere else into bech32 addresses (or old base58)
func (*Wallit) BuildAndSign ¶
func (w *Wallit) BuildAndSign( utxos []*portxo.PorTxo, txos []*wire.TxOut, nlt uint32) (*wire.MsgTx, error)
BuildAndSign builds a tx from a slice of utxos and txOuts. It then signs all the inputs and returns the tx. Should pretty much always work for any inputs.
func (*Wallit) BuildDontSign ¶
Builds tx from inputs and outputs, returns tx. Sorts. Doesn't sign.
func (*Wallit) CurrentHeight ¶
func (*Wallit) DirectSendTx ¶
Directly send out a tx. For things that plug in to the uspv wallet.
func (*Wallit) ExportHook ¶
func (*Wallit) ExportUtxo ¶
ExportUtxo is really *IM*port utxo on this side. Not implemented yet. Fix "ingest many" at the same time eh?
func (*Wallit) FindFreezeTx ¶
FindFreezeTx looks through the frozen map to find a tx. Error if it can't find it
func (*Wallit) GainUtxo ¶
GainUtxo registers the utxo in the duffel bag don't register address; they shouldn't be re-used ever anyway.
func (*Wallit) GetAllUtxos ¶
GetAllUtxos returns a slice of all portxos in the db. empty slice is OK. Doesn't return watch only outpoints
func (*Wallit) GetDBSyncHeight ¶
SyncHeight returns the chain height to which the db has synced
func (*Wallit) GetUsePriv ¶
GetUsePrive generates a private key for the given use case & keypath
func (*Wallit) GetWalletPrivkey ¶
func (w *Wallit) GetWalletPrivkey(idx uint32) *koblitz.PrivateKey
get a private key from the regular wallet
func (*Wallit) HeightHandler ¶
func (*Wallit) IngestMany ¶
This should always work; there shouldn't be false positives getting to here, as those should be handled on the ChainHook level. IngestMany can probably work OK even if the txs are out of order. But don't do that, that's weird and untested. also it'll error if you give it more than 1M txs, so don't.
func (*Wallit) LetMeKnow ¶
func (w *Wallit) LetMeKnow() chan lnutil.OutPointEvent
func (*Wallit) LetMeKnowHeight ¶
func (w *Wallit) LetMeKnowHeight() chan lnutil.HeightEvent
func (*Wallit) MaybeSend ¶
Build a tx, kindof like with SendCoins, but don't sign or broadcast. Segwit inputs only. Freeze the utxos used so the tx can be signed and broadcast later. Use only segwit utxos. Return the txid, and indexes of where the txouts in the argument slice ended up in the final tx. Bunch of redundancy with SendMany, maybe move that to a shared function... NOTE this does not support multiple txouts with identical pkscripts in one tx. The code would be trivial; it's not supported on purpose. Use unique pkscripts.
func (*Wallit) NahDontSend ¶
Cancel the hold on a tx previously built with MaybeSend. Clears freeze on utxos so they can be used somewhere else.
func (*Wallit) NewAdr160 ¶
NewAdr creates a new, never before seen address, and increments the DB counter, and returns the hash160 of the pubkey.
func (*Wallit) NewChangeOut ¶
make a new change output. I guess this is supposed to be on a different branch than regular addresses...
func (*Wallit) NewOutgoingTx ¶
NewOutgoingTx runs a tx though the db first, then sends it out to the network.
func (*Wallit) PathPrivkey ¶
func (w *Wallit) PathPrivkey(kg portxo.KeyGen) *koblitz.PrivateKey
PathPrivkey returns a private key by descending the given path Returns nil if there's an error.
func (*Wallit) PathPubHash160 ¶
PathPubHash160 returns a 20 byte pubkey hash for the given path It'll always return 20 bytes, or a nil if there's an error.
func (*Wallit) PathPubkey ¶
PathPubkey returns a public key by descending the given path. Returns nil if there's an error.
func (*Wallit) PickUtxos ¶
func (w *Wallit) PickUtxos( amtWanted, outputByteSize, feePerByte int64, ow bool) (portxo.TxoSliceByBip69, int64, error)
PickUtxos Picks Utxos for spending. Tell it how much money you want. It returns a tx-sortable utxoslice, and the overshoot amount. Also errors. if "ow" is true, only gives witness utxos (for channel funding) The overshoot amount is *after* fees, so can be used directly for a change output.
func (*Wallit) ReallySend ¶
Sign and broadcast a tx previously built with MaybeSend. This clears the freeze on the utxos but they're not utxos anymore anyway.
func (*Wallit) RegisterWatchOP ¶
RegisterWatchOP registers an outpoint to watch. Called from ReallySend()
func (*Wallit) RollBack ¶
Rollback rewinds the wallet state to a previous height. It removes new UTXOs
func (*Wallit) SaveTx ¶
SaveTx unconditionally saves a tx in the DB, usually for sending out to nodes
func (*Wallit) SendOne ¶
SendOne is for the sweep function, and doesn't do change. Probably can get rid of this for real txs.
func (*Wallit) SetDBSyncHeight ¶
SetDBSyncHeight sets sync height of the db, indicated the latest block of which it has ingested all the transactions.
func (*Wallit) SignMyInputs ¶
SignMyInputs finds the inputs in a transaction that came from our own wallet, and signs them with our private keys. Will modify the transaction in place, but will ignore inputs that we can't sign and leave them unsigned.
func (*Wallit) StopWatchingThis ¶
StopWatchingThis removes an outpoint to watch.
func (*Wallit) TxHandler ¶
func (w *Wallit) TxHandler(incomingTxAndHeight chan lnutil.TxAndHeight)
TxHandler is the goroutine that receives & ingests new txs for the wallit.
func (*Wallit) UnregisterWatchOP ¶
UnregisterWatchOP unregisters an outpoint to watch. Used to remove watched HTLC OPs if we claim them ourselves.