Skip to content

Commit

Permalink
feat: use env variable
Browse files Browse the repository at this point in the history
  • Loading branch information
omarsy committed Oct 2, 2024
1 parent 21ec6ae commit be85651
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 32 deletions.
8 changes: 5 additions & 3 deletions gno_github_agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ func main() {
if err != nil {
panic(err)
}
password := os.Getenv("GNOKEY_PASSWORD")
user := os.Getenv("GNOKEY_USER")
mnemonic := os.Getenv("GNO_MNEMONIC")
chainID := os.Getenv("GNO_CHAIN_ID")
rpcAddr := os.Getenv("GNO_RPC_ADDR")
realmPath := os.Getenv("GNO_REALM_PATH")

gnoSigner = signer.New(db, logger.Sugar(), user, password)
gnoSigner = signer.New(db, logger.Sugar(), mnemonic, chainID, rpcAddr, realmPath)

clientql := clientql.New("http://localhost:8546/graphql/query", db, logger.Sugar(), gnoSigner)
schedule := gocron.NewScheduler(time.UTC)
Expand Down
43 changes: 14 additions & 29 deletions gno_github_agent/signer/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,51 +3,38 @@ package signer
import (
"github.com/gnolang/gno/gno.land/pkg/gnoclient"
"github.com/gnolang/gno/gno.land/pkg/sdk/vm"
"github.com/gnolang/gno/gnovm/pkg/gnoenv"
rpcclient "github.com/gnolang/gno/tm2/pkg/bft/rpc/client"
"github.com/gnolang/gno/tm2/pkg/crypto/keys"
"go.uber.org/zap"
"gorm.io/gorm"
)

func (s *Signer) sign(message string) ([]byte, error) {
signature, _, err := s.kb.Sign(s.user, s.pass, []byte(message))
return signature, err
}

type Signer struct {
kb keys.Keybase
user string
pass string
db *gorm.DB
logger *zap.SugaredLogger
keyInfo keys.Info
gnoclient *gnoclient.Client
realmPath string
}

const (
plID = "test4"
plRPC = "https://rpc.gno.land:443"
ghverifyPath = "gno.land/r/gnoland/ghverify"
)

func New(db *gorm.DB, logger *zap.SugaredLogger, user, pass string) *Signer {
kb, _ := keys.NewKeyBaseFromDir(gnoenv.HomeDir())

keyInfo, err := kb.GetByName(user)
func New(db *gorm.DB,
logger *zap.SugaredLogger,
mnemonic, chainID,
rpcAddr,
realmPath string,
) *Signer {
signer, err := gnoclient.SignerFromBip39(mnemonic, chainID, "", 0, 0)
if err != nil {
panic(err)
}

signer := gnoclient.SignerFromKeybase{
Keybase: kb,
Account: "main",
Password: pass,
ChainID: plID,
keyInfo, err := signer.Info()
if err != nil {
panic(err)
}

// Initialize the RPC client
rpc, err := rpcclient.NewHTTPClient(plRPC)
rpc, err := rpcclient.NewHTTPClient(rpcAddr)
if err != nil {
panic(err)
}
Expand All @@ -59,12 +46,10 @@ func New(db *gorm.DB, logger *zap.SugaredLogger, user, pass string) *Signer {
}

return &Signer{
kb: kb,
user: user,
pass: pass,
db: db,
logger: logger,
keyInfo: keyInfo,
realmPath: realmPath,
gnoclient: &client,
}
}
Expand All @@ -87,7 +72,7 @@ func (s *Signer) CallVerify(address string) error {

_, err = s.gnoclient.Call(baseCfg, vm.MsgCall{
Caller: s.keyInfo.GetAddress(),
PkgPath: ghverifyPath,
PkgPath: s.realmPath,
Func: "GnorkleEntryPoint",
Args: []string{arg},
})
Expand Down

0 comments on commit be85651

Please sign in to comment.