Add RPC Interface
To add RPC interfaces, it's necessary to add the corresponding association information of RPC name and implementation in the StartRPCServer method in the servers/httpjsonrpc/server.go file. At present, the existing RPC interfaces are as follows:
1
func StartRPCServer() {
2
mainMux = make(map[string]func(Params) map[string]interface{})
3
4
mainMux["setloglevel"] = SetLogLevel
5
mainMux["getinfo"] = GetInfo
6
mainMux["getblock"] = GetBlockByHash
7
mainMux["getconfirmbyheight"] = GetConfirmByHeight
8
mainMux["getconfirmbyhash"] = GetConfirmByHash
9
mainMux["getcurrentheight"] = GetBlockHeight
10
mainMux["getblockhash"] = GetBlockHash
11
mainMux["getconnectioncount"] = GetConnectionCount
12
mainMux["getrawmempool"] = GetTransactionPool
13
mainMux["getrawtransaction"] = GetRawTransaction
14
mainMux["getneighbors"] = GetNeighbors
15
mainMux["getnodestate"] = GetNodeState
16
mainMux["sendrawtransaction"] = SendRawTransaction
17
mainMux["getarbitratorgroupbyheight"] = GetArbitratorGroupByHeight
18
mainMux["getbestblockhash"] = GetBestBlockHash
19
mainMux["getblockcount"] = GetBlockCount
20
mainMux["getblockbyheight"] = GetBlockByHeight
21
mainMux["getexistwithdrawtransactions"] = GetExistWithdrawTransactions
22
mainMux["getreceivedbyaddress"] = GetReceivedByAddress
23
mainMux["getexistreturndeposittransactions"] = GetExistSideChainReturnDepositTransactions
24
25
// register sidechain interfaces
26
mainMux["getregistertransactionsbyheight"] = Getregistertransactionsbyheight
27
mainMux["getallregistertransactions"] = Getallregistertransactions
28
29
// wallet interfaces
30
mainMux["getamountbyinputs"] = GetAmountByInputs
31
mainMux["getutxosbyamount"] = GetUTXOsByAmount
32
mainMux["listunspent"] = ListUnspent
33
mainMux["createrawtransaction"] = CreateRawTransaction
34
mainMux["decoderawtransaction"] = DecodeRawTransaction
35
mainMux["signrawtransactionwithkey"] = SignRawTransactionWithKey
36
// aux interfaces
37
mainMux["help"] = AuxHelp
38
mainMux["submitauxblock"] = SubmitAuxBlock
39
mainMux["createauxblock"] = CreateAuxBlock
40
// mining interfaces
41
mainMux["getmininginfo"] = GetMiningInfo
42
mainMux["togglemining"] = ToggleMining
43
mainMux["discretemining"] = DiscreteMining
44
// cr interfaces
45
mainMux["listcrcandidates"] = ListCRCandidates
46
mainMux["listcurrentcrs"] = ListCurrentCRs
47
mainMux["listcrproposalbasestate"] = ListCRProposalBaseState
48
mainMux["getcrproposalstate"] = GetCRProposalState
49
mainMux["getproposaldraftdata"] = GetProposalDraftData
50
mainMux["getsecretarygeneral"] = GetSecretaryGeneral
51
mainMux["getcrrelatedstage"] = GetCRRelatedStage
52
mainMux["getcommitteecanuseamount"] = GetCommitteeCanUseAmount
53
54
// vote interfaces
55
mainMux["listproducers"] = ListProducers
56
mainMux["producerstatus"] = ProducerStatus
57
mainMux["votestatus"] = VoteStatus
58
// for cross-chain arbiter
59
mainMux["submitsidechainillegaldata"] = SubmitSidechainIllegalData
60
mainMux["getarbiterpeersinfo"] = GetArbiterPeersInfo
61
mainMux["getcrcpeersinfo"] = GetCRCPeersInfo
62
mainMux["getcrosschainpeersinfo"] = GetCrossChainPeersInfo
63
mainMux["getsmallcrosstransfertxs"] = GetSmallCrossTransferTxs
64
65
mainMux["estimatesmartfee"] = EstimateSmartFee
66
mainMux["getdepositcoin"] = GetDepositCoin
67
mainMux["getcrdepositcoin"] = GetCRDepositCoin
68
mainMux["getarbitersinfo"] = GetArbitersInfo
69
70
var handler http.Handler
71
rpcServeMux := http.NewServeMux()
72
if config.Parameters.EnableCORS {
73
c := cors.New(cors.Options{})
74
handler = c.Handler(rpcServeMux)
75
} else {
76
handler = rpcServeMux
77
}
78
server := http.Server{
79
Handler: handler,
80
ReadTimeout: IOTimeout,
81
WriteTimeout: IOTimeout,
82
}
83
rpcServeMux.HandleFunc("/", Handle)
84
l, err := net.Listen("tcp4", ":"+strconv.Itoa(config.Parameters.HttpJsonPort))
85
if err != nil {
86
log.Fatal("Create listener error: ", err.Error())
87
return
88
}
89
err = server.Serve(l)
90
if err != nil {
91
log.Fatal("ListenAndServe error: ", err.Error())
92
}
93
}
Copied!
Copy link