Skip to content

Commit

Permalink
chore: Testing: In Hello, call execCall to add a message board reply.
Browse files Browse the repository at this point in the history
Signed-off-by: Jeff Thompson <[email protected]>
  • Loading branch information
jefft0 committed Aug 17, 2023
1 parent 01f8c6a commit 3b7be34
Showing 1 changed file with 80 additions and 2 deletions.
82 changes: 80 additions & 2 deletions framework/gnokey.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,90 @@
package gnomobile

import "fmt"
import (
"fmt"

"github.com/gnolang/gno/tm2/pkg/crypto/keys"
"github.com/gnolang/gno/tm2/pkg/crypto/keys/client"
)

type PromiseBlock interface {
CallResolve(reply string)
CallReject(error error)
}

type accountAndTxCfg struct {
TxCfg *makeTxCfg

KeyName string
Password string
}

func Hello(name string) string {
return fmt.Sprintf("Hello, %s", name)
cfg := getAccountAndTxCfg()

// Debug: We should only have to do this once. It seems that the Keybase dir is deleted when we reinstall the app.
kb, err := keys.NewKeyBaseFromDir(cfg.TxCfg.rootCfg.Home)
if err != nil {
return fmt.Sprintf("Error: unable to open Keybase: %s", err.Error())
}
_, err = kb.CreateAccount(cfg.KeyName,
"enable until hover project know foam join table educate room better scrub clever powder virus army pitch ranch fix try cupboard scatter dune fee",
"", cfg.Password, uint32(0), uint32(0))
if err != nil {
return fmt.Sprintf("Error: unable to create account: %s", err.Error())
}

message := "Hello from GnoMobile demo"
err = callCreateReply(cfg, "2", "1", "1", message)
if err != nil {
return fmt.Sprintf("Error: unable to exec call command: %s", err.Error())
}

return fmt.Sprintf("Posted: %s", message)
}

func getAccountAndTxCfg() *accountAndTxCfg {
dataDir := "data"
remote := "testnet.gno.berty.io:26657"
chainID := "dev"
keyName := "jefft0"
password := "password"

return &accountAndTxCfg{
TxCfg: &makeTxCfg{
rootCfg: &baseCfg{
BaseOptions: client.BaseOptions{
Home: dataDir,
Remote: remote,
},
},
gasWanted: 2000000,
gasFee: "1000000ugnot",

broadcast: true,
chainID: chainID,
},
KeyName: keyName,
Password: password,
}
}

func callCreateThread(cfg *accountAndTxCfg, boardId string, title string, body string) error {
callCfg := &callCfg{
rootCfg: cfg.TxCfg,
pkgPath: "gno.land/r/demo/boards",
funcName: "CreateThread",
args: []string{boardId, title, body},
}
return execCall(callCfg, cfg.KeyName, cfg.Password)
}

func callCreateReply(cfg *accountAndTxCfg, boardId string, threadId string, postId string, body string) error {
callCfg := &callCfg{
rootCfg: cfg.TxCfg,
pkgPath: "gno.land/r/demo/boards",
funcName: "CreateReply",
args: []string{boardId, threadId, postId, body},
}
return execCall(callCfg, cfg.KeyName, cfg.Password)
}

0 comments on commit 3b7be34

Please sign in to comment.