webrpc

package
v0.0.0-...-9802667 Latest Latest
Warning

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

Go to latest
Published: May 27, 2018 License: Apache-2.0 Imports: 18 Imported by: 0

README

JSON 2.0 RPC API Documentation

WARNING: The JSON-RPC 2.0 API interface is deprecated. Do not interface with it directly

This is a description about spo webrpc, which implemented the json-rpc 2.0 protocol. The rpc service entry point is /webrpc, and only accept the HTTP POST requests. The rpc service is exposed on port 8630.

Get Status

Get status of rpc server.

request:

{
    "id": "1",
    "jsonrpc": "2.0",
    "method": "get_status"
}

Get last blocks

Get last N blocks.

request:

{
    "id": "1",
    "jsonrpc": "2.0",
    "method": "get_lastblocks",
    "params": [3]
}

The params must be an array with one integer value.

Get blocks

Get blocks in specific range, inclusive.

request:

{
    "id": "1",
    "jsonrpc": "2.0",
    "method": "get_blocks",
    "params": [2, 10]
}

The params must be an array with two integer values.

Get blocks by sequence number

Get blocks at specific sequence numbers.

request:

{
    "id": "1",
    "jsonrpc": "2.0",
    "method": "get_blocks",
    "params": [133, 401, 212]
}

The params must be an array of integer values.

Get outputs

Get unspent outputs of specific addresses.

request:

{
    "id": "1",
    "jsonrpc": "2.0",
    "method": "get_outputs",
    "params": ["fyqX5YuwXMUs4GEUE3LjLyhrqvNztFHQ4C", "fyqX5YuwXMUs4GEUE3LjLyhrqvNztFHQ4B"]
}

The params must be an array of strings.

Inject transaction

Broadcast raw transaction.

request:

{
    "id": "1",
    "jsonrpc": "2.0",
    "method": "inject_transaction",
    "params": ["dc0000000010e05181fd4023f865a84359bf72a304e687b6f00e42f93ad9a4b8ee5a64aabc01000000dcb5b236eecd97a36c7d0a0b8ed68bb5df6274433a51fddf911f02f3926d20bf6eaabdc21529b7696f498545b06cc7e69f2f08b4dc5fa823c5b3f03da06794a300010000006d8a9c89177ce5e9d3b4b59fff67c00f0471fdebdfbb368377841b03fc7d688b02000000005771eeda2e253697cf5368f16fe05210d5cd319040420f0000000000af010000000000000060dfa95881cdc827b45a6d49b11dbc152ecd4de600093d0000000000af01000000000000"]
}

The params must be an array with one raw transaction string.

Get transaction

Get transaction verbose info of specific transaction id.

request:

{
    "id": "1",
    "jsonrpc": "2.0",
    "method": "get_transaction",
    "params": ["bdc4a85a3e9d17a8fe00aa7430d0347c7f1dd6480a16da7147b6e43905057d43"]
}

The params must be an array with one txid string.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrJSONUnmarshal = errors.New("JSON unmarshal failed")

ErrJSONUnmarshal is returned if JSON unmarshal fails

Functions

This section is empty.

Types

type AddrUxoutResult

type AddrUxoutResult struct {
	Address string                 `json:"address"`
	UxOuts  []*historydb.UxOutJSON `json:"uxouts"`
}

AddrUxoutResult the address uxout json format

type Client

type Client struct {
	Addr string
	// contains filtered or unexported fields
}

Client is an RPC client

func (*Client) Do

func (c *Client) Do(obj interface{}, method string, params interface{}) error

Do makes an RPC request

func (*Client) GetAddressUxOuts

func (c *Client) GetAddressUxOuts(addrs []string) ([]AddrUxoutResult, error)

GetAddressUxOuts returns unspent outputs for a set of addresses TODO -- what is the difference between this and GetUnspentOutputs?

func (*Client) GetBlocks

func (c *Client) GetBlocks(start, end uint64) (*visor.ReadableBlocks, error)

GetBlocks returns a range of blocks

func (*Client) GetBlocksBySeq

func (c *Client) GetBlocksBySeq(ss []uint64) (*visor.ReadableBlocks, error)

GetBlocksBySeq returns blocks for a set of block sequences (heights)

func (*Client) GetLastBlocks

func (c *Client) GetLastBlocks(n uint64) (*visor.ReadableBlocks, error)

GetLastBlocks returns the last n blocks

func (*Client) GetStatus

func (c *Client) GetStatus() (*StatusResult, error)

GetStatus returns status info for a spo node

