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:

func StartRPCServer() {
	mainMux = make(map[string]func(Params) map[string]interface{})

	mainMux["setloglevel"] = SetLogLevel
	mainMux["getinfo"] = GetInfo
	mainMux["getblock"] = GetBlockByHash
	mainMux["getconfirmbyheight"] = GetConfirmByHeight
	mainMux["getconfirmbyhash"] = GetConfirmByHash
	mainMux["getcurrentheight"] = GetBlockHeight
	mainMux["getblockhash"] = GetBlockHash
	mainMux["getconnectioncount"] = GetConnectionCount
	mainMux["getrawmempool"] = GetTransactionPool
	mainMux["getrawtransaction"] = GetRawTransaction
	mainMux["getneighbors"] = GetNeighbors
	mainMux["getnodestate"] = GetNodeState
	mainMux["sendrawtransaction"] = SendRawTransaction
	mainMux["getarbitratorgroupbyheight"] = GetArbitratorGroupByHeight
	mainMux["getbestblockhash"] = GetBestBlockHash
	mainMux["getblockcount"] = GetBlockCount
	mainMux["getblockbyheight"] = GetBlockByHeight
	mainMux["getexistwithdrawtransactions"] = GetExistWithdrawTransactions
	mainMux["getreceivedbyaddress"] = GetReceivedByAddress
	mainMux["getexistreturndeposittransactions"] = GetExistSideChainReturnDepositTransactions

	// register sidechain interfaces
	mainMux["getregistertransactionsbyheight"] = Getregistertransactionsbyheight
	mainMux["getallregistertransactions"] = Getallregistertransactions

	// wallet interfaces
	mainMux["getamountbyinputs"] = GetAmountByInputs
	mainMux["getutxosbyamount"] = GetUTXOsByAmount
	mainMux["listunspent"] = ListUnspent
	mainMux["createrawtransaction"] = CreateRawTransaction
	mainMux["decoderawtransaction"] = DecodeRawTransaction
	mainMux["signrawtransactionwithkey"] = SignRawTransactionWithKey
	// aux interfaces
	mainMux["help"] = AuxHelp
	mainMux["submitauxblock"] = SubmitAuxBlock
	mainMux["createauxblock"] = CreateAuxBlock
	// mining interfaces
	mainMux["getmininginfo"] = GetMiningInfo
	mainMux["togglemining"] = ToggleMining
	mainMux["discretemining"] = DiscreteMining
	// cr interfaces
	mainMux["listcrcandidates"] = ListCRCandidates
	mainMux["listcurrentcrs"] = ListCurrentCRs
	mainMux["listcrproposalbasestate"] = ListCRProposalBaseState
	mainMux["getcrproposalstate"] = GetCRProposalState
	mainMux["getproposaldraftdata"] = GetProposalDraftData
	mainMux["getsecretarygeneral"] = GetSecretaryGeneral
	mainMux["getcrrelatedstage"] = GetCRRelatedStage
	mainMux["getcommitteecanuseamount"] = GetCommitteeCanUseAmount

	// vote interfaces
	mainMux["listproducers"] = ListProducers
	mainMux["producerstatus"] = ProducerStatus
	mainMux["votestatus"] = VoteStatus
	// for cross-chain arbiter
	mainMux["submitsidechainillegaldata"] = SubmitSidechainIllegalData
	mainMux["getarbiterpeersinfo"] = GetArbiterPeersInfo
	mainMux["getcrcpeersinfo"] = GetCRCPeersInfo
	mainMux["getcrosschainpeersinfo"] = GetCrossChainPeersInfo
	mainMux["getsmallcrosstransfertxs"] = GetSmallCrossTransferTxs

	mainMux["estimatesmartfee"] = EstimateSmartFee
	mainMux["getdepositcoin"] = GetDepositCoin
	mainMux["getcrdepositcoin"] = GetCRDepositCoin
	mainMux["getarbitersinfo"] = GetArbitersInfo

	var handler http.Handler
	rpcServeMux := http.NewServeMux()
	if config.Parameters.EnableCORS {
		c := cors.New(cors.Options{})
		handler = c.Handler(rpcServeMux)
	} else {
		handler = rpcServeMux
	}
	server := http.Server{
		Handler:      handler,
		ReadTimeout:  IOTimeout,
		WriteTimeout: IOTimeout,
	}
	rpcServeMux.HandleFunc("/", Handle)
	l, err := net.Listen("tcp4", ":"+strconv.Itoa(config.Parameters.HttpJsonPort))
	if err != nil {
		log.Fatal("Create listener error: ", err.Error())
		return
	}
	err = server.Serve(l)
	if err != nil {
		log.Fatal("ListenAndServe error: ", err.Error())
	}
}

Last updated