chat2: Start to replace node with rpc client

This commit is contained in:
Oskar Thoren 2021-06-10 19:07:28 +08:00
parent 8aba5da260
commit e44e3414f2
No known key found for this signature in database
GPG Key ID: B2ECCFD3BC2EF77E
2 changed files with 11 additions and 4 deletions

View File

@ -7,13 +7,14 @@ import (
"time"
"log"
"github.com/ethereum/go-ethereum/rpc"
"github.com/golang/protobuf/proto"
"github.com/libp2p/go-libp2p-core/peer"
"github.com/status-im/go-waku/waku/v2/node"
wpb "github.com/status-im/go-waku/waku/v2/protocol/pb"
"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
@ -26,6 +27,7 @@ type Chat struct {
sub *node.Subscription
// TODO Replace with wrapper
//node *node.WakuNode
client *rpc.Client
self peer.ID
contentTopic string
@ -35,7 +37,7 @@ type Chat struct {
// NewChat tries to subscribe to the PubSub topic for the room name, returning
// 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
// TODO Do this with JSON RPC
// sub, err := n.Subscribe(nil)

View File

@ -22,6 +22,8 @@ import (
// TODO Replace with wrapper
// "github.com/status-im/go-waku/waku/v2/node"
// "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"
@ -62,6 +64,10 @@ func main() {
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()
// TODO Replace with wrapper
// wakuNode, err := node.New(ctx,
@ -86,9 +92,8 @@ func main() {
// join the chat
// Same as above
//chat, err := NewChat(wakuNode, wakuNode.Host().ID(), *contentTopicFlag, *payloadV1Flag, nick)
// 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 {
panic(err)
}