Documentation ¶
Index ¶
- Constants
- Variables
- func CmdMethod(cmd interface{}) (string, error)
- func IsValidIDType(id interface{}) bool
- func MarshalCmd(id interface{}, cmd interface{}) ([]byte, error)
- func MarshalResponse(id interface{}, result interface{}, rpcErr *RPCError) ([]byte, error)
- func MethodUsageText(method string) (string, error)
- func MustRegisterCmd(method string, cmd interface{}, flags UsageFlag, service string)
- func NewCmd(method string, args ...interface{}) (interface{}, error)
- func RegisterCmd(method string, cmd interface{}, flags UsageFlag) error
- func RegisteredCmdMethods() []string
- func UnmarshalCmd(r *Request) (interface{}, error)
- func UseLogger(logger l.Logger)
- type BanlistCmd
- type BlockAcceptedNtfn
- type BlockConnectedNtfn
- type BlockDetails
- type BlockDisconnectedNtfn
- type CheckAddressCmd
- type CreateRawTransactionCmd
- type DecodeRawTransactionCmd
- type Error
- type ErrorCode
- type GenerateCmd
- type GetBestBlockHashCmd
- type GetBlockByNumCmd
- type GetBlockByOrderCmd
- type GetBlockCmd
- type GetBlockCountCmd
- type GetBlockHeaderCmd
- type GetBlockTemplateCmd
- type GetBlockTotalCmd
- type GetBlockV2Cmd
- type GetBlockWeightCmd
- type GetBlockhashByRangeCmd
- type GetBlockhashCmd
- type GetCoinbaseCmd
- type GetFeesCmd
- type GetMainChainHeightCmd
- type GetMempoolCmd
- type GetNodeInfoCmd
- type GetOrphansTotalCmd
- type GetPeerInfoCmd
- type GetRawTransactionCmd
- type GetRawTransactionsCmd
- type GetRemoteGBTCmd
- type GetRpcInfoCmd
- type GetTimeInfoCmd
- type GetUtxoCmd
- type IsBlueCmd
- type IsCurrentCmd
- type IsOnMainChainCmd
- type JsonRequestStatus
- type NodeExitNtfn
- type NotificationTxConfirmNtfn
- type NotifyBlocksCmd
- type NotifyNewTransactionsCmd
- type NotifyReceivedCmd
- type NotifyTxsByAddrCmd
- type NotifyTxsConfirmedCmd
- type OutPoint
- type RPCError
- type RPCErrorCode
- type RedeemingTxNtfn
- type RemoveBanCmd
- type RemoveTxsConfirmedCmd
- type ReorganizationNtfn
- type Request
- type RescanCmd
- type RescanFinishedNtfn
- type RescanProgressNtfn
- type Response
- type SendRawTransactionCmd
- type SessionCmd
- type SetLogLevelCmd
- type SetRpcMaxClientsCmd
- type StopCmd
- type StopNotifyBlocksCmd
- type StopNotifyNewTransactionsCmd
- type SubmitBlockCmd
- type SubmitBlockHeaderCmd
- type TipsCmd
- type TxAcceptedNtfn
- type TxAcceptedVerboseNtfn
- type TxConfirm
- type TxConfirmResult
- type TxSignCmd
- type UnNotifyTxsByAddrCmd
- type UsageFlag
Constants ¶
const ( DefaultServiceNameSpace = "qitmeer" MinerNameSpace = "miner" TestNameSpace = "test" LogNameSpace = "log" NotifyNameSpace = "" )
These are all service namespace in node
const ( BlockConnectedNtfnMethod = "blockConnected" BlockDisconnectedNtfnMethod = "blockDisconnected" BlockAcceptedNtfnMethod = "blockAccepted" ReorganizationNtfnMethod = "reorganization" TxAcceptedNtfnMethod = "txaccepted" TxAcceptedVerboseNtfnMethod = "txacceptedverbose" TxConfirmNtfnMethod = "txconfirm" RescanProgressNtfnMethod = "rescanprocess" RescanCompleteNtfnMethod = "rescancomplete" NodeExitMethod = "nodeexit" )
Variables ¶
var ( ErrRPCInvalidRequest = &RPCError{ Code: -32600, Message: "Invalid request", } ErrRPCMethodNotFound = &RPCError{ Code: -32601, Message: "Method not found", } ErrRPCInvalidParams = &RPCError{ Code: -32602, Message: "Invalid parameters", } ErrRPCInternal = &RPCError{ Code: -32603, Message: "Internal error", } // ErrRPCDatabase indicates a database error. ErrRPCDatabase = &RPCError{ Code: -32001, Message: "Database error", } ErrRPCBlockNotFound = &RPCError{ Code: -32002, Message: "Block Not Found error", } ErrInvalidNode = &RPCError{ Code: -32003, Message: "Invalid Node", } ErrRPCParse = &RPCError{ Code: -32700, Message: "Parse error", } ErrRPCDecodeHexString = &RPCError{ Code: -32701, Message: "Hex decode error", } )
Functions ¶
func CmdMethod ¶
CmdMethod returns the method for the passed command. The provided command type must be a registered type. All commands provided by this package are registered by default.
func IsValidIDType ¶
func IsValidIDType(id interface{}) bool
func MarshalCmd ¶
MarshalCmd marshals the passed command to a JSON-RPC request byte slice that is suitable for transmission to an RPC server. The provided command type must be a registered type. All commands provided by this package are registered by default.
func MarshalResponse ¶
func MethodUsageText ¶
MethodUsageText returns a one-line usage string for the provided method. The provided method must be associated with a registered type. All commands provided by this package are registered by default.
func MustRegisterCmd ¶
MustRegisterCmd performs the same function as RegisterCmd except it panics if there is an error. This should only be called from package init functions.
func NewCmd ¶
NewCmd provides a generic mechanism to create a new command that can marshal to a JSON-RPC request while respecting the requirements of the provided method. The method must have been registered with the package already along with its type definition. All methods associated with the commands exported by this package are already registered by default.
The arguments are most efficient when they are the exact same type as the underlying field in the command struct associated with the the method, however this function also will perform a variety of conversions to make it more flexible. This allows, for example, command line args which are strings to be passed unaltered. In particular, the following conversions are supported:
- Conversion between any size signed or unsigned integer so long as the value does not overflow the destination type
- Conversion between float32 and float64 so long as the value does not overflow the destination type
- Conversion from string to boolean for everything strconv.ParseBool recognizes
- Conversion from string to any size integer for everything strconv.ParseInt and strconv.ParseUint recognizes
- Conversion from string to any size float for everything strconv.ParseFloat recognizes
- Conversion from string to arrays, slices, structs, and maps by treating the string as marshalled JSON and calling json.Unmarshal into the destination field
func RegisterCmd ¶
RegisterCmd registers a new command that will automatically marshal to and from JSON-RPC with full type checking and positional parameter support. It also accepts usage flags which identify the circumstances under which the command can be used.
This package automatically registers all of the exported commands by default using this function, however it is also exported so callers can easily register custom types.
The type format is very strict since it needs to be able to automatically marshal to and from JSON-RPC 1.0. The following enumerates the requirements:
- The provided command must be a single pointer to a struct
- All fields must be exported
- The order of the positional parameters in the marshalled JSON will be in the same order as declared in the struct definition
- Struct embedding is not supported
- Struct fields may NOT be channels, functions, complex, or interface
- A field in the provided struct with a pointer is treated as optional
- Multiple indirections (i.e **int) are not supported
- Once the first optional field (pointer) is encountered, the remaining fields must also be optional fields (pointers) as required by positional params
- A field that has a 'jsonrpcdefault' struct tag must be an optional field (pointer)
NOTE: This function only needs to be able to examine the structure of the passed struct, so it does not need to be an actual instance. Therefore, it is recommended to simply pass a nil pointer cast to the appropriate type. For example, (*FooCmd)(nil).
func RegisteredCmdMethods ¶
func RegisteredCmdMethods() []string
RegisteredCmdMethods returns a sorted list of methods for all registered commands.
func UnmarshalCmd ¶
UnmarshalCmd unmarshals a JSON-RPC request into a suitable concrete command so long as the method type contained within the marshalled request is registered.
Types ¶
type BlockAcceptedNtfn ¶
type BlockConnectedNtfn ¶
func NewBlockConnectedNtfn ¶
func NewBlockConnectedNtfn(hash string, height, order int64, time int64, txs []string) *BlockConnectedNtfn
type BlockDetails ¶
type BlockDetails struct { Order uint64 `json:"order"` Hash string `json:"hash"` Index int `json:"index"` Time int64 `json:"time"` }
BlockDetails describes details of a tx in a block.
type BlockDisconnectedNtfn ¶
func NewBlockDisconnectedNtfn ¶
func NewBlockDisconnectedNtfn(hash string, height, order int64, time int64, txs []string) *BlockDisconnectedNtfn
type CheckAddressCmd ¶
func NewCheckAddressCmd ¶
func NewCheckAddressCmd(address string, network string) *CheckAddressCmd
type CreateRawTransactionCmd ¶
type CreateRawTransactionCmd struct { Inputs []json.TransactionInput Amounts json.Amounts LockTime int64 }
func NewCreateRawTransactionCmd ¶
func NewCreateRawTransactionCmd(inputs []json.TransactionInput, amounts json.Amounts, lockTime int64) *CreateRawTransactionCmd
type DecodeRawTransactionCmd ¶
type DecodeRawTransactionCmd struct {
HexTx string
}
func NewDecodeRawTransactionCmd ¶
func NewDecodeRawTransactionCmd(hexTx string) *DecodeRawTransactionCmd
type Error ¶
type Error struct { ErrorCode ErrorCode // Describes the kind of error Description string // Human readable description of the issue }
Error identifies a general error. This differs from an RPCError in that this error typically is used more by the consumers of the package as opposed to RPCErrors which are intended to be returned to the client across the wire via a JSON-RPC Response. The caller can use type assertions to determine the specific error and access the ErrorCode field.
type ErrorCode ¶
type ErrorCode int
ErrorCode identifies a kind of error. These error codes are NOT used for JSON-RPC response errors.
const ( // ErrDuplicateMethod indicates a command with the specified method // already exists. ErrDuplicateMethod ErrorCode = iota // ErrInvalidUsageFlags indicates one or more unrecognized flag bits // were specified. ErrInvalidUsageFlags // ErrInvalidType indicates a type was passed that is not the required // type. ErrInvalidType // ErrEmbeddedType indicates the provided command struct contains an // embedded type which is not not supported. ErrEmbeddedType // ErrUnexportedField indiciates the provided command struct contains an // unexported field which is not supported. ErrUnexportedField // ErrUnsupportedFieldType indicates the type of a field in the provided // command struct is not one of the supported types. ErrUnsupportedFieldType // ErrNonOptionalField indicates a non-optional field was specified // after an optional field. ErrNonOptionalField // ErrNonOptionalDefault indicates a 'jsonrpcdefault' struct tag was // specified for a non-optional field. ErrNonOptionalDefault // ErrMismatchedDefault indicates a 'jsonrpcdefault' struct tag contains // a value that doesn't match the type of the field. ErrMismatchedDefault // ErrUnregisteredMethod indicates a method was specified that has not // been registered. ErrUnregisteredMethod // ErrMissingDescription indicates a description required to generate // help is missing. ErrMissingDescription // ErrNumParams inidcates the number of params supplied do not // match the requirements of the associated command. ErrNumParams )
These constants are used to identify a specific RuleError.
type GenerateCmd ¶
func NewGenerateCmd ¶
func NewGenerateCmd(numBlocks uint32, powType pow.PowType) *GenerateCmd
type GetBestBlockHashCmd ¶
type GetBestBlockHashCmd struct{}
func NewGetBestBlockHashCmd ¶
func NewGetBestBlockHashCmd() *GetBestBlockHashCmd
type GetBlockByNumCmd ¶
func NewGetBlockByNumCmd ¶
func NewGetBlockByNumCmd(id uint, verbose bool, inclTx bool, fullTx bool) *GetBlockByNumCmd
type GetBlockByOrderCmd ¶
func NewGetBlockByOrderCmd ¶
func NewGetBlockByOrderCmd(order uint, verbose bool, inclTx bool, fullTx bool) *GetBlockByOrderCmd
type GetBlockCmd ¶
func NewGetBlockCmd ¶
func NewGetBlockCmd(h string, verbose bool, inclTx bool, fullTx bool) *GetBlockCmd
func NewGetBlockV2Cmd ¶
func NewGetBlockV2Cmd(h string, verbose bool, inclTx bool, fullTx bool) *GetBlockCmd
type GetBlockCountCmd ¶
type GetBlockCountCmd struct{}
func NewGetBlockCountCmd ¶
func NewGetBlockCountCmd() *GetBlockCountCmd
type GetBlockHeaderCmd ¶
func NewGetBlockHeaderCmd ¶
func NewGetBlockHeaderCmd(hash string, verbose bool) *GetBlockHeaderCmd
type GetBlockTemplateCmd ¶
func NewGetBlockTemplateCmd ¶
func NewGetBlockTemplateCmd(capabilities []string, powType byte) *GetBlockTemplateCmd
type GetBlockTotalCmd ¶
type GetBlockTotalCmd struct{}
func NewGetBlockTotalCmd ¶
func NewGetBlockTotalCmd() *GetBlockTotalCmd
type GetBlockWeightCmd ¶
type GetBlockWeightCmd struct {
H string
}
func NewGetBlockWeightCmd ¶
func NewGetBlockWeightCmd(h string) *GetBlockWeightCmd
type GetBlockhashByRangeCmd ¶
func NewGetBlockhashByRangeCmd ¶
func NewGetBlockhashByRangeCmd(start uint, end uint) *GetBlockhashByRangeCmd
type GetBlockhashCmd ¶
type GetBlockhashCmd struct {
Order uint
}
func NewGetBlockhashCmd ¶
func NewGetBlockhashCmd(order uint) *GetBlockhashCmd
type GetCoinbaseCmd ¶
type GetCoinbaseCmd struct { }
func NewGetCoinbaseCmd ¶
func NewGetCoinbaseCmd() *GetCoinbaseCmd
type GetFeesCmd ¶
type GetFeesCmd struct {
H string
}
func NewGetFeesCmd ¶
func NewGetFeesCmd(h string) *GetFeesCmd
type GetMainChainHeightCmd ¶
type GetMainChainHeightCmd struct{}
func NewGetMainChainHeightCmd ¶
func NewGetMainChainHeightCmd() *GetMainChainHeightCmd
type GetMempoolCmd ¶
func NewGetMempoolCmd ¶
func NewGetMempoolCmd(txType string, verbose bool) *GetMempoolCmd
type GetNodeInfoCmd ¶
type GetNodeInfoCmd struct{}
func NewGetNodeInfoCmd ¶
func NewGetNodeInfoCmd() *GetNodeInfoCmd
type GetOrphansTotalCmd ¶
type GetOrphansTotalCmd struct{}
func NewGetOrphansTotalCmd ¶
func NewGetOrphansTotalCmd() *GetOrphansTotalCmd
type GetPeerInfoCmd ¶
type GetPeerInfoCmd struct{}
func NewGetPeerInfoCmd ¶
func NewGetPeerInfoCmd() *GetPeerInfoCmd
type GetRawTransactionCmd ¶
func NewGetRawTransactionCmd ¶
func NewGetRawTransactionCmd(txHash string, verbose bool) *GetRawTransactionCmd
type GetRawTransactionsCmd ¶
type GetRawTransactionsCmd struct { Addre string Vinext bool Count uint Skip uint Revers bool Verbose bool FilterAddrs []string }
type GetRemoteGBTCmd ¶ added in v0.10.6
func NewGetRemoteGBTCmd ¶ added in v0.10.6
func NewGetRemoteGBTCmd(powType pow.PowType) *GetRemoteGBTCmd
type GetRpcInfoCmd ¶
type GetRpcInfoCmd struct{}
func NewGetRpcInfoCmd ¶
func NewGetRpcInfoCmd() *GetRpcInfoCmd
type GetTimeInfoCmd ¶
type GetTimeInfoCmd struct{}
func NewGetTimeInfoCmd ¶
func NewGetTimeInfoCmd() *GetTimeInfoCmd
type GetUtxoCmd ¶
func NewGetUtxoCmd ¶
func NewGetUtxoCmd(txHash string, vout uint32, includeMempool bool) *GetUtxoCmd
type IsCurrentCmd ¶
type IsCurrentCmd struct { }
func NewIsCurrentCmd ¶
func NewIsCurrentCmd() *IsCurrentCmd
type IsOnMainChainCmd ¶
type IsOnMainChainCmd struct {
H string
}
func NewIsOnMainChainCmd ¶
func NewIsOnMainChainCmd(h string) *IsOnMainChainCmd
type JsonRequestStatus ¶
type JsonRequestStatus struct { Name string `json:"name"` TotalCalls int `json:"totalcalls"` TotalTime string `json:"totaltime"` AverageTime string `json:"averagetime"` MaxTime string `json:"maxtime"` MinTime string `json:"mintime"` MaxTimeReqID string `json:"maxtimereqid"` MinTimeReqID string `json:"mintimereqid"` RunningNum int `json:"runningnum"` }
type NodeExitNtfn ¶
type NodeExitNtfn struct { }
type NotificationTxConfirmNtfn ¶
type NotificationTxConfirmNtfn struct {
ConfirmResult TxConfirmResult
}
type NotifyBlocksCmd ¶
type NotifyBlocksCmd struct{}
func NewNotifyBlocksCmd ¶
func NewNotifyBlocksCmd() *NotifyBlocksCmd
type NotifyNewTransactionsCmd ¶
type NotifyNewTransactionsCmd struct {
Verbose bool
}
ws
func NewNotifyNewTransactionsCmd ¶
func NewNotifyNewTransactionsCmd(verbose bool) *NotifyNewTransactionsCmd
type NotifyReceivedCmd ¶
type NotifyReceivedCmd struct {
Addresses []string
}
TODO op
func NewNotifyReceivedCmd ¶
func NewNotifyReceivedCmd(addresses []string) *NotifyReceivedCmd
type NotifyTxsByAddrCmd ¶
ws
func NewNotifyTxsByAddrCmd ¶
func NewNotifyTxsByAddrCmd(reload bool, addr []string, outpoint []OutPoint) *NotifyTxsByAddrCmd
type NotifyTxsConfirmedCmd ¶
type NotifyTxsConfirmedCmd struct {
Txs []TxConfirm
}
func NewNotifyTxsConfirmed ¶
func NewNotifyTxsConfirmed(txs []TxConfirm) *NotifyTxsConfirmedCmd
type RPCError ¶
type RPCError struct { Code RPCErrorCode `json:"code,omitempty"` Message string `json:"message,omitempty"` }
func InternalRPCError ¶
func NewRPCError ¶
func NewRPCError(code RPCErrorCode, message string) *RPCError
type RPCErrorCode ¶
type RPCErrorCode int
type RedeemingTxNtfn ¶
type RedeemingTxNtfn struct { HexTx string Block *BlockDetails }
RedeemingTxNtfn defines the redeemingtx JSON-RPC notification.
type RemoveBanCmd ¶
type RemoveBanCmd struct {
Id string
}
func NewRemoveBanCmd ¶
func NewRemoveBanCmd(id string) *RemoveBanCmd
type RemoveTxsConfirmedCmd ¶ added in v0.10.6
type RemoveTxsConfirmedCmd struct {
Txs []TxConfirm
}
func NewRemoveTxsConfirmed ¶ added in v0.10.6
func NewRemoveTxsConfirmed(txs []TxConfirm) *RemoveTxsConfirmedCmd
type ReorganizationNtfn ¶
func NewReorganizationNtfn ¶
func NewReorganizationNtfn(hash string, order int64, olds []string) *ReorganizationNtfn
type Request ¶
type Request struct { Jsonrpc string `json:"jsonrpc"` Method string `json:"method"` Params []json.RawMessage `json:"params"` ID interface{} `json:"id"` }
func NewRequest ¶
type RescanFinishedNtfn ¶
RescanFinishedNtfn defines the rescanfinished JSON-RPC notification.
func NewRescanFinishedNtfn ¶
func NewRescanFinishedNtfn(hash, txHash string, order uint64, time int64) *RescanFinishedNtfn
NewRescanFinishedNtfn returns a new instance which can be used to issue a rescanfinished JSON-RPC notification.
type RescanProgressNtfn ¶
RescanProgressNtfn defines the rescanprogress JSON-RPC notification.
func NewRescanProgressNtfn ¶
func NewRescanProgressNtfn(hash string, order uint64, time int64) *RescanProgressNtfn
NewRescanProgressNtfn returns a new instance which can be used to issue a rescanprogress JSON-RPC notification.
type Response ¶
type Response struct { Result json.RawMessage `json:"result"` Error *RPCError `json:"error"` ID *interface{} `json:"id"` }
type SendRawTransactionCmd ¶
func NewSendRawTransactionCmd ¶
func NewSendRawTransactionCmd(hexTx string, allowHighFees bool) *SendRawTransactionCmd
type SetLogLevelCmd ¶
type SetLogLevelCmd struct {
Level string
}
func NewSetLogLevelCmd ¶
func NewSetLogLevelCmd(level string) *SetLogLevelCmd
type SetRpcMaxClientsCmd ¶
type SetRpcMaxClientsCmd struct {
Max int
}
func NewSetRpcMaxClientsCmd ¶
func NewSetRpcMaxClientsCmd(max int) *SetRpcMaxClientsCmd
type StopNotifyBlocksCmd ¶
type StopNotifyBlocksCmd struct{}
func NewStopNotifyBlocksCmd ¶
func NewStopNotifyBlocksCmd() *StopNotifyBlocksCmd
type StopNotifyNewTransactionsCmd ¶
type StopNotifyNewTransactionsCmd struct{}
func NewStopNotifyNewTransactionsCmd ¶
func NewStopNotifyNewTransactionsCmd() *StopNotifyNewTransactionsCmd
type SubmitBlockCmd ¶
type SubmitBlockCmd struct {
HexBlock string
}
func NewSubmitBlockCmd ¶
func NewSubmitBlockCmd(hexBlock string) *SubmitBlockCmd
type SubmitBlockHeaderCmd ¶ added in v0.10.6
type SubmitBlockHeaderCmd struct {
HexBlockHeader string
}
func NewSubmitBlockHeaderCmd ¶ added in v0.10.6
func NewSubmitBlockHeaderCmd(blockHeader *types.BlockHeader) *SubmitBlockHeaderCmd
type TxAcceptedNtfn ¶
type TxAcceptedNtfn struct { TxID string Amounts types.AmountGroup }
func NewTxAcceptedNtfn ¶
func NewTxAcceptedNtfn(txHash string, amounts types.AmountGroup) *TxAcceptedNtfn
type TxAcceptedVerboseNtfn ¶
type TxAcceptedVerboseNtfn struct {
Tx json.DecodeRawTransactionResult
}
func NewTxAcceptedVerboseNtfn ¶
func NewTxAcceptedVerboseNtfn(tx json.DecodeRawTransactionResult) *TxAcceptedVerboseNtfn
type TxConfirmResult ¶
type TxSignCmd ¶
func NewTxSignCmd ¶
type UnNotifyTxsByAddrCmd ¶
type UnNotifyTxsByAddrCmd struct {
Addresses []string
}
ws
func StopNotifyTxsByAddrCmd ¶
func StopNotifyTxsByAddrCmd(addr []string) *UnNotifyTxsByAddrCmd
type UsageFlag ¶
type UsageFlag uint32
UsageFlag define flags that specify additional properties about the circumstances under which a command can be used.
const ( // UFWalletOnly indicates that the command can only be used with an RPC // server that supports wallet commands. UFWalletOnly UsageFlag = 1 << iota // UFWebsocketOnly indicates that the command can only be used when // communicating with an RPC server over websockets. This typically // applies to notifications and notification registration functions // since neiher makes since when using a single-shot HTTP-POST request. UFWebsocketOnly // UFNotification indicates that the command is actually a notification. // This means when it is marshalled, the ID must be nil. UFNotification )
func MethodUsageFlags ¶
MethodUsageFlags returns the usage flags for the passed command method. The provided method must be associated with a registered type. All commands provided by this package are registered by default.