rpc

package
v0.0.0-...-03c5838 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 22, 2020 License: LGPL-3.0 Imports: 35 Imported by: 0

Documentation

Overview

Copyright (C) 2018 go-cloudcard authors

This file is part of the go-cloudcard library.

the go-cloudcard library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

the go-cloudcard library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with the go-cloudcard library. If not, see <http://www.gnu.org/licenses/>.

Index

Constants

View Source
const (
	API   = "api"
	Admin = "admin"
)

const

View Source
const (
	// DefaultHTTPLimit default max http conns
	DefaultHTTPLimit = 128
	// MaxGateWayRecvMsgSize Deafult max message size  gateway's grpc client can receive
	MaxGateWayRecvMsgSize = 64 * 1024 * 1024
)
View Source
const (
	DefaultConnectionLimits = 128
	MaxRecvMsgSize          = 64 * 1024 * 1024
	Rpc                     = "rpc"
)

Const

Variables

View Source
var (
	CoinbaseAddressIsNilError          = errors.New("the coinbase address is nil")
	PassphraseLengthIsZeroError        = errors.New("passphrase length is 0")
	MiningProcessingError              = errors.New("mining is in progress, please stop mining before starting")
	HasBeenStoppedError                = errors.New("the mining has been stopped, please restart")
	MessageLengthIsZeroError           = errors.New("message length must greater than 0")
	SignatureLengthIsZeroError         = errors.New("signature length must greater than 0")
	NotHexStringError                  = errors.New("not hex string")
	LogLevelLengthIsZeroError          = errors.New("the log level cannot be empty")
	LogAgeIsZeroError                  = errors.New("log age must be greater than 0")
	RotationTimeIsZeroError            = errors.New("rotation time must be greater than 0")
	LogPathIsEmptyError                = errors.New("the log path cannot be empty")
	BalanceNotEnoughError              = errors.New("balance not enough")
	TxPoolIsNilError                   = errors.New("tx poll is nil")
	DataIsNotHexStringError            = errors.New("data must be a hex string")
	PrivateKeyIsBlankError             = errors.New("private key is blank")
	PrivateKeyIsNotHexStrError         = errors.New("private key must be hex string")
	RotationTimeGreaterThanMaxAgeError = errors.New("rotation time must be less than max age")
	TxNonceLessThanAccountNonceError   = errors.New("transaction nonce must be greater than account nonce")
)
View Source
var (
	HashLengthIsNot128Error       = errors.New("hex hash length must be 128")
	SignLengthIsNot128Error       = errors.New("hex signature length must be 128")
	BlockHeightError              = errors.New("block height must be greater than 0")
	BlockNotExistError            = errors.New("block not exist")
	NoConfirmBlockError           = errors.New("no confirm block now")
	JsonTxHashIsNotHexStringError = errors.New("tx hash must be hex string")
	JsonTxValueInvalidError       = errors.New("tx value invalid")
	JsonTxFeeInvalidError         = errors.New("tx fee invalid")
	JsonTxChainIdInvalidError     = errors.New("tx chain id invalid")
	JsonTxTypeIsEmptyError        = errors.New("tx type is empty")
	TxPriorityInvalidError        = errors.New("tx priority out of rang")
	PubKeyLengthInvalidError      = errors.New("public key length is not 64")
	DataInvalidError              = errors.New("tx data must be hex string")
	PubKeyIsNotHexStringError     = errors.New("public key must be hex string")
	TxSignIsNotHexStringError     = errors.New("tx signature must be hex string")
	CalculateTxHashInvalidError   = errors.New("the calculated transaction hash is not equal to the transaction hash")
	CalculateTxFeeInvalidError    = errors.New("the calculated transaction fee is not equal to the transaction fee")
	VerifyTxSignError             = errors.New("verify signature failed")
)
View Source
var (
	ErrEmptyRPCListenList = errors.New("empty rpc listen list")
)

Errors

Functions

func Dial

func Dial(target string) (*grpc.ClientConn, error)

Dial returns a client connection.

func Run

func Run(config *RpcConfig) error

Run start gateway proxy to mapping grpc to http.

func SetRpcConfig

func SetRpcConfig(config *config.Config, rpcCfg *RpcConfig)

Types

type AdminService

type AdminService struct {
	// contains filtered or unexported fields
}

AdminService implements the RPC admin service interface.

func (*AdminService) Accounts

Accounts is the RPC API handler.

func (*AdminService) GeneratePrivateKey

func (s *AdminService) GeneratePrivateKey(context.Context, *rpcpb.NonParamsRequest) (*rpcpb.PrivateKey, error)

Return the key pair

func (*AdminService) ImportAccount

func (s *AdminService) ImportAccount(ctx context.Context, req *rpcpb.PrivKeyAndPassphrase) (*rpcpb.Address, error)

NewAccount create a new account with passphrase

func (*AdminService) LockAccount

LockAccount lock address

func (*AdminService) Logging

func (s *AdminService) Logging(ctx context.Context, req *rpcpb.LoggingInfo) (*rpcpb.LoggingInfo, error)

return Logging Info

func (*AdminService) NewAccount

NewAccount generate a new address with passphrase

func (*AdminService) SendTransaction

func (s *AdminService) SendTransaction(ctx context.Context, req *rpcpb.TransactionRequest) (*rpcpb.TransactionHash, error)

