-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Testing: In Hello, call execCall to add a message board reply.
Signed-off-by: Jeff Thompson <[email protected]>
- Loading branch information
Showing
1 changed file
with
80 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |