rpc: remove wrappers package, move things to result

These are all RPC call results, `wrappers` package doesn't make much sense to
me.
This commit is contained in:
Roman Khimov 2020-01-13 13:21:44 +03:00
parent b8f7ab8e6a
commit 1801e545a0
11 changed files with 24 additions and 26 deletions

View file

@ -8,7 +8,7 @@ import (
"github.com/CityOfZion/neo-go/pkg/core/state" "github.com/CityOfZion/neo-go/pkg/core/state"
"github.com/CityOfZion/neo-go/pkg/core/transaction" "github.com/CityOfZion/neo-go/pkg/core/transaction"
"github.com/CityOfZion/neo-go/pkg/rpc/wrappers" "github.com/CityOfZion/neo-go/pkg/rpc/result"
"github.com/CityOfZion/neo-go/pkg/util" "github.com/CityOfZion/neo-go/pkg/util"
errs "github.com/pkg/errors" errs "github.com/pkg/errors"
) )
@ -57,7 +57,7 @@ func (s NeoScanServer) CalculateInputs(address string, assetIDUint util.Uint256,
err error err error
us []*Unspent us []*Unspent
assetUnspent Unspent assetUnspent Unspent
assetID = wrappers.GlobalAssets[assetIDUint.StringLE()] assetID = result.GlobalAssets[assetIDUint.StringLE()]
) )
if us, err = s.GetBalance(address); err != nil { if us, err = s.GetBalance(address); err != nil {
return nil, util.Fixed8(0), errs.Wrapf(err, "Cannot get balance for address %v", address) return nil, util.Fixed8(0), errs.Wrapf(err, "Cannot get balance for address %v", address)

View file

@ -1,4 +1,4 @@
package wrappers package result
import ( import (
"bytes" "bytes"

View file

@ -1,4 +1,4 @@
package wrappers package result
import ( import (
"github.com/CityOfZion/neo-go/pkg/core/state" "github.com/CityOfZion/neo-go/pkg/core/state"

View file

@ -1,4 +1,4 @@
package wrappers package result
import ( import (
"strconv" "strconv"

View file

@ -1,4 +1,4 @@
package wrappers package result
import ( import (
"github.com/CityOfZion/neo-go/pkg/core/state" "github.com/CityOfZion/neo-go/pkg/core/state"

View file

@ -1,4 +1,4 @@
package wrappers package result
import ( import (
"github.com/CityOfZion/neo-go/pkg/core/transaction" "github.com/CityOfZion/neo-go/pkg/core/transaction"

View file

@ -1,4 +1,4 @@
package wrappers package result
import ( import (
"github.com/CityOfZion/neo-go/pkg/core" "github.com/CityOfZion/neo-go/pkg/core"

View file

@ -1,4 +1,4 @@
package wrappers package result
import ( import (
"github.com/CityOfZion/neo-go/pkg/core" "github.com/CityOfZion/neo-go/pkg/core"

View file

@ -15,7 +15,6 @@ import (
"github.com/CityOfZion/neo-go/pkg/io" "github.com/CityOfZion/neo-go/pkg/io"
"github.com/CityOfZion/neo-go/pkg/network" "github.com/CityOfZion/neo-go/pkg/network"
"github.com/CityOfZion/neo-go/pkg/rpc/result" "github.com/CityOfZion/neo-go/pkg/rpc/result"
"github.com/CityOfZion/neo-go/pkg/rpc/wrappers"
"github.com/CityOfZion/neo-go/pkg/util" "github.com/CityOfZion/neo-go/pkg/util"
"github.com/pkg/errors" "github.com/pkg/errors"
"go.uber.org/zap" "go.uber.org/zap"
@ -153,7 +152,7 @@ Methods:
} }
if len(reqParams) == 2 && reqParams[1].Value == 1 { if len(reqParams) == 2 && reqParams[1].Value == 1 {
results = wrappers.NewBlock(block, s.chain) results = result.NewBlock(block, s.chain)
} else { } else {
writer := io.NewBufBinWriter() writer := io.NewBufBinWriter()
block.EncodeBinary(writer.BinWriter) block.EncodeBinary(writer.BinWriter)
@ -228,7 +227,7 @@ Methods:
as := s.chain.GetAssetState(paramAssetID) as := s.chain.GetAssetState(paramAssetID)
if as != nil { if as != nil {
results = wrappers.NewAssetState(as) results = result.NewAssetState(as)
} else { } else {
resultsErr = NewRPCError("Unknown asset", "", nil) resultsErr = NewRPCError("Unknown asset", "", nil)
} }
@ -334,10 +333,10 @@ func (s *Server) getrawtransaction(reqParams Params) (interface{}, error) {
if v == 0 || v == "0" || v == 0.0 || v == false || v == "false" { if v == 0 || v == "0" || v == 0.0 || v == false || v == "false" {
results = hex.EncodeToString(tx.Bytes()) results = hex.EncodeToString(tx.Bytes())
} else { } else {
results = wrappers.NewTransactionOutputRaw(tx, header, s.chain) results = result.NewTransactionOutputRaw(tx, header, s.chain)
} }
default: default:
results = wrappers.NewTransactionOutputRaw(tx, header, s.chain) results = result.NewTransactionOutputRaw(tx, header, s.chain)
} }
} else { } else {
results = hex.EncodeToString(tx.Bytes()) results = hex.EncodeToString(tx.Bytes())
@ -377,7 +376,7 @@ func (s *Server) getTxOut(ps Params) (interface{}, error) {
} }
out := tx.Outputs[num] out := tx.Outputs[num]
return wrappers.NewTxOutput(&out), nil return result.NewTxOutput(&out), nil
} }
// getContractState returns contract state (contract information, according to the contract script hash). // getContractState returns contract state (contract information, according to the contract script hash).
@ -392,7 +391,7 @@ func (s *Server) getContractState(reqParams Params) (interface{}, error) {
} else { } else {
cs := s.chain.GetContractState(scriptHash) cs := s.chain.GetContractState(scriptHash)
if cs != nil { if cs != nil {
results = wrappers.NewContractState(cs) results = result.NewContractState(cs)
} else { } else {
return nil, NewRPCError("Unknown contract", "", nil) return nil, NewRPCError("Unknown contract", "", nil)
} }
@ -420,9 +419,9 @@ func (s *Server) getAccountState(reqParams Params, unspents bool) (interface{},
if err != nil { if err != nil {
return nil, errInvalidParams return nil, errInvalidParams
} }
results = wrappers.NewUnspents(as, s.chain, str) results = result.NewUnspents(as, s.chain, str)
} else { } else {
results = wrappers.NewAccountState(as) results = result.NewAccountState(as)
} }
} }
return results, resultsErr return results, resultsErr

View file

@ -12,7 +12,6 @@ import (
"github.com/CityOfZion/neo-go/pkg/io" "github.com/CityOfZion/neo-go/pkg/io"
"github.com/CityOfZion/neo-go/pkg/network" "github.com/CityOfZion/neo-go/pkg/network"
"github.com/CityOfZion/neo-go/pkg/rpc/result" "github.com/CityOfZion/neo-go/pkg/rpc/result"
"github.com/CityOfZion/neo-go/pkg/rpc/wrappers"
"github.com/CityOfZion/neo-go/pkg/util" "github.com/CityOfZion/neo-go/pkg/util"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"go.uber.org/zap/zaptest" "go.uber.org/zap/zaptest"
@ -89,9 +88,9 @@ type StringResultResponse struct {
// GetBlockResponse struct for testing. // GetBlockResponse struct for testing.
type GetBlockResponse struct { type GetBlockResponse struct {
Jsonrpc string `json:"jsonrpc"` Jsonrpc string `json:"jsonrpc"`
Result wrappers.Block `json:"result"` Result result.Block `json:"result"`
ID int `json:"id"` ID int `json:"id"`
} }
// GetAssetResponse struct for testing. // GetAssetResponse struct for testing.

View file

@ -2,7 +2,7 @@ package rpc
import ( import (
"github.com/CityOfZion/neo-go/pkg/core/transaction" "github.com/CityOfZion/neo-go/pkg/core/transaction"
"github.com/CityOfZion/neo-go/pkg/rpc/wrappers" "github.com/CityOfZion/neo-go/pkg/rpc/result"
"github.com/CityOfZion/neo-go/pkg/vm" "github.com/CityOfZion/neo-go/pkg/vm"
) )
@ -31,8 +31,8 @@ type AccountStateResponse struct {
// UnspentResponse represents server response to the `getunspents` command. // UnspentResponse represents server response to the `getunspents` command.
type UnspentResponse struct { type UnspentResponse struct {
responseHeader responseHeader
Error *Error `json:"error,omitempty"` Error *Error `json:"error,omitempty"`
Result *wrappers.Unspents `json:"result,omitempty"` Result *result.Unspents `json:"result,omitempty"`
} }
// Account represents details about a NEO account. // Account represents details about a NEO account.
@ -100,7 +100,7 @@ type GetRawTxResponse struct {
type GetTxOutResponse struct { type GetTxOutResponse struct {
responseHeader responseHeader
Error *Error Error *Error
Result *wrappers.TransactionOutput Result *result.TransactionOutput
} }
// RawTxResponse stores transaction with blockchain metadata to be sent as a response. // RawTxResponse stores transaction with blockchain metadata to be sent as a response.