chat2: Start to replace node with rpc client
This commit is contained in:
parent
8aba5da260
commit
e44e3414f2
|
@ -7,13 +7,14 @@ import (
|
||||||
"time"
|
"time"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/rpc"
|
||||||
"github.com/golang/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
"github.com/libp2p/go-libp2p-core/peer"
|
"github.com/libp2p/go-libp2p-core/peer"
|
||||||
"github.com/status-im/go-waku/waku/v2/node"
|
"github.com/status-im/go-waku/waku/v2/node"
|
||||||
wpb "github.com/status-im/go-waku/waku/v2/protocol/pb"
|
wpb "github.com/status-im/go-waku/waku/v2/protocol/pb"
|
||||||
"golang.org/x/crypto/pbkdf2"
|
"golang.org/x/crypto/pbkdf2"
|
||||||
|
|
||||||
"github.com/status-im/go-nwaku/nwaku"
|
// "github.com/status-im/go-nwaku/nwaku"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Chat represents a subscription to a single PubSub topic. Messages
|
// Chat represents a subscription to a single PubSub topic. Messages
|
||||||
|
@ -26,6 +27,7 @@ type Chat struct {
|
||||||
sub *node.Subscription
|
sub *node.Subscription
|
||||||
// TODO Replace with wrapper
|
// TODO Replace with wrapper
|
||||||
//node *node.WakuNode
|
//node *node.WakuNode
|
||||||
|
client *rpc.Client
|
||||||
|
|
||||||
self peer.ID
|
self peer.ID
|
||||||
contentTopic string
|
contentTopic string
|
||||||
|
@ -35,7 +37,7 @@ type Chat struct {
|
||||||
|
|
||||||
// NewChat tries to subscribe to the PubSub topic for the room name, returning
|
// NewChat tries to subscribe to the PubSub topic for the room name, returning
|
||||||
// a ChatRoom on success.
|
// a ChatRoom on success.
|
||||||
func NewChat(selfID peer.ID, contentTopic string, useV1Payload bool, nickname string) (*Chat, error) {
|
func NewChat(client *rpc.Client, selfID peer.ID, contentTopic string, useV1Payload bool, nickname string) (*Chat, error) {
|
||||||
// join the default waku topic and subscribe to it
|
// join the default waku topic and subscribe to it
|
||||||
// TODO Do this with JSON RPC
|
// TODO Do this with JSON RPC
|
||||||
// sub, err := n.Subscribe(nil)
|
// sub, err := n.Subscribe(nil)
|
||||||
|
|
|
@ -22,6 +22,8 @@ import (
|
||||||
// TODO Replace with wrapper
|
// TODO Replace with wrapper
|
||||||
// "github.com/status-im/go-waku/waku/v2/node"
|
// "github.com/status-im/go-waku/waku/v2/node"
|
||||||
// "github.com/status-im/go-waku/waku/v2/protocol/store"
|
// "github.com/status-im/go-waku/waku/v2/protocol/store"
|
||||||
|
"github.com/ethereum/go-ethereum/rpc"
|
||||||
|
//"github.com/status-im/go-nwaku/nwaku"
|
||||||
)
|
)
|
||||||
|
|
||||||
var DefaultContentTopic string = "/toy-chat/2/huilong/proto"
|
var DefaultContentTopic string = "/toy-chat/2/huilong/proto"
|
||||||
|
@ -62,6 +64,10 @@ func main() {
|
||||||
|
|
||||||
log.Printf("NYI prvKey use", prvKey)
|
log.Printf("NYI prvKey use", prvKey)
|
||||||
|
|
||||||
|
// TODO Start wrapper node
|
||||||
|
// Assumes node started
|
||||||
|
client, _ := rpc.Dial("http://127.0.0.1:8545")
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
// TODO Replace with wrapper
|
// TODO Replace with wrapper
|
||||||
// wakuNode, err := node.New(ctx,
|
// wakuNode, err := node.New(ctx,
|
||||||
|
@ -86,9 +92,8 @@ func main() {
|
||||||
|
|
||||||
// join the chat
|
// join the chat
|
||||||
// Same as above
|
// Same as above
|
||||||
//chat, err := NewChat(wakuNode, wakuNode.Host().ID(), *contentTopicFlag, *payloadV1Flag, nick)
|
|
||||||
// TODO Replace wakuNode
|
// TODO Replace wakuNode
|
||||||
chat, err := NewChat("go-nwaku-test", *contentTopicFlag, *payloadV1Flag, nick)
|
chat, err := NewChat(client, "go-nwaku-test", *contentTopicFlag, *payloadV1Flag, nick)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue