forked from abduramann/go-incognito-sdk-v2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhistory.go
64 lines (52 loc) · 1.54 KB
/
history.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"github.com/incognitochain/go-incognito-sdk-v2/common"
"github.com/incognitochain/go-incognito-sdk-v2/incclient"
"log"
)
// GetHistory retrieves the history of an account in a normal way.
// It is suitable for accounts that have a few transactions.
func GetHistory() {
// For main-net
client, err := incclient.NewMainNetClient()
if err != nil {
log.Fatal(err)
}
tokenIDStr := common.PRVIDStr // input the tokenID in which you want to retrieve the history of.
privateKey := "YOUR_PRIVATE_KEY" // input your private key here
// get the history in a normal way.
h, err := client.GetTxHistoryV1(privateKey, tokenIDStr)
if err != nil {
log.Fatal(err)
}
err = incclient.SaveTxHistory(h, "history.csv")
if err != nil {
log.Fatal(err)
}
}
// GetHistoryFaster helps retrieve the history faster by running parallel workers.
func GetHistoryFaster() {
// For main-net
client, err := incclient.NewMainNetClient()
if err != nil {
log.Fatal(err)
}
tokenIDStr := common.PRVIDStr // input the tokenID in which you want to retrieve the history of.
privateKey := "YOUR_PRIVATE_KEY" // input your private key here
numWorkers := 15
p := incclient.NewTxHistoryProcessor(client, numWorkers)
h, err := p.GetTokenHistory(privateKey, tokenIDStr)
if err != nil {
log.Fatal(err)
}
log.Printf("#TxIns: %v, #TxsOut: %v\n", len(h.TxInList), len(h.TxOutList))
err = incclient.SaveTxHistory(h, "history.csv")
if err != nil {
log.Fatal(err)
}
}
func main() {
// comment one of these functions.
//GetHistory()
GetHistoryFaster()
}