mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-20 02:27:21 +01:00
add pushtx, and outpoint comparitor
This commit is contained in:
parent
9215c18113
commit
fc100921e8
@ -346,6 +346,20 @@ func NewRootAndHeight(r wire.ShaHash, h int32) (rah RootAndHeight) {
|
||||
return
|
||||
}
|
||||
|
||||
func (s *SPVCon) PushTx(tx *wire.MsgTx) error {
|
||||
txid := tx.TxSha()
|
||||
err := s.TS.AddTxid(&txid, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = s.TS.AckTx(tx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
s.outMsgQueue <- tx
|
||||
return nil
|
||||
}
|
||||
|
||||
// AskForMerkBlocks requests blocks from current to last
|
||||
// right now this asks for 1 block per getData message.
|
||||
// Maybe it's faster to ask for many in a each message?
|
||||
|
@ -66,7 +66,7 @@ func (s *SPVCon) incomingMessageHandler() {
|
||||
s.AskForHeaders()
|
||||
}
|
||||
case *wire.MsgTx:
|
||||
err := s.TS.IngestTx(m)
|
||||
err := s.TS.AckTx(m)
|
||||
if err != nil {
|
||||
log.Printf("Incoming Tx error: %s\n", err.Error())
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ func (t *TxStore) GimmeFilter() (*bloom.Filter, error) {
|
||||
}
|
||||
|
||||
// Ingest a tx into wallet, dealing with both gains and losses
|
||||
func (t *TxStore) IngestTx(tx *wire.MsgTx) error {
|
||||
func (t *TxStore) AckTx(tx *wire.MsgTx) error {
|
||||
inTxid := tx.TxSha()
|
||||
height, ok := t.OKTxids[inTxid]
|
||||
if !ok {
|
||||
@ -158,7 +158,7 @@ func (t *TxStore) ExpellTx(tx *wire.MsgTx, height int32) error {
|
||||
|
||||
for _, in := range tx.TxIn {
|
||||
for i, myutxo := range t.Utxos {
|
||||
if myutxo.Op == in.PreviousOutPoint {
|
||||
if OutPointsEqual(myutxo.Op, in.PreviousOutPoint) {
|
||||
hits++
|
||||
loss += myutxo.Value
|
||||
err := t.MarkSpent(&myutxo.Op, height, tx)
|
||||
@ -175,6 +175,15 @@ func (t *TxStore) ExpellTx(tx *wire.MsgTx, height int32) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// need this because before I was comparing pointers maybe?
|
||||
// so they were the same outpoint but stored in 2 places so false negative?
|
||||
func OutPointsEqual(a, b wire.OutPoint) bool {
|
||||
if !a.Hash.IsEqual(&b.Hash) {
|
||||
return false
|
||||
}
|
||||
return a.Index == b.Index
|
||||
}
|
||||
|
||||
// TxToString prints out some info about a transaction. for testing / debugging
|
||||
func TxToString(tx *wire.MsgTx) string {
|
||||
str := "\t\t\t - Tx - \n"
|
||||
|
Loading…
Reference in New Issue
Block a user