2022-07-21 13:21:44 +00:00
|
|
|
package rpcsrv
|
2022-06-09 15:19:01 +00:00
|
|
|
|
|
|
|
import (
|
2022-07-22 16:09:29 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/neorpc"
|
2022-06-09 15:19:01 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// abstractResult is an interface which represents either single JSON-RPC 2.0 response
|
|
|
|
// or batch JSON-RPC 2.0 response.
|
|
|
|
type abstractResult interface {
|
2022-07-22 16:09:29 +00:00
|
|
|
RunForErrors(f func(jsonErr *neorpc.Error))
|
2022-06-09 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// abstract represents abstract JSON-RPC 2.0 response. It is used as a server-side response
|
|
|
|
// representation.
|
|
|
|
type abstract struct {
|
2022-07-22 16:09:29 +00:00
|
|
|
neorpc.Header
|
|
|
|
Error *neorpc.Error `json:"error,omitempty"`
|
2023-04-03 10:34:24 +00:00
|
|
|
Result any `json:"result,omitempty"`
|
2022-06-09 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// RunForErrors implements abstractResult interface.
|
2022-07-22 16:09:29 +00:00
|
|
|
func (a abstract) RunForErrors(f func(jsonErr *neorpc.Error)) {
|
2022-06-09 15:19:01 +00:00
|
|
|
if a.Error != nil {
|
2022-06-10 13:26:33 +00:00
|
|
|
f(a.Error)
|
2022-06-09 15:19:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// abstractBatch represents abstract JSON-RPC 2.0 batch-response.
|
|
|
|
type abstractBatch []abstract
|
|
|
|
|
|
|
|
// RunForErrors implements abstractResult interface.
|
2022-07-22 16:09:29 +00:00
|
|
|
func (ab abstractBatch) RunForErrors(f func(jsonErr *neorpc.Error)) {
|
2022-06-09 15:19:01 +00:00
|
|
|
for _, a := range ab {
|
2024-08-24 12:36:57 +00:00
|
|
|
a.RunForErrors(f)
|
2022-06-09 15:19:01 +00:00
|
|
|
}
|
|
|
|
}
|