SendTransaction is the RPC API handler.

func (*AdminService) SendTransactionWithPassphrase

func (s *AdminService) SendTransactionWithPassphrase(ctx context.Context, req *rpcpb.SendTransactionPassphraseRequest) (*rpcpb.TransactionHash, error)

SendTransactionWithPassphrase is the RPC API handler.

func (*AdminService) Sign

SignHash is the RPC API handler.

func (*AdminService) SignTransactionWithPassphrase

SignTransactionWithPassphrase is the RPC API handler.

func (*AdminService) StartMining

func (*AdminService) StartPprof

func (s *AdminService) StartPprof(ctx context.Context, req *rpcpb.PprofRequest) (*rpcpb.PprofResponse, error)

StartPprof is the RPC API handler.

func (*AdminService) Stop

stop the server

func (*AdminService) StopMining

func (*AdminService) UnlockAccount

UnlockAccount unlock address with the passphrase

func (*AdminService) UpdateAccount

NewAccount create a new account with passphrase

func (*AdminService) VerifyMessage

Sign sign msg

type ApiService

type ApiService struct {
	// contains filtered or unexported fields
}

func (*ApiService) GetAccount

func (api *ApiService) GetAccount(ctx context.Context, req *rpcpb.Address) (*rpcpb.AccountInfo, error)

get account info by address

func (*ApiService) GetActiveCount

Return the p2p node info.

func (*ApiService) GetBalance

func (s *ApiService) GetBalance(ctx context.Context, req *rpcpb.Address) (*rpcpb.BalanceResponse, error)

func (*ApiService) GetBestBlockByHeight

func (api *ApiService) GetBestBlockByHeight(ctx context.Context, req *rpcpb.BlockHeightAndFull) (*rpcpb.BlockResponse, error)

get best block by height

func (*ApiService) GetBestBlockHash

func (api *ApiService) GetBestBlockHash(context.Context, *rpcpb.NonParamsRequest) (*rpcpb.BlockHash, error)

func (*ApiService) GetBlockByHash

func (api *ApiService) GetBlockByHash(ctx context.Context, req *rpcpb.BlockHashAndFull) (*rpcpb.BlockResponse, error)

func (*ApiService) GetBlockChainInfo

func (api *ApiService) GetBlockChainInfo(context.Context, *rpcpb.NonParamsRequest) (*rpcpb.BlockChainInfo, error)

Return the block chain info

func (*ApiService) GetBlocksByHeight

func (api *ApiService) GetBlocksByHeight(ctx context.Context, req *rpcpb.BlockHeightAndFull) (*rpcpb.BlockListResponse, error)

get best block by height

func (*ApiService) GetCreditIndex

func (api *ApiService) GetCreditIndex(ctx context.Context, req *rpcpb.Address) (*rpcpb.CreditIndexResponse, error)

get creditIndex by address

func (*ApiService) GetMaxHeight

get max block height

func (*ApiService) GetNetVersion

Return the p2p node info.

func (*ApiService) GetPendingTransactionsByPage

func (api *ApiService) GetPendingTransactionsByPage(ctx context.Context, req *rpcpb.GetPendingTransactionsByPageRequest) (*rpcpb.PendingTransaction, error)

func (*ApiService) GetPendingTransactionsSize

func (api *ApiService) GetPendingTransactionsSize(ctx context.Context, req *rpcpb.NonParamsRequest) (*rpcpb.PendingTransactionsSize, error)

func (*ApiService) GetTransactionByContractAddress

func (s *ApiService) GetTransactionByContractAddress(ctx context.Context, req *rpcpb.ContractAddressRequest) (*rpcpb.TransactionReceipt, error)

func (*ApiService) GetTransactionByHash

func (s *ApiService) GetTransactionByHash(ctx context.Context, req *rpcpb.TransactionHash) (*rpcpb.TransactionReceipt, error)

func (*ApiService) NodeInfo

NodeInfo is the RPC API handler.

func (*ApiService) SendSignedTransaction

func (s *ApiService) SendSignedTransaction(ctx context.Context, req *rpcpb.Transaction) (*rpcpb.BoolResponse, error)

send sign tx

type GRPCServer

type GRPCServer interface {
	Start() error // Start start server
	Stop()        // Stop stop server
	RunGateway() error
}

GRPCServer server interface for api & management etc.

type RpcConfig

type RpcConfig struct {
	RpcListen  []string `yaml:"rpc_listen"`
	HttpListen []string `yaml:"http_listen"`
	HttpModule []string `yaml:"http_module"`
	HttpCors   []string `yaml:"http_cors"`
	HttpLimits uint32   `yaml:"http_limits"`
}

func GetRpcConfig

func GetRpcConfig(config *config.Config) *RpcConfig

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is the RPC server type.

func NewServer

func NewServer(cloudcard core.cloudcard) *Server

NewServer creates a new RPC server and registers the rpc endpoints.

func (*Server) RunGateway

func (s *Server) RunGateway() error

RunGateway run grpc mapping to http after apiserver have started.

func (*Server) Start

func (s *Server) Start() error

Start starts the rpc server and serves incoming requests.

func (*Server) Stop

func (s *Server) Stop()

Stop stops the rpc server and closes listener.

Directories

Path Synopsis
Package rpcpb is a reverse proxy.
Package rpcpb is a reverse proxy.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL