rpcjson

package
v0.0.0-...-7ee7fde Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2020 License: Apache-2.0 Imports: 4 Imported by: 3

Documentation

Overview

NOTE: This file is intended to house the RPC commands that are supported by a chain server.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRPCInternal = &RPCError{
		Code:    -32603,
		Message: "Internal error",
	}
)

Standard JSON-RPC 2.0 errors.

Functions

This section is empty.

Types

type AddNodeSubCmd

type AddNodeSubCmd string

AddNodeSubCmd defines the type used in the addnode JSON-RPC command for the sub command field.

const (
	// ANAdd indicates the specified host should be added as a persistent
	// peer.
	ANAdd AddNodeSubCmd = "add"

	// ANRemove indicates the specified peer should be removed.
	ANRemove AddNodeSubCmd = "remove"

	// ANOneTry indicates the specified host should try to connect once,
	// but it should not be made persistent.
	ANOneTry AddNodeSubCmd = "onetry"
)

type CallLogResult

type CallLogResult struct {
	EventName string      `json:"eventname"`
	Log       interface{} `json:"log"`
}

type CallResult

type CallResult struct {
	Result  interface{}     `json:"result"`
	Logs    []CallLogResult `json:"logs"`
	Name    string          `json:"name,omitempty"`
	GasUsed uint64          `json:"gasused,omitempty"`
}

type ContractTemplate

type ContractTemplate struct {
	TemplateTName string `json:"template_name"`
	TemplateType  uint16 `json:"template_type"`
}

type ContractTemplateDetail

type ContractTemplateDetail struct {
	Category     uint16 `json:"category"`
	TemplateName string `json:"template_name"`
	ByteCode     string `json:"byte_code"`
	Abi          string `json:"abi"`
	Source       string `json:"source"`
}

type CreateRawTransactionResult

type CreateRawTransactionResult struct {
	Hex          string            `json:"hex"`
	ContractAddr map[uint64]string `json:"contractaddr"`
}

type DecodeScriptResult

type DecodeScriptResult struct {
	Asm       string   `json:"asm"`
	ReqSigs   int32    `json:"reqSigs,omitempty"`
	Type      string   `json:"type"`
	Addresses []string `json:"addresses,omitempty"`
	P2sh      string   `json:"p2sh,omitempty"`
}

DecodeScriptResult models the data returned from the decodescript command.

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.

func (ErrorCode) String

func (e ErrorCode) String() string

String returns the ErrorCode as a human-readable name.

type FeeItemResult

type FeeItemResult struct {
	Assets string `json:"assets"`
	Height int32  `json:"height"`
}

type FeeResult

type FeeResult struct {
	Value int64  `json:"value"`
	Asset string `json:"asset"`
}

type GetBalanceResult

type GetBalanceResult struct {
	Asset string `json:"asset"`
	Value string `json:"value"`
}

type GetBalancesResult

type GetBalancesResult struct {
	Address string             `json:"address"`
	Assets  []GetBalanceResult `json:"assets"`
}

type GetBestBlockResult

type GetBestBlockResult struct {
	Hash   string `json:"hash"`
	Height int32  `json:"height"`
}

GetBestBlockResult models the data from the getbestblock command.

type GetBlockChainInfoResult

type GetBlockChainInfoResult struct {
	Chain         string `json:"chain"`
	Blocks        int32  `json:"blocks"`
	BestBlockHash string `json:"bestblockhash"`
	MedianTime    int64  `json:"mediantime"`
	Round         int32  `json:"round"`
	Slot          int16  `json:"slot"`
}

GetBlockChainInfoResult models the data returned from the getblockchaininfo command.

type GetBlockHeaderVerboseResult

type GetBlockHeaderVerboseResult struct {
	Hash          string `json:"hash"`
	Confirmations int64  `json:"confirmations"`
	Height        int32  `json:"height"`
	Version       int32  `json:"version"`
	// VersionHex    string `json:"versionHex"`
	MerkleRoot   string `json:"merkleroot"`
	StateRoot    string `json:"stateroot"`
	Time         int64  `json:"time"`
	PreviousHash string `json:"previousblockhash,omitempty"`
	NextHash     string `json:"nextblockhash,omitempty"`
	GasLimit     int64  `json:"gaslimist,omitempty"`
	GasUsed      int64  `json:"gasused,omitempty"`
}

GetBlockHeaderVerboseResult models the data from the getblockheader command when the verbose flag is set. When the verbose flag is not set, getblockheader returns a hex-encoded string.

type GetBlockTemplateResultAux

type GetBlockTemplateResultAux struct {
	Flags string `json:"flags"`
}

GetBlockTemplateResultAux models the coinbaseaux field of the getblocktemplate command.

type GetBlockVerboseResult

