Skip to content

Commit 0fda763

Browse files
committed
replace chain with registrar in rmb client
1 parent 8188c09 commit 0fda763

File tree

14 files changed

+211
-117
lines changed

14 files changed

+211
-117
lines changed

rmb-sdk-go/README.md

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,35 +21,8 @@ This connection could be established using a `direct-client`, or an `rmb-peer`.
2121
A process could connect to an `rmb-relay` using a direct client.\
2222
To create a new direct client instance, a process needs to have:
2323

24-
- A valid mnemonics, with an activated account on the TFChain.
24+
- A valid private key, with an activated account on the Registrar.
2525
- The key type of these mnemonics.
2626
- A relay URL that the direct client will connect to.
2727
- A session id. This could be anything, but a twin must only have a unique session id per connection.
2828
- A substrate connection.
29-
30-
#### **Example**
31-
32-
Creating a new direct client instance:
33-
34-
```Go
35-
subManager := substrate.NewManager("wss://tfchain.dev.grid.tf/ws")
36-
sub, err := subManager.Substrate()
37-
if err != nil {
38-
return fmt.Errorf("failed to connect to substrate: %w", err)
39-
}
40-
41-
defer sub.Close()
42-
client, err := direct.NewRpcClient(direct.KeyTypeSr25519, mnemonics, "wss://relay.dev.grid.tf", "test-client", sub, false)
43-
if err != nil {
44-
return fmt.Errorf("failed to create direct client: %w", err)
45-
}
46-
```
47-
48-
Assuming there is a remote calculator process that could add two integers, an rmb call using the direct client would look like this:
49-
50-
```Go
51-
x := 1
52-
y := 2
53-
var sum int
54-
err := client.Call(ctx, destinationTwinID, "calculator.add", []int{x, y}, &sum)
55-
```

