Skip to content

Commit

Permalink
chore: add std.ExecAsPkg
Browse files Browse the repository at this point in the history
Signed-off-by: Manfred Touron <[email protected]>
  • Loading branch information
moul authored and albttx committed Mar 23, 2023
1 parent f8fce91 commit 41d04a5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
28 changes: 28 additions & 0 deletions stdlibs/stdlibs.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,34 @@ func InjectPackage(store gno.Store, pn *gno.PackageNode) {
m.PushValue(res0)
},
)
pn.DefineNative("ExecAsPkg",
// TODO: rename UnsafeExecAsPkg?
gno.Flds( // params
"fn", gno.FuncT(nil, nil),
),
gno.Flds( // results
),
func(m *gno.Machine) {
// TODO: limit stack size: 1? 32?.
// TODO: limit usage in goroutines?
// TODO: build a new sub-context instead of patching the root one.
// to support multiple concurrent contexts and advanced flows.
arg0 := m.LastBlock().GetParams1().TV
fn := arg0.GetFunc()
println("#####################", arg0, fn.GetType(m.Store).String())
//gno.Call(fn, "nil")
//m.Eval(gno.Call(fn))
// m.Eval(gno.Call(gno.FuncT(nil, nil), fn))
println("@@@@@@@@@@")
//println(fn)

/*
ctx := m.Context.(stdlibs.ExecContext)
ctx.OrigCaller = crypto.Bech32Address(addr)
m.Context = ctx
*/
},
)
pn.DefineNative("GetCallerAt",
gno.Flds( // params
"n", "int",
Expand Down
4 changes: 4 additions & 0 deletions stdlibs/stdshim/stdshim.gno
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,7 @@ func DecodeBech32(addr Address) (prefix string, bytes [20]byte, ok bool) {
func DerivePkgAddr(pkgPath string) (addr Address) {
panic(shimWarn)
}

func ExecAsPkg(fn func()) {
panic(shimWarn)
}

0 comments on commit 41d04a5

Please sign in to comment.