-
Notifications
You must be signed in to change notification settings - Fork 373
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
450 additions
and
5 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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package subtests | ||
|
||
import ( | ||
"std" | ||
) | ||
|
||
func CurrentRealmPath() string { | ||
return std.CurrentRealmPath() | ||
} | ||
|
||
func GetCaller() std.Address { | ||
return std.GetCaller() | ||
} | ||
|
||
func Exec(fn func()) { | ||
fn() | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,122 @@ | ||
package fake20 | ||
|
||
import ( | ||
"std" | ||
"strings" | ||
|
||
"gno.land/p/demo/grc/grc20" | ||
"gno.land/p/demo/ufmt" | ||
) | ||
|
||
var ( | ||
foo *grc20.AdminToken | ||
admin std.Address = "g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj" // TODO: helper to change admin | ||
) | ||
|
||
func Init() { | ||
foo = grc20.NewAdminToken("Fake", "FAKE", 4) | ||
foo.Mint(admin, 1000000*10000) // @administrator (1M) | ||
foo.Mint("g1u7y667z64x2h7vc6fmpcprgey4ck233jaww9zq", 10000*10000) // @manfred (10k) | ||
foo.Mint("g1lpnflsxpr84dsqkznw85yd5wdzenkj89vsptmf", 10000*10000) // @gno.land/r/demo/tests/unsaferealm | ||
} | ||
|
||
func init() { | ||
Init() | ||
} | ||
|
||
|
||
// method proxies as public functions. | ||
// | ||
|
||
// getters. | ||
|
||
func GetCaller() std.Address { | ||
return std.GetCallerAt(1) | ||
// return std.GetOrigPkgAddr() | ||
} | ||
|
||
func TotalSupply() uint64 { | ||
return foo.TotalSupply() | ||
} | ||
|
||
func BalanceOf(owner std.Address) uint64 { | ||
balance, err := foo.BalanceOf(owner) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return balance | ||
} | ||
|
||
func Allowance(owner, spender std.Address) uint64 { | ||
allowance, err := foo.Allowance(owner, spender) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return allowance | ||
} | ||
|
||
// setters. | ||
|
||
func Transfer(to std.Address, amount uint64) { | ||
caller := std.GetCaller() | ||
println("transfering", amount, "from:", caller, "to:", to) | ||
foo.Transfer(caller, to, amount) | ||
} | ||
|
||
func Approve(spender std.Address, amount uint64) { | ||
caller := std.GetCaller() | ||
foo.Approve(caller, spender, amount) | ||
} | ||
|
||
func TransferFrom(from, to std.Address, amount uint64) { | ||
caller := std.GetCaller() | ||
foo.TransferFrom(caller, from, to, amount) | ||
} | ||
|
||
// faucet. | ||
|
||
func Faucet() { | ||
// FIXME: add limits? | ||
// FIXME: add payment in gnot? | ||
caller := std.GetCaller() | ||
foo.Mint(caller, 1000*10000) // 1k | ||
} | ||
|
||
// administration. | ||
|
||
func Mint(address std.Address, amount uint64) { | ||
caller := std.GetCaller() | ||
assertIsAdmin(caller) | ||
foo.Mint(address, amount) | ||
} | ||
|
||
func Burn(address std.Address, amount uint64) { | ||
caller := std.GetCaller() | ||
assertIsAdmin(caller) | ||
foo.Burn(address, amount) | ||
} | ||
|
||
// render. | ||
// | ||
|
||
func Render(path string) string { | ||
parts := strings.Split(path, "/") | ||
c := len(parts) | ||
|
||
switch { | ||
case path == "": | ||
return foo.RenderHome() | ||
case c == 2 && parts[0] == "balance": | ||
owner := std.Address(parts[1]) | ||
balance, _ := foo.BalanceOf(owner) | ||
return ufmt.Sprintf("%d\n", balance) | ||
default: | ||
return "404\n" | ||
} | ||
} | ||
|
||
func assertIsAdmin(address std.Address) { | ||
if address != admin { | ||
panic("restricted access") | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package phising | ||
|
||
func GetMillionaire() { | ||
} |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package subtests | ||
|
||
import ( | ||
"std" | ||
) | ||
|
||
func CurrentRealmPath() string { | ||
return std.CurrentRealmPath() | ||
} | ||
|
||
func GetCaller() std.Address { | ||
return std.GetCaller() | ||
} | ||
|
||
func Exec(fn func()) { | ||
fn() | ||
} |
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
52 changes: 52 additions & 0 deletions
52
examples/gno.land/r/demo/tests/unsaferealm/unsaferealm.gno
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package unsaferealm | ||
|
||
import ( | ||
"std" | ||
|
||
"gno.land/p/demo/grc/grc20" | ||
) | ||
|
||
var ( | ||
foo *grc20.AdminToken | ||
Owner = std.Address("g1lpnflsxpr84dsqkznw85yd5wdzenkj89vsptmf") | ||
) | ||
|
||
func init() { | ||
foo = grc20.NewAdminToken("Fake", "FAKE", 4) | ||
|
||
// std.TestDerivePkgAddr("gno.land/r/demo/tests/unsaferealm") | ||
// foo.Mint("g1lpnflsxpr84dsqkznw85yd5wdzenkj89vsptmf", 1000000*10000) | ||
foo.Mint(Owner, 1000000*10000) | ||
// foo.Mint(std.GetOrigPkgAddr(), 1000000*10000) | ||
} | ||
|
||
/* | ||
** Some grc20 functions | ||
*/ | ||
|
||
func GetCaller() std.Address { | ||
return std.GetCallerAt(1) | ||
} | ||
|
||
func BalanceOf(owner std.Address) uint64 { | ||
balance, err := foo.BalanceOf(owner) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
return balance | ||
} | ||
|
||
func Transfer(to std.Address, amount uint64) { | ||
caller := std.GetCaller() | ||
println("transfering", amount, "from:", caller, "to:", to) | ||
foo.Transfer(caller, to, amount) | ||
} | ||
|
||
/* | ||
** Realm unsafe functions | ||
*/ | ||
|
||
func Do(fn func()) { | ||
fn() | ||
} |
9 changes: 9 additions & 0 deletions
9
examples/gno.land/r/demo/tests/unsaferealm/unsaferealm_test.gno
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package unsaferealm | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestUnsafeRealm(t *testing.T) { | ||
println("Hello") | ||
} |
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,6 +1,8 @@ | ||
package gnolang | ||
|
||
import "fmt" | ||
import ( | ||
"fmt" | ||
) | ||
|
||
//---------------------------------------- | ||
// (runtime) Frame | ||
|
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
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
Oops, something went wrong.