Skip to content

Commit dab768f

Browse files
committed
Add some logs
1 parent bf31918 commit dab768f

File tree

1 file changed

+17
-23
lines changed

1 file changed

+17
-23
lines changed

bitcoind/bitcoind.go

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,50 +19,44 @@ func GetSenderAddresses(destTxs []string) ([]string, error) {
1919
return nil, fmt.Errorf("cannot create a bitcoind client")
2020
}
2121
addrs := []string{}
22+
errs := []error{}
2223
for _, txid := range destTxs {
2324
t, err := bc.GetRawTransaction(txid, true)
2425
if err != nil {
26+
log.Printf("GetSenderAddresses - GetRawTransaction(%s) error: %v", txid, err)
27+
errs = append(errs, err)
28+
continue
2529
}
2630
rawtx, ok := t.(gbitcoind.RawTransaction)
2731
if !ok {
32+
err = fmt.Errorf("failed to cast txid %s to RawTransaction", txid)
33+
log.Printf("GetSenderAddresses - %v", err)
34+
errs = append(errs, err)
2835
continue
2936
}
3037
for _, vin := range rawtx.Vin {
3138
tin, err := bc.GetRawTransaction(vin.Txid, true)
3239
if err != nil {
40+
log.Printf("GetSenderAddresses - GetRawTransaction(%s) error: %v", vin.Txid, err)
41+
errs = append(errs, err)
42+
continue
3343
}
3444
rawtin, ok := tin.(gbitcoind.RawTransaction)
3545
if !ok {
46+
err = fmt.Errorf("failed to cast txid %s to RawTransaction", txid)
47+
log.Printf("GetSenderAddresses - %v", err)
48+
errs = append(errs, err)
3649
continue
3750
}
3851
spk := rawtin.Vout[vin.Vout].ScriptPubKey
3952
addrs = append(addrs, spk.Address)
4053
addrs = append(addrs, spk.Addresses...)
41-
//fmt.Printf("from addr: %v\n", address)
4254
}
4355
}
44-
return addrs, nil
45-
}
4656

47-
func GetTransaction(txid string) (*gbitcoind.RawTransaction, error) {
48-
bitcoindPort, err := strconv.Atoi(os.Getenv("BITCOIND_PORT"))
49-
if err != nil {
50-
return nil, fmt.Errorf("no valid port for bitcoind: %v", os.Getenv("BITCOIND_PORT"))
57+
err = nil
58+
if len(errs) > 0 {
59+
err = fmt.Errorf("failed to get some addresses")
5160
}
52-
bc, err := gbitcoind.New(os.Getenv("BITCOIND_HOST"), bitcoindPort, os.Getenv("BITCOIND_USER"), os.Getenv("BITCOIND_PASSWORD"), false)
53-
if err != nil {
54-
return nil, fmt.Errorf("cannot create a bitcoind client: %w", err)
55-
}
56-
57-
t, err := bc.GetRawTransaction(txid, true)
58-
if err != nil {
59-
return nil, fmt.Errorf("error getting tx: %w", err)
60-
}
61-
62-
rawtx, ok := t.(gbitcoind.RawTransaction)
63-
if !ok {
64-
return nil, fmt.Errorf("tx is not a gbitcoind.RawTransaction: %w", err)
65-
}
66-
67-
return &rawtx, nil
61+
return addrs, err
6862
}

0 commit comments

Comments
 (0)