Compare commits

..

No commits in common. "master" and "listaddresses" have entirely different histories.

5 changed files with 8 additions and 98 deletions

21
api.go
View File

@ -2,7 +2,6 @@ package zcashrpc
import (
"encoding/json"
"strconv"
)
// Method restricts method definitions to constants
@ -10,7 +9,6 @@ type Method string
// Constant block of Method assignments
const (
GetBlock Method = "getblock"
GetTransaction Method = "gettransaction"
ZGetTotalBalance = "z_gettotalbalance"
@ -33,24 +31,14 @@ func setupZcashRequest() zcashRequest {
}
// NewGetTransaction constructs a properly formatted gettransaction request
func NewGetTransaction(id string) []byte {
func NewGetTransaction(is string) []byte {
request := setupZcashRequest()
request.Method = GetTransaction
request.Params = append(request.Params, id)
request.Params = append(request.Params, is)
data, _ := json.Marshal(request)
return data
}
// NewGetBlock constructs a properly formatted getblock request
func NewGetBlock(is int) []byte {
request := setupZcashRequest()
request.Method = GetBlock
request.Params = append(request.Params, strconv.Itoa(is))
data, _ := json.Marshal(request)
return data
}
// NewZValidateAddress constructs a properly formatted z_validateaddress request
func NewZValidateAddress(address string) []byte {
request := setupZcashRequest()
@ -114,11 +102,6 @@ type Transaction struct {
Time int `json:"time"`
}
// Block
type Block struct {
Transactions []string `json:"tx"`
}
// ZcashTransaction defines a transaction received to a zaddress
type ZcashTransaction struct {
TransactionID string `json:"txid"`

View File

@ -1,67 +0,0 @@
package main
import (
"encoding/json"
"fmt"
"git.openprivacy.ca/openprivacy/libricochet-go/log"
"git.openprivacy.ca/openprivacy/zcashrpc"
"io/ioutil"
"time"
)
type zcashConfig struct {
Username string `json:"username"`
Password string `json:"password"`
Onion string `json:"onion"`
ZAddress string `json:"zaddress"`
}
type transaction struct {
time time.Time
transaction zcashrpc.ZcashTransaction
}
type timeSlice []transaction
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.LevelInfo)
configFile, _ := ioutil.ReadFile("local.json")
config := zcashConfig{}
_ = json.Unmarshal([]byte(configFile), &config)
zc := zcashrpc.NewLocalClient(config.Username, config.Password)
txcount := make(map[int]int)
for i:=760161-((86400*60)/150);i<760161;i++ {
block, err := zc.GetBlock(i)
if err != nil {
log.Errorf("Error fetching zcash transactions: %v", err)
}
_,exists := txcount[len(block.Transactions)]
if !exists {
txcount[len(block.Transactions)] = 0
}
txcount[len(block.Transactions)]++
if i % 1000 == 0 {
log.Infof("Processing Block %v", i)
}
}
for txs:=0;txs<5000;txs++ {
if txcount[txs] > 0 {
fmt.Printf("%v,%v\n", txs, txcount[txs])
}
}
}

2
go.mod
View File

@ -4,6 +4,8 @@ go 1.12
require (
git.openprivacy.ca/openprivacy/libricochet-go v1.0.6
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/golang/protobuf v1.3.2 // indirect
github.com/kr/pretty v0.1.0 // indirect
github.com/stretchr/testify v1.4.0 // indirect
golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586 // indirect

4
go.sum
View File

@ -6,8 +6,12 @@ github.com/cretz/bine v0.1.0 h1:1/fvhLE+fk0bPzjdO5Ci+0ComYxEMuB1JhM4X5skT3g=
github.com/cretz/bine v0.1.0/go.mod h1:6PF6fWAvYtwjRGkAuDEJeWNOv3a2hUouSP/yRYXmvHw=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=

View File

@ -18,7 +18,6 @@ type ZcashClient interface {
GetTransaction(string) (Transaction, error)
ListAddresses() ([]string, error)
ListReceivedTransactionsByAddress(string) ([]ZcashTransaction, error)
GetBlock(int) (Block, error)
SendOne(string, string, string, float64) ([]byte, error)
ValidateAddress(address string) (ZValidateAddressResponse, error)
}
@ -72,17 +71,6 @@ func (zc *zcashClient) GetTotalBalance(minConfirmations int) (float64, error) {
return strconv.ParseFloat(totalBalance.Private, 64)
}
// GetTransaction returns a specific transaction given an id
func (zc *zcashClient) GetBlock(id int) (Block, error) {
body, err := zc.sendRequest(NewGetBlock(id))
block := Block{}
if err == nil {
result := &ZcashResult{Result: &block}
err = json.Unmarshal(body, &result)
}
return block, err
}
// GetTransaction returns a specific transaction given an id
func (zc *zcashClient) GetTransaction(id string) (Transaction, error) {
body, err := zc.sendRequest(NewGetTransaction(id))