forked from tanitall/memo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
transactions.go
56 lines (52 loc) · 1.42 KB
/
transactions.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main_node
import (
"fmt"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/jchavannes/btcd/wire"
"github.com/jchavannes/jgo/jerr"
"github.com/memocash/memo/app/bitcoin/transaction"
"github.com/memocash/memo/app/db"
)
func onTx(n *Node, msg *wire.MsgTx) {
block := findHashBlock([]map[string]*db.Block{n.BlockHashes, n.PrevBlockHashes}, msg.TxHash())
if (!n.HeaderSyncComplete || !n.BlocksSyncComplete) && block == nil {
return
}
savedTxn, memoTxn, err := transaction.ConditionallySaveTransaction(msg, block, n.UserNode)
if err != nil {
jerr.Get("error conditionally saving transaction", err).Print()
}
if savedTxn {
n.AllTxnsFound++
if memoTxn {
n.MemoTxnsFound++
if block == nil {
fmt.Printf("Saved unconfirmed memo txn: %s\n", msg.TxHash().String())
}
} else if block == nil {
fmt.Printf("Saved unconfirmed txn: %s\n", msg.TxHash().String())
}
}
}
func findHashBlock(blockHashes []map[string]*db.Block, hash chainhash.Hash) *db.Block {
for _, hashMap := range blockHashes {
for hashString, block := range hashMap {
if hashString == hash.String() {
return block
}
}
}
return nil
}
func getTransaction(n *Node, txId chainhash.Hash) {
msgGetData := wire.NewMsgGetData()
err := msgGetData.AddInvVect(&wire.InvVect{
Type: wire.InvTypeTx,
Hash: txId,
})
if err != nil {
jerr.Get("error adding invVect: %s\n", err).Print()
return
}
n.Peer.QueueMessage(msgGetData, nil)
}