type GetBlockVerboseResult struct {
	Hash          string           `json:"hash"`
	Confirmations int64            `json:"confirmations"`
	Size          int32            `json:"size"`
	Height        int64            `json:"height"`
	Version       int32            `json:"version"`
	MerkleRoot    string           `json:"merkleroot"`
	Tx            []string         `json:"tx,omitempty"`
	RawTx         []TxResult       `json:"rawtx,omitempty"`
	Time          int64            `json:"time"`
	TxCount       uint64           `json:"txCount"`
	PreviousHash  string           `json:"previousblockhash"`
	StateRoot     string           `json:"stateroot"`
	NextHash      string           `json:"nextblockhash,omitempty"`
	Vtxs          []TxResult       `json:"vtxs,omitempty"`
	Receipts      []*ReceiptResult `json:"receipts,omitempty"`
	Round         uint32           `json:"round"`
	Slot          uint16           `json:"slot"`
	GasLimit      uint64           `json:"gaslimit,omitempty"`
	GasUsed       uint64           `json:"gasused,omitempty"`
	Reward        int64            `json:"reward,omitempty"`
	FeeList       []FeeResult      `json:"FeeList,omitempty"`
	PreSigList    []MsgSignResult  `json:"presiglist,omitempty"`
	Weight        uint16           `json:"weight"`
}

GetBlockVerboseResult models the data from the getblock command when the verbose flag is set. When the verbose flag is not set, getblock returns a hex-encoded string.

type GetConsensusMiningInfoResult

type GetConsensusMiningInfoResult struct {
	ContractAddr    string `json:"contractAddr"`
	MiningMemberAbi string `json:"miningMemberAbi"`
	SignUpFunc      string `json:"signUpFunc"`
}

type GetMergeUtxoResult

type GetMergeUtxoResult struct {
	Asset       string            `json:"asset"`
	Value       int64             `json:"value"`
	PreOutsList []protos.OutPoint `json:"preOutsList"`
}

type GetNetTotalsResult

type GetNetTotalsResult struct {
	TotalBytesRecv uint64 `json:"totalbytesrecv"`
	TotalBytesSent uint64 `json:"totalbytessent"`
	TimeMillis     int64  `json:"timemillis"`
}

GetNetTotalsResult models the data returned from the getnettotals command.

type GetRawMempoolVerboseResult

type GetRawMempoolVerboseResult struct {
	Size    int32    `json:"size"`
	Fee     int64    `json:"fee"`
	Time    int64    `json:"time"`
	Height  int64    `json:"height"`
	Depends []string `json:"depends"`
}

GetRawMempoolVerboseResult models the data returned from the getrawmempool command when the verbose flag is set. When the verbose flag is not set, getrawmempool returns an array of transaction hashes.

type GetSignUpStatusResult

type GetSignUpStatusResult struct {
	AutoSignUp  bool              `json:"autoSignUp"`
	PreOutsList []protos.OutPoint `json:"preOutsList"`
	Balance     int64             `json:"balance"`
}

type ListUnspentResult

type ListUnspentResult struct {
	TxID         string `json:"txid"`
	Vout         uint32 `json:"vout"`
	Address      string `json:"address"`
	Height       int32  `json:"height"`
	ScriptPubKey string `json:"scriptPubKey"`
	//RedeemScript  string  `json:"redeemScript,omitempty"`
	Amount        int64              `json:"amount"`
	Confirmations int64              `json:"confirmations"`
	Spendable     bool               `json:"spendable"`
	Assets        string             `json:"assets"`
	ListLockEntry []*LockEntryResult `json:"locks"`
}

ListUnspentResult models a successful response from the listunspent request.

type LockEntryResult

type LockEntryResult struct {
	Id     string `json:"id"`
	Amount int64  `json:"amount"`
}

type LogResult

type LogResult struct {
	// Consensus fields:
	// address of the contract that generated the event
	Address string `json:"address" gencodec:"required"`
	// list of topics provided by the contract.
	Topics []string `json:"topics" gencodec:"required"`
	// supplied by the contract, usually ABI-encoded
	Data string `json:"data" gencodec:"required"`

	// Derived fields. These fields are filled in by the node
	// but not secured by consensus.
	// block in which the transaction was included
	BlockNumber uint64 `json:"blockNumber"`
	// hash of the transaction
	TxHash string `json:"transactionHash" gencodec:"required"`
	// index of the transaction in the block
	TxIndex uint `json:"transactionIndex" gencodec:"required"`
	// hash of the block in which the transaction was included
	BlockHash string `json:"blockHash"`
	// index of the log in the receipt
	Index uint `json:"logIndex" gencodec:"required"`

	// The Removed field is true if this log was reverted due to a chain reorganisation.
	// You must pay attention to this field if you receive logs through a filter query.
	Removed bool `json:"removed"`
}

