Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP]feat: Protocol to support contract-contract interaction #473

Draft
wants to merge 21 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions examples/gno.land/r/demo/x/calls/await/greet/greet.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package greet

func Greet(name string, country string, age int8, isSomething bool) string {

//chainID := std.GetChainID()
//call := std.EncodeMsgCall(chainID, "gno.land/r/demo/x/calls/await/hola", "Hola", []string{"hola"})
//
//r, err := std.Await(call)
//println("done ")
//println("r is :", r)
//println("errMsg is: ", err)
//return "greet" + r

println("name is: ", name)
println("country is: ", country)
println("age is: ", age)
println("isSomething is: ", isSomething)

return "greet"
}
16 changes: 16 additions & 0 deletions examples/gno.land/r/demo/x/calls/await/hello_ibc/hello_ibc.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package hello

import "std"

func Hello() string {

chainID := "remote"
call := std.EncodeMsgCall(chainID, "gno.land/r/demo/x/calls/await/greet", "Greet", []string{"hey"})

r, err := std.Await(call)
println("done ")
println("r is :", r)
println("errMsg is: ", err)

return "hello" + r
}
16 changes: 16 additions & 0 deletions examples/gno.land/r/demo/x/calls/await/hello_vm/hello_vm.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package hello

import "std"

func Hello() string {

chainID := std.GetChainID()
call := std.EncodeMsgCall(chainID, "gno.land/r/demo/x/calls/await/greet", "Greet", []string{"\"first\"", "\"hey\"", "0", "false"})

r, err := std.Await(call)
println("done ")
println("r is :", r)
println("errMsg is: ", err)

return "hello" + r
}
6 changes: 6 additions & 0 deletions examples/gno.land/r/demo/x/calls/await/hola/hola.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package hola

func Hola(msg string) string {
return "hola"
}

3 changes: 2 additions & 1 deletion tm2/pkg/sdk/vm/builtins.go → gno.land/keeper/builtins.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package vm
package vmk

import (
"os"
Expand Down Expand Up @@ -37,6 +37,7 @@ func (vm *VMKeeper) initBuiltinPackagesAndTypes(store gno.Store) {
store.SetPackageGetter(getPackage)
store.SetPackageInjector(vm.packageInjector)
stdlibs.InjectNativeMappings(store)
stdlibs.InjectVMKeeper(vm)
}

func (vm *VMKeeper) packageInjector(store gno.Store, pn *gno.PackageNode) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package vm
package vmk

// DONTCOVER

import (
"path/filepath"

bft "github.com/gnolang/gno/tm2/pkg/bft/types"
dbm "github.com/gnolang/gno/tm2/pkg/db"
"github.com/gnolang/gno/tm2/pkg/log"
Expand Down Expand Up @@ -39,8 +37,7 @@ func setupTestEnv() testEnv {
ctx := sdk.NewContext(sdk.RunTxModeDeliver, ms, &bft.Header{ChainID: "test-chain-id"}, log.NewNopLogger())
acck := authm.NewAccountKeeper(iavlCapKey, std.ProtoBaseAccount)
bank := bankm.NewBankKeeper(acck)
stdlibsDir := filepath.Join("..", "..", "..", "..", "gnovm", "stdlibs")
vmk := NewVMKeeper(baseCapKey, iavlCapKey, acck, bank, stdlibsDir)
vmk := NewVMKeeper(baseCapKey, iavlCapKey, acck, bank, "../../gnovm/stdlibs")

vmk.Initialize(ms.MultiCacheWrap())

Expand Down
11 changes: 10 additions & 1 deletion tm2/pkg/sdk/vm/convert.go → gno.land/keeper/convert.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package vm
package vmk

import (
"encoding/base64"
"fmt"
"strconv"

gno "github.com/gnolang/gno/gnovm/pkg/gnolang"
vmh "github.com/gnolang/gno/tm2/pkg/sdk/vm"
)

// These convert string representations of public-facing arguments to GNO types.
Expand Down Expand Up @@ -195,3 +196,11 @@ func convertArgToGno(arg string, argT gno.Type) (tv gno.TypedValue) {
panic(fmt.Sprintf("unexpected type in contract arg: %v", argT))
}
}

func convertMsg(msg vmh.GnoMsg) vmh.MsgCall {
var msgCall vmh.MsgCall
msgCall.PkgPath = msg.PkgPath
msgCall.Func = msg.Func
msgCall.Args = msg.Args
return msgCall
}
33 changes: 33 additions & 0 deletions gno.land/keeper/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package vmk

import "github.com/gnolang/gno/tm2/pkg/errors"

// for convenience:
type abciError struct{}

func (abciError) AssertABCIError() {}

// declare all script errors.
// NOTE: these are meant to be used in conjunction with pkgs/errors.
type InvalidPkgPathError struct{ abciError }

type (
InvalidStmtError struct{ abciError }
InvalidExprError struct{ abciError }
)

func (e InvalidPkgPathError) Error() string { return "invalid package path" }
func (e InvalidStmtError) Error() string { return "invalid statement" }
func (e InvalidExprError) Error() string { return "invalid expression" }

func ErrInvalidPkgPath(msg string) error {
return errors.Wrap(InvalidPkgPathError{}, msg)
}

func ErrInvalidStmt(msg string) error {
return errors.Wrap(InvalidStmtError{}, msg)
}

func ErrInvalidExpr(msg string) error {
return errors.Wrap(InvalidExprError{}, msg)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package vm
package vmk

import (
"github.com/gnolang/gno/tm2/pkg/sdk"
Expand Down
Loading
Loading