Fix imports

This commit is contained in:
Łukasz Magiera 2019-07-08 14:46:30 +02:00
parent 4ef4721820
commit 9299ba5fa6
8 changed files with 33 additions and 62 deletions

View File

@ -2,12 +2,12 @@ package client
import (
"github.com/filecoin-project/go-lotus/api"
"github.com/filecoin-project/go-lotus/lib"
"github.com/filecoin-project/go-lotus/lib/jsonrpc"
)
// NewRPC creates a new http jsonrpc client.
func NewRPC(addr string) api.API {
var res api.Struct
lib.NewClient(addr, "Filecoin", &res.Internal)
jsonrpc.NewClient(addr, "Filecoin", &res.Internal)
return &res
}

View File

@ -13,7 +13,6 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
tf "github.com/filecoin-project/go-filecoin/testhelpers/testflags"
"github.com/filecoin-project/go-lotus/lib/bls-signatures"
"github.com/filecoin-project/go-lotus/lib/crypto"
)
@ -23,8 +22,6 @@ func init() {
}
func TestRandomIDAddress(t *testing.T) {
tf.UnitTest(t)
assert := assert.New(t)
addr, err := NewIDAddress(uint64(rand.Int()))
@ -41,8 +38,6 @@ func TestRandomIDAddress(t *testing.T) {
}
func TestVectorsIDAddress(t *testing.T) {
tf.UnitTest(t)
testCases := []struct {
input uint64
expected string
@ -91,8 +86,6 @@ func TestVectorsIDAddress(t *testing.T) {
}
func TestSecp256k1Address(t *testing.T) {
tf.UnitTest(t)
assert := assert.New(t)
sk, err := crypto.GenerateKey()
@ -112,8 +105,6 @@ func TestSecp256k1Address(t *testing.T) {
}
func TestVectorSecp256k1Address(t *testing.T) {
tf.UnitTest(t)
testCases := []struct {
input []byte
expected string
@ -189,8 +180,6 @@ func TestVectorSecp256k1Address(t *testing.T) {
}
func TestRandomActorAddress(t *testing.T) {
tf.UnitTest(t)
assert := assert.New(t)
actorMsg := make([]byte, 20)
@ -210,8 +199,6 @@ func TestRandomActorAddress(t *testing.T) {
}
func TestVectorActorAddress(t *testing.T) {
tf.UnitTest(t)
testCases := []struct {
input []byte
expected string
@ -265,8 +252,6 @@ func TestVectorActorAddress(t *testing.T) {
}
func TestRandomBLSAddress(t *testing.T) {
tf.UnitTest(t)
assert := assert.New(t)
pk := bls.PrivateKeyPublicKey(bls.PrivateKeyGenerate())
@ -285,8 +270,6 @@ func TestRandomBLSAddress(t *testing.T) {
}
func TestVectorBLSAddress(t *testing.T) {
tf.UnitTest(t)
testCases := []struct {
input []byte
expected string
@ -350,8 +333,6 @@ func TestVectorBLSAddress(t *testing.T) {
}
func TestInvalidStringAddresses(t *testing.T) {
tf.UnitTest(t)
testCases := []struct {
input string
expetErr error
@ -378,8 +359,6 @@ func TestInvalidStringAddresses(t *testing.T) {
}
func TestInvalidByteAddresses(t *testing.T) {
tf.UnitTest(t)
testCases := []struct {
input []byte
expetErr error
@ -414,8 +393,6 @@ func TestInvalidByteAddresses(t *testing.T) {
}
func TestChecksum(t *testing.T) {
tf.UnitTest(t)
assert := assert.New(t)
data := []byte("helloworld")
@ -430,8 +407,6 @@ func TestChecksum(t *testing.T) {
}
func TestAddressFormat(t *testing.T) {
tf.UnitTest(t)
assert := assert.New(t)
require := require.New(t)

View File

@ -4,7 +4,7 @@ import (
"bufio"
"context"
"fmt"
"github.com/filecoin-project/go-lotus/lib"
"github.com/filecoin-project/go-lotus/lib/cborrpc"
"github.com/libp2p/go-libp2p-core/protocol"
"math/rand"
"sync"
@ -14,7 +14,6 @@ import (
cbor "github.com/ipfs/go-ipld-cbor"
inet "github.com/libp2p/go-libp2p-core/network"
"github.com/libp2p/go-libp2p-peer"
//"github.com/libp2p/go-libp2p-protocol"
)
type NewStreamFunc func(context.Context, peer.ID, ...protocol.ID) (inet.Stream, error)
@ -80,7 +79,7 @@ func (bss *BlockSyncService) HandleStream(s inet.Stream) {
log.Error("handling block sync request")
var req BlockSyncRequest
if err := lib.ReadCborRPC(bufio.NewReader(s), &req); err != nil {
if err := cborrpc.ReadCborRPC(bufio.NewReader(s), &req); err != nil {
log.Errorf("failed to read block sync request: %s", err)
return
}
@ -92,7 +91,7 @@ func (bss *BlockSyncService) HandleStream(s inet.Stream) {
return
}
if err := lib.WriteCborRPC(s, resp); err != nil {
if err := cborrpc.WriteCborRPC(s, resp); err != nil {
log.Error("failed to write back response for handle stream: ", err)
return
}
@ -326,12 +325,12 @@ func (bs *BlockSync) sendRequestToPeer(ctx context.Context, p peer.ID, req *Bloc
return nil, err
}
if err := lib.WriteCborRPC(s, req); err != nil {
if err := cborrpc.WriteCborRPC(s, req); err != nil {
return nil, err
}
var res BlockSyncResponse
if err := lib.ReadCborRPC(bufio.NewReader(s), &res); err != nil {
if err := cborrpc.ReadCborRPC(bufio.NewReader(s), &res); err != nil {
return nil, err
}

View File

@ -1,14 +1,14 @@
package daemon
import (
"github.com/filecoin-project/go-lotus/lib"
"github.com/filecoin-project/go-lotus/lib/jsonrpc"
"net/http"
"github.com/filecoin-project/go-lotus/api"
)
func serveRPC(api api.API) error {
rpcServer := lib.NewServer()
rpcServer := jsonrpc.NewServer()
rpcServer.Register("Filecoin", api)
http.Handle("/rpc/v0", rpcServer)
return http.ListenAndServe(":1234", http.DefaultServeMux)

View File

@ -6,7 +6,6 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/filecoin-project/go-lotus/lib"
"net/http"
"reflect"
"sync/atomic"
@ -41,7 +40,7 @@ type clientResponse struct {
Jsonrpc string `json:"jsonrpc"`
Result result `json:"result"`
ID int64 `json:"id"`
Error *lib.respError `json:"error,omitempty"`
Error *respError `json:"error,omitempty"`
}
// ClientCloser is used to close Client from further use
@ -73,7 +72,7 @@ func NewClient(addr string, namespace string, handler interface{}) ClientCloser
panic("handler field not a func")
}
valOut, errOut, nout := lib.processFuncOut(ftyp)
valOut, errOut, nout := processFuncOut(ftyp)
processResponse := func(resp clientResponse, code int) []reflect.Value {
out := make([]reflect.Value, nout)
@ -112,14 +111,14 @@ func NewClient(addr string, namespace string, handler interface{}) ClientCloser
fn := reflect.MakeFunc(ftyp, func(args []reflect.Value) (results []reflect.Value) {
id := atomic.AddInt64(&idCtr, 1)
params := make([]lib.param, len(args)-hasCtx)
params := make([]param, len(args)-hasCtx)
for i, arg := range args[hasCtx:] {
params[i] = lib.param{
params[i] = param{
v: arg,
}
}
req := lib.request{
req := request{
Jsonrpc: "2.0",
ID: &id,
Method: namespace + "." + f.Name,

View File

@ -4,7 +4,6 @@ import (
"bytes"
"encoding/json"
"fmt"
"github.com/filecoin-project/go-lotus/lib"
"net/http"
"reflect"
)
@ -176,7 +175,7 @@ func (s *RPCServer) Register(namespace string, r interface{}) {
funcType := method.Func.Type()
hasCtx := 0
if funcType.NumIn() >= 2 && funcType.In(1) == lib.contextType {
if funcType.NumIn() >= 2 && funcType.In(1) == contextType {
hasCtx = 1
}
@ -213,7 +212,7 @@ func processFuncOut(funcType reflect.Type) (valOut int, errOut int, n int) {
switch n {
case 0:
case 1:
if funcType.Out(0) == lib.errorType {
if funcType.Out(0) == errorType {
errOut = 0
} else {
valOut = 0
@ -221,7 +220,7 @@ func processFuncOut(funcType reflect.Type) (valOut int, errOut int, n int) {
case 2:
valOut = 0
errOut = 1
if funcType.Out(1) != lib.errorType {
if funcType.Out(1) != errorType {
panic("expected error as second return value")
}
default:

View File

@ -3,7 +3,6 @@ package jsonrpc
import (
"context"
"errors"
"github.com/filecoin-project/go-lotus/lib"
"net/http/httptest"
"strconv"
"sync"
@ -57,7 +56,7 @@ func TestRPC(t *testing.T) {
serverHandler := &SimpleServerHandler{}
rpcServer := lib.NewServer()
rpcServer := NewServer()
rpcServer.Register("SimpleServerHandler", serverHandler)
// httptest stuff
@ -71,7 +70,7 @@ func TestRPC(t *testing.T) {
AddGet func(int) int
StringMatch func(t TestType, i2 int64) (out TestOut, err error)
}
closer := lib.NewClient(testServ.URL, "SimpleServerHandler", &client)
closer := NewClient(testServ.URL, "SimpleServerHandler", &client)
defer closer()
// Add(int) error
@ -131,7 +130,7 @@ func TestRPC(t *testing.T) {
var noret struct {
Add func(int)
}
closer = lib.NewClient(testServ.URL, "SimpleServerHandler", &noret)
closer = NewClient(testServ.URL, "SimpleServerHandler", &noret)
// this one should actually work
noret.Add(4)
@ -143,7 +142,7 @@ func TestRPC(t *testing.T) {
var noparam struct {
Add func()
}
closer = lib.NewClient(testServ.URL, "SimpleServerHandler", &noparam)
closer = NewClient(testServ.URL, "SimpleServerHandler", &noparam)
// shouldn't panic
noparam.Add()
@ -152,7 +151,7 @@ func TestRPC(t *testing.T) {
var erronly struct {
AddGet func() (int, error)
}
closer = lib.NewClient(testServ.URL, "SimpleServerHandler", &erronly)
closer = NewClient(testServ.URL, "SimpleServerHandler", &erronly)
_, err = erronly.AddGet()
if err == nil || err.Error() != "RPC error (-32602): wrong param count" {
@ -163,7 +162,7 @@ func TestRPC(t *testing.T) {
var wrongtype struct {
Add func(string) error
}
closer = lib.NewClient(testServ.URL, "SimpleServerHandler", &wrongtype)
closer = NewClient(testServ.URL, "SimpleServerHandler", &wrongtype)
err = wrongtype.Add("not an int")
if err == nil || err.Error() != "RPC error (-32700): json: cannot unmarshal string into Go value of type int" {
@ -174,7 +173,7 @@ func TestRPC(t *testing.T) {
var notfound struct {
NotThere func(string) error
}
closer = lib.NewClient(testServ.URL, "SimpleServerHandler", &notfound)
closer = NewClient(testServ.URL, "SimpleServerHandler", &notfound)
err = notfound.NotThere("hello?")
if err == nil || err.Error() != "RPC error (-32601): method 'SimpleServerHandler.NotThere' not found" {
@ -208,7 +207,7 @@ func TestCtx(t *testing.T) {
serverHandler := &CtxHandler{}
rpcServer := lib.NewServer()
rpcServer := NewServer()
rpcServer.Register("CtxHandler", serverHandler)
// httptest stuff
@ -220,7 +219,7 @@ func TestCtx(t *testing.T) {
var client struct {
Test func(ctx context.Context)
}
closer := lib.NewClient(testServ.URL, "CtxHandler", &client)
closer := NewClient(testServ.URL, "CtxHandler", &client)
ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
defer cancel()
@ -240,7 +239,7 @@ func TestCtx(t *testing.T) {
var noCtxClient struct {
Test func()
}
closer = lib.NewClient(testServ.URL, "CtxHandler", &noCtxClient)
closer = NewClient(testServ.URL, "CtxHandler", &noCtxClient)
noCtxClient.Test()

View File

@ -4,7 +4,7 @@ import (
"context"
"fmt"
"github.com/filecoin-project/go-lotus/chain"
"github.com/filecoin-project/go-lotus/lib"
"github.com/filecoin-project/go-lotus/lib/cborrpc"
"github.com/libp2p/go-libp2p-core/host"
@ -46,7 +46,7 @@ func (hs *Service) HandleStream(s inet.Stream) {
defer s.Close()
var hmsg Message
if err := lib.ReadCborRPC(s, &hmsg); err != nil {
if err := cborrpc.ReadCborRPC(s, &hmsg); err != nil {
log.Infow("failed to read hello message", "error", err)
return
}
@ -91,7 +91,7 @@ func (hs *Service) SayHello(ctx context.Context, pid peer.ID) error {
fmt.Println("SENDING HELLO MESSAGE: ", hts.Cids())
fmt.Println("hello message genesis: ", gen.Cid())
if err := lib.WriteCborRPC(s, hmsg); err != nil {
if err := cborrpc.WriteCborRPC(s, hmsg); err != nil {
return err
}