func (*Client) GetTransactionByID

func (c *Client) GetTransactionByID(txid string) (*TxnResult, error)

GetTransactionByID returns a transaction given a txid

func (*Client) GetUnspentOutputs

func (c *Client) GetUnspentOutputs(addrs []string) (*OutputsResult, error)

GetUnspentOutputs returns unspent outputs for a set of addresses TODO -- what is the difference between this and GetAddressUxOuts?

func (*Client) InjectTransaction

func (c *Client) InjectTransaction(tx *coin.Transaction) (string, error)

InjectTransaction injects a *coin.Transaction to the network

func (*Client) InjectTransactionString

func (c *Client) InjectTransactionString(rawtx string) (string, error)

InjectTransactionString injects a hex-encoded transaction string to the network

type Config

type Config struct {
	ReadTimeout  time.Duration
	WriteTimeout time.Duration
	IdleTimeout  time.Duration
	WorkerNum    uint
	ChanBuffSize uint // size of ops channel
}

Config configures the WebRPC

type Gatewayer

type Gatewayer interface {
	GetLastBlocks(num uint64) (*visor.ReadableBlocks, error)
	GetBlocks(start, end uint64) (*visor.ReadableBlocks, error)
	GetBlocksInDepth(vs []uint64) (*visor.ReadableBlocks, error)
	GetUnspentOutputs(filters ...daemon.OutputsFilter) (*visor.ReadableOutputSet, error)
	GetTransaction(txid cipher.SHA256) (*visor.Transaction, error)
	InjectBroadcastTransaction(tx coin.Transaction) error
	GetAddrUxOuts(addr []cipher.Address) ([]*historydb.UxOut, error)
	GetTimeNow() uint64
}

Gatewayer provides interfaces for getting spo related info.

type HandlerFunc

type HandlerFunc func(req Request, gateway Gatewayer) Response

HandlerFunc represents the function type for processing the request

type OutputsResult

type OutputsResult struct {
	Outputs visor.ReadableOutputSet `json:"outputs"`
}

OutputsResult the output json format

type RPCError

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

RPCError response error

func (RPCError) Error

func (e RPCError) Error() string

type Request

type Request struct {
	ID      string          `json:"id"`
	Jsonrpc string          `json:"jsonrpc"`
	Method  string          `json:"method"`
	Params  json.RawMessage `json:"params,omitempty"`
}

Request rpc request struct

func NewRequest

func NewRequest(method string, params interface{}, id string) (*Request, error)

NewRequest create new webrpc request.

func (*Request) DecodeParams

func (r *Request) DecodeParams(v interface{}) error

DecodeParams decodes request params to specific value.

type Response

type Response struct {
	ID      *string         `json:"id"`
	Jsonrpc string          `json:"jsonrpc"`
	Error   *RPCError       `json:"error,omitempty"`
	Result  json.RawMessage `json:"result,omitempty"`
}

Response rpc response struct

func Do

func Do(req *Request, rpcAddress string) (*Response, error)

Do send request to web

type StatusResult

type StatusResult struct {
	Running            bool   `json:"running"`
	BlockNum           uint64 `json:"num_of_blocks"`
	LastBlockHash      string `json:"hash_of_last_block"`
	TimeSinceLastBlock string `json:"time_since_last_block"`
}

StatusResult result struct of get_status

type TxIDJson

type TxIDJson struct {
	Txid string `json:"txid"`
}

TxIDJson wraps txid with json tags

type TxnResult

type TxnResult struct {
	Transaction *visor.TransactionResult `json:"transaction"`
}

TxnResult wraps the visor.TransactionResult

type WebRPC

type WebRPC struct {
	Addr         string // service address
	Gateway      Gatewayer
	WorkerNum    uint
	ChanBuffSize uint // size of ops channel
	// contains filtered or unexported fields
}

WebRPC manage the web rpc state and handles

func New

func New(addr string, c Config, gw Gatewayer) (*WebRPC, error)

New returns a new WebRPC object

func (*WebRPC) HandleFunc

func (rpc *WebRPC) HandleFunc(method string, h HandlerFunc) error

HandleFunc registers handler function

func (*WebRPC) Handler

func (rpc *WebRPC) Handler(w http.ResponseWriter, r *http.Request)

Handler processes the http request

func (*WebRPC) Run

func (rpc *WebRPC) Run() error

Run starts the webrpc service.

func (*WebRPC) Shutdown

func (rpc *WebRPC) Shutdown() error

Shutdown close the webrpc service

Jump to

Keyboard shortcuts

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