rmb-sdk-go/examples/rpc_client/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This is a `Go` example for the `RMB` [rpc client](https://github.com/threefoldte
66

77
To use the example, you needs to:
88

9-
- Set the mnemonics variable to a valid mnemonics, with an activated account on the TFChain.
9+
- Set the private key variable to a valid private key, with an activated account on the Registrar.
1010
- A node id to send the call to
1111

1212
## Usage

rmb-sdk-go/examples/rpc_client/main.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ package main
22

33
import (
44
"context"
5+
"encoding/hex"
56
"fmt"
67
"log"
78
"time"
89

9-
substrate "github.com/threefoldtech/tfchain/clients/tfchain-client-go"
1010
"github.com/threefoldtech/tfgrid-sdk-go/rmb-sdk-go/peer"
1111
)
1212

@@ -16,13 +16,20 @@ type version struct {
1616
}
1717

1818
func app() error {
19-
mnemonics := "<mnemonics goes here>"
20-
subNodeURL := "wss://tfchain.dev.grid.tf/ws"
21-
relayURL := "wss://relay.dev.grid.tf"
19+
privateKey := "<private key goes here>"
2220

23-
subManager := substrate.NewManager(subNodeURL)
21+
privateKeyBytes, err := hex.DecodeString(privateKey)
22+
if err != nil {
23+
return fmt.Errorf("failed to decode private key: %w", err)
24+
}
2425

25-
client, err := peer.NewRpcClient(context.Background(), mnemonics, subManager, peer.WithRelay(relayURL), peer.WithSession("test-client"))
26+
client, err := peer.NewRpcClient(
27+
context.Background(),
28+
privateKeyBytes,
29+
peer.WithRegistrarUrl("https://registrar.dev4.grid.tf"),
30+
peer.WithRelay("wss://relay.dev.grid.tf"),
31+
peer.WithSession("test-client"),
32+
)
2633
if err != nil {
2734
return fmt.Errorf("failed to create direct client: %w", err)
2835
}

rmb-sdk-go/peer/examples/peer/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This is a `Go` example for the `RMB` [direct client](https://github.com/threefol
66

77
To use the example, you needs to:
88

9-
- Set the mnemonics variable to a valid mnemonics, with an activated account on the TFChain.
9+
- Set the mnemonics variable to a valid mnemonics, with an activated account on the Registrar.
1010
- Set dst to the twinId of a remote calculator process that could add two integers
1111

1212
## Usage

rmb-sdk-go/peer/examples/peer/main.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,36 @@ package main
22

33
import (
44
"context"
5+
"encoding/hex"
56
"fmt"
67
"math/rand"
78

89
"github.com/google/uuid"
910
"github.com/rs/zerolog/log"
10-
substrate "github.com/threefoldtech/tfchain/clients/tfchain-client-go"
1111
"github.com/threefoldtech/tfgrid-sdk-go/rmb-sdk-go/peer"
1212
"github.com/threefoldtech/tfgrid-sdk-go/rmb-sdk-go/peer/types"
1313
)
1414

1515
var resultsChan = make(chan bool)
1616

1717
func app() error {
18-
mnemonics := "<mnemonics goes here>"
19-
subManager := substrate.NewManager("wss://tfchain.dev.grid.tf/ws")
18+
privateKey := "<private key here>"
2019
ctx := context.Background()
2120

21+
privateKeyBytes, err := hex.DecodeString(privateKey)
22+
if err != nil {
23+
return fmt.Errorf("failed to decode private key: %w", err)
24+
}
25+
2226
peer, err := peer.NewPeer(
2327
ctx,
24-
mnemonics,
25-
subManager,
28+
privateKeyBytes,
2629
relayCallback,
30+
peer.WithRegistrarUrl("https://registrar.dev4.grid.tf"),
2731
peer.WithRelay("wss://relay.dev.grid.tf"),
2832
peer.WithSession("test-client"),
2933
peer.WithInMemoryExpiration(6*60*60), // six hours
34+
peer.WithKeyType(peer.KeyTypeEd25519),
3035
)
3136

3237
if err != nil {

rmb-sdk-go/peer/examples/peer_pingmany/main.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"context"
5+
"encoding/hex"
56
"encoding/json"
67
"fmt"
78
"net/http"
@@ -10,17 +11,14 @@ import (
1011
"time"
1112

1213
"github.com/rs/zerolog/log"
13-
substrate "github.com/threefoldtech/tfchain/clients/tfchain-client-go"
1414

1515
"github.com/threefoldtech/tfgrid-sdk-go/rmb-sdk-go/peer"
1616
"github.com/threefoldtech/tfgrid-sdk-go/rmb-sdk-go/peer/types"
17-
// "rmbClient/peer"
1817
)
1918

2019
const (
21-
chainUrl = "wss://tfchain.grid.tf/"
22-
relayUrl = "ws://localhost:"
23-
mnemonic = "<mnemonic>"
20+
relayUrl = "ws://localhost:"
21+
privateKey = "<private key>"
2422
)
2523

2624
type Node struct {
@@ -32,8 +30,6 @@ var static = []uint32{7, 9, 10, 13, 14, 16, 22, 23, 24, 27, 29, 35, 46, 47, 69,
3230
const use_static = true
3331

3432
func main() {
35-
subMan := substrate.NewManager(chainUrl)
36-
3733
count := 500
3834
var wg sync.WaitGroup
3935
wg.Add(count)
@@ -59,10 +55,16 @@ func main() {
5955
log.Info().Uint32("twin", env.Source.Twin).Str("version", version).Msg("received response")
6056
}
6157

58+
privateKeyBytes, err := hex.DecodeString(privateKey)
59+
if err != nil {
60+
log.Error().Err(err).Msg("failed to decode private key")
61+
return
62+
}
63+
6264
bus, err := peer.NewPeer(context.Background(),
63-
mnemonic,
64-
subMan,
65+
privateKeyBytes,
6566
handler,
67+
peer.WithRegistrarUrl("https://registrar.dev4.grid.tf"),
6668
peer.WithKeyType(peer.KeyTypeSr25519),
6769
peer.WithSession("rmb-playground999"),
6870
peer.WithInMemoryExpiration(10*60*60), // in seconds that's 10 hours

rmb-sdk-go/peer/examples/router_server/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This is a `Go` example for the `RMB` [peer router using direct client](https://g
66

77
To use the example, you needs to:
88

9-
- Set the mnemonics variable to a valid mnemonics for client peer and server, with an activated account on the TFChain.
9+
- Set the mnemonics variable to a valid mnemonics for client peer and server, with an activated account on the Registrar.
1010
- set the client peer destination twin and session with the ones of the created peer router.
1111
- make sure you are running the server before the client peer.
1212

rmb-sdk-go/peer/examples/router_server/main.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ package main
22

33
import (
44
"context"
5+
"encoding/hex"
56
"encoding/json"
67
"errors"
78
"fmt"
89
"os"
910

10-
substrate "github.com/threefoldtech/tfchain/clients/tfchain-client-go"
1111
"github.com/threefoldtech/tfgrid-sdk-go/rmb-sdk-go"
1212
"github.com/threefoldtech/tfgrid-sdk-go/rmb-sdk-go/peer"
1313
)
@@ -59,20 +59,25 @@ func app() error {
5959
})
6060

6161
// adding a peer for the router
62-
mnemonics := "<mnemonics goes here>"
63-
subManager := substrate.NewManager("wss://tfchain.dev.grid.tf/ws")
62+
privateKey := "<private key here>"
6463
ctx := context.Background()
6564

65+
privateKeyBytes, err := hex.DecodeString(privateKey)
66+
if err != nil {
67+
return fmt.Errorf("failed to decode private key: %w", err)
68+
}
69+
6670
// this peer will be a 'calculator' session.
6771
// means other peers on the network need to know that
6872
// session id to use when they are making calls
69-
_, err := peer.NewPeer(
73+
_, err = peer.NewPeer(
7074
ctx,
71-
mnemonics,
72-
subManager,
75+
privateKeyBytes,
7376
router.Serve,
77+
peer.WithRegistrarUrl("https://registrar.dev4.grid.tf"),
7478
peer.WithRelay("wss://relay.dev.grid.tf"),
7579
peer.WithSession("calculator"),
80+
peer.WithKeyType(peer.KeyTypeEd25519),
7681
)
7782

7883
if err != nil {

rmb-sdk-go/peer/examples/rpc/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This is a `Go` example for the `RMB` [rpc client](https://github.com/threefoldte
66

77
To use the example, you needs to:
88

9-
- Set the mnemonics variable to a valid mnemonics, with an activated account on the TFChain.
9+
- Set the mnemonics variable to a valid mnemonics, with an activated account on the Registrar.
1010
- A twinId of a remote calculator process that could add two integers
1111

1212
## Usage

rmb-sdk-go/peer/examples/rpc/main.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,27 @@ package main
22

33
import (
44
"context"
5+
"encoding/hex"
56
"fmt"
67
"time"
78

89
"log"
910

10-
substrate "github.com/threefoldtech/tfchain/clients/tfchain-client-go"
1111
"github.com/threefoldtech/tfgrid-sdk-go/rmb-sdk-go/peer"
1212
)
1313

1414
func app() error {
15-
mnemonics := "<mnemonics goes here>"
16-
subManager := substrate.NewManager("wss://tfchain.dev.grid.tf/ws")
15+
privateKey := "<private key goes here>"
16+
17+
privateKeyBytes, err := hex.DecodeString(privateKey)
18+
if err != nil {
19+
return fmt.Errorf("failed to decode private key: %w", err)
20+
}
1721

1822
client, err := peer.NewRpcClient(
1923
context.Background(),
20-
mnemonics,
21-
subManager,
24+
privateKeyBytes,
25+
peer.WithRegistrarUrl("https://registrar.dev4.grid.tf"),
2226
peer.WithKeyType(peer.KeyTypeSr25519),
2327
peer.WithRelay("wss://relay.dev.grid.tf"),
2428
peer.WithSession("test-client"),

0 commit comments

Comments
 (0)