neoneo-go/pkg/rpc/response/types.go
Roman Khimov fc22a46a4c rpc/server: add notification subscription
Note that the protocol differs a bit from #895 in its notifications format,
to avoid additional server-side processing we're omitting some metadata like:
 * block size and confirmations
 * transaction fees, confirmations, block hash and timestamp
 * application execution doesn't have ScriptHash populated

Some block fields may also differ in encoding compared to `getblock` results
(like nonce field).

I think these differences are unnoticieable for most use cases, so we can
leave them as is, but it can be changed in the future.
2020-05-26 11:36:47 +03:00

48 lines
1.3 KiB
Go

package response
import (
"encoding/json"
"github.com/nspcc-dev/neo-go/pkg/rpc/response/result"
)
// Header is a generic JSON-RPC 2.0 response header (ID and JSON-RPC version).
type Header struct {
ID json.RawMessage `json:"id"`
JSONRPC string `json:"jsonrpc"`
}
// HeaderAndError adds an Error (that can be empty) to the Header, it's used
// to construct type-specific responses.
type HeaderAndError struct {
Header
Error *Error `json:"error,omitempty"`
}
// Raw represents a standard raw JSON-RPC 2.0
// response: http://www.jsonrpc.org/specification#response_object.
type Raw struct {
HeaderAndError
Result json.RawMessage `json:"result,omitempty"`
}
// GetTxOut represents result of `gettxout` RPC call.
type GetTxOut struct {
HeaderAndError
Result *result.TransactionOutput
}
// GetRawTx represents verbose output of `getrawtransaction` RPC call.
type GetRawTx struct {
HeaderAndError
Result *result.TransactionOutputRaw `json:"result"`
}
// Notification is a type used to represent wire format of events, they're
// special in that they look like requests but they don't have IDs and their
// "method" is actually an event name.
type Notification struct {
JSONRPC string `json:"jsonrpc"`
Event EventID `json:"method"`
Payload []interface{} `json:"params"`
}