2019-09-14 01:13:29 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"git.openprivacy.ca/openprivacy/libricochet-go/connectivity"
|
|
|
|
"git.openprivacy.ca/openprivacy/libricochet-go/log"
|
2019-12-03 21:26:52 +00:00
|
|
|
"git.openprivacy.ca/openprivacy/zcashrpc"
|
2019-09-14 01:13:29 +00:00
|
|
|
"io/ioutil"
|
|
|
|
"sort"
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2019-12-01 21:24:59 +00:00
|
|
|
type zcashConfig struct {
|
|
|
|
Username string `json:"username"`
|
|
|
|
Password string `json:"password"`
|
|
|
|
Onion string `json:"onion"`
|
|
|
|
ZAddress string `json:"zaddress"`
|
2019-09-14 01:13:29 +00:00
|
|
|
}
|
|
|
|
|
2019-12-01 21:24:59 +00:00
|
|
|
type transaction struct {
|
2019-09-14 01:13:29 +00:00
|
|
|
time time.Time
|
2019-12-01 21:24:59 +00:00
|
|
|
transaction zcashrpc.ZcashTransaction
|
2019-09-14 01:13:29 +00:00
|
|
|
}
|
|
|
|
|
2019-12-01 21:24:59 +00:00
|
|
|
type timeSlice []transaction
|
2019-09-14 01:13:29 +00:00
|
|
|
|
|
|
|
func (p timeSlice) Len() int {
|
|
|
|
return len(p)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p timeSlice) Less(i, j int) bool {
|
|
|
|
return p[i].time.Before(p[j].time)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p timeSlice) Swap(i, j int) {
|
|
|
|
p[i], p[j] = p[j], p[i]
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
log.SetLevel(log.LevelDebug)
|
|
|
|
configFile, _ := ioutil.ReadFile("accounting.json")
|
2019-12-01 21:24:59 +00:00
|
|
|
config := zcashConfig{}
|
2019-09-14 01:13:29 +00:00
|
|
|
_ = json.Unmarshal([]byte(configFile), &config)
|
|
|
|
var acn connectivity.ACN
|
|
|
|
acn, _ = connectivity.StartTor("./", "")
|
|
|
|
acn.WaitTillBootstrapped()
|
2019-12-01 21:24:59 +00:00
|
|
|
zc := zcashrpc.NewOnionClient(config.Onion, config.Username, config.Password, acn)
|
2019-09-14 01:13:29 +00:00
|
|
|
transactions, err := zc.ListReceivedTransactionsByAddress(config.ZAddress)
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf("Error fetching zcash transactions: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
sortedTransactions := make(timeSlice, 0)
|
|
|
|
|
2019-12-01 21:24:59 +00:00
|
|
|
for _, tr := range transactions {
|
|
|
|
t, err := zc.GetTransaction(tr.TransactionID)
|
|
|
|
log.Infof("Transaction: %v, Err %v", t, err)
|
2019-09-14 01:13:29 +00:00
|
|
|
ttime := time.Unix(int64(t.Time), 0)
|
2019-12-01 21:24:59 +00:00
|
|
|
sortedTransactions = append(sortedTransactions, transaction{ttime, tr})
|
2019-09-14 01:13:29 +00:00
|
|
|
}
|
|
|
|
sort.Sort(sortedTransactions)
|
|
|
|
|
|
|
|
// Output a CSV of all transactions
|
|
|
|
for _, transaction := range sortedTransactions {
|
2019-12-01 21:24:59 +00:00
|
|
|
memoBytes, _ := transaction.transaction.Memo.Decode()
|
2019-09-14 01:13:29 +00:00
|
|
|
memo := strings.ReplaceAll(string(memoBytes), "\"", "\"\"")
|
2019-12-01 21:24:59 +00:00
|
|
|
memo = strings.ReplaceAll(memo, string([]byte{0x00}), "")
|
2019-09-14 01:13:29 +00:00
|
|
|
fmt.Printf("%s,%s,%f,%v,\"%s\"\n", transaction.time, transaction.transaction.TransactionID, transaction.transaction.Amount, transaction.transaction.Change, memo)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|