Skip to content

RPC Module

linj edited this page Nov 23, 2022 · 1 revision

RPC Module

[TOC]

1 Module Introduction

RPC is Remote Procedure Call

  • RPC Module in Chain33 mainly provide transaction construction and sending for external program, as well as blocks, transactions and other information query interfaces.

  • RPC module supports both GRPC and jsonrpc interfaces. Other processes can call both GRPC and JRPC interfaces.In general, if a process construct data by Chain33's internal data structure, the GRPC interface is preferred, whereas the JRPC interface is recommended.

2 Logical Architecture and Context

The RPC module references the "GRPC" and "net/ RPC "packages and registers the service processing server for all RPC call methods when the system is initialized.

RPC module binds the corresponding port according to the configuration file. At the system level, it listens on the TCP port. Once receiving the request message, it calls the previously registered method for response according to the method name in the message data.

RPC module instantiates a QueueProtocol to interact with other modules in Chain33. For example, the actual block/transaction queries are interacted with the BlockChain module via messages.For information about message queues, please refer to the Queue module.

3 Data Structure

RPC defines GrpcServer and JSONRPCServer, which work for GRPC and JRPC services respectively. As can be seen from the following structure, inside chain33 the interaction is still through Queue

type channelClient struct {
	client.QueueProtocolAPI
	accountdb *account.DB
}

type Chain33 struct {
	cli channelClient
}

type Grpc struct {
	cli channelClient
}

type Grpcserver struct {
	grpc Grpc
	s    *grpc.Server
	l    net.Listener
	//addr string
}

type JSONRPCServer struct {
	jrpc Chain33
	s    *rpc.Server
	l    net.Listener
	//addr string
}
  • The interfaces provided by GRPC, defined by rpc.proto, unlike normal data, the data type defined here is service, not message.

  • The interfaces provided by JRPC are defined separately in jrpchandler.go.

4 Optimization Function

RPC provides the ability to whitelist remoteIP and whitelist/blacklist calling methods, and to filter requests based on various whitelist/blacklist configurations when RPC responds to request data.

5 Configuration File

[rpc]

jrpcBindAddr="localhost:8801"

grpcBindAddr="localhost:8802"

whitelist=["127.0.0.1"]

jrpcFuncWhitelist=["*"]

grpcFuncWhitelist=["*"]
  • The [RPC] sub-item in the configuration file is used to configure RPC

  • Currently the configuration used mainly includes binding addresses of JRPC and GRPC, and it is necessary to ensure the correct configuration of addresses and ports in the real environment

  • whitelist/jrpcFuncWhitelist/grpcFuncWhitelist are used to configure the white/black list. When there is no special needs, just maintain the default.

6 JRPC Interface List

As mentioned above, JRPC interface is recommended by DAPP. Chain33 now supports a large number of JRPC interfaces, which can basically meet various requirements of daily development. Due to the large amount of data, the interface names are listed here. Please refer to the JRPC interface documentation for specific parameters and instructions

6.1 Wallet Interface

  • Lock Lock

  • Unlock UnLock

  • Set/change the password SetPasswd

  • Set label SetLabl

  • Create account NewAccount

  • get the account list GetAccounts

  • Merge balance MergeBalance

  • Set transaction fee SetTxFee

  • Transaction SendToAddress

  • Import private key ImportPrivKey

  • Get the wallet transaction list WalletTxList

  • Get ticket count GetTicketCount

  • Export the private key dumpprivkey

  • Transaction signature SignRawTx

  • Create bound mining transaction CreateBindMiner

  • Get wallet status GetWalletStatus

6.2 Mempool Interface

  • Get GetMempool

6.3 Transaction Interface

  • Send transaction SendTransaction

  • Create transaction CreateTransaction

  • Send signed transaction SendRawTransaction

  • Construct and send no commission transaction CreateNoBalanceTransaction

  • Query the transaction information based on hash QueryTransaction

  • Get transaction information based on address GetTxByAddr

  • Get the transaction information in batch according to the hash array GetTxByHashes

  • Gets the string of the transaction based on hash GetHexTxByHash

  • Get address related summary information GetAddrOverview

  • Transform the contract name to actual address in Chain33 ConvertExectoAddr

  • Construct transaction block CreateRawTxGroup

6.4 Blockchain Interface

  • Get version Version

  • Get interval block GetBlocks

  • Get the latest block header GetLastHeader

  • Get the interval block header GetHeaders

  • Get the hash value for the block GetBlockHash

  • Get block details GetBlockOverview

  • Get the latest block serial number GetLastBlockSequence

  • Get the interval block number GetBlockSequences

  • Get the Hash list block GetBlockByHashes

6.5 Synchronous State Interface

  • Get the remote node list GetPeerInfo

  • Query node status GetNetInfo

  • Query time status GetTimeStatus

  • Query synchronization status IsSync

6.6 Wallet SEED

  • Generate random seed GenSeed

  • Save the seed and encrypt it with cipher SaveSeed

  • Get the seed text for the wallet through the wallet password GetSeed

6.7 Query Balance

  • Get balance on address address GetBalance

  • Get token balance on address GetTokenBalance

  • Get balance of all contract addresses GetAllExecBalance

Clone this wiki locally