-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathblockchain.go
1022 lines (861 loc) · 29 KB
/
blockchain.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
// Copyright © 2018-2020 Satinderjit Singh.
//
// See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at
// the top-level directory of this distribution for the individual copyright
// holder information and the developer policies on copyright and licensing.
//
// Unless otherwise agreed in a custom licensing agreement, no part of the
// kmdgo software, including this file may be copied, modified, propagated.
// or distributed except according to the terms contained in the LICENSE file
//
// Removal or modification of this copyright notice is prohibited.
package kmdgo
import (
//"fmt"
"encoding/json"
"errors"
"strconv"
)
// CoinSupply type
type CoinSupply struct {
Result struct {
Result string `json:"result"`
Coin string `json:"coin"`
Height int `json:"height"`
Supply float64 `json:"supply"`
Zfunds float64 `json:"zfunds"`
Sprout float64 `json:"sprout"`
Total float64 `json:"total"`
} `json:"result"`
Error Error `json:"error"`
ID string `json:"id"`
}
// CoinSupply method returns the coin supply information for the indicated block height.
// If no height is given, the method defaults to the blockchain's current height.
func (appName AppType) CoinSupply(params APIParams) (CoinSupply, error) {
if params[0] == nil {
params[0] = 100
}
paramsJSON, _ := json.Marshal(params)
//fmt.Println(string(paramsJSON))
query := APIQuery{
Method: `coinsupply`,
Params: string(paramsJSON),
}
//fmt.Println(query)
var coinsupply CoinSupply
coinsupplyJSON := appName.APICall(&query)
if coinsupplyJSON == "EMPTY RPC INFO" {
return coinsupply, errors.New("EMPTY RPC INFO")
}
var result APIResult
json.Unmarshal([]byte(coinsupplyJSON), &result)
if result.Result == nil {
answerError, err := json.Marshal(result.Error)
if err != nil {
}
json.Unmarshal([]byte(coinsupplyJSON), &coinsupply)
return coinsupply, errors.New(string(answerError))
}
json.Unmarshal([]byte(coinsupplyJSON), &coinsupply)
return coinsupply, nil
}
// GetBestBlockhash type
type GetBestBlockhash struct {
Result interface{} `json:"result"`
Error Error `json:"error"`
ID string `json:"id"`
}
// GetBestBlockhash method returns the hash of the best (tip) block in the longest block chain.
func (appName AppType) GetBestBlockhash() (GetBestBlockhash, error) {
query := APIQuery{
Method: `getbestblockhash`,
Params: `[]`,
}
var getbestblockhash GetBestBlockhash
getbestblockhashJSON := appName.APICall(&query)
if getbestblockhashJSON == "EMPTY RPC INFO" {
return getbestblockhash, errors.New("EMPTY RPC INFO")
}
var result APIResult
json.Unmarshal([]byte(getbestblockhashJSON), &result)
if result.Result == nil {
answerError, err := json.Marshal(result.Error)
if err != nil {
}
json.Unmarshal([]byte(getbestblockhashJSON), &getbestblockhash)
return getbestblockhash, errors.New(string(answerError))
}
json.Unmarshal([]byte(getbestblockhashJSON), &getbestblockhash)
return getbestblockhash, nil
}
// GetBlock type
type GetBlock struct {
Result struct {
Hash string `json:"hash"`
Validationtype string `json:"validationtype"`
Postarget string `json:"postarget"`
Poshashbh string `json:"poshashbh"`
Poshashtx string `json:"poshashtx"`
Possourcetxid string `json:"possourcetxid"`
Possourcevoutnum int `json:"possourcevoutnum"`
Posrewarddest string `json:"posrewarddest"`
Posrewardpk string `json:"posrewardpk"`
Postxddest string `json:"postxddest"`
Confirmations int `json:"confirmations"`
Rawconfirmations int `json:"rawconfirmations"`
Size int `json:"size"`
Height int `json:"height"`
Version int `json:"version"`
Merkleroot string `json:"merkleroot"`
Segid int `json:"segid"`
Finalsaplingroot string `json:"finalsaplingroot"`
Tx []struct {
Txid string `json:"txid"`
Overwintered bool `json:"overwintered"`
Version int `json:"version"`
Versiongroupid string `json:"versiongroupid"`
Locktime int `json:"locktime"`
Expiryheight int `json:"expiryheight"`
Vin []struct {
Txid string `json:"txid"`
Vout int `json:"vout"`
ScriptSig struct {
Asm string `json:"asm"`
Hex string `json:"hex"`
} `json:"scriptSig"`
Value float64 `json:"value"`
ValueSat int `json:"valueSat"`
Address string `json:"address"`
Coinbase string `json:"coinbase"`
Sequence int64 `json:"sequence"`
} `json:"vin"`
Vout []struct {
Value float64 `json:"value"`
ValueZat int `json:"valueZat"`
ValueSat int `json:"valueSat"`
N int `json:"n"`
ScriptPubKey struct {
Type string `json:"type"`
Identityprimary struct {
Version int `json:"version"`
Flags int `json:"flags"`
Primaryaddresses []string `json:"primaryaddresses"`
Minimumsignatures int `json:"minimumsignatures"`
Identityaddress string `json:"identityaddress"`
Parent string `json:"parent"`
Name string `json:"name"`
Contentmap interface{} `json:"contentmap"`
Revocationauthority string `json:"revocationauthority"`
Recoveryauthority string `json:"recoveryauthority"`
Privateaddress string `json:"privateaddress"`
Timelock float64 `json:"timelock"`
} `json:"identityprimary"`
ReqSigs int `json:"reqSigs"`
Addresses []string `json:"addresses"`
Asm string `json:"asm"`
Hex string `json:"hex"`
Hec string `json:"hec"`
} `json:"scriptPubKey"`
SpentTxID string `json:"spentTxId"`
SpentIndex int `json:"spentIndex"`
SpentHeight int `json:"spentHeight"`
} `json:"vout"`
Vjoinsplit []interface{} `json:"vjoinsplit"`
ValueBalance float64 `json:"valueBalance"`
ValueBalanceZat int `json:"valueBalanceZat"`
VShieldedSpend []interface{} `json:"vShieldedSpend"`
VShieldedOutput []interface{} `json:"vShieldedOutput"`
} `json:"tx"`
Time int `json:"time"`
Nonce string `json:"nonce"`
Solution string `json:"solution"`
Bits string `json:"bits"`
Difficulty float64 `json:"difficulty"`
Chainwork string `json:"chainwork"`
Chainstake string `json:"chainstake"`
Anchor string `json:"anchor"`
Blocktype string `json:"blocktype"`
ValuePools []struct {
ID string `json:"id"`
Monitored bool `json:"monitored"`
ChainValue float64 `json:"chainValue"`
ChainValueZat int64 `json:"chainValueZat"`
ValueDelta float64 `json:"valueDelta"`
ValueDeltaZat int `json:"valueDeltaZat"`
} `json:"valuePools"`
Previousblockhash string `json:"previousblockhash"`
Nextblockhash string `json:"nextblockhash"`
} `json:"result"`
Error Error `json:"error"`
ID string `json:"id"`
}
// GetBlock method returns the block's relevant state information.
// The verbose input is optional. The default value is true, and it will return
// a json object with information about the indicated block.
// If verbose is false, the command returns a string that is
// serialized hex-encoded data for the indicated block.
func (appName AppType) GetBlock(params APIParams) (GetBlock, error) {
if params[1] == nil {
params[1] = 1
}
paramsJSON, _ := json.Marshal(params)
//fmt.Println(string(paramsJSON))
query := APIQuery{
Method: `getblock`,
Params: string(paramsJSON),
}
//fmt.Println(query)
var getblock GetBlock
getblockJSON := appName.APICall(&query)
if getblockJSON == "EMPTY RPC INFO" {
return getblock, errors.New("EMPTY RPC INFO")
}
// fmt.Println(getblockJSON)
var result APIResult
json.Unmarshal([]byte(getblockJSON), &result)
if result.Result == nil {
answerError, err := json.Marshal(result.Error)
if err != nil {
}
json.Unmarshal([]byte(getblockJSON), &getblock)
return getblock, errors.New(string(answerError))
}
json.Unmarshal([]byte(getblockJSON), &getblock)
return getblock, nil
}
// GetBlockchainInfo type
type GetBlockchainInfo struct {
Result struct {
Chain string `json:"chain"`
Blocks int `json:"blocks"`
Headers int `json:"headers"`
Bestblockhash string `json:"bestblockhash"`
Difficulty float64 `json:"difficulty"`
Verificationprogress float64 `json:"verificationprogress"`
Chainwork string `json:"chainwork"`
Pruned bool `json:"pruned"`
Commitments int `json:"commitments"`
ValuePools []struct {
ID string `json:"id"`
Monitored bool `json:"monitored"`
ChainValue float64 `json:"chainValue"`
ChainValueZat int64 `json:"chainValueZat"`
} `json:"valuePools"`
Softforks []struct {
ID string `json:"id"`
Version int `json:"version"`
Enforce struct {
Status bool `json:"status"`
Found int `json:"found"`
Required int `json:"required"`
Window int `json:"window"`
} `json:"enforce"`
Reject struct {
Status bool `json:"status"`
Found int `json:"found"`
Required int `json:"required"`
Window int `json:"window"`
} `json:"reject"`
} `json:"softforks"`
Upgrades struct {
FiveBa81B19 struct {
Name string `json:"name"`
Activationheight int `json:"activationheight"`
Status string `json:"status"`
Info string `json:"info"`
} `json:"5ba81b19"`
Seven6B809Bb struct {
Name string `json:"name"`
Activationheight int `json:"activationheight"`
Status string `json:"status"`
Info string `json:"info"`
} `json:"76b809bb"`
} `json:"upgrades"`
Consensus struct {
Chaintip string `json:"chaintip"`
Nextblock string `json:"nextblock"`
} `json:"consensus"`
} `json:"result"`
Error Error `json:"error"`
ID string `json:"id"`
}
// GetBlockchainInfo method returns a json object containing state information about blockchain processing.
func (appName AppType) GetBlockchainInfo() (GetBlockchainInfo, error) {
query := APIQuery{
Method: `getblockchaininfo`,
Params: `[]`,
}
//fmt.Println(query)
var getblockchaininfo GetBlockchainInfo
getblockchaininfoJSON := appName.APICall(&query)
if getblockchaininfoJSON == "EMPTY RPC INFO" {
return getblockchaininfo, errors.New("EMPTY RPC INFO")
}
var result APIResult
json.Unmarshal([]byte(getblockchaininfoJSON), &result)
if result.Result == nil {
answerError, err := json.Marshal(result.Error)
if err != nil {
}
json.Unmarshal([]byte(getblockchaininfoJSON), &getblockchaininfo)
return getblockchaininfo, errors.New(string(answerError))
}
json.Unmarshal([]byte(getblockchaininfoJSON), &getblockchaininfo)
return getblockchaininfo, nil
}
// GetBlockCount type
type GetBlockCount struct {
Result int64 `json:"result"`
Error Error `json:"error"`
ID string `json:"id"`
}
// GetBlockCount method returns the number of blocks in the best valid block chain.
func (appName AppType) GetBlockCount() (GetBlockCount, error) {
query := APIQuery{
Method: `getblockcount`,
Params: `[]`,
}
var getblockcount GetBlockCount
getbestblockhashJSON := appName.APICall(&query)
if getbestblockhashJSON == "EMPTY RPC INFO" {
return getblockcount, errors.New("EMPTY RPC INFO")
}
var result APIResult
json.Unmarshal([]byte(getbestblockhashJSON), &result)
if result.Result == nil {
answerError, err := json.Marshal(result.Error)
if err != nil {
}
json.Unmarshal([]byte(getbestblockhashJSON), &getblockcount)
return getblockcount, errors.New(string(answerError))
}
json.Unmarshal([]byte(getbestblockhashJSON), &getblockcount)
return getblockcount, nil
}
// GetBlockHash type
type GetBlockHash struct {
Result string `json:"result"`
Error Error `json:"error"`
ID string `json:"id"`
}
// GetBlockHash method returns the hash of the indicated block index, according to the best blockchain at the time provided.
func (appName AppType) GetBlockHash(h int) (GetBlockHash, error) {
query := APIQuery{
Method: `getblockhash`,
Params: `[` + strconv.Itoa(h) + `]`,
}
//fmt.Println(query)
var getblockhash GetBlockHash
getblockhashJSON := appName.APICall(&query)
if getblockhashJSON == "EMPTY RPC INFO" {
return getblockhash, errors.New("EMPTY RPC INFO")
}
var result APIResult
json.Unmarshal([]byte(getblockhashJSON), &result)
if result.Result == nil {
answerError, err := json.Marshal(result.Error)
if err != nil {
}
json.Unmarshal([]byte(getblockhashJSON), &getblockhash)
return getblockhash, errors.New(string(answerError))
}
json.Unmarshal([]byte(getblockhashJSON), &getblockhash)
return getblockhash, nil
}
// GetBlockHeader type
type GetBlockHeader struct {
Result struct {
Hash string `json:"hash"`
Confirmations int `json:"confirmations"`
Rawconfirmations int `json:"rawconfirmations"`
Height int `json:"height"`
Version int `json:"version"`
Merkleroot string `json:"merkleroot"`
Finalsaplingroot string `json:"finalsaplingroot"`
Time int `json:"time"`
Nonce string `json:"nonce"`
Solution string `json:"solution"`
Bits string `json:"bits"`
Difficulty float64 `json:"difficulty"`
Chainwork string `json:"chainwork"`
Segid int `json:"segid"`
Previousblockhash string `json:"previousblockhash"`
} `json:"result"`
Error Error `json:"error"`
ID string `json:"id"`
}
// GetBlockHeader method returns information about the indicated block.
// The verbose input is optional. If verbose is false, the method returns a string that is serialized,
// hex-encoded data for the indicated blockheader. If verbose is true,
// the method returns a json object with information about the indicated blockheader.
func (appName AppType) GetBlockHeader(params APIParams) (GetBlockHeader, error) {
if params[1] == nil {
params[1] = true
}
paramsJSON, _ := json.Marshal(params)
//fmt.Println(string(paramsJSON))
query := APIQuery{
Method: `getblockheader`,
Params: string(paramsJSON),
}
//fmt.Println(query)
var getblockheader GetBlockHeader
getblockheaderJSON := appName.APICall(&query)
if getblockheaderJSON == "EMPTY RPC INFO" {
return getblockheader, errors.New("EMPTY RPC INFO")
}
var result APIResult
json.Unmarshal([]byte(getblockheaderJSON), &result)
if result.Result == nil {
answerError, err := json.Marshal(result.Error)
if err != nil {
}
json.Unmarshal([]byte(getblockheaderJSON), &getblockheader)
return getblockheader, errors.New(string(answerError))
}
json.Unmarshal([]byte(getblockheaderJSON), &getblockheader)
return getblockheader, nil
}
// GetChainTips type
type GetChainTips struct {
Result []struct {
Height int `json:"height"`
Hash string `json:"hash"`
Branchlen int `json:"branchlen"`
Status string `json:"status"`
} `json:"result"`
Error Error `json:"error"`
ID string `json:"id"`
}
// GetChainTips method returns information about all known tips in the block tree,
// including the main chain and any orphaned branches.
func (appName AppType) GetChainTips() (GetChainTips, error) {
query := APIQuery{
Method: `getchaintips`,
Params: `[]`,
}
//fmt.Println(query)
var getchaintips GetChainTips
getchaintipsJSON := appName.APICall(&query)
if getchaintipsJSON == "EMPTY RPC INFO" {
return getchaintips, errors.New("EMPTY RPC INFO")
}
var result APIResult
json.Unmarshal([]byte(getchaintipsJSON), &result)
if result.Result == nil {
answerError, err := json.Marshal(result.Error)
if err != nil {
}
json.Unmarshal([]byte(getchaintipsJSON), &getchaintips)
return getchaintips, errors.New(string(answerError))
}
json.Unmarshal([]byte(getchaintipsJSON), &getchaintips)
return getchaintips, nil
}
// GetDifficulty type
type GetDifficulty struct {
Result float64 `json:"result"`
Error Error `json:"error"`
ID string `json:"id"`
}
// GetDifficulty method returns the proof-of-work difficulty as a multiple of the minimum difficulty.
func (appName AppType) GetDifficulty() (GetDifficulty, error) {
query := APIQuery{
Method: `getdifficulty`,
Params: `[]`,
}
//fmt.Println(query)
var getdifficulty GetDifficulty
getdifficultyJSON := appName.APICall(&query)
if getdifficultyJSON == "EMPTY RPC INFO" {
return getdifficulty, errors.New("EMPTY RPC INFO")
}
var result APIResult
json.Unmarshal([]byte(getdifficultyJSON), &result)
if result.Result == nil {
answerError, err := json.Marshal(result.Error)
if err != nil {
}
json.Unmarshal([]byte(getdifficultyJSON), &getdifficulty)
return getdifficulty, errors.New(string(answerError))
}
json.Unmarshal([]byte(getdifficultyJSON), &getdifficulty)
return getdifficulty, nil
}
// GetMempoolInfo type
type GetMempoolInfo struct {
Result struct {
Size int `json:"size"`
Bytes int `json:"bytes"`
Usage int `json:"usage"`
} `json:"result"`
Error Error `json:"error"`
ID string `json:"id"`
}
// GetMempoolInfo method returns details on the active state of the transaction memory pool.
func (appName AppType) GetMempoolInfo() (GetMempoolInfo, error) {
query := APIQuery{
Method: `getmempoolinfo`,
Params: `[]`,
}
//fmt.Println(query)
var getmempoolinfo GetMempoolInfo
getmempoolinfoJSON := appName.APICall(&query)
if getmempoolinfoJSON == "EMPTY RPC INFO" {
return getmempoolinfo, errors.New("EMPTY RPC INFO")
}
var result APIResult
json.Unmarshal([]byte(getmempoolinfoJSON), &result)
if result.Result == nil {
answerError, err := json.Marshal(result.Error)
if err != nil {
}
json.Unmarshal([]byte(getmempoolinfoJSON), &getmempoolinfo)
return getmempoolinfo, errors.New(string(answerError))
}
json.Unmarshal([]byte(getmempoolinfoJSON), &getmempoolinfo)
return getmempoolinfo, nil
}
// GetRawMempoolTrue type
type GetRawMempoolTrue struct {
Result map[string]RawMempoolTrue `json:"result"`
Error Error `json:"error"`
ID string `json:"id"`
}
// RawMempoolTrue type
type RawMempoolTrue struct {
Size int `json:"size"`
Fee float64 `json:"fee"`
Time int `json:"time"`
Height int `json:"height"`
Startingpriority float64 `json:"startingpriority"`
Currentpriority float64 `json:"currentpriority"`
Depends []interface{} `json:"depends"`
}
// GetRawMempoolFalse type
type GetRawMempoolFalse struct {
Result []string `json:"result"`
Error Error `json:"error"`
ID string `json:"id"`
}
// GetRawMempoolTrue method returns all transaction ids in the memory pool as a json array of transaction ids.
// The verbose input is optional and is false by default.
// When it is true, the method instead returns a json object with various related data.
func (appName AppType) GetRawMempoolTrue(b bool) (GetRawMempoolTrue, error) {
query := APIQuery{
Method: `getrawmempool`,
Params: `[` + strconv.FormatBool(b) + `]`,
}
//fmt.Println(query)
var getrawmempool GetRawMempoolTrue
getrawmempoolJSON := appName.APICall(&query)
if getrawmempoolJSON == "EMPTY RPC INFO" {
return getrawmempool, errors.New("EMPTY RPC INFO")
}
//fmt.Println(getrawmempoolJSON)
var result APIResult
json.Unmarshal([]byte(getrawmempoolJSON), &result)
if result.Result == nil {
answerError, err := json.Marshal(result.Error)
if err != nil {
}
json.Unmarshal([]byte(getrawmempoolJSON), &getrawmempool)
return getrawmempool, errors.New(string(answerError))
}
json.Unmarshal([]byte(getrawmempoolJSON), &getrawmempool)
return getrawmempool, nil
}
// GetRawMempoolFalse method returns all transaction ids in the memory pool as a json array of transaction ids.
// The verbose input is optional and is false by default.
// When it is true, the method instead returns a json object with various related data.
func (appName AppType) GetRawMempoolFalse(b bool) (GetRawMempoolFalse, error) {
query := APIQuery{
Method: `getrawmempool`,
Params: `[` + strconv.FormatBool(b) + `]`,
}
//fmt.Println(query)
var getrawmempool GetRawMempoolFalse
getrawmempoolJSON := appName.APICall(&query)
if getrawmempoolJSON == "EMPTY RPC INFO" {
return getrawmempool, errors.New("EMPTY RPC INFO")
}
//fmt.Println(getrawmempoolJSON)
var result APIResult
json.Unmarshal([]byte(getrawmempoolJSON), &result)
if result.Result == nil {
answerError, err := json.Marshal(result.Error)
if err != nil {
}
json.Unmarshal([]byte(getrawmempoolJSON), &getrawmempool)
return getrawmempool, errors.New(string(answerError))
}
json.Unmarshal([]byte(getrawmempoolJSON), &getrawmempool)
return getrawmempool, nil
}
// GetTxOut type
type GetTxOut struct {
Result struct {
Bestblock string `json:"bestblock"`
Confirmations int `json:"confirmations"`
Rawconfirmations int `json:"rawconfirmations"`
Value float64 `json:"value"`
ScriptPubKey struct {
Asm string `json:"asm"`
Hex string `json:"hex"`
ReqSigs int `json:"reqSigs"`
Type string `json:"type"`
Addresses []string `json:"addresses"`
} `json:"scriptPubKey"`
Version int `json:"version"`
Coinbase bool `json:"coinbase"`
} `json:"result"`
Error Error `json:"error"`
ID string `json:"id"`
}
// GetTxOut method returns details about an unspent transaction output.
func (appName AppType) GetTxOut(params APIParams) (GetTxOut, error) {
if params[2] == nil {
params[2] = false
}
paramsJSON, _ := json.Marshal(params)
//fmt.Println(string(paramsJSON))
query := APIQuery{
Method: `gettxout`,
Params: string(paramsJSON),
}
//fmt.Println(query)
var gettxout GetTxOut
gettxoutJSON := appName.APICall(&query)
if gettxoutJSON == "EMPTY RPC INFO" {
return gettxout, errors.New("EMPTY RPC INFO")
}
var result APIResult
json.Unmarshal([]byte(gettxoutJSON), &result)
if result.Result == nil {
answerError, err := json.Marshal(result.Error)
if err != nil {
}
json.Unmarshal([]byte(gettxoutJSON), &gettxout)
return gettxout, errors.New(string(answerError))
}
json.Unmarshal([]byte(gettxoutJSON), &gettxout)
return gettxout, nil
}
// GetTxOutProof type
type GetTxOutProof struct {
Result string `json:"result"`
Error Error `json:"error"`
ID string `json:"id"`
}
// GetTxOutProof method returns a hex-encoded proof showing that the indicated transaction was included in a block.
func (appName AppType) GetTxOutProof(txids string) (GetTxOutProof, error) {
query := APIQuery{
Method: `gettxoutproof`,
Params: `[` + txids + `]`,
}
//fmt.Println(query)
var gettxoutproof GetTxOutProof
gettxoutproofJSON := appName.APICall(&query)
if gettxoutproofJSON == "EMPTY RPC INFO" {
return gettxoutproof, errors.New("EMPTY RPC INFO")
}
var result APIResult
json.Unmarshal([]byte(gettxoutproofJSON), &result)
if result.Result == nil {
answerError, err := json.Marshal(result.Error)
if err != nil {
}
json.Unmarshal([]byte(gettxoutproofJSON), &gettxoutproof)
return gettxoutproof, errors.New(string(answerError))
}
json.Unmarshal([]byte(gettxoutproofJSON), &gettxoutproof)
return gettxoutproof, nil
}
// GetTxOutSetInfo type
type GetTxOutSetInfo struct {
Result struct {
Height int `json:"height"`
Bestblock string `json:"bestblock"`
Transactions int `json:"transactions"`
Txouts int `json:"txouts"`
BytesSerialized int `json:"bytes_serialized"`
HashSerialized string `json:"hash_serialized"`
TotalAmount float64 `json:"total_amount"`
} `json:"result"`
Error Error `json:"error"`
ID string `json:"id"`
}
// GetTxOutSetInfo method returns statistics about the unspent transaction output set.
func (appName AppType) GetTxOutSetInfo() (GetTxOutSetInfo, error) {
query := APIQuery{
Method: `gettxoutsetinfo`,
Params: `[]`,
}
//fmt.Println(query)
var gettxoutsetinfo GetTxOutSetInfo
gettxoutsetinfoJSON := appName.APICall(&query)
if gettxoutsetinfoJSON == "EMPTY RPC INFO" {
return gettxoutsetinfo, errors.New("EMPTY RPC INFO")
}
var result APIResult
json.Unmarshal([]byte(gettxoutsetinfoJSON), &result)
if result.Result == nil {
answerError, err := json.Marshal(result.Error)
if err != nil {
}
json.Unmarshal([]byte(gettxoutsetinfoJSON), &gettxoutsetinfo)
return gettxoutsetinfo, errors.New(string(answerError))
}
json.Unmarshal([]byte(gettxoutsetinfoJSON), &gettxoutsetinfo)
return gettxoutsetinfo, nil
}
// MinerIDs type
type MinerIDs struct {
Result struct {
Mined []struct {
Notaryid int `json:"notaryid,omitempty"`
KMDaddress string `json:"KMDaddress,omitempty"`
Pubkey string `json:"pubkey"`
Blocks int `json:"blocks"`
} `json:"mined"`
Numnotaries int `json:"numnotaries"`
} `json:"result"`
Error Error `json:"error"`
ID string `json:"id"`
}
// MinerIDs method returns information about the notary nodes and external miners at a specific block height.
// The response will calculate results according to the 2000 blocks proceeding the indicated "height" block.
func (appName AppType) MinerIDs(ht string) (MinerIDs, error) {
query := APIQuery{
Method: `minerids`,
Params: `["` + ht + `"]`,
}
//fmt.Println(query)
var minerids MinerIDs
mineridsJSON := appName.APICall(&query)
if mineridsJSON == "EMPTY RPC INFO" {
return minerids, errors.New("EMPTY RPC INFO")
}
var result APIResult
json.Unmarshal([]byte(mineridsJSON), &result)
if result.Result == nil {
answerError, err := json.Marshal(result.Error)
if err != nil {
}
json.Unmarshal([]byte(mineridsJSON), &minerids)
return minerids, errors.New(string(answerError))
}
json.Unmarshal([]byte(mineridsJSON), &minerids)
return minerids, nil
}
// Notaries type
type Notaries struct {
Result struct {
Notaries []struct {
Pubkey string `json:"pubkey"`
BTCaddress string `json:"BTCaddress"`
KMDaddress string `json:"KMDaddress"`
} `json:"notaries"`
Numnotaries int `json:"numnotaries"`
Height int `json:"height"`
Timestamp int `json:"timestamp"`
} `json:"result"`
Error Error `json:"error"`
ID string `json:"id"`
}
// Notaries method returns the public key, BTC address, and KMD address for each Komodo notary node.
// Either or both of the height and timestamp parameters will suffice
func (appName AppType) Notaries(ht string) (Notaries, error) {
query := APIQuery{
Method: `notaries`,
Params: `["` + ht + `"]`,
}
//fmt.Println(query)
var notaries Notaries
notariesJSON := appName.APICall(&query)
if notariesJSON == "EMPTY RPC INFO" {
return notaries, errors.New("EMPTY RPC INFO")
}
var result APIResult
json.Unmarshal([]byte(notariesJSON), &result)
if result.Result == nil {
answerError, err := json.Marshal(result.Error)
if err != nil {
}
json.Unmarshal([]byte(notariesJSON), ¬aries)
return notaries, errors.New(string(answerError))
}
json.Unmarshal([]byte(notariesJSON), ¬aries)
return notaries, nil
}
// VerifyChain type
type VerifyChain struct {
Result bool `json:"result"`
Error Error `json:"error"`
ID string `json:"id"`
}
// VerifyChain method verifies the coin daemon's blockchain database.
func (appName AppType) VerifyChain(params APIParams) (VerifyChain, error) {
if params[0] == nil {
params[0] = 3
}
if params[1] == nil {
params[1] = 288
}
paramsJSON, _ := json.Marshal(params)
//fmt.Println(string(paramsJSON))
query := APIQuery{
Method: `verifychain`,
Params: string(paramsJSON),
}
//fmt.Println(query)
var verifychain VerifyChain
verifychainJSON := appName.APICall(&query)
if verifychainJSON == "EMPTY RPC INFO" {
return verifychain, errors.New("EMPTY RPC INFO")
}
var result APIResult
json.Unmarshal([]byte(verifychainJSON), &result)
if result.Result == nil {
answerError, err := json.Marshal(result.Error)
if err != nil {
}
json.Unmarshal([]byte(verifychainJSON), &verifychain)
return verifychain, errors.New(string(answerError))
}
json.Unmarshal([]byte(verifychainJSON), &verifychain)
return verifychain, nil
}
// VerifyTxOutProof type
type VerifyTxOutProof struct {
Result []string `json:"result"`
Error Error `json:"error"`
ID string `json:"id"`
}
// VerifyTxOutProof method verifies that a proof points to a transaction in a block.
// It returns the transaction to which the proof is committed,
// or it will throw an RPC error if the block is not in the current best chain
func (appName AppType) VerifyTxOutProof(pf string) (VerifyTxOutProof, error) {
query := APIQuery{
Method: `verifytxoutproof`,
Params: `["` + pf + `"]`,
}
//fmt.Println(query)