-
Notifications
You must be signed in to change notification settings - Fork 3
/
wallet_listener.go
44 lines (40 loc) · 1.1 KB
/
wallet_listener.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
package bitcoin
import (
"github.com/evenfound/even-go/node/repo"
"github.com/OpenBazaar/wallet-interface"
)
type WalletListener struct {
db repo.Datastore
broadcast chan repo.Notifier
coinType wallet.CoinType
}
func NewWalletListener(db repo.Datastore, broadcast chan repo.Notifier, coinType wallet.CoinType) *WalletListener {
l := &WalletListener{db, broadcast, coinType}
return l
}
func (l *WalletListener) OnTransactionReceived(cb wallet.TransactionCallback) {
if !cb.WatchOnly {
metadata, _ := l.db.TxMetadata().Get(cb.Txid)
status := "UNCONFIRMED"
confirmations := 0
if cb.Height > 0 {
status = "PENDING"
confirmations = 1
}
n := repo.IncomingTransaction{
Wallet: l.coinType.CurrencyCode(),
Txid: cb.Txid,
Value: cb.Value,
Address: metadata.Address,
Status: status,
Memo: metadata.Memo,
Timestamp: cb.Timestamp,
Confirmations: int32(confirmations),
OrderId: metadata.OrderId,
Thumbnail: metadata.Thumbnail,
Height: cb.Height,
CanBumpFee: cb.Value > 0,
}
l.broadcast <- n
}
}