Skip to content
This repository was archived by the owner on Mar 15, 2019. It is now read-only.

Commit 7c7473e

Browse files
committed
Major update, work with new notifications after Decred 0.6.0.
Squashed commit of the following: commit 9b30cbc Author: Jon Chappelow <[email protected]> Date: Wed Nov 16 17:59:18 2016 -0800 Make messages debug instead of info, remove TODO. commit 663005f Author: Jon Chappelow <[email protected]> Date: Wed Nov 16 14:08:16 2016 -0800 Move code to new files, impove balance alignment. Add OnWinningTickets with debug level logging of the hashes. Include tx out index in message. commit 0b6f0fc Author: Jon Chappelow <[email protected]> Date: Wed Nov 16 11:31:37 2016 -0800 Refactoring, move channels and ntfns to own files. Make channels global, which simplifies all the interfaces and structures. commit cf45c11 Author: Jon Chappelow <[email protected]> Date: Tue Nov 15 22:47:18 2016 -0800 Sort of working again. commit 3a8a4d0 Author: Jon Chappelow <[email protected]> Date: Tue Nov 15 07:22:08 2016 -0800 This is going to be massive, stop Travis. commit 5765d09 Author: Jon Chappelow <[email protected]> Date: Mon Nov 14 21:15:36 2016 -0800 Fix up watchedAddrTx. commit dd639fd Author: Jon Chappelow <[email protected]> Date: Mon Nov 14 10:35:03 2016 -0800 Begin changes for the new websocket notifications
1 parent 14ae414 commit 7c7473e

15 files changed

+823
-530
lines changed

TODO

-40
This file was deleted.

