rpc: merge response and request under pkg/neorpc

Move result there also.
This commit is contained in:
Roman Khimov 2022-07-22 19:09:29 +03:00
parent 2e27c3d829
commit 1e0750e3cd
55 changed files with 462 additions and 466 deletions

View file

@ -19,7 +19,7 @@ import (
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
"github.com/nspcc-dev/neo-go/pkg/rpc/response/result"
"github.com/nspcc-dev/neo-go/pkg/neorpc/result"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/nef"
"github.com/nspcc-dev/neo-go/pkg/util"

View file

@ -12,7 +12,7 @@ import (
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
"github.com/nspcc-dev/neo-go/pkg/rpc/response/result"
"github.com/nspcc-dev/neo-go/pkg/neorpc/result"
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
"github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neo-go/pkg/vm/vmstate"

View file

@ -17,7 +17,7 @@ import (
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
"github.com/nspcc-dev/neo-go/pkg/rpc/response/result"
"github.com/nspcc-dev/neo-go/pkg/neorpc/result"
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
"github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neo-go/pkg/vm"

View file

@ -21,8 +21,8 @@ import (
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
"github.com/nspcc-dev/neo-go/pkg/neorpc/result"
"github.com/nspcc-dev/neo-go/pkg/rpcclient"
"github.com/nspcc-dev/neo-go/pkg/rpc/response/result"
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/nef"

View file

@ -15,7 +15,7 @@ import (
"github.com/nspcc-dev/neo-go/pkg/core/native/nativenames"
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
"github.com/nspcc-dev/neo-go/pkg/rpc/response/result"
"github.com/nspcc-dev/neo-go/pkg/neorpc/result"
"github.com/nspcc-dev/neo-go/pkg/rpcclient"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
"github.com/nspcc-dev/neo-go/pkg/util"

View file

@ -19,7 +19,7 @@ import (
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neo-go/pkg/rpc/response/result/subscriptions"
"github.com/nspcc-dev/neo-go/pkg/neorpc/result/subscriptions"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger"
"github.com/nspcc-dev/neo-go/pkg/util"
uatomic "go.uber.org/atomic"

View file

@ -33,7 +33,7 @@ import (
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
"github.com/nspcc-dev/neo-go/pkg/io"
"github.com/nspcc-dev/neo-go/pkg/rpc/response/result/subscriptions"
"github.com/nspcc-dev/neo-go/pkg/neorpc/result/subscriptions"
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"

View file

@ -36,7 +36,7 @@ import (
"github.com/nspcc-dev/neo-go/pkg/io"
"github.com/nspcc-dev/neo-go/pkg/neotest"
"github.com/nspcc-dev/neo-go/pkg/neotest/chain"
"github.com/nspcc-dev/neo-go/pkg/rpc/response/result/subscriptions"
"github.com/nspcc-dev/neo-go/pkg/neorpc/result/subscriptions"
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger"
"github.com/nspcc-dev/neo-go/pkg/util"

View file

@ -12,7 +12,7 @@ import (
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neo-go/pkg/rpc/response/result/subscriptions"
"github.com/nspcc-dev/neo-go/pkg/neorpc/result/subscriptions"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger"
"github.com/nspcc-dev/neo-go/pkg/util"
)

View file

@ -1,4 +1,4 @@
package response
package neorpc
import (
"fmt"

View file

@ -1,4 +1,4 @@
package response
package neorpc
import (
"encoding/json"

View file

@ -1,4 +1,9 @@
package request
/*
Package neorpc contains a set of types used for JSON-RPC communication with Neo servers.
It defines basic request/response types as well as a set of errors and additional
parameters used for specific requests/responses.
*/
package neorpc
import (
"encoding/json"
@ -17,10 +22,10 @@ const (
)
type (
// Raw represents JSON-RPC request. It's generic enough to be used in many
// Request represents JSON-RPC request. It's generic enough to be used in many
// generic JSON-RPC communication scenarios, yet at the same time it's
// tailored for NeoGo RPC Client needs.
Raw struct {
Request struct {
// JSONRPC is the protocol version, only valid when it contains JSONRPCVersion.
JSONRPC string `json:"jsonrpc"`
// Method is the method being called.
@ -37,6 +42,35 @@ type (
ID uint64 `json:"id"`
}
// Header is a generic JSON-RPC 2.0 response header (ID and JSON-RPC version).
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.
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.
Response struct {
HeaderAndError
Result json.RawMessage `json:"result,omitempty"`
}
// 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.
Notification struct {
JSONRPC string `json:"jsonrpc"`
Event EventID `json:"method"`
Payload []interface{} `json:"params"`
}
// BlockFilter is a wrapper structure for the block event filter. The only
// allowed filter is primary index.
BlockFilter struct {

View file

@ -1,34 +0,0 @@
package response
import (
"encoding/json"
)
// 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"`
}
// 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"`
}

View file

@ -13,8 +13,7 @@ import (
"time"
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
"github.com/nspcc-dev/neo-go/pkg/rpc/request"
"github.com/nspcc-dev/neo-go/pkg/rpc/response"
"github.com/nspcc-dev/neo-go/pkg/neorpc"
"github.com/nspcc-dev/neo-go/pkg/util"
"go.uber.org/atomic"
)
@ -34,7 +33,7 @@ type Client struct {
endpoint *url.URL
ctx context.Context
opts Options
requestF func(*request.Raw) (*response.Raw, error)
requestF func(*neorpc.Request) (*neorpc.Response, error)
cacheLock sync.RWMutex
// cache stores RPC node related information the client is bound to.
@ -176,8 +175,8 @@ func (c *Client) performRequest(method string, p []interface{}, v interface{}) e
if p == nil {
p = []interface{}{} // neo-project/neo-modules#742
}
var r = request.Raw{
JSONRPC: request.JSONRPCVersion,
var r = neorpc.Request{
JSONRPC: neorpc.JSONRPCVersion,
Method: method,
Params: p,
ID: c.getNextRequestID(),
@ -195,10 +194,10 @@ func (c *Client) performRequest(method string, p []interface{}, v interface{}) e
return json.Unmarshal(raw.Result, v)
}
func (c *Client) makeHTTPRequest(r *request.Raw) (*response.Raw, error) {
func (c *Client) makeHTTPRequest(r *neorpc.Request) (*neorpc.Response, error) {
var (
buf = new(bytes.Buffer)
raw = new(response.Raw)
raw = new(neorpc.Response)
)
if err := json.NewEncoder(buf).Encode(r); err != nil {

View file

@ -10,8 +10,8 @@ import (
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neo-go/pkg/io"
"github.com/nspcc-dev/neo-go/pkg/neorpc/result"
"github.com/nspcc-dev/neo-go/pkg/rpcclient/nns"
"github.com/nspcc-dev/neo-go/pkg/rpc/response/result"
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
"github.com/nspcc-dev/neo-go/pkg/util"

View file

@ -11,8 +11,8 @@ import (
"github.com/nspcc-dev/neo-go/pkg/core/native/nativenames"
"github.com/nspcc-dev/neo-go/pkg/core/native/noderoles"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neo-go/pkg/neorpc/result"
"github.com/nspcc-dev/neo-go/pkg/rpcclient/nns"
"github.com/nspcc-dev/neo-go/pkg/rpc/response/result"
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
"github.com/nspcc-dev/neo-go/pkg/util"
)

View file

@ -7,7 +7,7 @@ import (
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
"github.com/nspcc-dev/neo-go/pkg/io"
"github.com/nspcc-dev/neo-go/pkg/rpc/response/result"
"github.com/nspcc-dev/neo-go/pkg/neorpc/result"
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"

View file

@ -20,9 +20,9 @@ import (
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
"github.com/nspcc-dev/neo-go/pkg/io"
"github.com/nspcc-dev/neo-go/pkg/neorpc"
"github.com/nspcc-dev/neo-go/pkg/neorpc/result"
"github.com/nspcc-dev/neo-go/pkg/network/payload"
"github.com/nspcc-dev/neo-go/pkg/rpc/request"
"github.com/nspcc-dev/neo-go/pkg/rpc/response/result"
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger"
"github.com/nspcc-dev/neo-go/pkg/util"
@ -694,9 +694,9 @@ func (c *Client) invokeSomething(method string, p []interface{}, signers []trans
if len(witnesses) != len(signers) {
return nil, fmt.Errorf("number of witnesses should match number of signers, got %d vs %d", len(witnesses), len(signers))
}
signersWithWitnesses := make([]request.SignerWithWitness, len(signers))
signersWithWitnesses := make([]neorpc.SignerWithWitness, len(signers))
for i := range signersWithWitnesses {
signersWithWitnesses[i] = request.SignerWithWitness{
signersWithWitnesses[i] = neorpc.SignerWithWitness{
Signer: signers[i],
Witness: witnesses[i],
}

View file

@ -27,7 +27,7 @@ import (
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
"github.com/nspcc-dev/neo-go/pkg/io"
"github.com/nspcc-dev/neo-go/pkg/rpc/response/result"
"github.com/nspcc-dev/neo-go/pkg/neorpc/result"
"github.com/nspcc-dev/neo-go/pkg/services/rpcsrv/params"
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"

View file

@ -13,9 +13,8 @@ import (
"github.com/nspcc-dev/neo-go/pkg/core/block"
"github.com/nspcc-dev/neo-go/pkg/core/state"
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
"github.com/nspcc-dev/neo-go/pkg/rpc/request"
"github.com/nspcc-dev/neo-go/pkg/rpc/response"
"github.com/nspcc-dev/neo-go/pkg/rpc/response/result/subscriptions"
"github.com/nspcc-dev/neo-go/pkg/neorpc"
"github.com/nspcc-dev/neo-go/pkg/neorpc/result/subscriptions"
"github.com/nspcc-dev/neo-go/pkg/util"
"go.uber.org/atomic"
)
@ -38,7 +37,7 @@ type WSClient struct {
ws *websocket.Conn
done chan struct{}
requests chan *request.Raw
requests chan *neorpc.Request
shutdown chan struct{}
closeCalled atomic.Bool
@ -49,21 +48,21 @@ type WSClient struct {
subscriptions map[string]bool
respLock sync.RWMutex
respChannels map[uint64]chan *response.Raw
respChannels map[uint64]chan *neorpc.Response
}
// Notification represents a server-generated notification for client subscriptions.
// Value can be one of block.Block, state.AppExecResult, subscriptions.NotificationEvent
// transaction.Transaction or subscriptions.NotaryRequestEvent based on Type.
type Notification struct {
Type response.EventID
Type neorpc.EventID
Value interface{}
}
// requestResponse is a combined type for request and response since we can get
// any of them here.
type requestResponse struct {
response.Raw
neorpc.Response
Method string `json:"method"`
RawParams []json.RawMessage `json:"params,omitempty"`
}
@ -103,8 +102,8 @@ func NewWS(ctx context.Context, endpoint string, opts Options) (*WSClient, error
shutdown: make(chan struct{}),
done: make(chan struct{}),
closeCalled: *atomic.NewBool(false),
respChannels: make(map[uint64]chan *response.Raw),
requests: make(chan *request.Raw),
respChannels: make(map[uint64]chan *neorpc.Response),
requests: make(chan *neorpc.Request),
subscriptions: make(map[string]bool),
}
@ -159,20 +158,20 @@ readloop:
break readloop
}
if rr.ID == nil && rr.Method != "" {
event, err := response.GetEventIDFromString(rr.Method)
event, err := neorpc.GetEventIDFromString(rr.Method)
if err != nil {
// Bad event received.
connCloseErr = fmt.Errorf("failed to perse event ID from string %s: %w", rr.Method, err)
break readloop
}
if event != response.MissedEventID && len(rr.RawParams) != 1 {
if event != neorpc.MissedEventID && len(rr.RawParams) != 1 {
// Bad event received.
connCloseErr = fmt.Errorf("bad event received: %s / %d", event, len(rr.RawParams))
break readloop
}
var val interface{}
switch event {
case response.BlockEventID:
case neorpc.BlockEventID:
sr, err := c.StateRootInHeader()
if err != nil {
// Client is not initialized.
@ -180,22 +179,22 @@ readloop:
break readloop
}
val = block.New(sr)
case response.TransactionEventID:
case neorpc.TransactionEventID:
val = &transaction.Transaction{}
case response.NotificationEventID:
case neorpc.NotificationEventID:
val = new(subscriptions.NotificationEvent)
case response.ExecutionEventID:
case neorpc.ExecutionEventID:
val = new(state.AppExecResult)
case response.NotaryRequestEventID:
case neorpc.NotaryRequestEventID:
val = new(subscriptions.NotaryRequestEvent)
case response.MissedEventID:
case neorpc.MissedEventID:
// No value.
default:
// Bad event received.
connCloseErr = fmt.Errorf("unknown event received: %d", event)
break readloop
}
if event != response.MissedEventID {
if event != neorpc.MissedEventID {
err = json.Unmarshal(rr.RawParams[0], val)
if err != nil {
// Bad event received.
@ -215,7 +214,7 @@ readloop:
connCloseErr = fmt.Errorf("unknown response channel for response %d", id)
break readloop // Unknown response (unexpected response ID).
}
ch <- &rr.Raw
ch <- &rr.Response
} else {
// Malformed response, neither valid request, nor valid response.
connCloseErr = fmt.Errorf("malformed response")
@ -284,14 +283,14 @@ func (c *WSClient) unregisterRespChannel(id uint64) {
}
}
func (c *WSClient) getResponseChannel(id uint64) chan *response.Raw {
func (c *WSClient) getResponseChannel(id uint64) chan *neorpc.Response {
c.respLock.RLock()
defer c.respLock.RUnlock()
return c.respChannels[id]
}
func (c *WSClient) makeWsRequest(r *request.Raw) (*response.Raw, error) {
ch := make(chan *response.Raw)
func (c *WSClient) makeWsRequest(r *neorpc.Request) (*neorpc.Response, error) {
ch := make(chan *neorpc.Response)
c.respLock.Lock()
select {
case <-c.done:
@ -354,7 +353,7 @@ func (c *WSClient) performUnsubscription(id string) error {
func (c *WSClient) SubscribeForNewBlocks(primary *int) (string, error) {
params := []interface{}{"block_added"}
if primary != nil {
params = append(params, request.BlockFilter{Primary: *primary})
params = append(params, neorpc.BlockFilter{Primary: *primary})
}
return c.performSubscription(params)
}
@ -365,7 +364,7 @@ func (c *WSClient) SubscribeForNewBlocks(primary *int) (string, error) {
func (c *WSClient) SubscribeForNewTransactions(sender *util.Uint160, signer *util.Uint160) (string, error) {
params := []interface{}{"transaction_added"}
if sender != nil || signer != nil {
params = append(params, request.TxFilter{Sender: sender, Signer: signer})
params = append(params, neorpc.TxFilter{Sender: sender, Signer: signer})
}
return c.performSubscription(params)
}
@ -377,7 +376,7 @@ func (c *WSClient) SubscribeForNewTransactions(sender *util.Uint160, signer *uti
func (c *WSClient) SubscribeForExecutionNotifications(contract *util.Uint160, name *string) (string, error) {
params := []interface{}{"notification_from_execution"}
if contract != nil || name != nil {
params = append(params, request.NotificationFilter{Contract: contract, Name: name})
params = append(params, neorpc.NotificationFilter{Contract: contract, Name: name})
}
return c.performSubscription(params)
}
@ -392,7 +391,7 @@ func (c *WSClient) SubscribeForTransactionExecutions(state *string) (string, err
if *state != "HALT" && *state != "FAULT" {
return "", errors.New("bad state parameter")
}
params = append(params, request.ExecutionFilter{State: *state})
params = append(params, neorpc.ExecutionFilter{State: *state})
}
return c.performSubscription(params)
}
@ -404,7 +403,7 @@ func (c *WSClient) SubscribeForTransactionExecutions(state *string) (string, err
func (c *WSClient) SubscribeForNotaryRequests(sender *util.Uint160, mainSigner *util.Uint160) (string, error) {
params := []interface{}{"notary_request_event"}
if sender != nil {
params = append(params, request.TxFilter{Sender: sender, Signer: mainSigner})
params = append(params, neorpc.TxFilter{Sender: sender, Signer: mainSigner})
}
return c.performSubscription(params)
}

View file

@ -16,8 +16,8 @@ import (
"github.com/gorilla/websocket"
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
"github.com/nspcc-dev/neo-go/pkg/neorpc"
"github.com/nspcc-dev/neo-go/pkg/network/payload"
"github.com/nspcc-dev/neo-go/pkg/rpc/request"
"github.com/nspcc-dev/neo-go/pkg/services/rpcsrv/params"
"github.com/nspcc-dev/neo-go/pkg/util"
"github.com/stretchr/testify/require"
@ -200,7 +200,7 @@ func TestWSFilteredSubscriptions(t *testing.T) {
},
func(t *testing.T, p *params.Params) {
param := p.Value(1)
filt := new(request.BlockFilter)
filt := new(neorpc.BlockFilter)
require.NoError(t, json.Unmarshal(param.RawMessage, filt))
require.Equal(t, 3, filt.Primary)
},
@ -213,7 +213,7 @@ func TestWSFilteredSubscriptions(t *testing.T) {
},
func(t *testing.T, p *params.Params) {
param := p.Value(1)
filt := new(request.TxFilter)
filt := new(neorpc.TxFilter)
require.NoError(t, json.Unmarshal(param.RawMessage, filt))
require.Equal(t, util.Uint160{1, 2, 3, 4, 5}, *filt.Sender)
require.Nil(t, filt.Signer)
@ -227,7 +227,7 @@ func TestWSFilteredSubscriptions(t *testing.T) {
},
func(t *testing.T, p *params.Params) {
param := p.Value(1)
filt := new(request.TxFilter)
filt := new(neorpc.TxFilter)
require.NoError(t, json.Unmarshal(param.RawMessage, filt))
require.Nil(t, filt.Sender)
require.Equal(t, util.Uint160{0, 42}, *filt.Signer)
@ -242,7 +242,7 @@ func TestWSFilteredSubscriptions(t *testing.T) {
},
func(t *testing.T, p *params.Params) {
param := p.Value(1)
filt := new(request.TxFilter)
filt := new(neorpc.TxFilter)
require.NoError(t, json.Unmarshal(param.RawMessage, filt))
require.Equal(t, util.Uint160{1, 2, 3, 4, 5}, *filt.Sender)
require.Equal(t, util.Uint160{0, 42}, *filt.Signer)
@ -256,7 +256,7 @@ func TestWSFilteredSubscriptions(t *testing.T) {
},
func(t *testing.T, p *params.Params) {
param := p.Value(1)
filt := new(request.NotificationFilter)
filt := new(neorpc.NotificationFilter)
require.NoError(t, json.Unmarshal(param.RawMessage, filt))
require.Equal(t, util.Uint160{1, 2, 3, 4, 5}, *filt.Contract)
require.Nil(t, filt.Name)
@ -270,7 +270,7 @@ func TestWSFilteredSubscriptions(t *testing.T) {
},
func(t *testing.T, p *params.Params) {
param := p.Value(1)
filt := new(request.NotificationFilter)
filt := new(neorpc.NotificationFilter)
require.NoError(t, json.Unmarshal(param.RawMessage, filt))
require.Equal(t, "my_pretty_notification", *filt.Name)
require.Nil(t, filt.Contract)
@ -285,7 +285,7 @@ func TestWSFilteredSubscriptions(t *testing.T) {
},
func(t *testing.T, p *params.Params) {
param := p.Value(1)
filt := new(request.NotificationFilter)
filt := new(neorpc.NotificationFilter)
require.NoError(t, json.Unmarshal(param.RawMessage, filt))
require.Equal(t, util.Uint160{1, 2, 3, 4, 5}, *filt.Contract)
require.Equal(t, "my_pretty_notification", *filt.Name)
@ -299,7 +299,7 @@ func TestWSFilteredSubscriptions(t *testing.T) {
},
func(t *testing.T, p *params.Params) {
param := p.Value(1)
filt := new(request.ExecutionFilter)
filt := new(neorpc.ExecutionFilter)
require.NoError(t, json.Unmarshal(param.RawMessage, filt))
require.Equal(t, "FAULT", filt.State)
},

View file

@ -26,8 +26,8 @@ import (
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
"github.com/nspcc-dev/neo-go/pkg/io"
"github.com/nspcc-dev/neo-go/pkg/neorpc/result"
"github.com/nspcc-dev/neo-go/pkg/network"
"github.com/nspcc-dev/neo-go/pkg/rpc/response/result"
"github.com/nspcc-dev/neo-go/pkg/rpcclient"
"github.com/nspcc-dev/neo-go/pkg/rpcclient/nns"
"github.com/nspcc-dev/neo-go/pkg/smartcontract"

View file

@ -3,25 +3,25 @@ package rpcsrv
import (
"net/http"
"github.com/nspcc-dev/neo-go/pkg/rpc/response"
"github.com/nspcc-dev/neo-go/pkg/neorpc"
)
// abstractResult is an interface which represents either single JSON-RPC 2.0 response
// or batch JSON-RPC 2.0 response.
type abstractResult interface {
RunForErrors(f func(jsonErr *response.Error))
RunForErrors(f func(jsonErr *neorpc.Error))
}
// abstract represents abstract JSON-RPC 2.0 response. It is used as a server-side response
// representation.
type abstract struct {
response.Header
Error *response.Error `json:"error,omitempty"`
Result interface{} `json:"result,omitempty"`
neorpc.Header
Error *neorpc.Error `json:"error,omitempty"`
Result interface{} `json:"result,omitempty"`
}
// RunForErrors implements abstractResult interface.
func (a abstract) RunForErrors(f func(jsonErr *response.Error)) {
func (a abstract) RunForErrors(f func(jsonErr *neorpc.Error)) {
if a.Error != nil {
f(a.Error)
}
@ -31,7 +31,7 @@ func (a abstract) RunForErrors(f func(jsonErr *response.Error)) {
type abstractBatch []abstract
// RunForErrors implements abstractResult interface.
func (ab abstractBatch) RunForErrors(f func(jsonErr *response.Error)) {
func (ab abstractBatch) RunForErrors(f func(jsonErr *neorpc.Error)) {
for _, a := range ab {
if a.Error != nil {
f(a.Error)
@ -39,16 +39,16 @@ func (ab abstractBatch) RunForErrors(f func(jsonErr *response.Error)) {
}
}
func getHTTPCodeForError(respErr *response.Error) int {
func getHTTPCodeForError(respErr *neorpc.Error) int {
var httpCode int
switch respErr.Code {
case response.BadRequestCode:
case neorpc.BadRequestCode:
httpCode = http.StatusBadRequest
case response.InvalidRequestCode, response.RPCErrorCode, response.InvalidParamsCode:
case neorpc.InvalidRequestCode, neorpc.RPCErrorCode, neorpc.InvalidParamsCode:
httpCode = http.StatusUnprocessableEntity
case response.MethodNotFoundCode:
case neorpc.MethodNotFoundCode:
httpCode = http.StatusMethodNotAllowed
case response.InternalServerErrorCode:
case neorpc.InternalServerErrorCode:
httpCode = http.StatusInternalServerError
default:
httpCode = http.StatusUnprocessableEntity

View file

@ -14,7 +14,7 @@ import (
"github.com/google/uuid"
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
"github.com/nspcc-dev/neo-go/pkg/rpc/request"
"github.com/nspcc-dev/neo-go/pkg/neorpc"
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
"github.com/nspcc-dev/neo-go/pkg/util"
)
@ -380,13 +380,13 @@ func (p *Param) GetBytesBase64() ([]byte, error) {
return base64.StdEncoding.DecodeString(s)
}
// GetSignerWithWitness returns a request.SignerWithWitness value of the parameter.
func (p *Param) GetSignerWithWitness() (request.SignerWithWitness, error) {
// GetSignerWithWitness returns a neorpc.SignerWithWitness value of the parameter.
func (p *Param) GetSignerWithWitness() (neorpc.SignerWithWitness, error) {
// This one doesn't need to be cached, it's used only once.
c := request.SignerWithWitness{}
c := neorpc.SignerWithWitness{}
err := json.Unmarshal(p.RawMessage, &c)
if err != nil {
return request.SignerWithWitness{}, fmt.Errorf("not a signer: %w", err)
return neorpc.SignerWithWitness{}, fmt.Errorf("not a signer: %w", err)
}
return c, nil
}

View file

@ -12,7 +12,7 @@ import (
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
"github.com/nspcc-dev/neo-go/pkg/rpc/request"
"github.com/nspcc-dev/neo-go/pkg/neorpc"
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
"github.com/nspcc-dev/neo-go/pkg/util"
"github.com/stretchr/testify/assert"
@ -155,7 +155,7 @@ func TestParam_UnmarshalJSON(t *testing.T) {
require.NoError(t, err)
expectedAcc, err := util.Uint160DecodeStringLE("cadb3dc2faa3ef14a13b619c9a43124755aa2569")
require.NoError(t, err)
require.Equal(t, request.SignerWithWitness{Signer: transaction.Signer{Account: expectedAcc}}, actual)
require.Equal(t, neorpc.SignerWithWitness{Signer: transaction.Signer{Account: expectedAcc}}, actual)
},
expectedRawMessage: []byte(`{"account": "0xcadb3dc2faa3ef14a13b619c9a43124755aa2569"}`),
},
@ -165,7 +165,7 @@ func TestParam_UnmarshalJSON(t *testing.T) {
require.NoError(t, err)
expectedAcc, err := address.StringToUint160("NYxb4fSZVKAz8YsgaPK2WkT3KcAE9b3Vag")
require.NoError(t, err)
require.Equal(t, request.SignerWithWitness{Signer: transaction.Signer{Account: expectedAcc, Scopes: transaction.Global}}, actual)
require.Equal(t, neorpc.SignerWithWitness{Signer: transaction.Signer{Account: expectedAcc, Scopes: transaction.Global}}, actual)
},
expectedRawMessage: []byte(`{"account": "NYxb4fSZVKAz8YsgaPK2WkT3KcAE9b3Vag", "scopes": "Global"}`),
},
@ -244,21 +244,21 @@ func TestGetWitness(t *testing.T) {
testCases := []struct {
raw string
expected request.SignerWithWitness
expected neorpc.SignerWithWitness
}{
{`{"account": "0xcadb3dc2faa3ef14a13b619c9a43124755aa2569"}`, request.SignerWithWitness{
{`{"account": "0xcadb3dc2faa3ef14a13b619c9a43124755aa2569"}`, neorpc.SignerWithWitness{
Signer: transaction.Signer{
Account: accountHash,
Scopes: transaction.None,
}},
},
{`{"account": "NYxb4fSZVKAz8YsgaPK2WkT3KcAE9b3Vag", "scopes": "Global"}`, request.SignerWithWitness{
{`{"account": "NYxb4fSZVKAz8YsgaPK2WkT3KcAE9b3Vag", "scopes": "Global"}`, neorpc.SignerWithWitness{
Signer: transaction.Signer{
Account: addrHash,
Scopes: transaction.Global,
}},
},
{`{"account": "0xcadb3dc2faa3ef14a13b619c9a43124755aa2569", "scopes": "Global"}`, request.SignerWithWitness{
{`{"account": "0xcadb3dc2faa3ef14a13b619c9a43124755aa2569", "scopes": "Global"}`, neorpc.SignerWithWitness{
Signer: transaction.Signer{
Account: accountHash,
Scopes: transaction.Global,
@ -405,7 +405,7 @@ func TestParamGetBytesBase64(t *testing.T) {
}
func TestParamGetSigner(t *testing.T) {
c := request.SignerWithWitness{
c := neorpc.SignerWithWitness{
Signer: transaction.Signer{
Account: util.Uint160{1, 2, 3, 4},
Scopes: transaction.Global,

View file

@ -7,7 +7,7 @@ import (
"fmt"
"io"
"github.com/nspcc-dev/neo-go/pkg/rpc/request"
"github.com/nspcc-dev/neo-go/pkg/neorpc"
)
const (
@ -106,6 +106,6 @@ func NewRequest() *Request {
// NewIn creates a new In struct.
func NewIn() *In {
return &In{
JSONRPC: request.JSONRPCVersion,
JSONRPC: neorpc.JSONRPCVersion,
}
}

File diff suppressed because it is too large Load diff

View file

@ -33,12 +33,12 @@ import (
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
"github.com/nspcc-dev/neo-go/pkg/io"
"github.com/nspcc-dev/neo-go/pkg/neorpc"
"github.com/nspcc-dev/neo-go/pkg/neorpc/result"
"github.com/nspcc-dev/neo-go/pkg/network"
"github.com/nspcc-dev/neo-go/pkg/network/payload"
"github.com/nspcc-dev/neo-go/pkg/rpc/response"
"github.com/nspcc-dev/neo-go/pkg/rpc/response/result"
"github.com/nspcc-dev/neo-go/pkg/services/rpcsrv/params"
rpc2 "github.com/nspcc-dev/neo-go/pkg/services/oracle/broadcaster"
"github.com/nspcc-dev/neo-go/pkg/services/rpcsrv/params"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger"
"github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
@ -1928,11 +1928,11 @@ func testRPCProtocol(t *testing.T, doRPCCall func(string, string, *testing.T) []
}
resultRPC = `[` + resultRPC[:len(resultRPC)-1] + `]`
body := doRPCCall(resultRPC, httpSrv.URL, t)
var responses []response.Raw
var responses []neorpc.Response
err := json.Unmarshal(body, &responses)
require.Nil(t, err)
for i, tc := range cases {
var resp response.Raw
var resp neorpc.Response
for _, r := range responses {
if bytes.Equal(r.ID, []byte(strconv.Itoa(i))) {
resp = r
@ -2478,7 +2478,7 @@ func (tc rpcTestCase) getResultPair(e *executor) (expected interface{}, res inte
}
func checkErrGetResult(t *testing.T, body []byte, expectingFail bool, expectedErr ...string) json.RawMessage {
var resp response.Raw
var resp neorpc.Response
err := json.Unmarshal(body, &resp)
require.Nil(t, err)
if expectingFail {
@ -2495,7 +2495,7 @@ func checkErrGetResult(t *testing.T, body []byte, expectingFail bool, expectedEr
}
func checkErrGetBatchResult(t *testing.T, body []byte, expectingFail bool) json.RawMessage {
var resp []response.Raw
var resp []neorpc.Response
err := json.Unmarshal(body, &resp)
require.Nil(t, err)
require.Equal(t, 1, len(resp))

View file

@ -5,9 +5,8 @@ import (
"github.com/nspcc-dev/neo-go/pkg/core/block"
"github.com/nspcc-dev/neo-go/pkg/core/state"
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
"github.com/nspcc-dev/neo-go/pkg/rpc/request"
"github.com/nspcc-dev/neo-go/pkg/rpc/response"
"github.com/nspcc-dev/neo-go/pkg/rpc/response/result/subscriptions"
"github.com/nspcc-dev/neo-go/pkg/neorpc"
"github.com/nspcc-dev/neo-go/pkg/neorpc/result/subscriptions"
"go.uber.org/atomic"
)
@ -24,7 +23,7 @@ type (
feeds [maxFeeds]feed
}
feed struct {
event response.EventID
event neorpc.EventID
filter interface{}
}
)
@ -44,7 +43,7 @@ const (
notificationBufSize = 1024
)
func (f *feed) Matches(r *response.Notification) bool {
func (f *feed) Matches(r *neorpc.Notification) bool {
if r.Event != f.event {
return false
}
@ -52,12 +51,12 @@ func (f *feed) Matches(r *response.Notification) bool {
return true
}
switch f.event {
case response.BlockEventID:
filt := f.filter.(request.BlockFilter)
case neorpc.BlockEventID:
filt := f.filter.(neorpc.BlockFilter)
b := r.Payload[0].(*block.Block)
return int(b.PrimaryIndex) == filt.Primary
case response.TransactionEventID:
filt := f.filter.(request.TxFilter)
case neorpc.TransactionEventID:
filt := f.filter.(neorpc.TxFilter)
tx := r.Payload[0].(*transaction.Transaction)
senderOK := filt.Sender == nil || tx.Sender().Equals(*filt.Sender)
signerOK := true
@ -71,18 +70,18 @@ func (f *feed) Matches(r *response.Notification) bool {
}
}
return senderOK && signerOK
case response.NotificationEventID:
filt := f.filter.(request.NotificationFilter)
case neorpc.NotificationEventID:
filt := f.filter.(neorpc.NotificationFilter)
notification := r.Payload[0].(*subscriptions.NotificationEvent)
hashOk := filt.Contract == nil || notification.ScriptHash.Equals(*filt.Contract)
nameOk := filt.Name == nil || notification.Name == *filt.Name
return hashOk && nameOk
case response.ExecutionEventID:
filt := f.filter.(request.ExecutionFilter)
case neorpc.ExecutionEventID:
filt := f.filter.(neorpc.ExecutionFilter)
applog := r.Payload[0].(*state.AppExecResult)
return applog.VMState.String() == filt.State
case response.NotaryRequestEventID:
filt := f.filter.(request.TxFilter)
case neorpc.NotaryRequestEventID:
filt := f.filter.(neorpc.TxFilter)
req := r.Payload[0].(*subscriptions.NotaryRequestEvent)
senderOk := filt.Sender == nil || req.NotaryRequest.FallbackTransaction.Signers[1].Account == *filt.Sender
signerOK := true

View file

@ -11,7 +11,7 @@ import (
"github.com/nspcc-dev/neo-go/internal/testchain"
"github.com/nspcc-dev/neo-go/pkg/core"
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
"github.com/nspcc-dev/neo-go/pkg/rpc/response"
"github.com/nspcc-dev/neo-go/pkg/neorpc"
"github.com/stretchr/testify/require"
"go.uber.org/atomic"
)
@ -36,8 +36,8 @@ func wsReader(t *testing.T, ws *websocket.Conn, msgCh chan<- []byte, isFinished
}
}
func callWSGetRaw(t *testing.T, ws *websocket.Conn, msg string, respCh <-chan []byte) *response.Raw {
var resp = new(response.Raw)
func callWSGetRaw(t *testing.T, ws *websocket.Conn, msg string, respCh <-chan []byte) *neorpc.Response {
var resp = new(neorpc.Response)
require.NoError(t, ws.SetWriteDeadline(time.Now().Add(time.Second)))
require.NoError(t, ws.WriteMessage(websocket.TextMessage, []byte(msg)))
@ -47,8 +47,8 @@ func callWSGetRaw(t *testing.T, ws *websocket.Conn, msg string, respCh <-chan []
return resp
}
func getNotification(t *testing.T, respCh <-chan []byte) *response.Notification {
var resp = new(response.Notification)
func getNotification(t *testing.T, respCh <-chan []byte) *neorpc.Notification {
var resp = new(neorpc.Notification)
body := <-respCh
require.NoError(t, json.Unmarshal(body, resp))
return resp
@ -107,10 +107,10 @@ func TestSubscriptions(t *testing.T) {
for _, b := range getTestBlocks(t) {
require.NoError(t, chain.AddBlock(b))
resp := getNotification(t, respMsgs)
require.Equal(t, response.ExecutionEventID, resp.Event)
require.Equal(t, neorpc.ExecutionEventID, resp.Event)
for {
resp = getNotification(t, respMsgs)
if resp.Event != response.NotificationEventID {
if resp.Event != neorpc.NotificationEventID {
break
}
}
@ -118,25 +118,25 @@ func TestSubscriptions(t *testing.T) {
if i > 0 {
resp = getNotification(t, respMsgs)
}
require.Equal(t, response.ExecutionEventID, resp.Event)
require.Equal(t, neorpc.ExecutionEventID, resp.Event)
for {
resp := getNotification(t, respMsgs)
if resp.Event == response.NotificationEventID {
if resp.Event == neorpc.NotificationEventID {
continue
}
require.Equal(t, response.TransactionEventID, resp.Event)
require.Equal(t, neorpc.TransactionEventID, resp.Event)
break
}
}
resp = getNotification(t, respMsgs)
require.Equal(t, response.ExecutionEventID, resp.Event)
require.Equal(t, neorpc.ExecutionEventID, resp.Event)
for {
resp = getNotification(t, respMsgs)
if resp.Event != response.NotificationEventID {
if resp.Event != neorpc.NotificationEventID {
break
}
}
require.Equal(t, response.BlockEventID, resp.Event)
require.Equal(t, neorpc.BlockEventID, resp.Event)
}
// We should manually add NotaryRequest to test notification.
@ -145,7 +145,7 @@ func TestSubscriptions(t *testing.T) {
require.NoError(t, err)
for {
resp := getNotification(t, respMsgs)
if resp.Event == response.NotaryRequestEventID {
if resp.Event == neorpc.NotaryRequestEventID {
break
}
}
@ -163,22 +163,22 @@ func TestFilteredSubscriptions(t *testing.T) {
var cases = map[string]struct {
params string
check func(*testing.T, *response.Notification)
check func(*testing.T, *neorpc.Notification)
}{
"tx matching sender": {
params: `["transaction_added", {"sender":"` + goodSender.StringLE() + `"}]`,
check: func(t *testing.T, resp *response.Notification) {
check: func(t *testing.T, resp *neorpc.Notification) {
rmap := resp.Payload[0].(map[string]interface{})
require.Equal(t, response.TransactionEventID, resp.Event)
require.Equal(t, neorpc.TransactionEventID, resp.Event)
sender := rmap["sender"].(string)
require.Equal(t, address.Uint160ToString(goodSender), sender)
},
},
"tx matching signer": {
params: `["transaction_added", {"signer":"` + goodSender.StringLE() + `"}]`,
check: func(t *testing.T, resp *response.Notification) {
check: func(t *testing.T, resp *neorpc.Notification) {
rmap := resp.Payload[0].(map[string]interface{})
require.Equal(t, response.TransactionEventID, resp.Event)
require.Equal(t, neorpc.TransactionEventID, resp.Event)
signers := rmap["signers"].([]interface{})
signer0 := signers[0].(map[string]interface{})
signer0acc := signer0["account"].(string)
@ -187,9 +187,9 @@ func TestFilteredSubscriptions(t *testing.T) {
},
"tx matching sender and signer": {
params: `["transaction_added", {"sender":"` + goodSender.StringLE() + `", "signer":"` + goodSender.StringLE() + `"}]`,
check: func(t *testing.T, resp *response.Notification) {
check: func(t *testing.T, resp *neorpc.Notification) {
rmap := resp.Payload[0].(map[string]interface{})
require.Equal(t, response.TransactionEventID, resp.Event)
require.Equal(t, neorpc.TransactionEventID, resp.Event)
sender := rmap["sender"].(string)
require.Equal(t, address.Uint160ToString(goodSender), sender)
signers := rmap["signers"].([]interface{})
@ -200,27 +200,27 @@ func TestFilteredSubscriptions(t *testing.T) {
},
"notification matching contract hash": {
params: `["notification_from_execution", {"contract":"` + testContractHash + `"}]`,
check: func(t *testing.T, resp *response.Notification) {
check: func(t *testing.T, resp *neorpc.Notification) {
rmap := resp.Payload[0].(map[string]interface{})
require.Equal(t, response.NotificationEventID, resp.Event)
require.Equal(t, neorpc.NotificationEventID, resp.Event)
c := rmap["contract"].(string)
require.Equal(t, "0x"+testContractHash, c)
},
},
"notification matching name": {
params: `["notification_from_execution", {"name":"my_pretty_notification"}]`,
check: func(t *testing.T, resp *response.Notification) {
check: func(t *testing.T, resp *neorpc.Notification) {
rmap := resp.Payload[0].(map[string]interface{})
require.Equal(t, response.NotificationEventID, resp.Event)
require.Equal(t, neorpc.NotificationEventID, resp.Event)
n := rmap["name"].(string)
require.Equal(t, "my_pretty_notification", n)
},
},
"notification matching contract hash and name": {
params: `["notification_from_execution", {"contract":"` + testContractHash + `", "name":"my_pretty_notification"}]`,
check: func(t *testing.T, resp *response.Notification) {
check: func(t *testing.T, resp *neorpc.Notification) {
rmap := resp.Payload[0].(map[string]interface{})
require.Equal(t, response.NotificationEventID, resp.Event)
require.Equal(t, neorpc.NotificationEventID, resp.Event)
c := rmap["contract"].(string)
require.Equal(t, "0x"+testContractHash, c)
n := rmap["name"].(string)
@ -229,28 +229,28 @@ func TestFilteredSubscriptions(t *testing.T) {
},
"execution matching": {
params: `["transaction_executed", {"state":"HALT"}]`,
check: func(t *testing.T, resp *response.Notification) {
check: func(t *testing.T, resp *neorpc.Notification) {
rmap := resp.Payload[0].(map[string]interface{})
require.Equal(t, response.ExecutionEventID, resp.Event)
require.Equal(t, neorpc.ExecutionEventID, resp.Event)
st := rmap["vmstate"].(string)
require.Equal(t, "HALT", st)
},
},
"tx non-matching": {
params: `["transaction_added", {"sender":"00112233445566778899aabbccddeeff00112233"}]`,
check: func(t *testing.T, _ *response.Notification) {
check: func(t *testing.T, _ *neorpc.Notification) {
t.Fatal("unexpected match for EnrollmentTransaction")
},
},
"notification non-matching": {
params: `["notification_from_execution", {"contract":"00112233445566778899aabbccddeeff00112233"}]`,
check: func(t *testing.T, _ *response.Notification) {
check: func(t *testing.T, _ *neorpc.Notification) {
t.Fatal("unexpected match for contract 00112233445566778899aabbccddeeff00112233")
},
},
"execution non-matching": {
params: `["transaction_executed", {"state":"FAULT"}]`,
check: func(t *testing.T, _ *response.Notification) {
check: func(t *testing.T, _ *neorpc.Notification) {
t.Fatal("unexpected match for faulted execution")
},
},
@ -276,7 +276,7 @@ func TestFilteredSubscriptions(t *testing.T) {
for {
resp := getNotification(t, respMsgs)
rmap := resp.Payload[0].(map[string]interface{})
if resp.Event == response.BlockEventID {
if resp.Event == neorpc.BlockEventID {
index := rmap["index"].(float64)
if uint32(index) == lastBlock {
break
@ -302,13 +302,13 @@ func TestFilteredNotaryRequestSubscriptions(t *testing.T) {
var cases = map[string]struct {
params string
check func(*testing.T, *response.Notification)
check func(*testing.T, *neorpc.Notification)
}{
"matching sender": {
params: `["notary_request_event", {"sender":"` + goodSender.StringLE() + `"}]`,
check: func(t *testing.T, resp *response.Notification) {
check: func(t *testing.T, resp *neorpc.Notification) {
rmap := resp.Payload[0].(map[string]interface{})
require.Equal(t, response.NotaryRequestEventID, resp.Event)
require.Equal(t, neorpc.NotaryRequestEventID, resp.Event)
require.Equal(t, "added", rmap["type"].(string))
req := rmap["notaryrequest"].(map[string]interface{})
fbTx := req["fallbacktx"].(map[string]interface{})
@ -318,9 +318,9 @@ func TestFilteredNotaryRequestSubscriptions(t *testing.T) {
},
"matching signer": {
params: `["notary_request_event", {"signer":"` + goodSender.StringLE() + `"}]`,
check: func(t *testing.T, resp *response.Notification) {
check: func(t *testing.T, resp *neorpc.Notification) {
rmap := resp.Payload[0].(map[string]interface{})
require.Equal(t, response.NotaryRequestEventID, resp.Event)
require.Equal(t, neorpc.NotaryRequestEventID, resp.Event)
require.Equal(t, "added", rmap["type"].(string))
req := rmap["notaryrequest"].(map[string]interface{})
mainTx := req["maintx"].(map[string]interface{})
@ -332,9 +332,9 @@ func TestFilteredNotaryRequestSubscriptions(t *testing.T) {
},
"matching sender and signer": {
params: `["notary_request_event", {"sender":"` + goodSender.StringLE() + `", "signer":"` + goodSender.StringLE() + `"}]`,
check: func(t *testing.T, resp *response.Notification) {
check: func(t *testing.T, resp *neorpc.Notification) {
rmap := resp.Payload[0].(map[string]interface{})
require.Equal(t, response.NotaryRequestEventID, resp.Event)
require.Equal(t, neorpc.NotaryRequestEventID, resp.Event)
require.Equal(t, "added", rmap["type"].(string))
req := rmap["notaryrequest"].(map[string]interface{})
mainTx := req["maintx"].(map[string]interface{})
@ -370,7 +370,7 @@ func TestFilteredNotaryRequestSubscriptions(t *testing.T) {
require.NoError(t, err)
nonce++
var resp = new(response.Notification)
var resp = new(neorpc.Notification)
select {
case body := <-respMsgs:
require.NoError(t, json.Unmarshal(body, resp))
@ -378,7 +378,7 @@ func TestFilteredNotaryRequestSubscriptions(t *testing.T) {
t.Fatal("timeout waiting for event")
}
require.Equal(t, response.NotaryRequestEventID, resp.Event)
require.Equal(t, neorpc.NotaryRequestEventID, resp.Event)
this.check(t, resp)
callUnsubscribe(t, c, respMsgs, subID)
@ -410,7 +410,7 @@ func TestFilteredBlockSubscriptions(t *testing.T) {
}
for i := 0; i < expectedCnt; i++ {
var resp = new(response.Notification)
var resp = new(neorpc.Notification)
select {
case body := <-respMsgs:
require.NoError(t, json.Unmarshal(body, resp))
@ -418,7 +418,7 @@ func TestFilteredBlockSubscriptions(t *testing.T) {
t.Fatal("timeout waiting for event")
}
require.Equal(t, response.BlockEventID, resp.Event)
require.Equal(t, neorpc.BlockEventID, resp.Event)
rmap := resp.Payload[0].(map[string]interface{})
primary := rmap["primary"].(float64)
require.Equal(t, 3, int(primary))
@ -565,8 +565,8 @@ func TestSubscriptionOverflow(t *testing.T) {
}
for i := 0; i < blockCnt; i++ {
resp := getNotification(t, respMsgs)
if resp.Event != response.BlockEventID {
require.Equal(t, response.MissedEventID, resp.Event)
if resp.Event != neorpc.BlockEventID {
require.Equal(t, neorpc.MissedEventID, resp.Event)
receivedMiss = true
break
}

View file

@ -1,7 +1,7 @@
package rpcsrv
import (
"github.com/nspcc-dev/neo-go/pkg/rpc/response/result"
"github.com/nspcc-dev/neo-go/pkg/neorpc/result"
)
// tokenTransfers is a generic type used to represent NEP-11 and NEP-17 transfers.