type MsgSignResult

type MsgSignResult struct {
	BlockHeight int32  `json:"blockheight"`
	BlockHash   string `json:"blockhash"`
	Signer      string `json:"signer"`
	Signature   string `json:"signature"`
}

MsgSignResult models the data from the GetBlock command.

type PrevOut

type PrevOut struct {
	Addresses []string `json:"addresses,omitempty"`
	Value     int64    `json:"value"`
	Asset     string   `json:"asset"`
	Data      string   `json:"data"`
}

PrevOut represents previous output for an input Vin.

type RPCError

type RPCError struct {
	Code    RPCErrorCode `json:"code,omitempty"`
	Message string       `json:"message,omitempty"`
}

RPCError represents an error that is used as a part of a JSON-RPC Response object.

func NewRPCError

func NewRPCError(code RPCErrorCode, message string) *RPCError

NewRPCError constructs and returns a new JSON-RPC error that is suitable for use in a JSON-RPC Response object.

func (RPCError) Error

func (e RPCError) Error() string

Error returns a string describing the RPC error. This satisifies the builtin error interface.

type RPCErrorCode

type RPCErrorCode int

RPCErrorCode represents an error code to be used as a part of an RPCError which is in turn used in a JSON-RPC Response object.

A specific type is used to help ensure the wrong errors aren't used.

const (
	ErrRPCMisc                RPCErrorCode = -11
	ErrRPCInvalidOutPutAmount RPCErrorCode = -12
	ErrRPCInvalidAddressOrKey RPCErrorCode = -13
	ErrRPCInvalidParameter    RPCErrorCode = -14
	ErrRPCDeserialization     RPCErrorCode = -15
)

General application defined JSON errors.

const (
	ErrRPCBlockNotFound       RPCErrorCode = -200
	ErrRPCBlockHeaderNotFound RPCErrorCode = -201
	ErrRPCBlockHeightNotFound RPCErrorCode = -202
	ErrRPCBlockHashNotFound   RPCErrorCode = -203
	ErrRPCNoTxInfo            RPCErrorCode = -204
	ErrRPCInvalidTxVout       RPCErrorCode = -205
	ErrRPCDecodeHexString     RPCErrorCode = -206
)

Specific Errors related to commands. These are the ones a user of the RPC server are most likely to see. Generally, the codes should match one of the more general errors above.

type ReceiptResult

type ReceiptResult struct {
	// Consensus fields
	PostState         string       `json:"root"`
	Status            uint64       `json:"status"`
	CumulativeGasUsed uint64       `json:"cumulativeGasUsed" gencodec:"required"`
	Bloom             string       `json:"logsBloom"         gencodec:"required"`
	Logs              []*LogResult `json:"logs"              gencodec:"required"`

	// Implementation fields (don't reorder!)
	TxHash          string `json:"transactionHash" gencodec:"required"`
	ContractAddress string `json:"contractAddress"`
	GasUsed         uint64 `json:"gasUsed" gencodec:"required"`
}

type RunTxResult

type RunTxResult struct {
	Receipt *types.Receipt     `json:"receipt"`
	GasUsed uint64             `json:"gasUsed"`
	VTX     *TxRawDecodeResult `json:"vtx"`
}

type ScriptPubKeyResult

type ScriptPubKeyResult struct {
	Asm       string   `json:"asm"`
	Hex       string   `json:"hex,omitempty"`
	ReqSigs   int32    `json:"reqSigs,omitempty"`
	Type      string   `json:"type"`
	Addresses []string `json:"addresses,omitempty"`
}

ScriptPubKeyResult models the scriptPubKey data of a tx script. It is defined separately since it is used by multiple commands.

type ScriptSig

type ScriptSig struct {
	Asm string `json:"asm"`
	Hex string `json:"hex"`
}

ScriptSig models a signature script. It is defined separately since it only applies to non-coinbase. Therefore the field in the Vin structure needs to be a pointer.

type SearchRawTransactionsResult

type SearchRawTransactionsResult struct {
	Hex           string       `json:"hex,omitempty"`
	Txid          string       `json:"txid"`
	Hash          string       `json:"hash"`
	Size          string       `json:"size"`
	Vsize         string       `json:"vsize"`
	Version       uint32       `json:"version"`
	LockTime      uint32       `json:"locktime"`
	Vin           []VinPrevOut `json:"vin"`
	Vout          []Vout       `json:"vout"`
	BlockHash     string       `json:"blockhash,omitempty"`
	Confirmations int64        `json:"confirmations,omitempty"`
	Time          int64        `json:"time,omitempty"`
	Blocktime     int64        `json:"blocktime,omitempty"`
	GasLimit      int64        `json:"gaslimit,omitempty"`
	GasUsed       int64        `json:"gasused,omitempty"`
	Fee           []FeeResult  `json:"fee,omitempty"`
}

