add pushtx, and outpoint comparitor
This commit is contained in:
1 parent
9215c18113
commit
fc100921e8
3 files changed
+26
-3
No files matched your search
@@ -346,6 +346,20 @@ func NewRootAndHeight(r wire.ShaHash, h int32) (rah RootAndHeight) {
|
|||||||
return
|
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
|
// AskForMerkBlocks requests blocks from current to last
|
||||||
// right now this asks for 1 block per getData message.
|
// right now this asks for 1 block per getData message.
|
||||||
// Maybe it's faster to ask for many in a each message?
|
// Maybe it's faster to ask for many in a each message?
|
||||||
|
|||||||
+1
-1
@@ -66,7 +66,7 @@ func (s *SPVCon) incomingMessageHandler() {
|
|||||||
s.AskForHeaders()
|
s.AskForHeaders()
|
||||||
}
|
}
|
||||||
case *wire.MsgTx:
|
case *wire.MsgTx:
|
||||||
err := s.TS.IngestTx(m)
|
err := s.TS.AckTx(m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Incoming Tx error: %s\n", err.Error())
|
log.Printf("Incoming Tx error: %s\n", err.Error())
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-2
@@ -86,7 +86,7 @@ func (t *TxStore) GimmeFilter() (*bloom.Filter, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Ingest a tx into wallet, dealing with both gains and losses
|
// 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()
|
inTxid := tx.TxSha()
|
||||||
height, ok := t.OKTxids[inTxid]
|
height, ok := t.OKTxids[inTxid]
|
||||||
if !ok {
|
if !ok {
|
||||||
@@ -158,7 +158,7 @@ func (t *TxStore) ExpellTx(tx *wire.MsgTx, height int32) error {
|
|||||||
|
|
||||||
for _, in := range tx.TxIn {
|
for _, in := range tx.TxIn {
|
||||||
for i, myutxo := range t.Utxos {
|
for i, myutxo := range t.Utxos {
|
||||||
if myutxo.Op == in.PreviousOutPoint {
|
if OutPointsEqual(myutxo.Op, in.PreviousOutPoint) {
|
||||||
hits++
|
hits++
|
||||||
loss += myutxo.Value
|
loss += myutxo.Value
|
||||||
err := t.MarkSpent(&myutxo.Op, height, tx)
|
err := t.MarkSpent(&myutxo.Op, height, tx)
|
||||||
@@ -175,6 +175,15 @@ func (t *TxStore) ExpellTx(tx *wire.MsgTx, height int32) error {
|
|||||||
return nil
|
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
|
// TxToString prints out some info about a transaction. for testing / debugging
|
||||||
func TxToString(tx *wire.MsgTx) string {
|
func TxToString(tx *wire.MsgTx) string {
|
||||||
str := "\t\t\t - Tx - \n"
|
str := "\t\t\t - Tx - \n"
|
||||||
|
|||||||
Reference in new issue
Block a user