Skip to content

Commit

Permalink
add generic rmb call to griddriver
Browse files Browse the repository at this point in the history
Co-authored-by: omarabdulasis <[email protected]>
  • Loading branch information
MarioBassem and Omarabdul3ziz committed Oct 15, 2023
1 parent fa6de26 commit 6bb56f6
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
41 changes: 41 additions & 0 deletions griddriver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,47 @@ func main() {
},
Action: deployVM(),
},
{
Name: "rmb",
Usage: "Make RMB call",
Flags: []cli.Flag{
cli.StringFlag{
Name: "substrate",
Value: "wss://tfchain.grid.tf/ws",
Usage: "substrate URL",
Required: true,
},
cli.StringFlag{
Name: "mnemonics",
Value: "",
Usage: "user mnemonics",
Required: true,
},
cli.StringFlag{
Name: "relay",
Value: "wss://relay.grid.tf/ws",
Usage: "relay URL",
Required: true,
},
cli.UintFlag{
Name: "dst",
Value: 0,
Usage: "destination node",
Required: true,
},
cli.StringFlag{
Name: "cmd",
Usage: "rmb command",
Required: true,
},
cli.StringFlag{
Name: "payload",
Value: "",
Usage: "command payload",
},
},
Action: rmbDecorator(rmbCall),
},
},
}

Expand Down
26 changes: 26 additions & 0 deletions griddriver/rmb.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,32 @@ func rmbDecorator(action func(c *cli.Context, client *direct.RpcCLient) (interfa
}
}

func rmbCall(c *cli.Context, client *direct.RpcCLient) (interface{}, error) {
dst := uint32(c.Uint("dst"))
cmd := c.String("cmd")
payload := c.String("payload")

ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
defer cancel()

var pl interface{}
if err := json.Unmarshal([]byte(payload), &pl); err != nil {
return nil, err
}

var res interface{}
if err := client.Call(ctx, dst, cmd, pl, &res); err != nil {
return nil, err
}

b, err := json.Marshal(res)
if err != nil {
return nil, err
}

return string(b), nil
}

func deploymentChanges(c *cli.Context, client *direct.RpcCLient) (interface{}, error) {
dst := uint32(c.Uint("dst"))
contractID := c.Uint64("contract_id")
Expand Down

0 comments on commit 6bb56f6

Please sign in to comment.