config.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ type config struct {
8282
NoCollectStakeInfo bool `long:"nostakeinfo" description:"Do not collect stake info data (default false)"`
8383
PoolValue bool `short:"p" long:"poolvalue" description:"Collect ticket pool value information (8-9 sec)."`
8484

85-
WatchAddresses []string `short:"w" long:"watchaddress" description:"Decred address for which to watch for incoming transactions. One per line."`
85+
WatchAddresses []string `short:"w" long:"watchaddress" description:"Watched address (receiving). One per line."`
86+
//WatchOutpoints []string `short:"o" long:"watchout" description:"Watched outpoint (sending). One per line."`
8687

8788
SMTPUser string `long:"smtpuser" description:"SMTP user name"`
8889
SMTPPass string `long:"smtppass" description:"SMTP password"`
@@ -382,5 +383,13 @@ func loadConfig() (*config, error) {
382383
log.Debugf("Output folder: %v", cfg.OutFolder)
383384
log.Debugf("Log folder: %v", cfg.LogDir)
384385

386+
// mempool: new transactions, new tickets
387+
//cfg.MonitorMempool = cfg.MonitorMempool && !cfg.NoMonitor
388+
if cfg.MonitorMempool && cfg.NoMonitor {
389+
log.Warn("Both --nomonitor (-e) and --mempool (-m) specified. " +
390+
"Not monitoring mempool.")
391+
cfg.MonitorMempool = false
392+
}
393+
385394
return &cfg, nil
386395
}

datasaver.go

+12-7
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ import (
1313
"io"
1414
"os"
1515
"path/filepath"
16+
"strings"
1617
"sync"
17-
//"github.com/decred/dcrd/dcrjson"
18-
//"github.com/decred/dcrutil"
1918
)
2019

2120
type fileSaver struct {
@@ -359,20 +358,26 @@ func (s *StakeInfoDataToSummaryStdOut) Store(data *stakeInfoData) error {
359358

360359
fmt.Println("- Balances (by account)")
361360
for acct, balances := range *data.accountBalances {
362-
fmt.Printf("\tBalances (%s): \t %10.4f (any), %10.4f (spendable), %10.4f (locked)\n",
363-
acct, balances["all"].ToCoin(), balances["spendable"].ToCoin(),
361+
padWidth := len("imported") - len(acct) + 5
362+
if padWidth < 0 {
363+
padWidth = 0
364+
}
365+
padding := strings.Repeat(" ", padWidth)
366+
fmt.Printf("\tBalances (%s):%s%12.4f (any),%12.4f (spendable),%12.4f (locked)\n",
367+
acct, padding,
368+
balances["all"].ToCoin(), balances["spendable"].ToCoin(),
364369
balances["locked"].ToCoin())
365370
}
366371

367372
fmt.Println("- Balances (by type)")
368-
fmt.Printf("\tBalances (spendable): %9.4f (default), %9.4f (all)\n",
373+
fmt.Printf("\tBalances (spendable):%12.4f (default),%12.4f (all)\n",
369374
data.balances.SpendableDefaultAccount,
370375
data.balances.SpendableAllAccounts)
371-
fmt.Printf("\tBalances (locked): %9.4f (default), %9.4f (all), %9.4f (imported)\n",
376+
fmt.Printf("\tBalances (locked): %12.4f (default),%12.4f (all),%12.4f (imported)\n",
372377
data.balances.LockedDefaultAccount,
373378
data.balances.LockedAllAccounts,
374379
data.balances.LockedImportedAccount)
375-
fmt.Printf("\tBalances (any): %9.4f (default), %9.4f (all)\n",
380+
fmt.Printf("\tBalances (any): %12.4f (default),%12.4f (all)\n",
376381
data.balances.AllDefaultAcount, data.balances.AllAllAcounts)
377382

378383
fmt.Println("- Stake Info")

email.go

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package main
2+
3+
import (
4+
"errors"
5+
"fmt"
6+
"net/smtp"
7+
"strconv"
8+
)
9+
10+
type emailConfig struct {
11+
emailAddr string
12+
smtpUser, smtpPass, smtpServer string
13+
smtpPort int
14+
}
15+
16+
// sendEmailWatchRecv Sends an email using the input emailConfig and message
17+
// string.
18+
func sendEmailWatchRecv(message string, ecfg *emailConfig) error {
19+
// Check for nil pointer emailConfig
20+
if ecfg == nil {
21+
return errors.New("emailConfig must not be a nil pointer")
22+
}
23+
24+
auth := smtp.PlainAuth(
25+
"",
26+
ecfg.smtpUser,
27+
ecfg.smtpPass,
28+
ecfg.smtpServer,
29+
)
30+
31+
// The SMTP server address includes the port
32+
addr := ecfg.smtpServer + ":" + strconv.Itoa(ecfg.smtpPort)
33+
//log.Debug(addr)
34+
35+
// Make a header using a map for clarity
36+
header := make(map[string]string)
37+
header["From"] = ecfg.smtpUser
38+
header["To"] = ecfg.emailAddr
39+
// TODO: make subject line adjustable or include an amount
40+
header["Subject"] = "dcrspy notification"
41+
//header["MIME-Version"] = "1.0"
42+
//header["Content-Type"] = "text/plain; charset=\"utf-8\""
43+
//header["Content-Transfer-Encoding"] = "base64"
44+
45+
// Build the full message with the header + input message string
46+
messageFull := ""
47+
for k, v := range header {
48+
messageFull += fmt.Sprintf("%s: %s\r\n", k, v)
49+
}
50+
51+
messageFull += "\r\n" + message
52+
53+
// Send email
54+
err := smtp.SendMail(
55+
addr,
56+
auth,
57+
ecfg.smtpUser, // sender is receiver
58+
[]string{ecfg.emailAddr}, // recipients
59+
[]byte(messageFull),
60+
)
61+
62+
if err != nil {
63+
log.Errorf("Failed to send email: %v", err)
64+
return err
65+
}
66+
67+
log.Tracef("Send email to address %v\n", ecfg.emailAddr)
68+
return nil
69+
}

glide.lock

+10-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

glide.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import:
1212
- package: github.com/btcsuite/websocket
1313
- package: github.com/decred/blake256
1414
- package: github.com/decred/dcrd
15+
version: master
1516
subpackages:
1617
- blockchain
1718
- blockchain/stake
@@ -26,6 +27,7 @@ import:
2627
- txscript
2728
- wire
2829
- package: github.com/decred/dcrrpcclient
30+
version: master
2931
- package: github.com/decred/dcrutil
3032
subpackages:
3133
- base58

0 commit comments

Comments
 (0)