-
Notifications
You must be signed in to change notification settings - Fork 105
/
node.go
1177 lines (1104 loc) · 55.2 KB
/
node.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package rocketpool
import (
"encoding/hex"
"fmt"
"math/big"
"strconv"
"strings"
"github.com/ethereum/go-ethereum/common"
"github.com/goccy/go-json"
"github.com/rocket-pool/rocketpool-go/types"
"github.com/rocket-pool/smartnode/shared/types/api"
utils "github.com/rocket-pool/smartnode/shared/utils/api"
)
// Get node status
func (c *Client) NodeStatus() (api.NodeStatusResponse, error) {
responseBytes, err := c.callAPI("node status")
if err != nil {
return api.NodeStatusResponse{}, fmt.Errorf("Could not get node status: %w", err)
}
var response api.NodeStatusResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return api.NodeStatusResponse{}, fmt.Errorf("Could not decode node status response: %w", err)
}
if response.Error != "" {
return api.NodeStatusResponse{}, fmt.Errorf("Could not get node status: %s", response.Error)
}
utils.ZeroIfNil(&response.RplStake)
utils.ZeroIfNil(&response.EffectiveRplStake)
utils.ZeroIfNil(&response.MinimumRplStake)
utils.ZeroIfNil(&response.MaximumRplStake)
utils.ZeroIfNil(&response.AccountBalances.ETH)
utils.ZeroIfNil(&response.AccountBalances.RPL)
utils.ZeroIfNil(&response.AccountBalances.RETH)
utils.ZeroIfNil(&response.AccountBalances.FixedSupplyRPL)
utils.ZeroIfNil(&response.PrimaryWithdrawalBalances.ETH)
utils.ZeroIfNil(&response.PrimaryWithdrawalBalances.RPL)
utils.ZeroIfNil(&response.PrimaryWithdrawalBalances.RETH)
utils.ZeroIfNil(&response.PrimaryWithdrawalBalances.FixedSupplyRPL)
utils.ZeroIfNil(&response.NodeRPLLocked)
utils.ZeroIfNil(&response.RPLWithdrawalBalances.ETH)
utils.ZeroIfNil(&response.RPLWithdrawalBalances.RPL)
utils.ZeroIfNil(&response.RPLWithdrawalBalances.RETH)
utils.ZeroIfNil(&response.RPLWithdrawalBalances.FixedSupplyRPL)
utils.ZeroIfNil(&response.PendingEffectiveRplStake)
utils.ZeroIfNil(&response.PendingMinimumRplStake)
utils.ZeroIfNil(&response.PendingMaximumRplStake)
utils.ZeroIfNil(&response.EthMatched)
utils.ZeroIfNil(&response.EthMatchedLimit)
utils.ZeroIfNil(&response.PendingMatchAmount)
utils.ZeroIfNil(&response.CreditBalance)
utils.ZeroIfNil(&response.FeeDistributorBalance)
return response, nil
}
// Check whether the node can be registered
func (c *Client) CanRegisterNode(timezoneLocation string) (api.CanRegisterNodeResponse, error) {
responseBytes, err := c.callAPI("node can-register", timezoneLocation)
if err != nil {
return api.CanRegisterNodeResponse{}, fmt.Errorf("Could not get can register node status: %w", err)
}
var response api.CanRegisterNodeResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return api.CanRegisterNodeResponse{}, fmt.Errorf("Could not decode can register node response: %w", err)
}
if response.Error != "" {
return api.CanRegisterNodeResponse{}, fmt.Errorf("Could not get can register node status: %s", response.Error)
}
return response, nil
}
// Register the node
func (c *Client) RegisterNode(timezoneLocation string) (api.RegisterNodeResponse, error) {
responseBytes, err := c.callAPI("node register", timezoneLocation)
if err != nil {
return api.RegisterNodeResponse{}, fmt.Errorf("Could not register node: %w", err)
}
var response api.RegisterNodeResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return api.RegisterNodeResponse{}, fmt.Errorf("Could not decode register node response: %w", err)
}
if response.Error != "" {
return api.RegisterNodeResponse{}, fmt.Errorf("Could not register node: %s", response.Error)
}
return response, nil
}
// Checks if the node's primary withdrawal address can be set
func (c *Client) CanSetNodePrimaryWithdrawalAddress(withdrawalAddress common.Address, confirm bool) (api.CanSetNodePrimaryWithdrawalAddressResponse, error) {
responseBytes, err := c.callAPI("node can-set-primary-withdrawal-address", withdrawalAddress.Hex(), strconv.FormatBool(confirm))
if err != nil {
return api.CanSetNodePrimaryWithdrawalAddressResponse{}, fmt.Errorf("Could not get can set node primary withdrawal address: %w", err)
}
var response api.CanSetNodePrimaryWithdrawalAddressResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return api.CanSetNodePrimaryWithdrawalAddressResponse{}, fmt.Errorf("Could not decode can set node primary withdrawal address response: %w", err)
}
if response.Error != "" {
return api.CanSetNodePrimaryWithdrawalAddressResponse{}, fmt.Errorf("Could not get can set node primary withdrawal address: %s", response.Error)
}
return response, nil
}
// Set the node's primary withdrawal address
func (c *Client) SetNodePrimaryWithdrawalAddress(withdrawalAddress common.Address, confirm bool) (api.SetNodePrimaryWithdrawalAddressResponse, error) {
responseBytes, err := c.callAPI("node set-primary-withdrawal-address", withdrawalAddress.Hex(), strconv.FormatBool(confirm))
if err != nil {
return api.SetNodePrimaryWithdrawalAddressResponse{}, fmt.Errorf("Could not set node primary withdrawal address: %w", err)
}
var response api.SetNodePrimaryWithdrawalAddressResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return api.SetNodePrimaryWithdrawalAddressResponse{}, fmt.Errorf("Could not decode set node primary withdrawal address response: %w", err)
}
if response.Error != "" {
return api.SetNodePrimaryWithdrawalAddressResponse{}, fmt.Errorf("Could not set node primary withdrawal address: %s", response.Error)
}
return response, nil
}
// Checks if the node's primary withdrawal address can be confirmed
func (c *Client) CanConfirmNodePrimaryWithdrawalAddress() (api.CanSetNodePrimaryWithdrawalAddressResponse, error) {
responseBytes, err := c.callAPI("node can-confirm-primary-withdrawal-address")
if err != nil {
return api.CanSetNodePrimaryWithdrawalAddressResponse{}, fmt.Errorf("Could not get can confirm node primary withdrawal address: %w", err)
}
var response api.CanSetNodePrimaryWithdrawalAddressResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return api.CanSetNodePrimaryWithdrawalAddressResponse{}, fmt.Errorf("Could not decode can confirm node primary withdrawal address response: %w", err)
}
if response.Error != "" {
return api.CanSetNodePrimaryWithdrawalAddressResponse{}, fmt.Errorf("Could not get can confirm node primary withdrawal address: %s", response.Error)
}
return response, nil
}
// Confirm the node's primary withdrawal address
func (c *Client) ConfirmNodePrimaryWithdrawalAddress() (api.SetNodePrimaryWithdrawalAddressResponse, error) {
responseBytes, err := c.callAPI("node confirm-primary-withdrawal-address")
if err != nil {
return api.SetNodePrimaryWithdrawalAddressResponse{}, fmt.Errorf("Could not confirm node primary withdrawal address: %w", err)
}
var response api.SetNodePrimaryWithdrawalAddressResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return api.SetNodePrimaryWithdrawalAddressResponse{}, fmt.Errorf("Could not decode confirm node primary withdrawal address response: %w", err)
}
if response.Error != "" {
return api.SetNodePrimaryWithdrawalAddressResponse{}, fmt.Errorf("Could not confirm node primary withdrawal address: %s", response.Error)
}
return response, nil
}
// Checks if the node's RPL withdrawal address can be set
func (c *Client) CanSetNodeRPLWithdrawalAddress(withdrawalAddress common.Address, confirm bool) (api.CanSetNodeRPLWithdrawalAddressResponse, error) {
responseBytes, err := c.callAPI("node can-set-rpl-withdrawal-address", withdrawalAddress.Hex(), strconv.FormatBool(confirm))
if err != nil {
return api.CanSetNodeRPLWithdrawalAddressResponse{}, fmt.Errorf("Could not get can set node RPL withdrawal address: %w", err)
}
var response api.CanSetNodeRPLWithdrawalAddressResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return api.CanSetNodeRPLWithdrawalAddressResponse{}, fmt.Errorf("Could not decode can set node RPL withdrawal address response: %w", err)
}
if response.Error != "" {
return api.CanSetNodeRPLWithdrawalAddressResponse{}, fmt.Errorf("Could not get can set node RPL withdrawal address: %s", response.Error)
}
return response, nil
}
// Set the node's RPL withdrawal address
func (c *Client) SetNodeRPLWithdrawalAddress(withdrawalAddress common.Address, confirm bool) (api.SetNodeRPLWithdrawalAddressResponse, error) {
responseBytes, err := c.callAPI("node set-rpl-withdrawal-address", withdrawalAddress.Hex(), strconv.FormatBool(confirm))
if err != nil {
return api.SetNodeRPLWithdrawalAddressResponse{}, fmt.Errorf("Could not set node RPL withdrawal address: %w", err)
}
var response api.SetNodeRPLWithdrawalAddressResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return api.SetNodeRPLWithdrawalAddressResponse{}, fmt.Errorf("Could not decode set node RPL withdrawal address response: %w", err)
}
if response.Error != "" {
return api.SetNodeRPLWithdrawalAddressResponse{}, fmt.Errorf("Could not set node RPL withdrawal address: %s", response.Error)
}
return response, nil
}
// Checks if the node's RPL withdrawal address can be confirmed
func (c *Client) CanConfirmNodeRPLWithdrawalAddress() (api.CanSetNodeRPLWithdrawalAddressResponse, error) {
responseBytes, err := c.callAPI("node can-confirm-rpl-withdrawal-address")
if err != nil {
return api.CanSetNodeRPLWithdrawalAddressResponse{}, fmt.Errorf("Could not get can confirm node RPL withdrawal address: %w", err)
}
var response api.CanSetNodeRPLWithdrawalAddressResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return api.CanSetNodeRPLWithdrawalAddressResponse{}, fmt.Errorf("Could not decode can confirm node RPL withdrawal address response: %w", err)
}
if response.Error != "" {
return api.CanSetNodeRPLWithdrawalAddressResponse{}, fmt.Errorf("Could not get can confirm node RPL withdrawal address: %s", response.Error)
}
return response, nil
}
// Confirm the node's RPL withdrawal address
func (c *Client) ConfirmNodeRPLWithdrawalAddress() (api.SetNodeRPLWithdrawalAddressResponse, error) {
responseBytes, err := c.callAPI("node confirm-rpl-withdrawal-address")
if err != nil {
return api.SetNodeRPLWithdrawalAddressResponse{}, fmt.Errorf("Could not confirm node RPL withdrawal address: %w", err)
}
var response api.SetNodeRPLWithdrawalAddressResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return api.SetNodeRPLWithdrawalAddressResponse{}, fmt.Errorf("Could not decode confirm node RPL withdrawal address response: %w", err)
}
if response.Error != "" {
return api.SetNodeRPLWithdrawalAddressResponse{}, fmt.Errorf("Could not confirm node RPL withdrawal address: %s", response.Error)
}
return response, nil
}
// Checks if the node's timezone location can be set
func (c *Client) CanSetNodeTimezone(timezoneLocation string) (api.CanSetNodeTimezoneResponse, error) {
responseBytes, err := c.callAPI("node can-set-timezone", timezoneLocation)
if err != nil {
return api.CanSetNodeTimezoneResponse{}, fmt.Errorf("Could not get can set node timezone: %w", err)
}
var response api.CanSetNodeTimezoneResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return api.CanSetNodeTimezoneResponse{}, fmt.Errorf("Could not decode can set node timezone response: %w", err)
}
if response.Error != "" {
return api.CanSetNodeTimezoneResponse{}, fmt.Errorf("Could not get can set node timezone: %s", response.Error)
}
return response, nil
}
// Set the node's timezone location
func (c *Client) SetNodeTimezone(timezoneLocation string) (api.SetNodeTimezoneResponse, error) {
responseBytes, err := c.callAPI("node set-timezone", timezoneLocation)
if err != nil {
return api.SetNodeTimezoneResponse{}, fmt.Errorf("Could not set node timezone: %w", err)
}
var response api.SetNodeTimezoneResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return api.SetNodeTimezoneResponse{}, fmt.Errorf("Could not decode set node timezone response: %w", err)
}
if response.Error != "" {
return api.SetNodeTimezoneResponse{}, fmt.Errorf("Could not set node timezone: %s", response.Error)
}
return response, nil
}
// Check whether the node can swap RPL tokens
func (c *Client) CanNodeSwapRpl(amountWei *big.Int) (api.CanNodeSwapRplResponse, error) {
responseBytes, err := c.callAPI(fmt.Sprintf("node can-swap-rpl %s", amountWei.String()))
if err != nil {
return api.CanNodeSwapRplResponse{}, fmt.Errorf("Could not get can node swap RPL status: %w", err)
}
var response api.CanNodeSwapRplResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return api.CanNodeSwapRplResponse{}, fmt.Errorf("Could not decode can node swap RPL response: %w", err)
}
if response.Error != "" {
return api.CanNodeSwapRplResponse{}, fmt.Errorf("Could not get can node swap RPL status: %s", response.Error)
}
return response, nil
}
// Get the gas estimate for approving legacy RPL interaction
func (c *Client) NodeSwapRplApprovalGas(amountWei *big.Int) (api.NodeSwapRplApproveGasResponse, error) {
responseBytes, err := c.callAPI(fmt.Sprintf("node get-swap-rpl-approval-gas %s", amountWei.String()))
if err != nil {
return api.NodeSwapRplApproveGasResponse{}, fmt.Errorf("Could not get old RPL approval gas: %w", err)
}
var response api.NodeSwapRplApproveGasResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return api.NodeSwapRplApproveGasResponse{}, fmt.Errorf("Could not decode node swap RPL approve gas response: %w", err)
}
if response.Error != "" {
return api.NodeSwapRplApproveGasResponse{}, fmt.Errorf("Could not get old RPL approval gas: %s", response.Error)
}
return response, nil
}
// Approves old RPL for a token swap
func (c *Client) NodeSwapRplApprove(amountWei *big.Int) (api.NodeSwapRplApproveResponse, error) {
responseBytes, err := c.callAPI(fmt.Sprintf("node swap-rpl-approve-rpl %s", amountWei.String()))
if err != nil {
return api.NodeSwapRplApproveResponse{}, fmt.Errorf("Could not approve old RPL: %w", err)
}
var response api.NodeSwapRplApproveResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return api.NodeSwapRplApproveResponse{}, fmt.Errorf("Could not decode node swap RPL approve response: %w", err)
}
if response.Error != "" {
return api.NodeSwapRplApproveResponse{}, fmt.Errorf("Could not approve old RPL tokens for swapping: %s", response.Error)
}
return response, nil
}
// Swap node's old RPL tokens for new RPL tokens, waiting for the approval to be included in a block first
func (c *Client) NodeWaitAndSwapRpl(amountWei *big.Int, approvalTxHash common.Hash) (api.NodeSwapRplSwapResponse, error) {
responseBytes, err := c.callAPI(fmt.Sprintf("node wait-and-swap-rpl %s %s", amountWei.String(), approvalTxHash.String()))
if err != nil {
return api.NodeSwapRplSwapResponse{}, fmt.Errorf("Could not swap node's RPL tokens: %w", err)
}
var response api.NodeSwapRplSwapResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return api.NodeSwapRplSwapResponse{}, fmt.Errorf("Could not decode node swap RPL tokens response: %w", err)
}
if response.Error != "" {
return api.NodeSwapRplSwapResponse{}, fmt.Errorf("Could not swap node's RPL tokens: %s", response.Error)
}
return response, nil
}
// Swap node's old RPL tokens for new RPL tokens
func (c *Client) NodeSwapRpl(amountWei *big.Int) (api.NodeSwapRplSwapResponse, error) {
responseBytes, err := c.callAPI(fmt.Sprintf("node swap-rpl %s", amountWei.String()))
if err != nil {
return api.NodeSwapRplSwapResponse{}, fmt.Errorf("Could not swap node's RPL tokens: %w", err)
}
var response api.NodeSwapRplSwapResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return api.NodeSwapRplSwapResponse{}, fmt.Errorf("Could not decode node swap RPL tokens response: %w", err)
}
if response.Error != "" {
return api.NodeSwapRplSwapResponse{}, fmt.Errorf("Could not swap node's RPL tokens: %s", response.Error)
}
return response, nil
}
// Get a node's legacy RPL allowance for swapping on the new RPL contract
func (c *Client) GetNodeSwapRplAllowance() (api.NodeSwapRplAllowanceResponse, error) {
responseBytes, err := c.callAPI(fmt.Sprintf("node swap-rpl-allowance"))
if err != nil {
return api.NodeSwapRplAllowanceResponse{}, fmt.Errorf("Could not get node swap RPL allowance: %w", err)
}
var response api.NodeSwapRplAllowanceResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return api.NodeSwapRplAllowanceResponse{}, fmt.Errorf("Could not decode node swap RPL allowance response: %w", err)
}
if response.Error != "" {
return api.NodeSwapRplAllowanceResponse{}, fmt.Errorf("Could not get node swap RPL allowance: %s", response.Error)
}
return response, nil
}
// Check whether the node can stake RPL
func (c *Client) CanNodeStakeRpl(amountWei *big.Int) (api.CanNodeStakeRplResponse, error) {
responseBytes, err := c.callAPI(fmt.Sprintf("node can-stake-rpl %s", amountWei.String()))
if err != nil {
return api.CanNodeStakeRplResponse{}, fmt.Errorf("Could not get can node stake RPL status: %w", err)
}
var response api.CanNodeStakeRplResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return api.CanNodeStakeRplResponse{}, fmt.Errorf("Could not decode can node stake RPL response: %w", err)
}
if response.Error != "" {
return api.CanNodeStakeRplResponse{}, fmt.Errorf("Could not get can node stake RPL status: %s", response.Error)
}
return response, nil
}
// Get the gas estimate for approving new RPL interaction
func (c *Client) NodeStakeRplApprovalGas(amountWei *big.Int) (api.NodeStakeRplApproveGasResponse, error) {
responseBytes, err := c.callAPI(fmt.Sprintf("node get-stake-rpl-approval-gas %s", amountWei.String()))
if err != nil {
return api.NodeStakeRplApproveGasResponse{}, fmt.Errorf("Could not get new RPL approval gas: %w", err)
}
var response api.NodeStakeRplApproveGasResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return api.NodeStakeRplApproveGasResponse{}, fmt.Errorf("Could not decode node stake RPL approve gas response: %w", err)
}
if response.Error != "" {
return api.NodeStakeRplApproveGasResponse{}, fmt.Errorf("Could not get new RPL approval gas: %s", response.Error)
}
return response, nil
}
// Approve RPL for staking against the node
func (c *Client) NodeStakeRplApprove(amountWei *big.Int) (api.NodeStakeRplApproveResponse, error) {
responseBytes, err := c.callAPI(fmt.Sprintf("node stake-rpl-approve-rpl %s", amountWei.String()))
if err != nil {
return api.NodeStakeRplApproveResponse{}, fmt.Errorf("Could not approve RPL for staking: %w", err)
}
var response api.NodeStakeRplApproveResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return api.NodeStakeRplApproveResponse{}, fmt.Errorf("Could not decode stake node RPL approve response: %w", err)
}
if response.Error != "" {
return api.NodeStakeRplApproveResponse{}, fmt.Errorf("Could not approve RPL for staking: %s", response.Error)
}
return response, nil
}
// Stake RPL against the node waiting for approvalTxHash to be included in a block first
func (c *Client) NodeWaitAndStakeRpl(amountWei *big.Int, approvalTxHash common.Hash) (api.NodeStakeRplStakeResponse, error) {
responseBytes, err := c.callAPI(fmt.Sprintf("node wait-and-stake-rpl %s %s", amountWei.String(), approvalTxHash.String()))
if err != nil {
return api.NodeStakeRplStakeResponse{}, fmt.Errorf("Could not stake node RPL: %w", err)
}
var response api.NodeStakeRplStakeResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return api.NodeStakeRplStakeResponse{}, fmt.Errorf("Could not decode stake node RPL response: %w", err)
}
if response.Error != "" {
return api.NodeStakeRplStakeResponse{}, fmt.Errorf("Could not stake node RPL: %s", response.Error)
}
return response, nil
}
// Stake RPL against the node
func (c *Client) NodeStakeRpl(amountWei *big.Int) (api.NodeStakeRplStakeResponse, error) {
responseBytes, err := c.callAPI(fmt.Sprintf("node stake-rpl %s", amountWei.String()))
if err != nil {
return api.NodeStakeRplStakeResponse{}, fmt.Errorf("Could not stake node RPL: %w", err)
}
var response api.NodeStakeRplStakeResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return api.NodeStakeRplStakeResponse{}, fmt.Errorf("Could not decode stake node RPL response: %w", err)
}
if response.Error != "" {
return api.NodeStakeRplStakeResponse{}, fmt.Errorf("Could not stake node RPL: %s", response.Error)
}
return response, nil
}
// Get a node's RPL allowance for the staking contract
func (c *Client) GetNodeStakeRplAllowance() (api.NodeStakeRplAllowanceResponse, error) {
responseBytes, err := c.callAPI(fmt.Sprintf("node stake-rpl-allowance"))
if err != nil {
return api.NodeStakeRplAllowanceResponse{}, fmt.Errorf("Could not get node stake RPL allowance: %w", err)
}
var response api.NodeStakeRplAllowanceResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return api.NodeStakeRplAllowanceResponse{}, fmt.Errorf("Could not decode node stake RPL allowance response: %w", err)
}
if response.Error != "" {
return api.NodeStakeRplAllowanceResponse{}, fmt.Errorf("Could not get node stake RPL allowance: %s", response.Error)
}
return response, nil
}
// Checks if the node operator can set RPL locking allowed
func (c *Client) CanSetRPLLockingAllowed(allowed bool) (api.CanSetRplLockingAllowedResponse, error) {
responseBytes, err := c.callAPI(fmt.Sprintf("node can-set-rpl-locking-allowed %t", allowed))
if err != nil {
return api.CanSetRplLockingAllowedResponse{}, fmt.Errorf("Could not get can set RPL locking allowed: %w", err)
}
var response api.CanSetRplLockingAllowedResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return api.CanSetRplLockingAllowedResponse{}, fmt.Errorf("Could not decode can set RPL locking allowed: %w", err)
}
if response.Error != "" {
return api.CanSetRplLockingAllowedResponse{}, fmt.Errorf("Could not set RPL locking allowed: %s", response.Error)
}
return response, nil
}
// Sets the allow state for the node to lock RPL
func (c *Client) SetRPLLockingAllowed(allowed bool) (api.SetRplLockingAllowedResponse, error) {
responseBytes, err := c.callAPI(fmt.Sprintf("node set-rpl-locking-allowed %t", allowed))
if err != nil {
return api.SetRplLockingAllowedResponse{}, fmt.Errorf("Could not set RPL locking allowed: %w", err)
}
var response api.SetRplLockingAllowedResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return api.SetRplLockingAllowedResponse{}, fmt.Errorf("Could not decode set RPL locking allowed response: %w", err)
}
if response.Error != "" {
return api.SetRplLockingAllowedResponse{}, fmt.Errorf("Could not set RPL locking allowed: %s", response.Error)
}
return response, nil
}
// Checks if the node operator can set RPL stake for allowed
func (c *Client) CanSetStakeRPLForAllowed(caller common.Address, allowed bool) (api.CanSetStakeRplForAllowedResponse, error) {
responseBytes, err := c.callAPI(fmt.Sprintf("node can-set-stake-rpl-for-allowed %s %t", caller.Hex(), allowed))
if err != nil {
return api.CanSetStakeRplForAllowedResponse{}, fmt.Errorf("Could not get can set stake RPL for allowed: %w", err)
}
var response api.CanSetStakeRplForAllowedResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return api.CanSetStakeRplForAllowedResponse{}, fmt.Errorf("Could not decode can set stake RPL for allowed: %w", err)
}
if response.Error != "" {
return api.CanSetStakeRplForAllowedResponse{}, fmt.Errorf("Could not set stake RPL for allowed: %s", response.Error)
}
return response, nil
}
// Sets the allow state of another address staking on behalf of the node
func (c *Client) SetStakeRPLForAllowed(caller common.Address, allowed bool) (api.SetStakeRplForAllowedResponse, error) {
responseBytes, err := c.callAPI(fmt.Sprintf("node set-stake-rpl-for-allowed %s %t", caller.Hex(), allowed))
if err != nil {
return api.SetStakeRplForAllowedResponse{}, fmt.Errorf("Could not set stake RPL for allowed: %w", err)
}
var response api.SetStakeRplForAllowedResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return api.SetStakeRplForAllowedResponse{}, fmt.Errorf("Could not decode set stake RPL for allowed response: %w", err)
}
if response.Error != "" {
return api.SetStakeRplForAllowedResponse{}, fmt.Errorf("Could not set stake RPL for allowed: %s", response.Error)
}
return response, nil
}
// Check whether the node can withdraw RPL
func (c *Client) CanNodeWithdrawRpl(amountWei *big.Int) (api.CanNodeWithdrawRplResponse, error) {
responseBytes, err := c.callAPI(fmt.Sprintf("node can-withdraw-rpl %s", amountWei.String()))
if err != nil {
return api.CanNodeWithdrawRplResponse{}, fmt.Errorf("Could not get can node withdraw RPL status: %w", err)
}
var response api.CanNodeWithdrawRplResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return api.CanNodeWithdrawRplResponse{}, fmt.Errorf("Could not decode can node withdraw RPL response: %w", err)
}
if response.Error != "" {
return api.CanNodeWithdrawRplResponse{}, fmt.Errorf("Could not get can node withdraw RPL status: %s", response.Error)
}
return response, nil
}
// Withdraw RPL staked against the node
func (c *Client) NodeWithdrawRpl(amountWei *big.Int) (api.NodeWithdrawRplResponse, error) {
responseBytes, err := c.callAPI(fmt.Sprintf("node withdraw-rpl %s", amountWei.String()))
if err != nil {
return api.NodeWithdrawRplResponse{}, fmt.Errorf("Could not withdraw node RPL: %w", err)
}
var response api.NodeWithdrawRplResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return api.NodeWithdrawRplResponse{}, fmt.Errorf("Could not decode withdraw node RPL response: %w", err)
}
if response.Error != "" {
return api.NodeWithdrawRplResponse{}, fmt.Errorf("Could not withdraw node RPL: %s", response.Error)
}
return response, nil
}
// Check whether we can withdraw ETH staked on behalf of the node
func (c *Client) CanNodeWithdrawEth(amountWei *big.Int) (api.CanNodeWithdrawEthResponse, error) {
responseBytes, err := c.callAPI(fmt.Sprintf("node can-withdraw-eth %s", amountWei.String()))
if err != nil {
return api.CanNodeWithdrawEthResponse{}, fmt.Errorf("Could not get can node withdraw ETH status: %w", err)
}
var response api.CanNodeWithdrawEthResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return api.CanNodeWithdrawEthResponse{}, fmt.Errorf("Could not decode can node withdraw ETH response: %w", err)
}
if response.Error != "" {
return api.CanNodeWithdrawEthResponse{}, fmt.Errorf("Could not get can node withdraw ETH status: %s", response.Error)
}
return response, nil
}
// Withdraw ETH staked on behalf of the node
func (c *Client) NodeWithdrawEth(amountWei *big.Int) (api.NodeWithdrawEthResponse, error) {
responseBytes, err := c.callAPI(fmt.Sprintf("node withdraw-eth %s", amountWei.String()))
if err != nil {
return api.NodeWithdrawEthResponse{}, fmt.Errorf("Could not withdraw node ETH: %w", err)
}
var response api.NodeWithdrawEthResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return api.NodeWithdrawEthResponse{}, fmt.Errorf("Could not decode withdraw node ETH response: %w", err)
}
if response.Error != "" {
return api.NodeWithdrawEthResponse{}, fmt.Errorf("Could not withdraw node ETH: %s", response.Error)
}
return response, nil
}
// Check whether the node can make a deposit
func (c *Client) CanNodeDeposit(amountWei *big.Int, minFee float64, salt *big.Int) (api.CanNodeDepositResponse, error) {
responseBytes, err := c.callAPI(fmt.Sprintf("node can-deposit %s %f %s", amountWei.String(), minFee, salt.String()))
if err != nil {
return api.CanNodeDepositResponse{}, fmt.Errorf("Could not get can node deposit status: %w", err)
}
var response api.CanNodeDepositResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return api.CanNodeDepositResponse{}, fmt.Errorf("Could not decode can node deposit response: %w", err)
}
if response.Error != "" {
return api.CanNodeDepositResponse{}, fmt.Errorf("Could not get can node deposit status: %s", response.Error)
}
return response, nil
}
// Make a node deposit
func (c *Client) NodeDeposit(amountWei *big.Int, minFee float64, salt *big.Int, useCreditBalance bool, submit bool) (api.NodeDepositResponse, error) {
responseBytes, err := c.callAPI(fmt.Sprintf("node deposit %s %f %s %t %t", amountWei.String(), minFee, salt.String(), useCreditBalance, submit))
if err != nil {
return api.NodeDepositResponse{}, fmt.Errorf("Could not make node deposit: %w", err)
}
var response api.NodeDepositResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return api.NodeDepositResponse{}, fmt.Errorf("Could not decode node deposit response: %w", err)
}
if response.Error != "" {
return api.NodeDepositResponse{}, fmt.Errorf("Could not make node deposit: %s", response.Error)
}
return response, nil
}
// Check whether the node can send tokens
func (c *Client) CanNodeSend(amountWei *big.Int, token string, toAddress common.Address) (api.CanNodeSendResponse, error) {
responseBytes, err := c.callAPI(fmt.Sprintf("node can-send %s %s %s", amountWei.String(), token, toAddress.Hex()))
if err != nil {
return api.CanNodeSendResponse{}, fmt.Errorf("Could not get can node send status: %w", err)
}
var response api.CanNodeSendResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return api.CanNodeSendResponse{}, fmt.Errorf("Could not decode can node send response: %w", err)
}
if response.Error != "" {
return api.CanNodeSendResponse{}, fmt.Errorf("Could not get can node send status: %s", response.Error)
}
return response, nil
}
// Send tokens from the node to an address
func (c *Client) NodeSend(amountWei *big.Int, token string, toAddress common.Address) (api.NodeSendResponse, error) {
responseBytes, err := c.callAPI(fmt.Sprintf("node send %s %s %s", amountWei.String(), token, toAddress.Hex()))
if err != nil {
return api.NodeSendResponse{}, fmt.Errorf("Could not send tokens from node: %w", err)
}
var response api.NodeSendResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return api.NodeSendResponse{}, fmt.Errorf("Could not decode node send response: %w", err)
}
if response.Error != "" {
return api.NodeSendResponse{}, fmt.Errorf("Could not send tokens from node: %s", response.Error)
}
return response, nil
}
// Check whether the node can burn tokens
func (c *Client) CanNodeBurn(amountWei *big.Int, token string) (api.CanNodeBurnResponse, error) {
responseBytes, err := c.callAPI(fmt.Sprintf("node can-burn %s %s", amountWei.String(), token))
if err != nil {
return api.CanNodeBurnResponse{}, fmt.Errorf("Could not get can node burn status: %w", err)
}
var response api.CanNodeBurnResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return api.CanNodeBurnResponse{}, fmt.Errorf("Could not decode can node burn response: %w", err)
}
if response.Error != "" {
return api.CanNodeBurnResponse{}, fmt.Errorf("Could not get can node burn status: %s", response.Error)
}
return response, nil
}
// Burn tokens owned by the node for ETH
func (c *Client) NodeBurn(amountWei *big.Int, token string) (api.NodeBurnResponse, error) {
responseBytes, err := c.callAPI(fmt.Sprintf("node burn %s %s", amountWei.String(), token))
if err != nil {
return api.NodeBurnResponse{}, fmt.Errorf("Could not burn tokens owned by node: %w", err)
}
var response api.NodeBurnResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return api.NodeBurnResponse{}, fmt.Errorf("Could not decode node burn response: %w", err)
}
if response.Error != "" {
return api.NodeBurnResponse{}, fmt.Errorf("Could not burn tokens owned by node: %s", response.Error)
}
return response, nil
}
// Get node sync progress
func (c *Client) NodeSync() (api.NodeSyncProgressResponse, error) {
responseBytes, err := c.callAPI("node sync")
if err != nil {
return api.NodeSyncProgressResponse{}, fmt.Errorf("Could not get node sync: %w", err)
}
var response api.NodeSyncProgressResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return api.NodeSyncProgressResponse{}, fmt.Errorf("Could not decode node sync response: %w", err)
}
if response.Error != "" {
return api.NodeSyncProgressResponse{}, fmt.Errorf("Could not get node sync: %s", response.Error)
}
return response, nil
}
// Check whether the node has RPL rewards available to claim
func (c *Client) CanNodeClaimRpl() (api.CanNodeClaimRplResponse, error) {
responseBytes, err := c.callAPI("node can-claim-rpl-rewards")
if err != nil {
return api.CanNodeClaimRplResponse{}, fmt.Errorf("Could not get can node claim rpl rewards status: %w", err)
}
var response api.CanNodeClaimRplResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return api.CanNodeClaimRplResponse{}, fmt.Errorf("Could not decode can node claim rpl rewards response: %w", err)
}
if response.Error != "" {
return api.CanNodeClaimRplResponse{}, fmt.Errorf("Could not get can node claim rpl rewards status: %s", response.Error)
}
return response, nil
}
// Claim available RPL rewards
func (c *Client) NodeClaimRpl() (api.NodeClaimRplResponse, error) {
responseBytes, err := c.callAPI("node claim-rpl-rewards")
if err != nil {
return api.NodeClaimRplResponse{}, fmt.Errorf("Could not claim rpl rewards: %w", err)
}
var response api.NodeClaimRplResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return api.NodeClaimRplResponse{}, fmt.Errorf("Could not decode node claim rpl rewards response: %w", err)
}
if response.Error != "" {
return api.NodeClaimRplResponse{}, fmt.Errorf("Could not claim rpl rewards: %s", response.Error)
}
return response, nil
}
// Get node RPL rewards status
func (c *Client) NodeRewards() (api.NodeRewardsResponse, error) {
responseBytes, err := c.callAPI("node rewards")
if err != nil {
return api.NodeRewardsResponse{}, fmt.Errorf("Could not get node rewards: %w", err)
}
var response api.NodeRewardsResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return api.NodeRewardsResponse{}, fmt.Errorf("Could not decode node rewards response: %w", err)
}
if response.Error != "" {
return api.NodeRewardsResponse{}, fmt.Errorf("Could not get node rewards: %s", response.Error)
}
return response, nil
}
// Get the deposit contract info for Rocket Pool and the Beacon Client
func (c *Client) DepositContractInfo() (api.DepositContractInfoResponse, error) {
responseBytes, err := c.callAPI("node deposit-contract-info")
if err != nil {
return api.DepositContractInfoResponse{}, fmt.Errorf("Could not get deposit contract info: %w", err)
}
var response api.DepositContractInfoResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return api.DepositContractInfoResponse{}, fmt.Errorf("Could not decode deposit contract info response: %w", err)
}
if response.Error != "" {
return api.DepositContractInfoResponse{}, fmt.Errorf("Could not get deposit contract info: %s", response.Error)
}
return response, nil
}
// Estimate the gas required to set a voting snapshot delegate
func (c *Client) EstimateSetSnapshotDelegateGas(address common.Address) (api.EstimateSetSnapshotDelegateGasResponse, error) {
responseBytes, err := c.callAPI(fmt.Sprintf("node estimate-set-snapshot-delegate-gas %s", address.Hex()))
if err != nil {
return api.EstimateSetSnapshotDelegateGasResponse{}, fmt.Errorf("Could not get estimate-set-snapshot-delegate-gas response: %w", err)
}
var response api.EstimateSetSnapshotDelegateGasResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return api.EstimateSetSnapshotDelegateGasResponse{}, fmt.Errorf("Could not decode estimate-set-snapshot-delegate-gas response: %w", err)
}
if response.Error != "" {
return api.EstimateSetSnapshotDelegateGasResponse{}, fmt.Errorf("Could not get estimate-set-snapshot-delegate-gas response: %s", response.Error)
}
return response, nil
}
// Set a voting snapshot delegate for the node
func (c *Client) SetSnapshotDelegate(address common.Address) (api.SetSnapshotDelegateResponse, error) {
responseBytes, err := c.callAPI(fmt.Sprintf("node set-snapshot-delegate %s", address.Hex()))
if err != nil {
return api.SetSnapshotDelegateResponse{}, fmt.Errorf("Could not get set-snapshot-delegate response: %w", err)
}
var response api.SetSnapshotDelegateResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return api.SetSnapshotDelegateResponse{}, fmt.Errorf("Could not decode set-snapshot-delegate response: %w", err)
}
if response.Error != "" {
return api.SetSnapshotDelegateResponse{}, fmt.Errorf("Could not get set-snapshot-delegate response: %s", response.Error)
}
return response, nil
}
// Estimate the gas required to clear the node's voting snapshot delegate
func (c *Client) EstimateClearSnapshotDelegateGas() (api.EstimateClearSnapshotDelegateGasResponse, error) {
responseBytes, err := c.callAPI("node estimate-clear-snapshot-delegate-gas")
if err != nil {
return api.EstimateClearSnapshotDelegateGasResponse{}, fmt.Errorf("Could not get estimate-clear-snapshot-delegate-gas response: %w", err)
}
var response api.EstimateClearSnapshotDelegateGasResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return api.EstimateClearSnapshotDelegateGasResponse{}, fmt.Errorf("Could not decode estimate-clear-snapshot-delegate-gas response: %w", err)
}
if response.Error != "" {
return api.EstimateClearSnapshotDelegateGasResponse{}, fmt.Errorf("Could not get estimate-clear-snapshot-delegate-gas response: %s", response.Error)
}
return response, nil
}
// Clear the node's voting snapshot delegate
func (c *Client) ClearSnapshotDelegate() (api.ClearSnapshotDelegateResponse, error) {
responseBytes, err := c.callAPI("node clear-snapshot-delegate")
if err != nil {
return api.ClearSnapshotDelegateResponse{}, fmt.Errorf("Could not get clear-snapshot-delegate response: %w", err)
}
var response api.ClearSnapshotDelegateResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return api.ClearSnapshotDelegateResponse{}, fmt.Errorf("Could not decode clear-snapshot-delegate response: %w", err)
}
if response.Error != "" {
return api.ClearSnapshotDelegateResponse{}, fmt.Errorf("Could not get clear-snapshot-delegate response: %s", response.Error)
}
return response, nil
}
// Get the initialization status of the fee distributor contract
func (c *Client) IsFeeDistributorInitialized() (api.NodeIsFeeDistributorInitializedResponse, error) {
responseBytes, err := c.callAPI("node is-fee-distributor-initialized")
if err != nil {
return api.NodeIsFeeDistributorInitializedResponse{}, fmt.Errorf("Could not get fee distributor initialization status: %w", err)
}
var response api.NodeIsFeeDistributorInitializedResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return api.NodeIsFeeDistributorInitializedResponse{}, fmt.Errorf("Could not decode fee distributor initialization status response: %w", err)
}
if response.Error != "" {
return api.NodeIsFeeDistributorInitializedResponse{}, fmt.Errorf("Could not get fee distributor initialization status: %s", response.Error)
}
return response, nil
}
// Get the gas cost for initializing the fee distributor contract
func (c *Client) GetInitializeFeeDistributorGas() (api.NodeInitializeFeeDistributorGasResponse, error) {
responseBytes, err := c.callAPI("node get-initialize-fee-distributor-gas")
if err != nil {
return api.NodeInitializeFeeDistributorGasResponse{}, fmt.Errorf("Could not get initialize fee distributor gas: %w", err)
}
var response api.NodeInitializeFeeDistributorGasResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return api.NodeInitializeFeeDistributorGasResponse{}, fmt.Errorf("Could not decode initialize fee distributor gas response: %w", err)
}
if response.Error != "" {
return api.NodeInitializeFeeDistributorGasResponse{}, fmt.Errorf("Could not get initialize fee distributor gas: %s", response.Error)
}
return response, nil
}
// Initialize the fee distributor contract
func (c *Client) InitializeFeeDistributor() (api.NodeInitializeFeeDistributorResponse, error) {
responseBytes, err := c.callAPI("node initialize-fee-distributor")
if err != nil {
return api.NodeInitializeFeeDistributorResponse{}, fmt.Errorf("Could not initialize fee distributor: %w", err)
}
var response api.NodeInitializeFeeDistributorResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return api.NodeInitializeFeeDistributorResponse{}, fmt.Errorf("Could not decode initialize fee distributor response: %w", err)
}
if response.Error != "" {
return api.NodeInitializeFeeDistributorResponse{}, fmt.Errorf("Could not initialize fee distributor: %s", response.Error)
}
return response, nil
}
// Check if distributing ETH from the node's fee distributor is possible
func (c *Client) CanDistribute() (api.NodeCanDistributeResponse, error) {
responseBytes, err := c.callAPI("node can-distribute")
if err != nil {
return api.NodeCanDistributeResponse{}, fmt.Errorf("Could not get can distribute: %w", err)
}
var response api.NodeCanDistributeResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return api.NodeCanDistributeResponse{}, fmt.Errorf("Could not decode can distribute response: %w", err)
}
if response.Error != "" {
return api.NodeCanDistributeResponse{}, fmt.Errorf("Could not get can distribute: %s", response.Error)
}
return response, nil
}
// Distribute ETH from the node's fee distributor
func (c *Client) Distribute() (api.NodeDistributeResponse, error) {
responseBytes, err := c.callAPI("node distribute")
if err != nil {
return api.NodeDistributeResponse{}, fmt.Errorf("Could not distribute ETH: %w", err)
}
var response api.NodeDistributeResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return api.NodeDistributeResponse{}, fmt.Errorf("Could not decode distribute response: %w", err)
}
if response.Error != "" {
return api.NodeDistributeResponse{}, fmt.Errorf("Could not distribute ETH: %s", response.Error)
}
return response, nil
}
// Get info about your eligible rewards periods, including balances and Merkle proofs
func (c *Client) GetRewardsInfo() (api.NodeGetRewardsInfoResponse, error) {
responseBytes, err := c.callAPI("node get-rewards-info")
if err != nil {
return api.NodeGetRewardsInfoResponse{}, fmt.Errorf("Could not get rewards info: %w", err)
}
var response api.NodeGetRewardsInfoResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return api.NodeGetRewardsInfoResponse{}, fmt.Errorf("Could not decode get rewards info response: %w", err)
}
if response.Error != "" {
return api.NodeGetRewardsInfoResponse{}, fmt.Errorf("Could not get rewards info: %s", response.Error)
}
return response, nil
}
// Check if the rewards for the given intervals can be claimed
func (c *Client) CanNodeClaimRewards(indices []uint64) (api.CanNodeClaimRewardsResponse, error) {
indexStrings := []string{}
for _, index := range indices {
indexStrings = append(indexStrings, fmt.Sprint(index))
}
responseBytes, err := c.callAPI("node can-claim-rewards", strings.Join(indexStrings, ","))
if err != nil {
return api.CanNodeClaimRewardsResponse{}, fmt.Errorf("Could not check if can claim rewards: %w", err)
}
var response api.CanNodeClaimRewardsResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return api.CanNodeClaimRewardsResponse{}, fmt.Errorf("Could not decode can claim rewards response: %w", err)
}
if response.Error != "" {
return api.CanNodeClaimRewardsResponse{}, fmt.Errorf("Could not check if can claim rewards: %s", response.Error)
}
return response, nil
}
// Claim rewards for the given reward intervals
func (c *Client) NodeClaimRewards(indices []uint64) (api.NodeClaimRewardsResponse, error) {
indexStrings := []string{}
for _, index := range indices {
indexStrings = append(indexStrings, fmt.Sprint(index))
}
responseBytes, err := c.callAPI("node claim-rewards", strings.Join(indexStrings, ","))
if err != nil {
return api.NodeClaimRewardsResponse{}, fmt.Errorf("Could not claim rewards: %w", err)
}
var response api.NodeClaimRewardsResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return api.NodeClaimRewardsResponse{}, fmt.Errorf("Could not decode claim rewards response: %w", err)
}
if response.Error != "" {
return api.NodeClaimRewardsResponse{}, fmt.Errorf("Could not claim rewards: %s", response.Error)
}
return response, nil
}
// Check if the rewards for the given intervals can be claimed, and RPL restaked automatically
func (c *Client) CanNodeClaimAndStakeRewards(indices []uint64, stakeAmountWei *big.Int) (api.CanNodeClaimAndStakeRewardsResponse, error) {
indexStrings := []string{}
for _, index := range indices {
indexStrings = append(indexStrings, fmt.Sprint(index))
}
responseBytes, err := c.callAPI("node can-claim-and-stake-rewards", strings.Join(indexStrings, ","), stakeAmountWei.String())
if err != nil {
return api.CanNodeClaimAndStakeRewardsResponse{}, fmt.Errorf("Could not check if can claim and stake rewards: %w", err)
}
var response api.CanNodeClaimAndStakeRewardsResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return api.CanNodeClaimAndStakeRewardsResponse{}, fmt.Errorf("Could not decode can claim and stake rewards response: %w", err)
}
if response.Error != "" {
return api.CanNodeClaimAndStakeRewardsResponse{}, fmt.Errorf("Could not check if can claim and stake rewards: %s", response.Error)
}
return response, nil
}
// Claim rewards for the given reward intervals and restake RPL automatically
func (c *Client) NodeClaimAndStakeRewards(indices []uint64, stakeAmountWei *big.Int) (api.NodeClaimAndStakeRewardsResponse, error) {
indexStrings := []string{}
for _, index := range indices {
indexStrings = append(indexStrings, fmt.Sprint(index))
}
responseBytes, err := c.callAPI("node claim-and-stake-rewards", strings.Join(indexStrings, ","), stakeAmountWei.String())
if err != nil {
return api.NodeClaimAndStakeRewardsResponse{}, fmt.Errorf("Could not claim and stake rewards: %w", err)
}
var response api.NodeClaimAndStakeRewardsResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return api.NodeClaimAndStakeRewardsResponse{}, fmt.Errorf("Could not decode claim and stake rewards response: %w", err)
}
if response.Error != "" {
return api.NodeClaimAndStakeRewardsResponse{}, fmt.Errorf("Could not claim and stake rewards: %s", response.Error)
}
return response, nil
}
// Check whether or not the node is opted into the Smoothing Pool
func (c *Client) NodeGetSmoothingPoolRegistrationStatus() (api.GetSmoothingPoolRegistrationStatusResponse, error) {
responseBytes, err := c.callAPI("node get-smoothing-pool-registration-status")
if err != nil {
return api.GetSmoothingPoolRegistrationStatusResponse{}, fmt.Errorf("Could not get smoothing pool registration status: %w", err)
}
var response api.GetSmoothingPoolRegistrationStatusResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return api.GetSmoothingPoolRegistrationStatusResponse{}, fmt.Errorf("Could not decode smoothing pool registration status response: %w", err)
}
if response.Error != "" {
return api.GetSmoothingPoolRegistrationStatusResponse{}, fmt.Errorf("Could not get smoothing pool registration status: %s", response.Error)
}
return response, nil