-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.go
125 lines (105 loc) · 4.23 KB
/
demo.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package main
import (
"log"
"math/big"
taraxa_client "github.com/Taraxa-project/taraxa-go-client/taraxa_client"
"github.com/ethereum/go-ethereum/common"
)
func main() {
taraxaClient, err := taraxa_client.NewDefaultTaraxaClient(taraxa_client.Devnet)
if err != nil {
log.Fatal(err)
}
totalEligibleVotesCount, err := taraxaClient.DposContractClient.GetTotalEligibleVotesCount()
if err != nil {
log.Print(err)
} else {
log.Printf("GetTotalEligibleVotesCount: %d\n\n", totalEligibleVotesCount)
}
validators, err := taraxaClient.DposContractClient.GetValidators()
if err != nil {
log.Print(err)
} else {
log.Printf("GetValidators count: %d\n\n", len(validators))
}
if len(validators) != 0 {
validator, err := taraxaClient.DposContractClient.GetValidator(validators[0].Account)
if err != nil {
log.Print(err)
} else {
log.Printf("GetValidator for %s: %s\n\n", validators[0].Account, validator.Description)
}
isValidatorEligible, err := taraxaClient.DposContractClient.IsValidatorEligible(validators[0].Account)
if err != nil {
log.Print(err)
} else {
log.Printf("IsValidatorEligible for %s: %t\n\n", validators[0].Account, isValidatorEligible)
}
validatorEligibleVotesCount, err := taraxaClient.DposContractClient.GetValidatorEligibleVotesCount(validators[0].Account)
if err != nil {
log.Print(err)
} else {
log.Printf("GetValidatorEligibleVotesCount for %s: %d\n\n", validators[0].Account, validatorEligibleVotesCount)
}
ownerValidators, err := taraxaClient.DposContractClient.GetOwnerValidators(validators[0].Info.Owner)
if err != nil {
log.Print(err)
} else {
log.Printf("GetOwnerValidators count for %s: %d\n\n", validators[0].Info.Owner, len(ownerValidators))
}
defaultDevnetDelegator := common.HexToAddress("0x7e4aa664f71de4e9d0b4a6473d796372639bdcde")
devnet_delegations, err := taraxaClient.DposContractClient.GetDelegations(defaultDevnetDelegator)
if err != nil {
log.Print(err)
} else {
log.Printf("GetDelegations count for %s: %d\n\n", defaultDevnetDelegator, len(devnet_delegations))
}
defaultTestnetDelegator := common.HexToAddress("0x76870407332398322576505f3c5423d0a71af296")
testnet_delegations, err := taraxaClient.DposContractClient.GetDelegations(defaultTestnetDelegator)
if err != nil {
log.Print(err)
} else {
log.Printf("GetDelegations count for %s: %d\n\n", defaultTestnetDelegator, len(testnet_delegations))
}
devnet_undelegations, err := taraxaClient.DposContractClient.GetUndelegations(defaultDevnetDelegator)
if err != nil {
log.Print(err)
} else {
log.Printf("GetUndelegations count for %s: %d\n\n", defaultDevnetDelegator, len(devnet_undelegations))
}
testnet_undelegations, err := taraxaClient.DposContractClient.GetUndelegations(defaultTestnetDelegator)
if err != nil {
log.Print(err)
} else {
log.Printf("GetUndelegations count for %s: %d\n\n", defaultTestnetDelegator, len(testnet_undelegations))
}
// TODO: add here valid private key
privateKey := "0000000000000000000000000000000000000000000000000000000000000000"
transactor, err := taraxaClient.DposContractClient.NewTransactor(privateKey)
if err != nil {
log.Fatal(err)
}
thousandTara, ok := big.NewInt(0).SetString("100000000000000000000", 10)
if !ok {
log.Fatal("Unable to create big.Int for delegeation")
}
delegate_tx, err := taraxaClient.DposContractClient.Delegate(transactor, thousandTara, validators[0].Account)
if err != nil {
log.Print(err)
} else {
log.Printf("Delegate %d to %s, tx hash: %s, tx nonce: %d\n\n", delegate_tx.Value(), validators[0].Account, delegate_tx.Hash(), delegate_tx.Nonce())
}
undelegate_tx, err := taraxaClient.DposContractClient.Undelegate(transactor, thousandTara, validators[0].Account)
if err != nil {
log.Print(err)
} else {
log.Printf("Undelegate %d to %s, tx hash: %s, tx nonce: %d\n\n", thousandTara, validators[0].Account, undelegate_tx.Hash(), undelegate_tx.Nonce())
}
confirmUndelegateTx, err := taraxaClient.DposContractClient.ConfirmUndelegate(transactor, validators[0].Account)
if err != nil {
log.Print(err)
} else {
log.Printf("ConfirmUndelegate to %s, tx hash: %s, tx nonce: %d\n\n", validators[0].Account, confirmUndelegateTx.Hash(), confirmUndelegateTx.Nonce())
}
}
}