SearchRawTransactionsResult models the data from the searchrawtransaction command.

type TestCallData

type TestCallData struct {
	Name      string  `json:"name"`
	Data      string  `json:"data"`
	Caller    string  `json:"caller"`
	Amount    uint32  `json:"amount"`
	Asset     string  `json:"asset"`
	AmountB   big.Int `json:"amountb"`
	VoteValue string  `json:"voteValue"`
}

type TestResult

type TestResult struct {
	List []CallResult `json:"list"`
}

type TransactionInput

type TransactionInput struct {
	Txid         string `json:"txid"`
	Vout         uint32 `json:"vout"`
	Assets       string `json:"assets"`
	ScriptPubKey string `json:"scriptpubkey"`
}

TransactionInput represents the inputs to a transaction. Specifically a transaction hash and output number pair.

type TransactionOutput

type TransactionOutput struct {
	Amount       string `json:"amount"`
	Assets       string `json:"assets"`
	Address      string `json:"address"`
	Data         string `json:"data"`
	ContractType string `json:"contracttype,omitempty"` //create call
}

type TxRawDecodeResult

type TxRawDecodeResult struct {
	Txid     string `json:"txid"`
	Version  uint32 `json:"version"`
	Locktime uint32 `json:"locktime"`
	Vin      []Vin  `json:"vin"`
	Vout     []Vout `json:"vout"`
}

TxRawDecodeResult models the data from the decoderawtransaction command.

type TxRawResult

type TxRawResult struct {
	Hex           string      `json:"hex"`
	Txid          string      `json:"txid"`
	Hash          string      `json:"hash,omitempty"`
	Size          int32       `json:"size,omitempty"`
	Version       uint32      `json:"version"`
	LockTime      uint32      `json:"locktime"`
	Vin           []Vin       `json:"vin"`
	Vout          []Vout      `json:"vout"`
	BlockHash     string      `json:"blockhash,omitempty"`
	Confirmations int64       `json:"confirmations,omitempty"`
	Time          int64       `json:"time,omitempty"`
	Blocktime     int64       `json:"blocktime,omitempty"`
	Fee           []FeeResult `json:"fee,omitempty"`
	GasLimit      int64       `json:"gaslimit"`
}

TxRawResult models the data from the getrawtransaction command.

type TxResult

type TxResult struct {
	Hex           string       `json:"hex"`
	Txid          string       `json:"txid"`
	Hash          string       `json:"hash,omitempty"`
	Size          int32        `json:"size,omitempty"`
	Version       uint32       `json:"version"`
	LockTime      uint32       `json:"locktime"`
	Vin           []VinPrevOut `json:"vin"`
	Vout          []Vout       `json:"vout"`
	BlockHash     string       `json:"blockhash,omitempty"`
	Confirmations int64        `json:"confirmations,omitempty"`
	Time          int64        `json:"time,omitempty"`
	Blocktime     int64        `json:"blocktime,omitempty"`
	Fee           []FeeResult  `json:"fee,omitempty"`
	GasLimit      int64        `json:"gaslimit"`
	GasUsed       int64        `json:"gasused"`
}

TxRawResult models the data from the getrawtransaction command.

type UnspentPageResult

type UnspentPageResult struct {
	ListUnspent []*ListUnspentResult `json:"utxos"`
	Count       int32                `json:"count"`
}

type Vin

type Vin struct {
	Coinbase  string     `json:"coinbase"`
	Txid      string     `json:"txid"`
	Vout      uint32     `json:"vout"`
	ScriptSig *ScriptSig `json:"scriptSig"`
	Sequence  uint32     `json:"sequence"`
}

Vin models parts of the tx data. It is defined separately since getrawtransaction, decoderawtransaction, and searchrawtransaction use the same structure.

type VinPrevOut

type VinPrevOut struct {
	Coinbase  string     `json:"coinbase"`
	Txid      string     `json:"txid"`
	Vout      uint32     `json:"vout"`
	ScriptSig *ScriptSig `json:"scriptSig"`
	PrevOut   *PrevOut   `json:"prevOut,omitempty"`
	Sequence  uint32     `json:"sequence"`
}

VinPrevOut is like Vin except it includes PrevOut. It is used by searchrawtransaction

type Vout

type Vout struct {
	Value        int64              `json:"value"`
	N            uint32             `json:"n"`
	ScriptPubKey ScriptPubKeyResult `json:"scriptPubKey"`
	Data         string             `json:"data"`
	Asset        string             `json:"asset"`
}

Vout models parts of the tx data. It is defined separately since both getrawtransaction and decoderawtransaction use the same structure.

Jump to

Keyboard shortcuts

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