diff --git a/docs/assets/how-to-guides/creating-grc20/mytoken-1.gno b/docs/assets/how-to-guides/creating-grc20/mytoken-1.gno index bbdf84f8a9f..df1fcac406c 100644 --- a/docs/assets/how-to-guides/creating-grc20/mytoken-1.gno +++ b/docs/assets/how-to-guides/creating-grc20/mytoken-1.gno @@ -17,7 +17,7 @@ var ( // init is called once at time of deployment func init() { // Set deployer of Realm to admin - admin = std.PrevRealm().Addr() + admin = std.PreviousRealm().Address() // Set token name, symbol and number of decimals banker = grc20.NewBanker("My Token", "TKN", 4) diff --git a/docs/assets/how-to-guides/creating-grc20/mytoken-2.gno b/docs/assets/how-to-guides/creating-grc20/mytoken-2.gno index 71616feba15..6f5d206f4b3 100644 --- a/docs/assets/how-to-guides/creating-grc20/mytoken-2.gno +++ b/docs/assets/how-to-guides/creating-grc20/mytoken-2.gno @@ -44,13 +44,13 @@ func TransferFrom(from, to std.Address, amount uint64) { // Mint mints amount of tokens to address. Callable only by admin of token func Mint(address std.Address, amount uint64) { - assertIsAdmin(std.PrevRealm().Addr()) + assertIsAdmin(std.PreviousRealm().Address()) checkErr(banker.Mint(address, amount)) } // Burn burns amount of tokens from address. Callable only by admin of token func Burn(address std.Address, amount uint64) { - assertIsAdmin(std.PrevRealm().Addr()) + assertIsAdmin(std.PreviousRealm().Address()) checkErr(banker.Burn(address, amount)) } diff --git a/docs/assets/how-to-guides/porting-solidity-to-gno/porting-11.gno b/docs/assets/how-to-guides/porting-solidity-to-gno/porting-11.gno index e48ebf919a0..8ee31bc4552 100644 --- a/docs/assets/how-to-guides/porting-solidity-to-gno/porting-11.gno +++ b/docs/assets/how-to-guides/porting-solidity-to-gno/porting-11.gno @@ -1,5 +1,5 @@ func AuctionEnd() { - if std.GetHeight() < auctionEndBlock { + if std.ChainHeight() < auctionEndBlock { panic("Auction hasn't ended") } @@ -10,8 +10,8 @@ func AuctionEnd() { ended = true // Send the highest bid to the recipient - banker := std.GetBanker(std.BankerTypeRealmSend) - pkgAddr := std.GetOrigPkgAddr() + banker := std.NewBanker(std.BankerTypeRealmSend) + pkgAddr := std.OriginPkgAddress() banker.SendCoins(pkgAddr, receiver, std.Coins{{"ugnot", int64(highestBid)}}) } diff --git a/docs/assets/how-to-guides/porting-solidity-to-gno/porting-12.gno b/docs/assets/how-to-guides/porting-solidity-to-gno/porting-12.gno index 55817537298..62738004f94 100644 --- a/docs/assets/how-to-guides/porting-solidity-to-gno/porting-12.gno +++ b/docs/assets/how-to-guides/porting-solidity-to-gno/porting-12.gno @@ -9,7 +9,7 @@ func TestAuctionEnd(t *testing.T) { shouldNoPanic(t, AuctionEnd) shouldEqual(t, ended, true) - banker := std.GetBanker(std.BankerTypeRealmSend) + banker := std.NewBanker(std.BankerTypeRealmSend) shouldEqual(t, banker.GetCoins(receiver).String(), "3ugnot") // Auction has already ended diff --git a/docs/assets/how-to-guides/porting-solidity-to-gno/porting-13.gno b/docs/assets/how-to-guides/porting-solidity-to-gno/porting-13.gno index 0e5f2d57de9..ec3f4145b21 100644 --- a/docs/assets/how-to-guides/porting-solidity-to-gno/porting-13.gno +++ b/docs/assets/how-to-guides/porting-solidity-to-gno/porting-13.gno @@ -15,22 +15,22 @@ func TestFull(t *testing.T) { // Send two or more types of coins { - std.TestSetOrigCaller(bidder01) - std.TestSetOrigSend(std.Coins{{"ugnot", 0}, {"test", 1}}, nil) + std.TestSetOriginCaller(bidder01) + std.TestSetOriginSend(std.Coins{{"ugnot", 0}, {"test", 1}}, nil) shouldPanic(t, Bid) } // Send less than the highest bid { - std.TestSetOrigCaller(bidder01) - std.TestSetOrigSend(std.Coins{{"ugnot", 0}}, nil) + std.TestSetOriginCaller(bidder01) + std.TestSetOriginSend(std.Coins{{"ugnot", 0}}, nil) shouldPanic(t, Bid) } // Send more than the highest bid { - std.TestSetOrigCaller(bidder01) - std.TestSetOrigSend(std.Coins{{"ugnot", 1}}, nil) + std.TestSetOriginCaller(bidder01) + std.TestSetOriginSend(std.Coins{{"ugnot", 1}}, nil) shouldNoPanic(t, Bid) shouldEqual(t, pendingReturns.Size(), 0) @@ -42,13 +42,13 @@ func TestFull(t *testing.T) { { // Send less amount than the current highest bid (current: 1) - std.TestSetOrigCaller(bidder02) - std.TestSetOrigSend(std.Coins{{"ugnot", 1}}, nil) + std.TestSetOriginCaller(bidder02) + std.TestSetOriginSend(std.Coins{{"ugnot", 1}}, nil) shouldPanic(t, Bid) // Send more amount than the current highest bid (exceeded) - std.TestSetOrigCaller(bidder02) - std.TestSetOrigSend(std.Coins{{"ugnot", 2}}, nil) + std.TestSetOriginCaller(bidder02) + std.TestSetOriginSend(std.Coins{{"ugnot", 2}}, nil) shouldNoPanic(t, Bid) shouldEqual(t, highestBid, 2) @@ -68,7 +68,7 @@ func TestFull(t *testing.T) { shouldNoPanic(t, AuctionEnd) shouldEqual(t, ended, true) - banker := std.GetBanker(std.BankerTypeRealmSend) + banker := std.NewBanker(std.BankerTypeRealmSend) shouldEqual(t, banker.GetCoins(receiver).String(), "2ugnot") } } diff --git a/docs/assets/how-to-guides/porting-solidity-to-gno/porting-3.gno b/docs/assets/how-to-guides/porting-solidity-to-gno/porting-3.gno index af8137b4044..ae429ed1a39 100644 --- a/docs/assets/how-to-guides/porting-solidity-to-gno/porting-3.gno +++ b/docs/assets/how-to-guides/porting-solidity-to-gno/porting-3.gno @@ -1,6 +1,6 @@ var ( receiver = std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") - auctionEndBlock = std.GetHeight() + uint(300) // in blocks + auctionEndBlock = std.ChainHeight() + uint(300) // in blocks highestBidder std.Address highestBid = uint(0) pendingReturns avl.Tree diff --git a/docs/assets/how-to-guides/porting-solidity-to-gno/porting-5.gno b/docs/assets/how-to-guides/porting-solidity-to-gno/porting-5.gno index 43f0b43b397..9750d3e90d2 100644 --- a/docs/assets/how-to-guides/porting-solidity-to-gno/porting-5.gno +++ b/docs/assets/how-to-guides/porting-solidity-to-gno/porting-5.gno @@ -1,9 +1,9 @@ func Bid() { - if std.GetHeight() > auctionEndBlock { + if std.ChainHeight() > auctionEndBlock { panic("Exceeded auction end block") } - sentCoins := std.GetOrigSend() + sentCoins := std.OriginSend() if len(sentCoins) != 1 { panic("Send only one type of coin") } @@ -23,7 +23,7 @@ func Bid() { } // Update the top bidder address - highestBidder = std.GetOrigCaller() + highestBidder = std.OriginCaller() // Update the top bid amount highestBid = sentAmount } diff --git a/docs/assets/how-to-guides/porting-solidity-to-gno/porting-6.gno b/docs/assets/how-to-guides/porting-solidity-to-gno/porting-6.gno index b544d0017c4..b226d4a69a2 100644 --- a/docs/assets/how-to-guides/porting-solidity-to-gno/porting-6.gno +++ b/docs/assets/how-to-guides/porting-solidity-to-gno/porting-6.gno @@ -1,39 +1,39 @@ // Bid Function Test - Send Coin func TestBidCoins(t *testing.T) { // Sending two types of coins - std.TestSetOrigCaller(bidder01) - std.TestSetOrigSend(std.Coins{{"ugnot", 0}, {"test", 1}}, nil) + std.TestSetOriginCaller(bidder01) + std.TestSetOriginSend(std.Coins{{"ugnot", 0}, {"test", 1}}, nil) shouldPanic(t, Bid) // Sending lower amount than the current highest bid - std.TestSetOrigCaller(bidder01) - std.TestSetOrigSend(std.Coins{{"ugnot", 0}}, nil) + std.TestSetOriginCaller(bidder01) + std.TestSetOriginSend(std.Coins{{"ugnot", 0}}, nil) shouldPanic(t, Bid) // Sending more amount than the current highest bid (exceeded) - std.TestSetOrigCaller(bidder01) - std.TestSetOrigSend(std.Coins{{"ugnot", 1}}, nil) + std.TestSetOriginCaller(bidder01) + std.TestSetOriginSend(std.Coins{{"ugnot", 1}}, nil) shouldNoPanic(t, Bid) } // Bid Function Test - Bid by two or more people func TestBidCoins(t *testing.T) { // bidder01 bidding with 1 coin - std.TestSetOrigCaller(bidder01) - std.TestSetOrigSend(std.Coins{{"ugnot", 1}}, nil) + std.TestSetOriginCaller(bidder01) + std.TestSetOriginSend(std.Coins{{"ugnot", 1}}, nil) shouldNoPanic(t, Bid) shouldEqual(t, highestBid, 1) shouldEqual(t, highestBidder, bidder01) shouldEqual(t, pendingReturns.Size(), 0) // bidder02 bidding with 1 coin - std.TestSetOrigCaller(bidder02) - std.TestSetOrigSend(std.Coins{{"ugnot", 1}}, nil) + std.TestSetOriginCaller(bidder02) + std.TestSetOriginSend(std.Coins{{"ugnot", 1}}, nil) shouldPanic(t, Bid) // bidder02 bidding with 2 coins - std.TestSetOrigCaller(bidder02) - std.TestSetOrigSend(std.Coins{{"ugnot", 2}}, nil) + std.TestSetOriginCaller(bidder02) + std.TestSetOriginSend(std.Coins{{"ugnot", 2}}, nil) shouldNoPanic(t, Bid) shouldEqual(t, highestBid, 2) shouldEqual(t, highestBidder, bidder02) diff --git a/docs/assets/how-to-guides/porting-solidity-to-gno/porting-8.gno b/docs/assets/how-to-guides/porting-solidity-to-gno/porting-8.gno index 7cb6bbd8d90..ad352d017c6 100644 --- a/docs/assets/how-to-guides/porting-solidity-to-gno/porting-8.gno +++ b/docs/assets/how-to-guides/porting-solidity-to-gno/porting-8.gno @@ -1,15 +1,15 @@ func Withdraw() { // Query the return amount to non-highest bidders - amount, _ := pendingReturns.Get(std.GetOrigCaller().String()) + amount, _ := pendingReturns.Get(std.OriginCaller().String()) if amount > 0 { // If there's an amount, reset the amount first, - pendingReturns.Set(std.GetOrigCaller().String(), 0) + pendingReturns.Set(std.OriginCaller().String(), 0) // Return the exceeded amount - banker := std.GetBanker(std.BankerTypeRealmSend) - pkgAddr := std.GetOrigPkgAddr() + banker := std.NewBanker(std.BankerTypeRealmSend) + pkgAddr := std.OriginPkgAddress() - banker.SendCoins(pkgAddr, std.GetOrigCaller(), std.Coins{{"ugnot", amount.(int64)}}) + banker.SendCoins(pkgAddr, std.OriginCaller(), std.Coins{{"ugnot", amount.(int64)}}) } } diff --git a/docs/assets/how-to-guides/porting-solidity-to-gno/porting-9.gno b/docs/assets/how-to-guides/porting-solidity-to-gno/porting-9.gno index fbc06792ce4..28f4917a66d 100644 --- a/docs/assets/how-to-guides/porting-solidity-to-gno/porting-9.gno +++ b/docs/assets/how-to-guides/porting-solidity-to-gno/porting-9.gno @@ -10,8 +10,8 @@ func TestWithdraw(t *testing.T) { shouldEqual(t, pendingReturns.Size(), 1) shouldEqual(t, pendingReturns.Has(returnAddr), true) - banker := std.GetBanker(std.BankerTypeRealmSend) - pkgAddr := std.GetOrigPkgAddr() + banker := std.NewBanker(std.BankerTypeRealmSend) + pkgAddr := std.OriginPkgAddress() banker.SendCoins(pkgAddr, std.Address(returnAddr), std.Coins{{"ugnot", returnAmount}}) shouldEqual(t, banker.GetCoins(std.Address(returnAddr)).String(), "3ugnot") } diff --git a/docs/assets/how-to-guides/simple-library/tapas.gno b/docs/assets/how-to-guides/simple-library/tapas.gno index c55fceaf3b8..9c523e72d91 100644 --- a/docs/assets/how-to-guides/simple-library/tapas.gno +++ b/docs/assets/how-to-guides/simple-library/tapas.gno @@ -28,9 +28,9 @@ var listOfTapas = []string{ func GetTapaSuggestion(userInput string) string { // Create a random number depending on the block height. - // We get the block height using std.GetHeight(), which is from an imported Gno library, "std" + // We get the block height using std.ChainHeight(), which is from an imported Gno library, "std" // Note: this value is not fully random and is easily guessable - randomNumber := int(std.GetHeight()) % len(listOfTapas) + randomNumber := int(std.ChainHeight()) % len(listOfTapas) // Return the random suggestion return listOfTapas[randomNumber] diff --git a/docs/assets/how-to-guides/write-simple-dapp/poll-2.gno b/docs/assets/how-to-guides/write-simple-dapp/poll-2.gno index c7dbaedfbb2..6aa4aa6e36a 100644 --- a/docs/assets/how-to-guides/write-simple-dapp/poll-2.gno +++ b/docs/assets/how-to-guides/write-simple-dapp/poll-2.gno @@ -22,7 +22,7 @@ func init() { // NewPoll - Creates a new Poll instance func NewPoll(title, description string, deadline int64) string { // get block height - if deadline <= std.GetHeight() { + if deadline <= std.ChainHeight() { panic("deadline has to be in the future") } @@ -40,7 +40,7 @@ func NewPoll(title, description string, deadline int64) string { // yes - true, no - false func Vote(id string, vote bool) string { // get txSender - txSender := std.GetOrigCaller() + txSender := std.OriginCaller() // get specific Poll from AVL tree pollRaw, exists := polls.Get(id) @@ -57,7 +57,7 @@ func Vote(id string, vote bool) string { panic("you've already voted!") } - if poll.Deadline() <= std.GetHeight() { + if poll.Deadline() <= std.ChainHeight() { panic("voting for this poll is closed") } diff --git a/docs/concepts/effective-gno.md b/docs/concepts/effective-gno.md index d4e2af8422e..74886a8e515 100644 --- a/docs/concepts/effective-gno.md +++ b/docs/concepts/effective-gno.md @@ -115,7 +115,7 @@ that could lead to user frustration or the need to fork the code. import "std" func Foobar() { - caller := std.PrevRealm().Addr() + caller := std.PreviousRealm().Address() if caller != "g1xxxxx" { panic("permission denied") } @@ -169,10 +169,10 @@ var ( func init() { created = time.Now() - // std.GetOrigCaller in the context of realm initialisation is, + // std.OriginCaller in the context of realm initialisation is, // of course, the publisher of the realm :) // This can be better than hardcoding an admin address as a constant. - admin = std.GetOrigCaller() + admin = std.OriginCaller() // list is already initialized, so it will already contain "foo", "bar" and // the current time as existing items. list = append(list, admin.String()) @@ -449,7 +449,7 @@ certain operations. import "std" func PublicMethod(nb int) { - caller := std.PrevRealm().Addr() + caller := std.PreviousRealm().Address() privateMethod(caller, nb) } @@ -457,7 +457,7 @@ func privateMethod(caller std.Address, nb int) { /* ... */ } ``` In this example, `PublicMethod` is a public function that can be called by other -realms. It retrieves the caller's address using `std.PrevRealm().Addr()`, and +realms. It retrieves the caller's address using `std.PreviousRealm().Address()`, and then passes it to `privateMethod`, which is a private function that performs the actual logic. This way, `privateMethod` can only be called from within the realm, and it can use the caller's address for authentication or authorization @@ -490,11 +490,11 @@ import ( var owner std.Address func init() { - owner = std.PrevRealm().Addr() + owner = std.PreviousRealm().Address() } func ChangeOwner(newOwner std.Address) { - caller := std.PrevRealm().Addr() + caller := std.PreviousRealm().Address() if caller != owner { panic("access denied") @@ -544,14 +544,14 @@ whitelisted or not. Let's deep dive into the different access control mechanisms we can use: -One strategy is to look at the caller with `std.PrevRealm()`, which could be the +One strategy is to look at the caller with `std.PreviousRealm()`, which could be the EOA (Externally Owned Account), or the preceding realm in the call stack. Another approach is to look specifically at the EOA. For this, you should call -`std.GetOrigCaller()`, which returns the public address of the account that +`std.OriginCaller()`, which returns the public address of the account that signed the transaction. -TODO: explain when to use `std.GetOrigCaller`. +TODO: explain when to use `std.OriginCaller`. Internally, this call will look at the frame stack, which is basically the stack of callers including all the functions, anonymous functions, other realms, and @@ -566,7 +566,7 @@ import "std" var admin std.Address = "g1xxxxx" func AdminOnlyFunction() { - caller := std.PrevRealm().Addr() + caller := std.PreviousRealm().Address() if caller != admin { panic("permission denied") } @@ -577,7 +577,7 @@ func AdminOnlyFunction() { ``` In this example, `AdminOnlyFunction` is a function that can only be called by -the admin. It retrieves the caller's address using `std.PrevRealm().Addr()`, +the admin. It retrieves the caller's address using `std.PreviousRealm().Address()`, this can be either another realm contract, or the calling user if there is no other intermediary realm. and then checks if the caller is the admin. If not, it panics and stops the execution. @@ -593,7 +593,7 @@ Here's an example: import "std" func TransferTokens(to std.Address, amount int64) { - caller := std.PrevRealm().Addr() + caller := std.PreviousRealm().Address() if caller != admin { panic("permission denied") } @@ -602,7 +602,7 @@ func TransferTokens(to std.Address, amount int64) { ``` In this example, `TransferTokens` is a function that can only be called by the -admin. It retrieves the caller's address using `std.PrevRealm().Addr()`, and +admin. It retrieves the caller's address using `std.PreviousRealm().Address()`, and then checks if the caller is the admin. If not, the function panics and execution is stopped. By using these access control mechanisms, you can ensure that your contract's @@ -681,7 +681,7 @@ type MySafeStruct { } func NewSafeStruct() *MySafeStruct { - caller := std.PrevRealm().Addr() + caller := std.PreviousRealm().Address() return &MySafeStruct{ counter: 0, admin: caller, @@ -690,7 +690,7 @@ func NewSafeStruct() *MySafeStruct { func (s *MySafeStruct) Counter() int { return s.counter } func (s *MySafeStruct) Inc() { - caller := std.PrevRealm().Addr() + caller := std.PreviousRealm().Address() if caller != s.admin { panic("permission denied") } @@ -754,7 +754,7 @@ import "gno.land/p/demo/grc/grc20" var fooToken = grc20.NewBanker("Foo Token", "FOO", 4) func MyBalance() uint64 { - caller := std.PrevRealm().Addr() + caller := std.PreviousRealm().Address() return fooToken.BalanceOf(caller) } ``` diff --git a/docs/concepts/stdlibs/banker.md b/docs/concepts/stdlibs/banker.md index 873fac7c418..2ba4ca4402b 100644 --- a/docs/concepts/stdlibs/banker.md +++ b/docs/concepts/stdlibs/banker.md @@ -11,7 +11,7 @@ The Banker module can be cast into 4 subtypes of bankers that expose different f ### Banker Types 1. `BankerTypeReadonly` - read-only access to coin balances -2. `BankerTypeOrigSend` - full access to coins sent with the transaction that called the banker +2. `BankerTypeOriginSend` - full access to coins sent with the transaction that called the banker 3. `BankerTypeRealmSend` - full access to coins that the realm itself owns, including the ones sent with the transaction 4. `BankerTypeRealmIssue` - able to issue new coins diff --git a/docs/how-to-guides/creating-grc20.md b/docs/how-to-guides/creating-grc20.md index 13f22fcc6a2..86718d5b89c 100644 --- a/docs/how-to-guides/creating-grc20.md +++ b/docs/how-to-guides/creating-grc20.md @@ -41,7 +41,7 @@ var ( // init is called once at time of deployment func init() { // Set deployer of Realm to admin - admin = std.PrevRealm().Addr() + admin = std.PreviousRealm().Address() // Set token name, symbol and number of decimals banker = grc20.NewBanker("My Token", "TKN", 4) @@ -142,7 +142,7 @@ caller’s allowance. ```go // Mint mints amount of tokens to address. Callable only by admin of token func Mint(address std.Address, amount uint64) { - assertIsAdmin(std.PrevRealm().Addr()) + assertIsAdmin(std.PreviousRealm().Address()) checkErr(banker.Mint(address, amount)) } ``` @@ -153,7 +153,7 @@ increasing the total supply. ```go // Burn burns amount of tokens from address. Callable only by admin of token func Burn(address std.Address, amount uint64) { - assertIsAdmin(std.PrevRealm().Addr()) + assertIsAdmin(std.PreviousRealm().Address()) checkErr(banker.Burn(address, amount)) } ``` @@ -162,7 +162,7 @@ decreasing the total supply. [embedmd]:# (../assets/how-to-guides/creating-grc20/mytoken-2.gno go /.*assertIsAdmin/ /^}/) ```go - assertIsAdmin(std.PrevRealm().Addr()) + assertIsAdmin(std.PreviousRealm().Address()) checkErr(banker.Mint(address, amount)) } ``` diff --git a/docs/how-to-guides/porting-solidity-to-gno.md b/docs/how-to-guides/porting-solidity-to-gno.md index 85c426c4c83..1c491eda5f2 100644 --- a/docs/how-to-guides/porting-solidity-to-gno.md +++ b/docs/how-to-guides/porting-solidity-to-gno.md @@ -287,7 +287,7 @@ constructor( ```go var ( receiver = std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") - auctionEndBlock = std.GetHeight() + uint(300) // in blocks + auctionEndBlock = std.ChainHeight() + uint(300) // in blocks highestBidder std.Address highestBid = uint(0) pendingReturns avl.Tree @@ -349,11 +349,11 @@ function bid() external payable { [embedmd]:# (../assets/how-to-guides/porting-solidity-to-gno/porting-5.gno go) ```go func Bid() { - if std.GetHeight() > auctionEndBlock { + if std.ChainHeight() > auctionEndBlock { panic("Exceeded auction end block") } - sentCoins := std.GetOrigSend() + sentCoins := std.OriginSend() if len(sentCoins) != 1 { panic("Send only one type of coin") } @@ -373,7 +373,7 @@ func Bid() { } // Update the top bidder address - highestBidder = std.GetOrigCaller() + highestBidder = std.OriginCaller() // Update the top bid amount highestBid = sentAmount } @@ -387,39 +387,39 @@ func Bid() { // Bid Function Test - Send Coin func TestBidCoins(t *testing.T) { // Sending two types of coins - std.TestSetOrigCaller(bidder01) - std.TestSetOrigSend(std.Coins{{"ugnot", 0}, {"test", 1}}, nil) + std.TestSetOriginCaller(bidder01) + std.TestSetOriginSend(std.Coins{{"ugnot", 0}, {"test", 1}}, nil) shouldPanic(t, Bid) // Sending lower amount than the current highest bid - std.TestSetOrigCaller(bidder01) - std.TestSetOrigSend(std.Coins{{"ugnot", 0}}, nil) + std.TestSetOriginCaller(bidder01) + std.TestSetOriginSend(std.Coins{{"ugnot", 0}}, nil) shouldPanic(t, Bid) // Sending more amount than the current highest bid (exceeded) - std.TestSetOrigCaller(bidder01) - std.TestSetOrigSend(std.Coins{{"ugnot", 1}}, nil) + std.TestSetOriginCaller(bidder01) + std.TestSetOriginSend(std.Coins{{"ugnot", 1}}, nil) shouldNoPanic(t, Bid) } // Bid Function Test - Bid by two or more people func TestBidCoins(t *testing.T) { // bidder01 bidding with 1 coin - std.TestSetOrigCaller(bidder01) - std.TestSetOrigSend(std.Coins{{"ugnot", 1}}, nil) + std.TestSetOriginCaller(bidder01) + std.TestSetOriginSend(std.Coins{{"ugnot", 1}}, nil) shouldNoPanic(t, Bid) shouldEqual(t, highestBid, 1) shouldEqual(t, highestBidder, bidder01) shouldEqual(t, pendingReturns.Size(), 0) // bidder02 bidding with 1 coin - std.TestSetOrigCaller(bidder02) - std.TestSetOrigSend(std.Coins{{"ugnot", 1}}, nil) + std.TestSetOriginCaller(bidder02) + std.TestSetOriginSend(std.Coins{{"ugnot", 1}}, nil) shouldPanic(t, Bid) // bidder02 bidding with 2 coins - std.TestSetOrigCaller(bidder02) - std.TestSetOrigSend(std.Coins{{"ugnot", 2}}, nil) + std.TestSetOriginCaller(bidder02) + std.TestSetOriginSend(std.Coins{{"ugnot", 2}}, nil) shouldNoPanic(t, Bid) shouldEqual(t, highestBid, 2) shouldEqual(t, highestBidder, bidder02) @@ -466,17 +466,17 @@ function withdraw() external returns (bool) { ```go func Withdraw() { // Query the return amount to non-highest bidders - amount, _ := pendingReturns.Get(std.GetOrigCaller().String()) + amount, _ := pendingReturns.Get(std.OriginCaller().String()) if amount > 0 { // If there's an amount, reset the amount first, - pendingReturns.Set(std.GetOrigCaller().String(), 0) + pendingReturns.Set(std.OriginCaller().String(), 0) // Return the exceeded amount - banker := std.GetBanker(std.BankerTypeRealmSend) - pkgAddr := std.GetOrigPkgAddr() + banker := std.NewBanker(std.BankerTypeRealmSend) + pkgAddr := std.OriginPkgAddress() - banker.SendCoins(pkgAddr, std.GetOrigCaller(), std.Coins{{"ugnot", amount.(int64)}}) + banker.SendCoins(pkgAddr, std.OriginCaller(), std.Coins{{"ugnot", amount.(int64)}}) } } ``` @@ -499,8 +499,8 @@ func TestWithdraw(t *testing.T) { shouldEqual(t, pendingReturns.Size(), 1) shouldEqual(t, pendingReturns.Has(returnAddr), true) - banker := std.GetBanker(std.BankerTypeRealmSend) - pkgAddr := std.GetOrigPkgAddr() + banker := std.NewBanker(std.BankerTypeRealmSend) + pkgAddr := std.OriginPkgAddress() banker.SendCoins(pkgAddr, std.Address(returnAddr), std.Coins{{"ugnot", returnAmount}}) shouldEqual(t, banker.GetCoins(std.Address(returnAddr)).String(), "3ugnot") } @@ -553,7 +553,7 @@ function auctionEnd() external { [embedmd]:# (../assets/how-to-guides/porting-solidity-to-gno/porting-11.gno go) ```go func AuctionEnd() { - if std.GetHeight() < auctionEndBlock { + if std.ChainHeight() < auctionEndBlock { panic("Auction hasn't ended") } @@ -564,8 +564,8 @@ func AuctionEnd() { ended = true // Send the highest bid to the recipient - banker := std.GetBanker(std.BankerTypeRealmSend) - pkgAddr := std.GetOrigPkgAddr() + banker := std.NewBanker(std.BankerTypeRealmSend) + pkgAddr := std.OriginPkgAddress() banker.SendCoins(pkgAddr, receiver, std.Coins{{"ugnot", int64(highestBid)}}) } @@ -586,7 +586,7 @@ func TestAuctionEnd(t *testing.T) { shouldNoPanic(t, AuctionEnd) shouldEqual(t, ended, true) - banker := std.GetBanker(std.BankerTypeRealmSend) + banker := std.NewBanker(std.BankerTypeRealmSend) shouldEqual(t, banker.GetCoins(receiver).String(), "3ugnot") // Auction has already ended @@ -620,22 +620,22 @@ func TestFull(t *testing.T) { // Send two or more types of coins { - std.TestSetOrigCaller(bidder01) - std.TestSetOrigSend(std.Coins{{"ugnot", 0}, {"test", 1}}, nil) + std.TestSetOriginCaller(bidder01) + std.TestSetOriginSend(std.Coins{{"ugnot", 0}, {"test", 1}}, nil) shouldPanic(t, Bid) } // Send less than the highest bid { - std.TestSetOrigCaller(bidder01) - std.TestSetOrigSend(std.Coins{{"ugnot", 0}}, nil) + std.TestSetOriginCaller(bidder01) + std.TestSetOriginSend(std.Coins{{"ugnot", 0}}, nil) shouldPanic(t, Bid) } // Send more than the highest bid { - std.TestSetOrigCaller(bidder01) - std.TestSetOrigSend(std.Coins{{"ugnot", 1}}, nil) + std.TestSetOriginCaller(bidder01) + std.TestSetOriginSend(std.Coins{{"ugnot", 1}}, nil) shouldNoPanic(t, Bid) shouldEqual(t, pendingReturns.Size(), 0) @@ -647,13 +647,13 @@ func TestFull(t *testing.T) { { // Send less amount than the current highest bid (current: 1) - std.TestSetOrigCaller(bidder02) - std.TestSetOrigSend(std.Coins{{"ugnot", 1}}, nil) + std.TestSetOriginCaller(bidder02) + std.TestSetOriginSend(std.Coins{{"ugnot", 1}}, nil) shouldPanic(t, Bid) // Send more amount than the current highest bid (exceeded) - std.TestSetOrigCaller(bidder02) - std.TestSetOrigSend(std.Coins{{"ugnot", 2}}, nil) + std.TestSetOriginCaller(bidder02) + std.TestSetOriginSend(std.Coins{{"ugnot", 2}}, nil) shouldNoPanic(t, Bid) shouldEqual(t, highestBid, 2) @@ -673,7 +673,7 @@ func TestFull(t *testing.T) { shouldNoPanic(t, AuctionEnd) shouldEqual(t, ended, true) - banker := std.GetBanker(std.BankerTypeRealmSend) + banker := std.NewBanker(std.BankerTypeRealmSend) shouldEqual(t, banker.GetCoins(receiver).String(), "2ugnot") } } diff --git a/docs/how-to-guides/simple-library.md b/docs/how-to-guides/simple-library.md index 62ff2bd2c0f..7582fa0b24d 100644 --- a/docs/how-to-guides/simple-library.md +++ b/docs/how-to-guides/simple-library.md @@ -128,9 +128,9 @@ var listOfTapas = []string{ func GetTapaSuggestion(userInput string) string { // Create a random number depending on the block height. - // We get the block height using std.GetHeight(), which is from an imported Gno library, "std" + // We get the block height using std.ChainHeight(), which is from an imported Gno library, "std" // Note: this value is not fully random and is easily guessable - randomNumber := int(std.GetHeight()) % len(listOfTapas) + randomNumber := int(std.ChainHeight()) % len(listOfTapas) // Return the random suggestion return listOfTapas[randomNumber] diff --git a/docs/how-to-guides/write-simple-dapp.md b/docs/how-to-guides/write-simple-dapp.md index f844f8ab7c8..b73e67bac74 100644 --- a/docs/how-to-guides/write-simple-dapp.md +++ b/docs/how-to-guides/write-simple-dapp.md @@ -156,7 +156,7 @@ func init() { // NewPoll - Creates a new Poll instance func NewPoll(title, description string, deadline int64) string { // get block height - if deadline <= std.GetHeight() { + if deadline <= std.ChainHeight() { panic("deadline has to be in the future") } @@ -174,7 +174,7 @@ func NewPoll(title, description string, deadline int64) string { // yes - true, no - false func Vote(id string, vote bool) string { // get txSender - txSender := std.GetOrigCaller() + txSender := std.OriginCaller() // get specific Poll from AVL tree pollRaw, exists := polls.Get(id) @@ -191,7 +191,7 @@ func Vote(id string, vote bool) string { panic("you've already voted!") } - if poll.Deadline() <= std.GetHeight() { + if poll.Deadline() <= std.ChainHeight() { panic("voting for this poll is closed") } diff --git a/docs/reference/stdlibs/std/banker.md b/docs/reference/stdlibs/std/banker.md index b60b55ee93b..1e5d48815ad 100644 --- a/docs/reference/stdlibs/std/banker.md +++ b/docs/reference/stdlibs/std/banker.md @@ -10,7 +10,7 @@ type BankerType uint8 const ( BankerTypeReadonly BankerType = iota - BankerTypeOrigSend + BankerTypeOriginSend BankerTypeRealmSend BankerTypeRealmIssue ) @@ -23,20 +23,20 @@ type Banker interface { } ``` -## GetBanker +## NewBanker Returns `Banker` of the specified type. #### Parameters - `BankerType` - type of Banker to get: - `BankerTypeReadonly` - read-only access to coin balances - - `BankerTypeOrigSend` - full access to coins sent with the transaction that calls the banker + - `BankerTypeOriginSend` - full access to coins sent with the transaction that calls the banker - `BankerTypeRealmSend` - full access to coins that the realm itself owns, including the ones sent with the transaction - `BankerTypeRealmIssue` - able to issue new coins #### Usage ```go -banker := std.GetBanker(std.) +banker := std.NewBanker(std.) ``` :::info `Banker` methods expect qualified denomination of the coins. Read more [here](./realm.md#coindenom). diff --git a/docs/reference/stdlibs/std/chain.md b/docs/reference/stdlibs/std/chain.md index 6a1da6483fd..a8d46762924 100644 --- a/docs/reference/stdlibs/std/chain.md +++ b/docs/reference/stdlibs/std/chain.md @@ -53,63 +53,63 @@ std.Emit("MyEvent", "myKey1", "myValue1", "myKey2", "myValue2") ``` --- -## GetChainID +## ChainID ```go -func GetChainID() string +func ChainID() string ``` Returns the chain ID. #### Usage ```go -chainID := std.GetChainID() // dev | test5 | main ... +chainID := std.ChainID() // dev | test5 | main ... ``` --- -## GetHeight +## ChainHeight ```go -func GetHeight() int64 +func ChainHeight() int64 ``` Returns the current block number (height). #### Usage ```go -height := std.GetHeight() +height := std.ChainHeight() ``` --- -## GetOrigSend +## OriginSend ```go -func GetOrigSend() Coins +func OriginSend() Coins ``` Returns the `Coins` that were sent along with the calling transaction. #### Usage ```go -coinsSent := std.GetOrigSend() +coinsSent := std.OriginSend() ``` --- -## GetOrigCaller +## OriginCaller ```go -func GetOrigCaller() Address +func OriginCaller() Address ``` Returns the original signer of the transaction. #### Usage ```go -caller := std.GetOrigCaller() +caller := std.OriginCaller() ``` --- -## GetOrigPkgAddr +## OriginPkgAddress ```go -func GetOrigPkgAddr() string +func OriginPkgAddress() string ``` Returns the address of the first (entry point) realm/package in a sequence of realm/package calls. #### Usage ```go -origPkgAddr := std.GetOrigPkgAddr() +originPkgAddr := std.OriginPkgAddress() ``` --- @@ -125,30 +125,30 @@ currentRealm := std.CurrentRealm() ``` --- -## PrevRealm +## PreviousRealm ```go -func PrevRealm() Realm +func PreviousRealm() Realm ``` Returns the previous caller [realm](realm.md) (can be code or user realm). If caller is a user realm, `pkgpath` will be empty. #### Usage ```go -prevRealm := std.PrevRealm() +prevRealm := std.PreviousRealm() ``` --- -## GetCallerAt +## CallerAt ```go -func GetCallerAt(n int) Address +func CallerAt(n int) Address ``` Returns the n-th caller of the function, going back in the call trace. #### Usage ```go -currentRealm := std.GetCallerAt(1) // returns address of current realm -previousRealm := std.GetCallerAt(2) // returns address of previous realm/caller -std.GetCallerAt(0) // error, n must be > 0 +currentRealm := std.CallerAt(1) // returns address of current realm +previousRealm := std.CallerAt(2) // returns address of previous realm/caller +std.CallerAt(0) // error, n must be > 0 ``` --- diff --git a/docs/reference/stdlibs/std/realm.md b/docs/reference/stdlibs/std/realm.md index f69cd874c75..207285ca546 100644 --- a/docs/reference/stdlibs/std/realm.md +++ b/docs/reference/stdlibs/std/realm.md @@ -11,18 +11,18 @@ type Realm struct { pkgPath string } -func (r Realm) Addr() Address {...} +func (r Realm) Address() Address {...} func (r Realm) PkgPath() string {...} func (r Realm) IsUser() bool {...} func (r Realm) CoinDenom(coinName string) string {...} ``` -## Addr +## Address Returns the **Address** field of the realm it was called upon. #### Usage ```go -realmAddr := r.Addr() // eg. g1n2j0gdyv45aem9p0qsfk5d2gqjupv5z536na3d +realmAddr := r.Address() // eg. g1n2j0gdyv45aem9p0qsfk5d2gqjupv5z536na3d ``` --- ## PkgPath diff --git a/docs/reference/stdlibs/std/testing.md b/docs/reference/stdlibs/std/testing.md index 8a95ecf7827..6a18d7381f2 100644 --- a/docs/reference/stdlibs/std/testing.md +++ b/docs/reference/stdlibs/std/testing.md @@ -6,9 +6,9 @@ id: testing ```go func TestSkipHeights(count int64) -func TestSetOrigCaller(addr Address) -func TestSetOrigPkgAddr(addr Address) -func TestSetOrigSend(sent, spent Coins) +func TestSetOriginCaller(addr Address) +func TestSetOriginPkgAddress(addr Address) +func TestSetOriginSend(sent, spent Coins) func TestIssueCoins(addr Address, coins Coins) func TestSetRealm(realm Realm) func NewUserRealm(address Address) Realm @@ -32,43 +32,43 @@ std.TestSkipHeights(100) ``` --- -## TestSetOrigCaller +## TestSetOriginCaller ```go -func TestSetOrigCaller(addr Address) +func TestSetOriginCaller(addr Address) ``` Sets the current caller of the transaction to **addr**. #### Usage ```go -std.TestSetOrigCaller(std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5")) +std.TestSetOriginCaller(std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5")) ``` --- -## TestSetOrigPkgAddr +## TestSetOriginPkgAddress ```go -func TestSetOrigPkgAddr(addr Address) +func TestSetOriginPkgAddress(addr Address) ``` Sets the call entry realm address to **addr**. #### Usage ```go -std.TestSetOrigPkgAddr(std.Address("g1ecely4gjy0yl6s9kt409ll330q9hk2lj9ls3ec")) +std.TestSetOriginPkgAddress(std.Address("g1ecely4gjy0yl6s9kt409ll330q9hk2lj9ls3ec")) ``` --- -## TestSetOrigSend +## TestSetOriginSend ```go -func TestSetOrigSend(sent, spent Coins) +func TestSetOriginSend(sent, spent Coins) ``` Sets the sent & spent coins for the current context. #### Usage ```go -std.TestSetOrigSend(sent, spent Coins) +std.TestSetOriginSend(sent, spent Coins) ``` --- @@ -98,7 +98,7 @@ func TestSetRealm(rlm Realm) Sets the realm for the current frame. After calling `TestSetRealm()`, calling [`CurrentRealm()`](chain.md#currentrealm) in the same test function will yield the value of `rlm`, and -any `PrevRealm()` called from a function used after TestSetRealm will yield `rlm`. +any `PreviousRealm()` called from a function used after TestSetRealm will yield `rlm`. Should be used in combination with [`NewUserRealm`](#newuserrealm) & [`NewCodeRealm`](#newcoderealm). diff --git a/examples/gno.land/p/demo/entropy/entropy.gno b/examples/gno.land/p/demo/entropy/entropy.gno index 9e8f656c21b..850365c8236 100644 --- a/examples/gno.land/p/demo/entropy/entropy.gno +++ b/examples/gno.land/p/demo/entropy/entropy.gno @@ -57,15 +57,15 @@ func (i *Instance) addEntropy() { // handle callers { - caller1 := std.GetCallerAt(1).String() + caller1 := std.CallerAt(1).String() i.djb2String(caller1) - caller2 := std.GetCallerAt(2).String() + caller2 := std.CallerAt(2).String() i.djb2String(caller2) } // height { - height := std.GetHeight() + height := std.ChainHeight() if height >= math.MaxUint32 { height -= math.MaxUint32 } diff --git a/examples/gno.land/p/demo/gnorkle/gnorkle/instance.gno b/examples/gno.land/p/demo/gnorkle/gnorkle/instance.gno index eea4782909e..00fbff0cdbf 100644 --- a/examples/gno.land/p/demo/gnorkle/gnorkle/instance.gno +++ b/examples/gno.land/p/demo/gnorkle/gnorkle/instance.gno @@ -106,7 +106,7 @@ type PostMessageHandler interface { // TODO: Consider further message types that could allow administrative action such as modifying // a feed's whitelist without the owner of this oracle having to maintain a reference to it. func (i *Instance) HandleMessage(msg string, postHandler PostMessageHandler) (string, error) { - caller := string(std.GetOrigCaller()) + caller := string(std.OriginCaller()) funcType, msg := message.ParseFunc(msg) diff --git a/examples/gno.land/p/demo/grc/grc1155/basic_grc1155_token.gno b/examples/gno.land/p/demo/grc/grc1155/basic_grc1155_token.gno index f152ee90e79..1ed5f93d5fd 100644 --- a/examples/gno.land/p/demo/grc/grc1155/basic_grc1155_token.gno +++ b/examples/gno.land/p/demo/grc/grc1155/basic_grc1155_token.gno @@ -62,7 +62,7 @@ func (s *basicGRC1155Token) SetApprovalForAll(operator std.Address, approved boo return ErrInvalidAddress } - caller := std.GetOrigCaller() + caller := std.OriginCaller() return s.setApprovalForAll(caller, operator, approved) } @@ -85,7 +85,7 @@ func (s *basicGRC1155Token) IsApprovedForAll(owner, operator std.Address) bool { // contract recipients are aware of the GRC1155 protocol to prevent // tokens from being forever locked. func (s *basicGRC1155Token) SafeTransferFrom(from, to std.Address, tid TokenID, amount uint64) error { - caller := std.GetOrigCaller() + caller := std.OriginCaller() if !s.IsApprovedForAll(caller, from) { return ErrCallerIsNotOwnerOrApproved } @@ -108,7 +108,7 @@ func (s *basicGRC1155Token) SafeTransferFrom(from, to std.Address, tid TokenID, // contract recipients are aware of the GRC1155 protocol to prevent // tokens from being forever locked. func (s *basicGRC1155Token) SafeBatchTransferFrom(from, to std.Address, batch []TokenID, amounts []uint64) error { - caller := std.GetOrigCaller() + caller := std.OriginCaller() if !s.IsApprovedForAll(caller, from) { return ErrCallerIsNotOwnerOrApproved } @@ -130,7 +130,7 @@ func (s *basicGRC1155Token) SafeBatchTransferFrom(from, to std.Address, batch [] // Creates `amount` tokens of token type `id`, and assigns them to `to`. Also checks that // contract recipients are using GRC1155 protocol. func (s *basicGRC1155Token) SafeMint(to std.Address, tid TokenID, amount uint64) error { - caller := std.GetOrigCaller() + caller := std.OriginCaller() err := s.mintBatch(to, []TokenID{tid}, []uint64{amount}) if err != nil { @@ -149,7 +149,7 @@ func (s *basicGRC1155Token) SafeMint(to std.Address, tid TokenID, amount uint64) // Batch version of `SafeMint()`. Also checks that // contract recipients are using GRC1155 protocol. func (s *basicGRC1155Token) SafeBatchMint(to std.Address, batch []TokenID, amounts []uint64) error { - caller := std.GetOrigCaller() + caller := std.OriginCaller() err := s.mintBatch(to, batch, amounts) if err != nil { @@ -167,7 +167,7 @@ func (s *basicGRC1155Token) SafeBatchMint(to std.Address, batch []TokenID, amoun // Destroys `amount` tokens of token type `id` from `from`. func (s *basicGRC1155Token) Burn(from std.Address, tid TokenID, amount uint64) error { - caller := std.GetOrigCaller() + caller := std.OriginCaller() err := s.burnBatch(from, []TokenID{tid}, []uint64{amount}) if err != nil { @@ -181,7 +181,7 @@ func (s *basicGRC1155Token) Burn(from std.Address, tid TokenID, amount uint64) e // Batch version of `Burn()` func (s *basicGRC1155Token) BatchBurn(from std.Address, batch []TokenID, amounts []uint64) error { - caller := std.GetOrigCaller() + caller := std.OriginCaller() err := s.burnBatch(from, batch, amounts) if err != nil { @@ -225,7 +225,7 @@ func (s *basicGRC1155Token) safeBatchTransferFrom(from, to std.Address, batch [] return ErrCannotTransferToSelf } - caller := std.GetOrigCaller() + caller := std.OriginCaller() s.beforeTokenTransfer(caller, from, to, batch, amounts) for i := 0; i < len(batch); i++ { @@ -265,7 +265,7 @@ func (s *basicGRC1155Token) mintBatch(to std.Address, batch []TokenID, amounts [ return ErrInvalidAddress } - caller := std.GetOrigCaller() + caller := std.OriginCaller() s.beforeTokenTransfer(caller, zeroAddress, to, batch, amounts) for i := 0; i < len(batch); i++ { @@ -294,7 +294,7 @@ func (s *basicGRC1155Token) burnBatch(from std.Address, batch []TokenID, amounts return ErrInvalidAddress } - caller := std.GetOrigCaller() + caller := std.OriginCaller() s.beforeTokenTransfer(caller, from, zeroAddress, batch, amounts) for i := 0; i < len(batch); i++ { diff --git a/examples/gno.land/p/demo/grc/grc1155/basic_grc1155_token_test.gno b/examples/gno.land/p/demo/grc/grc1155/basic_grc1155_token_test.gno index 930ae03fa04..4092af72037 100644 --- a/examples/gno.land/p/demo/grc/grc1155/basic_grc1155_token_test.gno +++ b/examples/gno.land/p/demo/grc/grc1155/basic_grc1155_token_test.gno @@ -91,7 +91,7 @@ func TestSetApprovalForAll(t *testing.T) { dummy := NewBasicGRC1155Token(dummyURI) uassert.True(t, dummy != nil, "should not be nil") - caller := std.GetOrigCaller() + caller := std.OriginCaller() addr := std.Address("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm") isApprovedForAll := dummy.IsApprovedForAll(caller, addr) @@ -114,7 +114,7 @@ func TestSafeTransferFrom(t *testing.T) { dummy := NewBasicGRC1155Token(dummyURI) uassert.True(t, dummy != nil, "should not be nil") - caller := std.GetOrigCaller() + caller := std.OriginCaller() addr := std.Address("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm") tid := TokenID("1") @@ -145,7 +145,7 @@ func TestSafeBatchTransferFrom(t *testing.T) { dummy := NewBasicGRC1155Token(dummyURI) uassert.True(t, dummy != nil, "should not be nil") - caller := std.GetOrigCaller() + caller := std.OriginCaller() addr := std.Address("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm") tid1 := TokenID("1") diff --git a/examples/gno.land/p/demo/grc/grc20/examples_test.gno b/examples/gno.land/p/demo/grc/grc20/examples_test.gno index 6a2bfa11d8c..17ceb240668 100644 --- a/examples/gno.land/p/demo/grc/grc20/examples_test.gno +++ b/examples/gno.land/p/demo/grc/grc20/examples_test.gno @@ -7,7 +7,7 @@ func ExampleExposeBankForMaketxRunOrImports() {} func ExampleCustomTellerImpl() {} func ExampleAllowance() {} func ExampleRealmBanker() {} -func ExamplePrevRealmBanker() {} +func ExamplePreviousRealmBanker() {} func ExampleAccountBanker() {} func ExampleTransfer() {} func ExampleApprove() {} diff --git a/examples/gno.land/p/demo/grc/grc20/tellers.gno b/examples/gno.land/p/demo/grc/grc20/tellers.gno index ee5d2d7fcca..733d10148e3 100644 --- a/examples/gno.land/p/demo/grc/grc20/tellers.gno +++ b/examples/gno.land/p/demo/grc/grc20/tellers.gno @@ -4,7 +4,7 @@ import ( "std" ) -// CallerTeller returns a GRC20 compatible teller that checks the PrevRealm +// CallerTeller returns a GRC20 compatible teller that checks the PreviousRealm // caller for each call. It's usually safe to expose it publicly to let users // manipulate their tokens directly, or for realms to use their allowance. func (tok *Token) CallerTeller() Teller { @@ -14,7 +14,7 @@ func (tok *Token) CallerTeller() Teller { return &fnTeller{ accountFn: func() std.Address { - caller := std.PrevRealm().Addr() + caller := std.PreviousRealm().Address() return caller }, Token: tok, @@ -44,7 +44,7 @@ func (tok *Token) RealmTeller() Teller { panic("Token cannot be nil") } - caller := std.PrevRealm().Addr() + caller := std.PreviousRealm().Address() return &fnTeller{ accountFn: func() std.Address { @@ -61,7 +61,7 @@ func (tok *Token) RealmSubTeller(slug string) Teller { panic("Token cannot be nil") } - caller := std.PrevRealm().Addr() + caller := std.PreviousRealm().Address() account := accountSlugAddr(caller, slug) return &fnTeller{ diff --git a/examples/gno.land/p/demo/grc/grc20/tellers_test.gno b/examples/gno.land/p/demo/grc/grc20/tellers_test.gno index 2a724964edc..3175359df85 100644 --- a/examples/gno.land/p/demo/grc/grc20/tellers_test.gno +++ b/examples/gno.land/p/demo/grc/grc20/tellers_test.gno @@ -115,12 +115,12 @@ func TestCallerTeller(t *testing.T) { checkBalances(1000, 0, 0) checkAllowances(0, 0, 0, 0, 0, 0) - std.TestSetOrigCaller(alice) + std.TestSetOriginCaller(alice) urequire.NoError(t, teller.Approve(bob, 600)) checkBalances(1000, 0, 0) checkAllowances(600, 0, 0, 0, 0, 0) - std.TestSetOrigCaller(bob) + std.TestSetOriginCaller(bob) urequire.Error(t, teller.TransferFrom(alice, carl, 700)) checkBalances(1000, 0, 0) checkAllowances(600, 0, 0, 0, 0, 0) diff --git a/examples/gno.land/p/demo/grc/grc721/basic_nft.gno b/examples/gno.land/p/demo/grc/grc721/basic_nft.gno index 0505aaa1c26..ed7f96dd598 100644 --- a/examples/gno.land/p/demo/grc/grc721/basic_nft.gno +++ b/examples/gno.land/p/demo/grc/grc721/basic_nft.gno @@ -81,7 +81,7 @@ func (s *basicNFT) SetTokenURI(tid TokenID, tURI TokenURI) (bool, error) { if err != nil { return false, err } - caller := std.PrevRealm().Addr() + caller := std.PreviousRealm().Address() if caller != owner { return false, ErrCallerIsNotOwner } @@ -115,7 +115,7 @@ func (s *basicNFT) Approve(to std.Address, tid TokenID) error { return ErrApprovalToCurrentOwner } - caller := std.PrevRealm().Addr() + caller := std.PreviousRealm().Address() if caller != owner && !s.IsApprovedForAll(owner, caller) { return ErrCallerIsNotOwnerOrApproved } @@ -147,7 +147,7 @@ func (s *basicNFT) SetApprovalForAll(operator std.Address, approved bool) error return ErrInvalidAddress } - caller := std.PrevRealm().Addr() + caller := std.PreviousRealm().Address() return s.setApprovalForAll(caller, operator, approved) } @@ -155,7 +155,7 @@ func (s *basicNFT) SetApprovalForAll(operator std.Address, approved bool) error // contract recipients are aware of the GRC721 protocol to prevent // tokens from being forever locked. func (s *basicNFT) SafeTransferFrom(from, to std.Address, tid TokenID) error { - caller := std.PrevRealm().Addr() + caller := std.PreviousRealm().Address() if !s.isApprovedOrOwner(caller, tid) { return ErrCallerIsNotOwnerOrApproved } @@ -174,7 +174,7 @@ func (s *basicNFT) SafeTransferFrom(from, to std.Address, tid TokenID) error { // Transfers `tokenId` token from `from` to `to`. func (s *basicNFT) TransferFrom(from, to std.Address, tid TokenID) error { - caller := std.PrevRealm().Addr() + caller := std.PreviousRealm().Address() if !s.isApprovedOrOwner(caller, tid) { return ErrCallerIsNotOwnerOrApproved } diff --git a/examples/gno.land/p/demo/grc/grc721/basic_nft_test.gno b/examples/gno.land/p/demo/grc/grc721/basic_nft_test.gno index 0481bf6b268..ed45373684a 100644 --- a/examples/gno.land/p/demo/grc/grc721/basic_nft_test.gno +++ b/examples/gno.land/p/demo/grc/grc721/basic_nft_test.gno @@ -111,7 +111,7 @@ func TestSetApprovalForAll(t *testing.T) { dummy := NewBasicNFT(dummyNFTName, dummyNFTSymbol) uassert.True(t, dummy != nil, "should not be nil") - caller := std.PrevRealm().Addr() + caller := std.PreviousRealm().Address() addr := std.Address("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm") isApprovedForAll := dummy.IsApprovedForAll(caller, addr) @@ -136,7 +136,7 @@ func TestApprove(t *testing.T) { dummy := NewBasicNFT(dummyNFTName, dummyNFTSymbol) uassert.True(t, dummy != nil, "should not be nil") - caller := std.PrevRealm().Addr() + caller := std.PreviousRealm().Address() addr := std.Address("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm") dummy.mint(caller, TokenID("1")) @@ -156,7 +156,7 @@ func TestTransferFrom(t *testing.T) { dummy := NewBasicNFT(dummyNFTName, dummyNFTSymbol) uassert.True(t, dummy != nil, "should not be nil") - caller := std.PrevRealm().Addr() + caller := std.PreviousRealm().Address() addr := std.Address("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm") dummy.mint(caller, TokenID("1")) @@ -185,7 +185,7 @@ func TestSafeTransferFrom(t *testing.T) { dummy := NewBasicNFT(dummyNFTName, dummyNFTSymbol) uassert.True(t, dummy != nil, "should not be nil") - caller := std.PrevRealm().Addr() + caller := std.PreviousRealm().Address() addr := std.Address("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm") dummy.mint(caller, TokenID("1")) @@ -259,7 +259,7 @@ func TestSetTokenURI(t *testing.T) { addr2 := std.Address("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj") tokenURI := "http://example.com/token" - std.TestSetOrigCaller(std.Address(addr1)) // addr1 + std.TestSetOriginCaller(std.Address(addr1)) // addr1 dummy.mint(addr1, TokenID("1")) _, derr := dummy.SetTokenURI(TokenID("1"), TokenURI(tokenURI)) @@ -269,13 +269,13 @@ func TestSetTokenURI(t *testing.T) { _, err := dummy.SetTokenURI(TokenID("3"), TokenURI(tokenURI)) uassert.ErrorIs(t, err, ErrInvalidTokenId) - std.TestSetOrigCaller(std.Address(addr2)) // addr2 + std.TestSetOriginCaller(std.Address(addr2)) // addr2 _, cerr := dummy.SetTokenURI(TokenID("1"), TokenURI(tokenURI)) // addr2 trying to set URI for token 1 uassert.ErrorIs(t, cerr, ErrCallerIsNotOwner) // Test case: Retrieving TokenURI - std.TestSetOrigCaller(std.Address(addr1)) // addr1 + std.TestSetOriginCaller(std.Address(addr1)) // addr1 dummyTokenURI, err := dummy.TokenURI(TokenID("1")) uassert.NoError(t, err, "TokenURI error") diff --git a/examples/gno.land/p/demo/grc/grc721/grc721_metadata_test.gno b/examples/gno.land/p/demo/grc/grc721/grc721_metadata_test.gno index ad002a7c98e..b1de830fb36 100644 --- a/examples/gno.land/p/demo/grc/grc721/grc721_metadata_test.gno +++ b/examples/gno.land/p/demo/grc/grc721/grc721_metadata_test.gno @@ -31,7 +31,7 @@ func TestSetMetadata(t *testing.T) { youtubeURL := "test" // Set the original caller to addr1 - std.TestSetOrigCaller(addr1) // addr1 + std.TestSetOriginCaller(addr1) // addr1 // Mint a new token for addr1 dummy.mint(addr1, TokenID("1")) @@ -69,7 +69,7 @@ func TestSetMetadata(t *testing.T) { uassert.ErrorIs(t, err, ErrInvalidTokenId) // Set the original caller to addr2 - std.TestSetOrigCaller(addr2) // addr2 + std.TestSetOriginCaller(addr2) // addr2 // Try to set metadata for token 1 from addr2 (should fail) cerr := dummy.SetTokenMetadata(TokenID("1"), Metadata{ @@ -88,7 +88,7 @@ func TestSetMetadata(t *testing.T) { uassert.ErrorIs(t, cerr, ErrCallerIsNotOwner) // Set the original caller back to addr1 - std.TestSetOrigCaller(addr1) // addr1 + std.TestSetOriginCaller(addr1) // addr1 // Retrieve metadata for token 1 dummyMetadata, err := dummy.TokenMetadata(TokenID("1")) diff --git a/examples/gno.land/p/demo/grc/grc721/grc721_royalty.gno b/examples/gno.land/p/demo/grc/grc721/grc721_royalty.gno index 9831c709121..df13ae76d20 100644 --- a/examples/gno.land/p/demo/grc/grc721/grc721_royalty.gno +++ b/examples/gno.land/p/demo/grc/grc721/grc721_royalty.gno @@ -45,7 +45,7 @@ func (r *royaltyNFT) SetTokenRoyalty(tid TokenID, royaltyInfo RoyaltyInfo) error if err != nil { return err } - caller := std.PrevRealm().Addr() + caller := std.PreviousRealm().Address() if caller != owner { return ErrCallerIsNotOwner } diff --git a/examples/gno.land/p/demo/grc/grc721/grc721_royalty_test.gno b/examples/gno.land/p/demo/grc/grc721/grc721_royalty_test.gno index af5b4d3b239..7d732854a7c 100644 --- a/examples/gno.land/p/demo/grc/grc721/grc721_royalty_test.gno +++ b/examples/gno.land/p/demo/grc/grc721/grc721_royalty_test.gno @@ -21,7 +21,7 @@ func TestSetTokenRoyalty(t *testing.T) { salePrice := uint64(1000) expectRoyaltyAmount := uint64(100) - std.TestSetOrigCaller(addr1) // addr1 + std.TestSetOriginCaller(addr1) // addr1 dummy.mint(addr1, TokenID("1")) @@ -38,7 +38,7 @@ func TestSetTokenRoyalty(t *testing.T) { }) uassert.ErrorIs(t, derr, ErrInvalidTokenId) - std.TestSetOrigCaller(addr2) // addr2 + std.TestSetOriginCaller(addr2) // addr2 cerr := dummy.SetTokenRoyalty(TokenID("1"), RoyaltyInfo{ PaymentAddress: paymentAddress, @@ -61,7 +61,7 @@ func TestSetTokenRoyalty(t *testing.T) { uassert.ErrorIs(t, perr, ErrInvalidRoyaltyPercentage) // Test case: Retrieving Royalty Info - std.TestSetOrigCaller(addr1) // addr1 + std.TestSetOriginCaller(addr1) // addr1 dummyPaymentAddress, dummyRoyaltyAmount, rerr := dummy.RoyaltyInfo(TokenID("1"), salePrice) uassert.NoError(t, rerr, "RoyaltyInfo error") diff --git a/examples/gno.land/p/demo/memeland/memeland.gno b/examples/gno.land/p/demo/memeland/memeland.gno index 38f42239bec..55a8dbb27b1 100644 --- a/examples/gno.land/p/demo/memeland/memeland.gno +++ b/examples/gno.land/p/demo/memeland/memeland.gno @@ -50,7 +50,7 @@ func (m *Memeland) PostMeme(data string, timestamp int64) string { newPost := &Post{ ID: id, Data: data, - Author: std.PrevRealm().Addr(), + Author: std.PreviousRealm().Address(), Timestamp: time.Unix(timestamp, 0), UpvoteTracker: avl.NewTree(), } @@ -65,7 +65,7 @@ func (m *Memeland) Upvote(id string) string { panic("post with specified ID does not exist") } - caller := std.PrevRealm().Addr().String() + caller := std.PreviousRealm().Address().String() if _, exists := post.UpvoteTracker.Get(caller); exists { panic("user has already upvoted this post") diff --git a/examples/gno.land/p/demo/memeland/memeland_test.gno b/examples/gno.land/p/demo/memeland/memeland_test.gno index 95065b8cd64..bf1084a6f55 100644 --- a/examples/gno.land/p/demo/memeland/memeland_test.gno +++ b/examples/gno.land/p/demo/memeland/memeland_test.gno @@ -122,7 +122,7 @@ func TestGetPostsInRangeByUpvote(t *testing.T) { m.Upvote(id2) // Change caller so avoid double upvote panic - std.TestSetOrigCaller(testutils.TestAddress("alice")) + std.TestSetOriginCaller(testutils.TestAddress("alice")) m.Upvote(id1) // Final upvote count: @@ -236,21 +236,21 @@ func TestUpvote(t *testing.T) { func TestDelete(t *testing.T) { alice := testutils.TestAddress("alice") - std.TestSetOrigCaller(alice) + std.TestSetOriginCaller(alice) // Alice is admin m := NewMemeland() // Set caller to Bob bob := testutils.TestAddress("bob") - std.TestSetOrigCaller(bob) + std.TestSetOriginCaller(bob) // Bob adds post to Memeland now := time.Now() postID := m.PostMeme("Meme #1", now.Unix()) // Alice removes Bob's post - std.TestSetOrigCaller(alice) + std.TestSetOriginCaller(alice) id := m.RemovePost(postID) uassert.Equal(t, postID, id, "post IDs not matching") @@ -259,7 +259,7 @@ func TestDelete(t *testing.T) { func TestDeleteByNonAdmin(t *testing.T) { alice := testutils.TestAddress("alice") - std.TestSetOrigCaller(alice) + std.TestSetOriginCaller(alice) m := NewMemeland() @@ -269,7 +269,7 @@ func TestDeleteByNonAdmin(t *testing.T) { // Bob will try to delete meme posted by Alice, which should fail bob := testutils.TestAddress("bob") - std.TestSetOrigCaller(bob) + std.TestSetOriginCaller(bob) defer func() { if r := recover(); r == nil { diff --git a/examples/gno.land/p/demo/microblog/microblog.gno b/examples/gno.land/p/demo/microblog/microblog.gno index f6d6709f20b..b94398f1cf0 100644 --- a/examples/gno.land/p/demo/microblog/microblog.gno +++ b/examples/gno.land/p/demo/microblog/microblog.gno @@ -48,7 +48,7 @@ func (m *Microblog) GetPages() []*Page { } func (m *Microblog) NewPost(text string) error { - author := std.GetOrigCaller() + author := std.OriginCaller() _, found := m.Pages.Get(author.String()) if !found { // make a new page for the new author diff --git a/examples/gno.land/p/demo/nestedpkg/nestedpkg.gno b/examples/gno.land/p/demo/nestedpkg/nestedpkg.gno index 4c489f430f9..9ed8f1a155c 100644 --- a/examples/gno.land/p/demo/nestedpkg/nestedpkg.gno +++ b/examples/gno.land/p/demo/nestedpkg/nestedpkg.gno @@ -2,10 +2,10 @@ // It is useful for upgrade patterns relying on namespaces. package nestedpkg -// To test this from a realm and have std.CurrentRealm/PrevRealm work correctly, +// To test this from a realm and have std.CurrentRealm/PreviousRealm work correctly, // this file is tested from gno.land/r/demo/tests/nestedpkg_test.gno // XXX: move test to ths directory once we support testing a package and -// specifying values for both PrevRealm and CurrentRealm. +// specifying values for both PreviousRealm and CurrentRealm. import ( "std" @@ -16,7 +16,7 @@ import ( func IsCallerSubPath() bool { var ( cur = std.CurrentRealm().PkgPath() + "/" - prev = std.PrevRealm().PkgPath() + "/" + prev = std.PreviousRealm().PkgPath() + "/" ) return strings.HasPrefix(prev, cur) } @@ -25,7 +25,7 @@ func IsCallerSubPath() bool { func AssertCallerIsSubPath() { var ( cur = std.CurrentRealm().PkgPath() + "/" - prev = std.PrevRealm().PkgPath() + "/" + prev = std.PreviousRealm().PkgPath() + "/" ) if !strings.HasPrefix(prev, cur) { panic("call restricted to nested packages. current realm is " + cur + ", previous realm is " + prev) @@ -36,7 +36,7 @@ func AssertCallerIsSubPath() { func IsCallerParentPath() bool { var ( cur = std.CurrentRealm().PkgPath() + "/" - prev = std.PrevRealm().PkgPath() + "/" + prev = std.PreviousRealm().PkgPath() + "/" ) return strings.HasPrefix(cur, prev) } @@ -45,7 +45,7 @@ func IsCallerParentPath() bool { func AssertCallerIsParentPath() { var ( cur = std.CurrentRealm().PkgPath() + "/" - prev = std.PrevRealm().PkgPath() + "/" + prev = std.PreviousRealm().PkgPath() + "/" ) if !strings.HasPrefix(cur, prev) { panic("call restricted to parent packages. current realm is " + cur + ", previous realm is " + prev) @@ -56,7 +56,7 @@ func AssertCallerIsParentPath() { func IsSameNamespace() bool { var ( cur = nsFromPath(std.CurrentRealm().PkgPath()) + "/" - prev = nsFromPath(std.PrevRealm().PkgPath()) + "/" + prev = nsFromPath(std.PreviousRealm().PkgPath()) + "/" ) return cur == prev } @@ -65,7 +65,7 @@ func IsSameNamespace() bool { func AssertIsSameNamespace() { var ( cur = nsFromPath(std.CurrentRealm().PkgPath()) + "/" - prev = nsFromPath(std.PrevRealm().PkgPath()) + "/" + prev = nsFromPath(std.PreviousRealm().PkgPath()) + "/" ) if cur != prev { panic("call restricted to packages from the same namespace. current realm is " + cur + ", previous realm is " + prev) diff --git a/examples/gno.land/p/demo/ownable/exts/authorizable/authorizable.gno b/examples/gno.land/p/demo/ownable/exts/authorizable/authorizable.gno index 95bd2ac4959..ef2428ab2ed 100644 --- a/examples/gno.land/p/demo/ownable/exts/authorizable/authorizable.gno +++ b/examples/gno.land/p/demo/ownable/exts/authorizable/authorizable.gno @@ -72,7 +72,7 @@ func (a *Authorizable) DeleteFromAuthList(addr std.Address) error { } func (a Authorizable) CallerOnAuthList() error { - caller := std.PrevRealm().Addr() + caller := std.PreviousRealm().Address() if !a.authorized.Has(caller.String()) { return ErrNotInAuthList @@ -82,7 +82,7 @@ func (a Authorizable) CallerOnAuthList() error { } func (a Authorizable) AssertOnAuthList() { - caller := std.PrevRealm().Addr() + caller := std.PreviousRealm().Address() if !a.authorized.Has(caller.String()) { panic(ErrNotInAuthList) diff --git a/examples/gno.land/p/demo/ownable/exts/authorizable/authorizable_test.gno b/examples/gno.land/p/demo/ownable/exts/authorizable/authorizable_test.gno index 10a5e411bdb..8fb1b9422f6 100644 --- a/examples/gno.land/p/demo/ownable/exts/authorizable/authorizable_test.gno +++ b/examples/gno.land/p/demo/ownable/exts/authorizable/authorizable_test.gno @@ -16,7 +16,7 @@ var ( func TestNewAuthorizable(t *testing.T) { std.TestSetRealm(std.NewUserRealm(alice)) - std.TestSetOrigCaller(alice) // TODO(bug, issue #2371): should not be needed + std.TestSetOriginCaller(alice) // TODO(bug, issue #2371): should not be needed a := NewAuthorizable() got := a.Owner() @@ -39,7 +39,7 @@ func TestNewAuthorizableWithAddress(t *testing.T) { func TestCallerOnAuthList(t *testing.T) { a := NewAuthorizableWithAddress(alice) std.TestSetRealm(std.NewUserRealm(alice)) - std.TestSetOrigCaller(alice) + std.TestSetOriginCaller(alice) if err := a.CallerOnAuthList(); err == ErrNotInAuthList { t.Fatalf("expected alice to be on the list") @@ -49,7 +49,7 @@ func TestCallerOnAuthList(t *testing.T) { func TestNotCallerOnAuthList(t *testing.T) { a := NewAuthorizableWithAddress(alice) std.TestSetRealm(std.NewUserRealm(bob)) - std.TestSetOrigCaller(bob) + std.TestSetOriginCaller(bob) if err := a.CallerOnAuthList(); err == nil { t.Fatalf("expected bob to not be on the list") @@ -59,14 +59,14 @@ func TestNotCallerOnAuthList(t *testing.T) { func TestAddToAuthList(t *testing.T) { a := NewAuthorizableWithAddress(alice) std.TestSetRealm(std.NewUserRealm(alice)) - std.TestSetOrigCaller(alice) + std.TestSetOriginCaller(alice) if err := a.AddToAuthList(bob); err != nil { t.Fatalf("Expected no error, got %v", err) } std.TestSetRealm(std.NewUserRealm(bob)) - std.TestSetOrigCaller(bob) + std.TestSetOriginCaller(bob) if err := a.AddToAuthList(bob); err == nil { t.Fatalf("Expected AddToAuth to error while bob called it, but it didn't") @@ -76,7 +76,7 @@ func TestAddToAuthList(t *testing.T) { func TestDeleteFromList(t *testing.T) { a := NewAuthorizableWithAddress(alice) std.TestSetRealm(std.NewUserRealm(alice)) - std.TestSetOrigCaller(alice) + std.TestSetOriginCaller(alice) if err := a.AddToAuthList(bob); err != nil { t.Fatalf("Expected no error, got %v", err) @@ -87,7 +87,7 @@ func TestDeleteFromList(t *testing.T) { } std.TestSetRealm(std.NewUserRealm(bob)) - std.TestSetOrigCaller(bob) + std.TestSetOriginCaller(bob) // Try an unauthorized deletion if err := a.DeleteFromAuthList(alice); err == nil { @@ -95,7 +95,7 @@ func TestDeleteFromList(t *testing.T) { } std.TestSetRealm(std.NewUserRealm(alice)) - std.TestSetOrigCaller(alice) + std.TestSetOriginCaller(alice) if err := a.DeleteFromAuthList(charlie); err != nil { t.Fatalf("Expected no error, got %v", err) @@ -104,11 +104,11 @@ func TestDeleteFromList(t *testing.T) { func TestAssertOnList(t *testing.T) { std.TestSetRealm(std.NewUserRealm(alice)) - std.TestSetOrigCaller(alice) + std.TestSetOriginCaller(alice) a := NewAuthorizableWithAddress(alice) std.TestSetRealm(std.NewUserRealm(bob)) - std.TestSetOrigCaller(bob) + std.TestSetOriginCaller(bob) uassert.PanicsWithMessage(t, ErrNotInAuthList.Error(), func() { a.AssertOnAuthList() diff --git a/examples/gno.land/p/demo/ownable/ownable.gno b/examples/gno.land/p/demo/ownable/ownable.gno index f565e27c0f2..132aba42f8e 100644 --- a/examples/gno.land/p/demo/ownable/ownable.gno +++ b/examples/gno.land/p/demo/ownable/ownable.gno @@ -13,7 +13,7 @@ type Ownable struct { func New() *Ownable { return &Ownable{ - owner: std.PrevRealm().Addr(), + owner: std.PreviousRealm().Address(), } } @@ -71,12 +71,12 @@ func (o Ownable) Owner() std.Address { // CallerIsOwner checks if the caller of the function is the Realm's owner func (o Ownable) CallerIsOwner() bool { - return std.PrevRealm().Addr() == o.owner + return std.PreviousRealm().Address() == o.owner } // AssertCallerIsOwner panics if the caller is not the owner func (o Ownable) AssertCallerIsOwner() { - if std.PrevRealm().Addr() != o.owner { + if std.PreviousRealm().Address() != o.owner { panic(ErrUnauthorized) } } diff --git a/examples/gno.land/p/demo/ownable/ownable_test.gno b/examples/gno.land/p/demo/ownable/ownable_test.gno index f58af9642c6..9407445848e 100644 --- a/examples/gno.land/p/demo/ownable/ownable_test.gno +++ b/examples/gno.land/p/demo/ownable/ownable_test.gno @@ -16,7 +16,7 @@ var ( func TestNew(t *testing.T) { std.TestSetRealm(std.NewUserRealm(alice)) - std.TestSetOrigCaller(alice) // TODO(bug): should not be needed + std.TestSetOriginCaller(alice) // TODO(bug): should not be needed o := New() got := o.Owner() @@ -50,7 +50,7 @@ func TestCallerIsOwner(t *testing.T) { unauthorizedCaller := bob std.TestSetRealm(std.NewUserRealm(unauthorizedCaller)) - std.TestSetOrigCaller(unauthorizedCaller) // TODO(bug): should not be needed + std.TestSetOriginCaller(unauthorizedCaller) // TODO(bug): should not be needed uassert.False(t, o.CallerIsOwner()) } @@ -71,12 +71,12 @@ func TestDropOwnership(t *testing.T) { func TestErrUnauthorized(t *testing.T) { std.TestSetRealm(std.NewUserRealm(alice)) - std.TestSetOrigCaller(alice) // TODO(bug): should not be needed + std.TestSetOriginCaller(alice) // TODO(bug): should not be needed o := New() std.TestSetRealm(std.NewUserRealm(bob)) - std.TestSetOrigCaller(bob) // TODO(bug): should not be needed + std.TestSetOriginCaller(bob) // TODO(bug): should not be needed uassert.ErrorContains(t, o.TransferOwnership(alice), ErrUnauthorized.Error()) uassert.ErrorContains(t, o.DropOwnership(), ErrUnauthorized.Error()) diff --git a/examples/gno.land/p/demo/pausable/pausable_test.gno b/examples/gno.land/p/demo/pausable/pausable_test.gno index c9557245bdf..5678c867dc7 100644 --- a/examples/gno.land/p/demo/pausable/pausable_test.gno +++ b/examples/gno.land/p/demo/pausable/pausable_test.gno @@ -14,7 +14,7 @@ var ( ) func TestNew(t *testing.T) { - std.TestSetOrigCaller(firstCaller) + std.TestSetOriginCaller(firstCaller) result := New() @@ -23,17 +23,17 @@ func TestNew(t *testing.T) { } func TestNewFromOwnable(t *testing.T) { - std.TestSetOrigCaller(firstCaller) + std.TestSetOriginCaller(firstCaller) o := ownable.New() - std.TestSetOrigCaller(secondCaller) + std.TestSetOriginCaller(secondCaller) result := NewFromOwnable(o) urequire.Equal(t, firstCaller.String(), result.Owner().String()) } func TestSetUnpaused(t *testing.T) { - std.TestSetOrigCaller(firstCaller) + std.TestSetOriginCaller(firstCaller) result := New() result.Unpause() @@ -42,7 +42,7 @@ func TestSetUnpaused(t *testing.T) { } func TestSetPaused(t *testing.T) { - std.TestSetOrigCaller(firstCaller) + std.TestSetOriginCaller(firstCaller) result := New() result.Pause() @@ -51,7 +51,7 @@ func TestSetPaused(t *testing.T) { } func TestIsPaused(t *testing.T) { - std.TestSetOrigCaller(firstCaller) + std.TestSetOriginCaller(firstCaller) result := New() urequire.False(t, result.IsPaused(), "Expected result to be unpaused") diff --git a/examples/gno.land/p/demo/simpledao/dao.gno b/examples/gno.land/p/demo/simpledao/dao.gno index 837f64a41d6..a8194eecdea 100644 --- a/examples/gno.land/p/demo/simpledao/dao.gno +++ b/examples/gno.land/p/demo/simpledao/dao.gno @@ -56,7 +56,7 @@ func (s *SimpleDAO) Propose(request dao.ProposalRequest) (uint64, error) { var ( caller = getDAOCaller() - sentCoins = std.GetOrigSend() // Get the sent coins, if any + sentCoins = std.OriginSend() // Get the sent coins, if any canCoverFee = sentCoins.AmountOf("ugnot") >= minProposalFee.Amount ) @@ -168,7 +168,7 @@ func (s *SimpleDAO) VoteOnProposal(id uint64, option dao.VoteOption) error { func (s *SimpleDAO) ExecuteProposal(id uint64) error { var ( caller = getDAOCaller() - sentCoins = std.GetOrigSend() // Get the sent coins, if any + sentCoins = std.OriginSend() // Get the sent coins, if any canCoverFee = sentCoins.AmountOf("ugnot") >= minExecuteFee.Amount ) @@ -219,5 +219,5 @@ func (s *SimpleDAO) ExecuteProposal(id uint64) error { // However, the current MsgRun context does not persist escaping the main() scope. // Until a better solution is developed, this enables proposals to be made through a package deployment + init() func getDAOCaller() std.Address { - return std.GetOrigCaller() + return std.OriginCaller() } diff --git a/examples/gno.land/p/demo/simpledao/dao_test.gno b/examples/gno.land/p/demo/simpledao/dao_test.gno index 46251e24dad..601dac8db77 100644 --- a/examples/gno.land/p/demo/simpledao/dao_test.gno +++ b/examples/gno.land/p/demo/simpledao/dao_test.gno @@ -74,7 +74,7 @@ func TestSimpleDAO_Propose(t *testing.T) { s = New(ms) ) - std.TestSetOrigSend(sentCoins, std.Coins{}) + std.TestSetOriginSend(sentCoins, std.Coins{}) _, err := s.Propose(dao.ProposalRequest{ Executor: ex, @@ -121,7 +121,7 @@ func TestSimpleDAO_Propose(t *testing.T) { // Set the sent coins to be lower // than the proposal fee - std.TestSetOrigSend(sentCoins, std.Coins{}) + std.TestSetOriginSend(sentCoins, std.Coins{}) _, err := s.Propose(dao.ProposalRequest{ Executor: ex, @@ -171,8 +171,8 @@ func TestSimpleDAO_Propose(t *testing.T) { // Set the sent coins to be enough // to cover the fee - std.TestSetOrigSend(sentCoins, std.Coins{}) - std.TestSetOrigCaller(proposer) + std.TestSetOriginSend(sentCoins, std.Coins{}) + std.TestSetOriginCaller(proposer) // Make sure the proposal was added id, err := s.Propose(dao.ProposalRequest{ @@ -221,7 +221,7 @@ func TestSimpleDAO_VoteOnProposal(t *testing.T) { s = New(ms) ) - std.TestSetOrigCaller(voter) + std.TestSetOriginCaller(voter) // Attempt to vote on the proposal uassert.ErrorContains( @@ -251,7 +251,7 @@ func TestSimpleDAO_VoteOnProposal(t *testing.T) { s = New(ms) ) - std.TestSetOrigCaller(voter) + std.TestSetOriginCaller(voter) // Attempt to vote on the proposal uassert.ErrorContains( @@ -285,7 +285,7 @@ func TestSimpleDAO_VoteOnProposal(t *testing.T) { } ) - std.TestSetOrigCaller(voter) + std.TestSetOriginCaller(voter) // Add an initial proposal id, err := s.addProposal(prop) @@ -327,7 +327,7 @@ func TestSimpleDAO_VoteOnProposal(t *testing.T) { } ) - std.TestSetOrigCaller(voter) + std.TestSetOriginCaller(voter) // Cast the initial vote urequire.NoError(t, prop.tally.castVote(member, dao.YesVote)) @@ -386,7 +386,7 @@ func TestSimpleDAO_VoteOnProposal(t *testing.T) { majorityIndex := (len(members)*2)/3 + 1 // 2/3+ for _, m := range members[:majorityIndex] { - std.TestSetOrigCaller(m.Address) + std.TestSetOriginCaller(m.Address) // Attempt to vote on the proposal urequire.NoError( @@ -441,7 +441,7 @@ func TestSimpleDAO_VoteOnProposal(t *testing.T) { majorityIndex := (len(members)*2)/3 + 1 // 2/3+ for _, m := range members[:majorityIndex] { - std.TestSetOrigCaller(m.Address) + std.TestSetOriginCaller(m.Address) // Attempt to vote on the proposal urequire.NoError( @@ -496,7 +496,7 @@ func TestSimpleDAO_VoteOnProposal(t *testing.T) { majorityIndex := (len(members)*2)/3 + 1 // 2/3+ for _, m := range members[:majorityIndex] { - std.TestSetOrigCaller(m.Address) + std.TestSetOriginCaller(m.Address) // Attempt to vote on the proposal urequire.NoError( @@ -551,7 +551,7 @@ func TestSimpleDAO_VoteOnProposal(t *testing.T) { // The first half votes yes for _, m := range members[:len(members)/2] { - std.TestSetOrigCaller(m.Address) + std.TestSetOriginCaller(m.Address) // Attempt to vote on the proposal urequire.NoError( @@ -562,7 +562,7 @@ func TestSimpleDAO_VoteOnProposal(t *testing.T) { // The other half votes no for _, m := range members[len(members)/2:] { - std.TestSetOrigCaller(m.Address) + std.TestSetOriginCaller(m.Address) // Attempt to vote on the proposal urequire.NoError( @@ -618,7 +618,7 @@ func TestSimpleDAO_VoteOnProposal(t *testing.T) { // The first quarter votes yes for _, m := range members[:len(members)/4] { - std.TestSetOrigCaller(m.Address) + std.TestSetOriginCaller(m.Address) // Attempt to vote on the proposal urequire.NoError( @@ -629,7 +629,7 @@ func TestSimpleDAO_VoteOnProposal(t *testing.T) { // The second quarter votes no for _, m := range members[len(members)/4 : len(members)/2] { - std.TestSetOrigCaller(m.Address) + std.TestSetOriginCaller(m.Address) // Attempt to vote on the proposal urequire.NoError( @@ -668,7 +668,7 @@ func TestSimpleDAO_ExecuteProposal(t *testing.T) { // Set the sent coins to be lower // than the execute fee - std.TestSetOrigSend(sentCoins, std.Coins{}) + std.TestSetOriginSend(sentCoins, std.Coins{}) uassert.ErrorIs( t, @@ -699,7 +699,7 @@ func TestSimpleDAO_ExecuteProposal(t *testing.T) { // Set the sent coins to be enough // so the execution can take place - std.TestSetOrigSend(sentCoins, std.Coins{}) + std.TestSetOriginSend(sentCoins, std.Coins{}) uassert.ErrorContains( t, @@ -726,7 +726,7 @@ func TestSimpleDAO_ExecuteProposal(t *testing.T) { } ) - std.TestSetOrigCaller(voter) + std.TestSetOriginCaller(voter) // Add an initial proposal id, err := s.addProposal(prop) @@ -776,7 +776,7 @@ func TestSimpleDAO_ExecuteProposal(t *testing.T) { } ) - std.TestSetOrigCaller(voter) + std.TestSetOriginCaller(voter) // Add an initial proposal id, err := s.addProposal(prop) @@ -820,7 +820,7 @@ func TestSimpleDAO_ExecuteProposal(t *testing.T) { } ) - std.TestSetOrigCaller(voter) + std.TestSetOriginCaller(voter) // Add an initial proposal id, err := s.addProposal(prop) @@ -864,7 +864,7 @@ func TestSimpleDAO_ExecuteProposal(t *testing.T) { } ) - std.TestSetOrigCaller(voter) + std.TestSetOriginCaller(voter) // Add an initial proposal id, err := s.addProposal(prop) diff --git a/examples/gno.land/p/demo/subscription/lifetime/lifetime.gno b/examples/gno.land/p/demo/subscription/lifetime/lifetime.gno index be661e70129..cbd7fde04a4 100644 --- a/examples/gno.land/p/demo/subscription/lifetime/lifetime.gno +++ b/examples/gno.land/p/demo/subscription/lifetime/lifetime.gno @@ -26,7 +26,7 @@ func NewLifetimeSubscription(amount int64) *LifetimeSubscription { // processSubscription handles the subscription process for a given receiver. func (ls *LifetimeSubscription) processSubscription(receiver std.Address) error { - amount := std.GetOrigSend() + amount := std.OriginSend() if amount.AmountOf("ugnot") != ls.amount { return ErrAmt @@ -45,7 +45,7 @@ func (ls *LifetimeSubscription) processSubscription(receiver std.Address) error // Subscribe processes the payment for a lifetime subscription. func (ls *LifetimeSubscription) Subscribe() error { - caller := std.PrevRealm().Addr() + caller := std.PreviousRealm().Address() return ls.processSubscription(caller) } diff --git a/examples/gno.land/p/demo/subscription/lifetime/lifetime_test.gno b/examples/gno.land/p/demo/subscription/lifetime/lifetime_test.gno index efbae90c11c..eba1f2b5367 100644 --- a/examples/gno.land/p/demo/subscription/lifetime/lifetime_test.gno +++ b/examples/gno.land/p/demo/subscription/lifetime/lifetime_test.gno @@ -18,11 +18,11 @@ func TestLifetimeSubscription(t *testing.T) { std.TestSetRealm(std.NewUserRealm(alice)) ls := NewLifetimeSubscription(1000) - std.TestSetOrigSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}, nil) + std.TestSetOriginSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}, nil) err := ls.Subscribe() uassert.NoError(t, err, "Expected ProcessPayment to succeed") - err = ls.HasValidSubscription(std.PrevRealm().Addr()) + err = ls.HasValidSubscription(std.PreviousRealm().Address()) uassert.NoError(t, err, "Expected Alice to have access") } @@ -30,7 +30,7 @@ func TestLifetimeSubscriptionGift(t *testing.T) { std.TestSetRealm(std.NewUserRealm(alice)) ls := NewLifetimeSubscription(1000) - std.TestSetOrigSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}, nil) + std.TestSetOriginSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}, nil) err := ls.GiftSubscription(bob) uassert.NoError(t, err, "Expected ProcessPaymentGift to succeed for Bob") @@ -48,7 +48,7 @@ func TestUpdateAmountAuthorization(t *testing.T) { err := ls.UpdateAmount(2000) uassert.NoError(t, err, "Expected Alice to succeed in updating amount") - std.TestSetOrigCaller(bob) + std.TestSetOriginCaller(bob) err = ls.UpdateAmount(3000) uassert.Error(t, err, "Expected Bob to fail when updating amount") @@ -58,7 +58,7 @@ func TestIncorrectPaymentAmount(t *testing.T) { std.TestSetRealm(std.NewUserRealm(alice)) ls := NewLifetimeSubscription(1000) - std.TestSetOrigSend([]std.Coin{{Denom: "ugnot", Amount: 500}}, nil) + std.TestSetOriginSend([]std.Coin{{Denom: "ugnot", Amount: 500}}, nil) err := ls.Subscribe() uassert.Error(t, err, "Expected payment to fail with incorrect amount") } @@ -67,11 +67,11 @@ func TestMultipleSubscriptionAttempts(t *testing.T) { std.TestSetRealm(std.NewUserRealm(alice)) ls := NewLifetimeSubscription(1000) - std.TestSetOrigSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}, nil) + std.TestSetOriginSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}, nil) err := ls.Subscribe() uassert.NoError(t, err, "Expected first subscription to succeed") - std.TestSetOrigSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}, nil) + std.TestSetOriginSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}, nil) err = ls.Subscribe() uassert.Error(t, err, "Expected second subscription to fail as Alice is already subscribed") } @@ -80,7 +80,7 @@ func TestGiftSubscriptionWithIncorrectAmount(t *testing.T) { std.TestSetRealm(std.NewUserRealm(alice)) ls := NewLifetimeSubscription(1000) - std.TestSetOrigSend([]std.Coin{{Denom: "ugnot", Amount: 500}}, nil) + std.TestSetOriginSend([]std.Coin{{Denom: "ugnot", Amount: 500}}, nil) err := ls.GiftSubscription(bob) uassert.Error(t, err, "Expected gift subscription to fail with incorrect amount") @@ -95,11 +95,11 @@ func TestUpdateAmountEffectiveness(t *testing.T) { err := ls.UpdateAmount(2000) uassert.NoError(t, err, "Expected Alice to succeed in updating amount") - std.TestSetOrigSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}, nil) + std.TestSetOriginSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}, nil) err = ls.Subscribe() uassert.Error(t, err, "Expected subscription to fail with old amount after update") - std.TestSetOrigSend([]std.Coin{{Denom: "ugnot", Amount: 2000}}, nil) + std.TestSetOriginSend([]std.Coin{{Denom: "ugnot", Amount: 2000}}, nil) err = ls.Subscribe() uassert.NoError(t, err, "Expected subscription to succeed with new amount") } diff --git a/examples/gno.land/p/demo/subscription/recurring/recurring.gno b/examples/gno.land/p/demo/subscription/recurring/recurring.gno index 8f116009aa6..2582c959bc6 100644 --- a/examples/gno.land/p/demo/subscription/recurring/recurring.gno +++ b/examples/gno.land/p/demo/subscription/recurring/recurring.gno @@ -43,7 +43,7 @@ func (rs *RecurringSubscription) HasValidSubscription(addr std.Address) error { // processSubscription processes the payment for a given receiver and renews or adds their subscription. func (rs *RecurringSubscription) processSubscription(receiver std.Address) error { - amount := std.GetOrigSend() + amount := std.OriginSend() if amount.AmountOf("ugnot") != rs.amount { return ErrAmt @@ -68,7 +68,7 @@ func (rs *RecurringSubscription) processSubscription(receiver std.Address) error // Subscribe handles the payment for the caller's subscription. func (rs *RecurringSubscription) Subscribe() error { - caller := std.PrevRealm().Addr() + caller := std.PreviousRealm().Address() return rs.processSubscription(caller) } diff --git a/examples/gno.land/p/demo/subscription/recurring/recurring_test.gno b/examples/gno.land/p/demo/subscription/recurring/recurring_test.gno index 0b458b716ec..c3289c05388 100644 --- a/examples/gno.land/p/demo/subscription/recurring/recurring_test.gno +++ b/examples/gno.land/p/demo/subscription/recurring/recurring_test.gno @@ -19,14 +19,14 @@ func TestRecurringSubscription(t *testing.T) { std.TestSetRealm(std.NewUserRealm(alice)) rs := NewRecurringSubscription(time.Hour*24, 1000) - std.TestSetOrigSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}, nil) + std.TestSetOriginSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}, nil) err := rs.Subscribe() uassert.NoError(t, err, "Expected ProcessPayment to succeed for Alice") - err = rs.HasValidSubscription(std.PrevRealm().Addr()) + err = rs.HasValidSubscription(std.PreviousRealm().Address()) uassert.NoError(t, err, "Expected Alice to have access") - _, err = rs.GetExpiration(std.PrevRealm().Addr()) + _, err = rs.GetExpiration(std.PreviousRealm().Address()) uassert.NoError(t, err, "Expected to get expiration for Alice") } @@ -34,7 +34,7 @@ func TestRecurringSubscriptionGift(t *testing.T) { std.TestSetRealm(std.NewUserRealm(alice)) rs := NewRecurringSubscription(time.Hour*24, 1000) - std.TestSetOrigSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}, nil) + std.TestSetOriginSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}, nil) err := rs.GiftSubscription(bob) uassert.NoError(t, err, "Expected ProcessPaymentGift to succeed for Bob") @@ -49,17 +49,17 @@ func TestRecurringSubscriptionExpiration(t *testing.T) { std.TestSetRealm(std.NewUserRealm(alice)) rs := NewRecurringSubscription(time.Hour, 1000) - std.TestSetOrigSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}, nil) + std.TestSetOriginSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}, nil) err := rs.Subscribe() uassert.NoError(t, err, "Expected ProcessPayment to succeed for Alice") - err = rs.HasValidSubscription(std.PrevRealm().Addr()) + err = rs.HasValidSubscription(std.PreviousRealm().Address()) uassert.NoError(t, err, "Expected Alice to have access") expiration := time.Now().Add(-time.Hour * 2) - rs.subs.Set(std.PrevRealm().Addr().String(), expiration) + rs.subs.Set(std.PreviousRealm().Address().String(), expiration) - err = rs.HasValidSubscription(std.PrevRealm().Addr()) + err = rs.HasValidSubscription(std.PreviousRealm().Address()) uassert.Error(t, err, "Expected Alice's subscription to be expired") } @@ -70,7 +70,7 @@ func TestUpdateAmountAuthorization(t *testing.T) { err := rs.UpdateAmount(2000) uassert.NoError(t, err, "Expected Alice to succeed in updating amount") - std.TestSetOrigCaller(bob) + std.TestSetOriginCaller(bob) err = rs.UpdateAmount(3000) uassert.Error(t, err, "Expected Bob to fail when updating amount") } @@ -93,7 +93,7 @@ func TestIncorrectPaymentAmount(t *testing.T) { std.TestSetRealm(std.NewUserRealm(alice)) rs := NewRecurringSubscription(time.Hour*24, 1000) - std.TestSetOrigSend([]std.Coin{{Denom: "ugnot", Amount: 500}}, nil) + std.TestSetOriginSend([]std.Coin{{Denom: "ugnot", Amount: 500}}, nil) err := rs.Subscribe() uassert.Error(t, err, "Expected payment with incorrect amount to fail") } @@ -102,11 +102,11 @@ func TestMultiplePaymentsForSameUser(t *testing.T) { std.TestSetRealm(std.NewUserRealm(alice)) rs := NewRecurringSubscription(time.Hour*24, 1000) - std.TestSetOrigSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}, nil) + std.TestSetOriginSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}, nil) err := rs.Subscribe() uassert.NoError(t, err, "Expected first ProcessPayment to succeed for Alice") - std.TestSetOrigSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}, nil) + std.TestSetOriginSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}, nil) err = rs.Subscribe() uassert.Error(t, err, "Expected second ProcessPayment to fail for Alice due to existing subscription") } @@ -115,20 +115,20 @@ func TestRecurringSubscriptionWithMultiplePayments(t *testing.T) { std.TestSetRealm(std.NewUserRealm(alice)) rs := NewRecurringSubscription(time.Hour, 1000) - std.TestSetOrigSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}, nil) + std.TestSetOriginSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}, nil) err := rs.Subscribe() uassert.NoError(t, err, "Expected first ProcessPayment to succeed for Alice") - err = rs.HasValidSubscription(std.PrevRealm().Addr()) + err = rs.HasValidSubscription(std.PreviousRealm().Address()) uassert.NoError(t, err, "Expected Alice to have access after first payment") expiration := time.Now().Add(-time.Hour * 2) - rs.subs.Set(std.PrevRealm().Addr().String(), expiration) + rs.subs.Set(std.PreviousRealm().Address().String(), expiration) - std.TestSetOrigSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}, nil) + std.TestSetOriginSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}, nil) err = rs.Subscribe() uassert.NoError(t, err, "Expected second ProcessPayment to succeed for Alice") - err = rs.HasValidSubscription(std.PrevRealm().Addr()) + err = rs.HasValidSubscription(std.PreviousRealm().Address()) uassert.NoError(t, err, "Expected Alice to have access after second payment") } diff --git a/examples/gno.land/p/demo/tests/subtests/subtests.gno b/examples/gno.land/p/demo/tests/subtests/subtests.gno index e8796a73081..8a7f3572cfa 100644 --- a/examples/gno.land/p/demo/tests/subtests/subtests.gno +++ b/examples/gno.land/p/demo/tests/subtests/subtests.gno @@ -8,8 +8,8 @@ func GetCurrentRealm() std.Realm { return std.CurrentRealm() } -func GetPrevRealm() std.Realm { - return std.PrevRealm() +func GetPreviousRealm() std.Realm { + return std.PreviousRealm() } func Exec(fn func()) { diff --git a/examples/gno.land/p/demo/tests/tests.gno b/examples/gno.land/p/demo/tests/tests.gno index ffad5b8c8cd..ae3468c5d48 100644 --- a/examples/gno.land/p/demo/tests/tests.gno +++ b/examples/gno.land/p/demo/tests/tests.gno @@ -47,12 +47,12 @@ func ModifyTestRealmObject2c() { SomeValue3.Field = "modified" } -func GetPrevRealm() std.Realm { - return std.PrevRealm() +func GetPreviousRealm() std.Realm { + return std.PreviousRealm() } -func GetPSubtestsPrevRealm() std.Realm { - return psubtests.GetPrevRealm() +func GetPSubtestsPreviousRealm() std.Realm { + return psubtests.GetPreviousRealm() } // Warning: unsafe pattern. diff --git a/examples/gno.land/p/demo/testutils/misc.gno b/examples/gno.land/p/demo/testutils/misc.gno index d48304ad441..60dd611ef49 100644 --- a/examples/gno.land/p/demo/testutils/misc.gno +++ b/examples/gno.land/p/demo/testutils/misc.gno @@ -1,6 +1,6 @@ package testutils -// For testing std.GetCallerAt(). +// For testing std.CallerAt(). func WrapCall(fn func()) { fn() } diff --git a/examples/gno.land/p/demo/todolist/todolist.gno b/examples/gno.land/p/demo/todolist/todolist.gno index a675344655f..531daf1dcb3 100644 --- a/examples/gno.land/p/demo/todolist/todolist.gno +++ b/examples/gno.land/p/demo/todolist/todolist.gno @@ -22,7 +22,7 @@ func NewTodoList(title string) *TodoList { return &TodoList{ Title: title, Tasks: avl.NewTree(), - Owner: std.GetOrigCaller(), + Owner: std.OriginCaller(), } } diff --git a/examples/gno.land/p/demo/todolist/todolist_test.gno b/examples/gno.land/p/demo/todolist/todolist_test.gno index 85836e2a17f..26daf05a374 100644 --- a/examples/gno.land/p/demo/todolist/todolist_test.gno +++ b/examples/gno.land/p/demo/todolist/todolist_test.gno @@ -13,7 +13,7 @@ func TestNewTodoList(t *testing.T) { uassert.Equal(t, title, todoList.GetTodolistTitle()) uassert.Equal(t, 0, len(todoList.GetTasks())) - uassert.Equal(t, std.GetOrigCaller().String(), todoList.GetTodolistOwner().String()) + uassert.Equal(t, std.OriginCaller().String(), todoList.GetTodolistOwner().String()) } func TestNewTask(t *testing.T) { diff --git a/examples/gno.land/p/moul/debug/debug.gno b/examples/gno.land/p/moul/debug/debug.gno index 9ba3dd36a98..3bfe612c780 100644 --- a/examples/gno.land/p/moul/debug/debug.gno +++ b/examples/gno.land/p/moul/debug/debug.gno @@ -50,10 +50,10 @@ func (d Debug) Render(path string) string { Headers: []string{"Key", "Value"}, } table.Append([]string{"`std.CurrentRealm().PkgPath()`", string(std.CurrentRealm().PkgPath())}) - table.Append([]string{"`std.CurrentRealm().Addr()`", string(std.CurrentRealm().Addr())}) - table.Append([]string{"`std.PrevRealm().PkgPath()`", string(std.PrevRealm().PkgPath())}) - table.Append([]string{"`std.PrevRealm().Addr()`", string(std.PrevRealm().Addr())}) - table.Append([]string{"`std.GetHeight()`", ufmt.Sprintf("%d", std.GetHeight())}) + table.Append([]string{"`std.CurrentRealm().Address()`", string(std.CurrentRealm().Address())}) + table.Append([]string{"`std.PreviousRealm().PkgPath()`", string(std.PreviousRealm().PkgPath())}) + table.Append([]string{"`std.PreviousRealm().Address()`", string(std.PreviousRealm().Address())}) + table.Append([]string{"`std.ChainHeight()`", ufmt.Sprintf("%d", std.ChainHeight())}) table.Append([]string{"`time.Now().Format(time.RFC3339)`", time.Now().Format(time.RFC3339)}) content += table.String() } diff --git a/examples/gno.land/p/moul/debug/z1_filetest.gno b/examples/gno.land/p/moul/debug/z1_filetest.gno index 8203749d3c7..5016fdab605 100644 --- a/examples/gno.land/p/moul/debug/z1_filetest.gno +++ b/examples/gno.land/p/moul/debug/z1_filetest.gno @@ -20,10 +20,10 @@ func main() { // | Key | Value | // | --- | --- | // | `std.CurrentRealm().PkgPath()` | | -// | `std.CurrentRealm().Addr()` | g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm | -// | `std.PrevRealm().PkgPath()` | | -// | `std.PrevRealm().Addr()` | g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm | -// | `std.GetHeight()` | 123 | +// | `std.CurrentRealm().Address()` | g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm | +// | `std.PreviousRealm().PkgPath()` | | +// | `std.PreviousRealm().Address()` | g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm | +// | `std.ChainHeight()` | 123 | // | `time.Now().Format(time.RFC3339)` | 2009-02-13T23:31:30Z | // // diff --git a/examples/gno.land/p/moul/debug/z2_filetest.gno b/examples/gno.land/p/moul/debug/z2_filetest.gno index 32c2fe49951..fab7e57cdc2 100644 --- a/examples/gno.land/p/moul/debug/z2_filetest.gno +++ b/examples/gno.land/p/moul/debug/z2_filetest.gno @@ -26,10 +26,10 @@ func main() { // | Key | Value | // | --- | --- | // | `std.CurrentRealm().PkgPath()` | | -// | `std.CurrentRealm().Addr()` | g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm | -// | `std.PrevRealm().PkgPath()` | | -// | `std.PrevRealm().Addr()` | g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm | -// | `std.GetHeight()` | 123 | +// | `std.CurrentRealm().Address()` | g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm | +// | `std.PreviousRealm().PkgPath()` | | +// | `std.PreviousRealm().Address()` | g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm | +// | `std.ChainHeight()` | 123 | // | `time.Now().Format(time.RFC3339)` | 2009-02-13T23:31:30Z | // // diff --git a/examples/gno.land/p/n2p5/loci/loci.gno b/examples/gno.land/p/n2p5/loci/loci.gno index 7bd5c29c3af..a50c537a8f4 100644 --- a/examples/gno.land/p/n2p5/loci/loci.gno +++ b/examples/gno.land/p/n2p5/loci/loci.gno @@ -25,10 +25,10 @@ func New() *LociStore { } } -// Set stores a byte slice in the AVL tree using the `std.PrevRealm().Addr()` +// Set stores a byte slice in the AVL tree using the `std.PreviousRealm().Address()` // string as the key. func (s *LociStore) Set(value []byte) { - key := string(std.PrevRealm().Addr()) + key := string(std.PreviousRealm().Address()) s.internal.Set(key, value) } diff --git a/examples/gno.land/p/n2p5/loci/loci_test.gno b/examples/gno.land/p/n2p5/loci/loci_test.gno index 6df6d4f9b2d..ad5342edf2d 100644 --- a/examples/gno.land/p/n2p5/loci/loci_test.gno +++ b/examples/gno.land/p/n2p5/loci/loci_test.gno @@ -15,7 +15,7 @@ func TestLociStore(t *testing.T) { m1 := []byte("hello") m2 := []byte("world") - std.TestSetOrigCaller(u1) + std.TestSetOriginCaller(u1) // Ensure that the value is nil before setting it. r1 := store.Get(u1) @@ -47,11 +47,11 @@ func TestLociStore(t *testing.T) { m2 := []byte("world") m3 := []byte("goodbye") - std.TestSetOrigCaller(u1) + std.TestSetOriginCaller(u1) store.Set(m1) - std.TestSetOrigCaller(u2) + std.TestSetOriginCaller(u2) store.Set(m2) - std.TestSetOrigCaller(u3) + std.TestSetOriginCaller(u3) store.Set(m3) // Ensure that the value is correct after setting it. diff --git a/examples/gno.land/p/n2p5/mgroup/mgroup.gno b/examples/gno.land/p/n2p5/mgroup/mgroup.gno index 566d625a003..6e14ca6d38b 100644 --- a/examples/gno.land/p/n2p5/mgroup/mgroup.gno +++ b/examples/gno.land/p/n2p5/mgroup/mgroup.gno @@ -74,7 +74,7 @@ func (g *ManagedGroup) RemoveBackupOwner(addr std.Address) error { // If the caller is not a backup owner, an error is returned. // The caller is automatically added as a member of the group. func (g *ManagedGroup) ClaimOwnership() error { - caller := std.PrevRealm().Addr() + caller := std.PreviousRealm().Address() // already owner, skip if caller == g.Owner() { return nil diff --git a/examples/gno.land/p/n2p5/mgroup/mgroup_test.gno b/examples/gno.land/p/n2p5/mgroup/mgroup_test.gno index cd02db98683..13db176d8bf 100644 --- a/examples/gno.land/p/n2p5/mgroup/mgroup_test.gno +++ b/examples/gno.land/p/n2p5/mgroup/mgroup_test.gno @@ -21,7 +21,7 @@ func TestManagedGroup(t *testing.T) { g := New(u1) // happy path { - std.TestSetOrigCaller(u1) + std.TestSetOriginCaller(u1) err := g.AddBackupOwner(u2) if err != nil { t.Errorf("expected nil, got %v", err.Error()) @@ -29,7 +29,7 @@ func TestManagedGroup(t *testing.T) { } // ensure checking for authorized caller { - std.TestSetOrigCaller(u2) + std.TestSetOriginCaller(u2) err := g.AddBackupOwner(u3) if err != ownable.ErrUnauthorized { t.Errorf("expected %v, got %v", ErrNotBackupOwner.Error(), err.Error()) @@ -37,7 +37,7 @@ func TestManagedGroup(t *testing.T) { } // ensure invalid address is caught { - std.TestSetOrigCaller(u1) + std.TestSetOriginCaller(u1) var badAddr std.Address err := g.AddBackupOwner(badAddr) if err != ErrInvalidAddress { @@ -50,7 +50,7 @@ func TestManagedGroup(t *testing.T) { g := New(u1) // happy path { - std.TestSetOrigCaller(u1) + std.TestSetOriginCaller(u1) g.AddBackupOwner(u2) err := g.RemoveBackupOwner(u2) if err != nil { @@ -59,7 +59,7 @@ func TestManagedGroup(t *testing.T) { } // running this twice should not error. { - std.TestSetOrigCaller(u1) + std.TestSetOriginCaller(u1) err := g.RemoveBackupOwner(u2) if err != nil { t.Errorf("expected nil, got %v", err.Error()) @@ -67,14 +67,14 @@ func TestManagedGroup(t *testing.T) { } // ensure checking for authorized caller { - std.TestSetOrigCaller(u2) + std.TestSetOriginCaller(u2) err := g.RemoveBackupOwner(u3) if err != ownable.ErrUnauthorized { t.Errorf("expected %v, got %v", ErrNotBackupOwner.Error(), err.Error()) } } { - std.TestSetOrigCaller(u1) + std.TestSetOriginCaller(u1) var badAddr std.Address err := g.RemoveBackupOwner(badAddr) if err != ErrInvalidAddress { @@ -82,7 +82,7 @@ func TestManagedGroup(t *testing.T) { } } { - std.TestSetOrigCaller(u1) + std.TestSetOriginCaller(u1) err := g.RemoveBackupOwner(u1) if err != ErrCannotRemoveOwner { t.Errorf("expected %v, got %v", ErrCannotRemoveOwner.Error(), err.Error()) @@ -95,7 +95,7 @@ func TestManagedGroup(t *testing.T) { g.AddBackupOwner(u2) // happy path { - std.TestSetOrigCaller(u2) + std.TestSetOriginCaller(u2) err := g.ClaimOwnership() if err != nil { t.Errorf("expected nil, got %v", err.Error()) @@ -109,7 +109,7 @@ func TestManagedGroup(t *testing.T) { } // running this twice should not error. { - std.TestSetOrigCaller(u2) + std.TestSetOriginCaller(u2) err := g.ClaimOwnership() if err != nil { t.Errorf("expected nil, got %v", err.Error()) @@ -117,7 +117,7 @@ func TestManagedGroup(t *testing.T) { } // ensure checking for authorized caller { - std.TestSetOrigCaller(u3) + std.TestSetOriginCaller(u3) err := g.ClaimOwnership() if err != ErrNotMember { t.Errorf("expected %v, got %v", ErrNotMember.Error(), err.Error()) @@ -129,7 +129,7 @@ func TestManagedGroup(t *testing.T) { g := New(u1) // happy path { - std.TestSetOrigCaller(u1) + std.TestSetOriginCaller(u1) err := g.AddMember(u2) if err != nil { t.Errorf("expected nil, got %v", err.Error()) @@ -140,7 +140,7 @@ func TestManagedGroup(t *testing.T) { } // ensure checking for authorized caller { - std.TestSetOrigCaller(u2) + std.TestSetOriginCaller(u2) err := g.AddMember(u3) if err != ownable.ErrUnauthorized { t.Errorf("expected %v, got %v", ownable.ErrUnauthorized.Error(), err.Error()) @@ -148,7 +148,7 @@ func TestManagedGroup(t *testing.T) { } // ensure invalid address is caught { - std.TestSetOrigCaller(u1) + std.TestSetOriginCaller(u1) var badAddr std.Address err := g.AddMember(badAddr) if err != ErrInvalidAddress { @@ -161,7 +161,7 @@ func TestManagedGroup(t *testing.T) { g := New(u1) // happy path { - std.TestSetOrigCaller(u1) + std.TestSetOriginCaller(u1) g.AddMember(u2) err := g.RemoveMember(u2) if err != nil { @@ -173,7 +173,7 @@ func TestManagedGroup(t *testing.T) { } // running this twice should not error. { - std.TestSetOrigCaller(u1) + std.TestSetOriginCaller(u1) err := g.RemoveMember(u2) if err != nil { t.Errorf("expected nil, got %v", err.Error()) @@ -181,7 +181,7 @@ func TestManagedGroup(t *testing.T) { } // ensure checking for authorized caller { - std.TestSetOrigCaller(u2) + std.TestSetOriginCaller(u2) err := g.RemoveMember(u3) if err != ownable.ErrUnauthorized { t.Errorf("expected %v, got %v", ownable.ErrUnauthorized.Error(), err.Error()) @@ -189,7 +189,7 @@ func TestManagedGroup(t *testing.T) { } // ensure invalid address is caught { - std.TestSetOrigCaller(u1) + std.TestSetOriginCaller(u1) var badAddr std.Address err := g.RemoveMember(badAddr) if err != ErrInvalidAddress { @@ -198,7 +198,7 @@ func TestManagedGroup(t *testing.T) { } // ensure owner cannot be removed { - std.TestSetOrigCaller(u1) + std.TestSetOriginCaller(u1) err := g.RemoveMember(u1) if err != ErrCannotRemoveOwner { t.Errorf("expected %v, got %v", ErrCannotRemoveOwner.Error(), err.Error()) @@ -281,7 +281,7 @@ func TestManagedGroup(t *testing.T) { if g.Owner() != u1 { t.Errorf("expected %v, got %v", u1, g.Owner()) } - std.TestSetOrigCaller(u2) + std.TestSetOriginCaller(u2) g.ClaimOwnership() if g.Owner() != u2 { t.Errorf("expected %v, got %v", u2, g.Owner()) @@ -289,7 +289,7 @@ func TestManagedGroup(t *testing.T) { }) t.Run("BackupOwners", func(t *testing.T) { t.Parallel() - std.TestSetOrigCaller(u1) + std.TestSetOriginCaller(u1) g := New(u1) g.AddBackupOwner(u2) g.AddBackupOwner(u3) @@ -309,7 +309,7 @@ func TestManagedGroup(t *testing.T) { }) t.Run("Members", func(t *testing.T) { t.Parallel() - std.TestSetOrigCaller(u1) + std.TestSetOriginCaller(u1) g := New(u1) g.AddMember(u2) g.AddMember(u3) diff --git a/examples/gno.land/r/demo/atomicswap/atomicswap.gno b/examples/gno.land/r/demo/atomicswap/atomicswap.gno index 8862feb1bed..4762431e258 100644 --- a/examples/gno.land/r/demo/atomicswap/atomicswap.gno +++ b/examples/gno.land/r/demo/atomicswap/atomicswap.gno @@ -76,14 +76,14 @@ func NewGRC20Swap(recipient std.Address, hashlock string, tokenRegistryKey strin // It allows specifying a custom timelock duration. // It is not callable with `gnokey maketx call`, but can be imported by another contract or `gnokey maketx run`. func NewCustomCoinSwap(recipient std.Address, hashlock string, timelock time.Time) (int, *Swap) { - sender := std.PrevRealm().Addr() - sent := std.GetOrigSend() + sender := std.PreviousRealm().Address() + sent := std.OriginSend() require(len(sent) != 0, "at least one coin needs to be sent") // Create the swap sendFn := func(to std.Address) { - banker := std.GetBanker(std.BankerTypeRealmSend) - pkgAddr := std.GetOrigPkgAddr() + banker := std.NewBanker(std.BankerTypeRealmSend) + pkgAddr := std.OriginPkgAddress() banker.SendCoins(pkgAddr, to, sent) } amountStr := sent.String() @@ -98,8 +98,8 @@ func NewCustomCoinSwap(recipient std.Address, hashlock string, timelock time.Tim // NewCustomGRC20Swap creates a new atomic swap contract for grc20 tokens. // It is not callable with `gnokey maketx call`, but can be imported by another contract or `gnokey maketx run`. func NewCustomGRC20Swap(recipient std.Address, hashlock string, timelock time.Time, token *grc20.Token) (int, *Swap) { - sender := std.PrevRealm().Addr() - curAddr := std.CurrentRealm().Addr() + sender := std.PreviousRealm().Address() + curAddr := std.CurrentRealm().Address() allowance := token.Allowance(sender, curAddr) require(allowance > 0, "no allowance") diff --git a/examples/gno.land/r/demo/atomicswap/atomicswap_test.gno b/examples/gno.land/r/demo/atomicswap/atomicswap_test.gno index 0bcf6a1342d..1e39a7d902d 100644 --- a/examples/gno.land/r/demo/atomicswap/atomicswap_test.gno +++ b/examples/gno.land/r/demo/atomicswap/atomicswap_test.gno @@ -29,7 +29,7 @@ func TestNewCustomCoinSwap_Claim(t *testing.T) { // Create a new swap std.TestSetRealm(std.NewUserRealm(sender)) - std.TestSetOrigSend(amount, nil) + std.TestSetOriginSend(amount, nil) id, swap := NewCustomCoinSwap(recipient, hashlockHex, timelock) uassert.Equal(t, 1, id) @@ -86,7 +86,7 @@ func TestNewCustomCoinSwap_Refund(t *testing.T) { // Create a new swap std.TestSetRealm(std.NewUserRealm(sender)) - std.TestSetOrigSend(amount, nil) + std.TestSetOriginSend(amount, nil) id, swap := NewCustomCoinSwap(recipient, hashlockHex, timelock) // Create a new swap uassert.Equal(t, 1, id) @@ -102,7 +102,7 @@ func TestNewCustomCoinSwap_Refund(t *testing.T) { // Test Refund pkgAddr := std.DerivePkgAddr("gno.land/r/demo/atomicswap") - std.TestSetOrigPkgAddr(pkgAddr) + std.TestSetOriginPkgAddress(pkgAddr) std.TestIssueCoins(pkgAddr, std.Coins{{"ugnot", 100000000}}) uassert.PanicsWithMessage(t, "timelock not expired", swap.Refund) swap.timelock = time.Now().Add(-1 * time.Hour) // override timelock @@ -233,7 +233,7 @@ func TestNewCustomGRC20Swap_Refund(t *testing.T) { // Test Refund pkgAddr := std.DerivePkgAddr("gno.land/r/demo/atomicswap") - std.TestSetOrigPkgAddr(pkgAddr) + std.TestSetOriginPkgAddress(pkgAddr) std.TestIssueCoins(pkgAddr, std.Coins{{"ugnot", 100000000}}) uassert.PanicsWithMessage(t, "timelock not expired", swap.Refund) swap.timelock = time.Now().Add(-1 * time.Hour) // override timelock @@ -372,7 +372,7 @@ func TestNewGRC20Swap_Refund(t *testing.T) { // Test Refund pkgAddr := std.DerivePkgAddr("gno.land/r/demo/atomicswap") - std.TestSetOrigPkgAddr(pkgAddr) + std.TestSetOriginPkgAddress(pkgAddr) std.TestIssueCoins(pkgAddr, std.Coins{{"ugnot", 100000000}}) uassert.PanicsWithMessage(t, "timelock not expired", swap.Refund) swap.timelock = time.Now().Add(-1 * time.Hour) // override timelock diff --git a/examples/gno.land/r/demo/atomicswap/swap.gno b/examples/gno.land/r/demo/atomicswap/swap.gno index da40805221e..299a369db26 100644 --- a/examples/gno.land/r/demo/atomicswap/swap.gno +++ b/examples/gno.land/r/demo/atomicswap/swap.gno @@ -47,7 +47,7 @@ func newSwap( func (s *Swap) Claim(preimage string) { require(!s.claimed, "already claimed") require(!s.refunded, "already refunded") - require(std.PrevRealm().Addr() == s.recipient, "unauthorized") + require(std.PreviousRealm().Address() == s.recipient, "unauthorized") hashlock := sha256.Sum256([]byte(preimage)) hashlockHex := hex.EncodeToString(hashlock[:]) @@ -61,7 +61,7 @@ func (s *Swap) Claim(preimage string) { func (s *Swap) Refund() { require(!s.claimed, "already claimed") require(!s.refunded, "already refunded") - require(std.PrevRealm().Addr() == s.sender, "unauthorized") + require(std.PreviousRealm().Address() == s.sender, "unauthorized") require(time.Now().After(s.timelock), "timelock not expired") s.refunded = true diff --git a/examples/gno.land/r/demo/banktest/README.md b/examples/gno.land/r/demo/banktest/README.md index 944757f9b12..7c41d5ca640 100644 --- a/examples/gno.land/r/demo/banktest/README.md +++ b/examples/gno.land/r/demo/banktest/README.md @@ -44,7 +44,7 @@ This means that calls to functions defined within this package are encapsulated // Deposit will take the coins (to the realm's pkgaddr) or return them to user. func Deposit(returnDenom string, returnAmount int64) string { std.AssertOriginCall() - caller := std.GetOrigCaller() + caller := std.OriginCaller() send := std.Coins{{returnDenom, returnAmount}} ``` @@ -54,7 +54,7 @@ This is the beginning of the definition of the contract function named "Deposit" // record activity act := &activity{ caller: caller, - sent: std.GetOrigSend(), + sent: std.OriginSend(), returned: send, time: time.Now(), } @@ -74,13 +74,13 @@ Updating the "latest" array for viewing at gno.land/r/demo/banktest: (w/ trailin If the user requested the return of coins... ```go - banker := std.GetBanker(std.BankerTypeOrigSend) + banker := std.NewBanker(std.BankerTypeOriginSend) ``` use a std.Banker instance to return any deposited coins to the original sender. ```go - pkgaddr := std.GetOrigPkgAddr() + pkgaddr := std.OriginPkgAddress() // TODO: use std.Coins constructors, this isn't generally safe. banker.SendCoins(pkgaddr, caller, send) return "returned!" @@ -93,8 +93,8 @@ Finally, the results are rendered via an ABCI query call when you visit [/r/demo ```go func Render(path string) string { // get realm coins. - banker := std.GetBanker(std.BankerTypeReadonly) - coins := banker.GetCoins(std.GetOrigPkgAddr()) + banker := std.NewBanker(std.BankerTypeReadonly) + coins := banker.GetCoins(std.OriginPkgAddress()) // render res := "" diff --git a/examples/gno.land/r/demo/banktest/banktest.gno b/examples/gno.land/r/demo/banktest/banktest.gno index 29c479dd025..94ec07b06e3 100644 --- a/examples/gno.land/r/demo/banktest/banktest.gno +++ b/examples/gno.land/r/demo/banktest/banktest.gno @@ -24,12 +24,12 @@ var latest [10]*activity // Deposit will take the coins (to the realm's pkgaddr) or return them to user. func Deposit(returnDenom string, returnAmount int64) string { std.AssertOriginCall() - caller := std.GetOrigCaller() + caller := std.OriginCaller() send := std.Coins{{returnDenom, returnAmount}} // record activity act := &activity{ caller: caller, - sent: std.GetOrigSend(), + sent: std.OriginSend(), returned: send, time: time.Now(), } @@ -39,8 +39,8 @@ func Deposit(returnDenom string, returnAmount int64) string { latest[0] = act // return if any. if returnAmount > 0 { - banker := std.GetBanker(std.BankerTypeOrigSend) - pkgaddr := std.GetOrigPkgAddr() + banker := std.NewBanker(std.BankerTypeOriginSend) + pkgaddr := std.OriginPkgAddress() // TODO: use std.Coins constructors, this isn't generally safe. banker.SendCoins(pkgaddr, caller, send) return "returned!" @@ -51,8 +51,8 @@ func Deposit(returnDenom string, returnAmount int64) string { func Render(path string) string { // get realm coins. - banker := std.GetBanker(std.BankerTypeReadonly) - coins := banker.GetCoins(std.GetOrigPkgAddr()) + banker := std.NewBanker(std.BankerTypeReadonly) + coins := banker.GetCoins(std.OriginPkgAddress()) // render res := "" diff --git a/examples/gno.land/r/demo/banktest/z_0_filetest.gno b/examples/gno.land/r/demo/banktest/z_0_filetest.gno index 5a8c8d70a48..066d6bb17d9 100644 --- a/examples/gno.land/r/demo/banktest/z_0_filetest.gno +++ b/examples/gno.land/r/demo/banktest/z_0_filetest.gno @@ -17,18 +17,18 @@ func main() { // set up main address and banktest addr. banktestAddr := std.DerivePkgAddr("gno.land/r/demo/banktest") mainaddr := std.DerivePkgAddr("gno.land/r/demo/bank1") - std.TestSetOrigCaller(mainaddr) - std.TestSetOrigPkgAddr(banktestAddr) + std.TestSetOriginCaller(mainaddr) + std.TestSetOriginPkgAddress(banktestAddr) // get and print balance of mainaddr. // with the SEND, + 200 gnot given by the TestContext, main should have 300gnot. - banker := std.GetBanker(std.BankerTypeRealmSend) + banker := std.NewBanker(std.BankerTypeRealmSend) mainbal := banker.GetCoins(mainaddr) println("main before:", mainbal) - // simulate a Deposit call. use Send + OrigSend to simulate -send. + // simulate a Deposit call. use Send + OriginSend to simulate -send. banker.SendCoins(mainaddr, banktestAddr, std.Coins{{"ugnot", 100_000_000}}) - std.TestSetOrigSend(std.Coins{{"ugnot", 100_000_000}}, nil) + std.TestSetOriginSend(std.Coins{{"ugnot", 100_000_000}}, nil) res := banktest.Deposit("ugnot", 50_000_000) println("Deposit():", res) diff --git a/examples/gno.land/r/demo/banktest/z_1_filetest.gno b/examples/gno.land/r/demo/banktest/z_1_filetest.gno index 39682d26330..eebe70f251d 100644 --- a/examples/gno.land/r/demo/banktest/z_1_filetest.gno +++ b/examples/gno.land/r/demo/banktest/z_1_filetest.gno @@ -15,9 +15,9 @@ func main() { banktestAddr := std.DerivePkgAddr("gno.land/r/demo/banktest") // simulate a Deposit call. - std.TestSetOrigPkgAddr(banktestAddr) + std.TestSetOriginPkgAddress(banktestAddr) std.TestIssueCoins(banktestAddr, std.Coins{{"ugnot", 100000000}}) - std.TestSetOrigSend(std.Coins{{"ugnot", 100000000}}, nil) + std.TestSetOriginSend(std.Coins{{"ugnot", 100000000}}, nil) res := banktest.Deposit("ugnot", 101000000) println(res) } diff --git a/examples/gno.land/r/demo/banktest/z_2_filetest.gno b/examples/gno.land/r/demo/banktest/z_2_filetest.gno index e839f60354a..454763b3a6f 100644 --- a/examples/gno.land/r/demo/banktest/z_2_filetest.gno +++ b/examples/gno.land/r/demo/banktest/z_2_filetest.gno @@ -16,16 +16,16 @@ func main() { // print main balance before. mainaddr := std.DerivePkgAddr("gno.land/r/demo/bank1") - std.TestSetOrigCaller(mainaddr) + std.TestSetOriginCaller(mainaddr) - banker := std.GetBanker(std.BankerTypeReadonly) + banker := std.NewBanker(std.BankerTypeReadonly) mainbal := banker.GetCoins(mainaddr) - println("main before:", mainbal) // plus OrigSend equals 300. + println("main before:", mainbal) // plus OriginSend equals 300. // simulate a Deposit call. - std.TestSetOrigPkgAddr(banktestAddr) + std.TestSetOriginPkgAddress(banktestAddr) std.TestIssueCoins(banktestAddr, std.Coins{{"ugnot", 100000000}}) - std.TestSetOrigSend(std.Coins{{"ugnot", 100000000}}, nil) + std.TestSetOriginSend(std.Coins{{"ugnot", 100000000}}, nil) res := banktest.Deposit("ugnot", 55000000) println("Deposit():", res) diff --git a/examples/gno.land/r/demo/banktest/z_3_filetest.gno b/examples/gno.land/r/demo/banktest/z_3_filetest.gno index 7b6758c3e4f..c08f89742d0 100644 --- a/examples/gno.land/r/demo/banktest/z_3_filetest.gno +++ b/examples/gno.land/r/demo/banktest/z_3_filetest.gno @@ -13,9 +13,9 @@ func main() { banktestAddr := std.DerivePkgAddr("gno.land/r/demo/banktest") mainaddr := std.DerivePkgAddr("gno.land/r/demo/bank1") - std.TestSetOrigCaller(mainaddr) + std.TestSetOriginCaller(mainaddr) - banker := std.GetBanker(std.BankerTypeRealmSend) + banker := std.NewBanker(std.BankerTypeRealmSend) send := std.Coins{{"ugnot", 123}} banker.SendCoins(banktestAddr, mainaddr, send) diff --git a/examples/gno.land/r/demo/bar20/bar20.gno b/examples/gno.land/r/demo/bar20/bar20.gno index 52f1baa7408..14ef7ada17d 100644 --- a/examples/gno.land/r/demo/bar20/bar20.gno +++ b/examples/gno.land/r/demo/bar20/bar20.gno @@ -22,7 +22,7 @@ func init() { } func Faucet() string { - caller := std.PrevRealm().Addr() + caller := std.PreviousRealm().Address() if err := adm.Mint(caller, 1_000_000); err != nil { return "error: " + err.Error() } diff --git a/examples/gno.land/r/demo/bar20/bar20_test.gno b/examples/gno.land/r/demo/bar20/bar20_test.gno index 0561d13c865..81e986a7584 100644 --- a/examples/gno.land/r/demo/bar20/bar20_test.gno +++ b/examples/gno.land/r/demo/bar20/bar20_test.gno @@ -11,7 +11,7 @@ import ( func TestPackage(t *testing.T) { alice := testutils.TestAddress("alice") std.TestSetRealm(std.NewUserRealm(alice)) - std.TestSetOrigCaller(alice) // XXX: should not need this + std.TestSetOriginCaller(alice) // XXX: should not need this urequire.Equal(t, UserTeller.BalanceOf(alice), uint64(0)) urequire.Equal(t, Faucet(), "OK") diff --git a/examples/gno.land/r/demo/boards/public.gno b/examples/gno.land/r/demo/boards/public.gno index 1d26126fcb2..0d0c40b9a1c 100644 --- a/examples/gno.land/r/demo/boards/public.gno +++ b/examples/gno.land/r/demo/boards/public.gno @@ -17,11 +17,11 @@ func GetBoardIDFromName(name string) (BoardID, bool) { } func CreateBoard(name string) BoardID { - if !(std.IsOriginCall() || std.PrevRealm().IsUser()) { + if !(std.IsOriginCall() || std.PreviousRealm().IsUser()) { panic("invalid non-user call") } bid := incGetBoardID() - caller := std.GetOrigCaller() + caller := std.OriginCaller() if usernameOf(caller) == "" { panic("unauthorized") } @@ -34,7 +34,7 @@ func CreateBoard(name string) BoardID { } func checkAnonFee() bool { - sent := std.GetOrigSend() + sent := std.OriginSend() anonFeeCoin := std.NewCoin("ugnot", int64(gDefaultAnonFee)) if len(sent) == 1 && sent[0].IsGTE(anonFeeCoin) { return true @@ -43,10 +43,10 @@ func checkAnonFee() bool { } func CreateThread(bid BoardID, title string, body string) PostID { - if !(std.IsOriginCall() || std.PrevRealm().IsUser()) { + if !(std.IsOriginCall() || std.PreviousRealm().IsUser()) { panic("invalid non-user call") } - caller := std.GetOrigCaller() + caller := std.OriginCaller() if usernameOf(caller) == "" { if !checkAnonFee() { panic("please register, otherwise minimum fee " + strconv.Itoa(gDefaultAnonFee) + " is required if anonymous") @@ -61,10 +61,10 @@ func CreateThread(bid BoardID, title string, body string) PostID { } func CreateReply(bid BoardID, threadid, postid PostID, body string) PostID { - if !(std.IsOriginCall() || std.PrevRealm().IsUser()) { + if !(std.IsOriginCall() || std.PreviousRealm().IsUser()) { panic("invalid non-user call") } - caller := std.GetOrigCaller() + caller := std.OriginCaller() if usernameOf(caller) == "" { if !checkAnonFee() { panic("please register, otherwise minimum fee " + strconv.Itoa(gDefaultAnonFee) + " is required if anonymous") @@ -91,10 +91,10 @@ func CreateReply(bid BoardID, threadid, postid PostID, body string) PostID { // If dstBoard is private, does not ping back. // If board specified by bid is private, panics. func CreateRepost(bid BoardID, postid PostID, title string, body string, dstBoardID BoardID) PostID { - if !(std.IsOriginCall() || std.PrevRealm().IsUser()) { + if !(std.IsOriginCall() || std.PreviousRealm().IsUser()) { panic("invalid non-user call") } - caller := std.GetOrigCaller() + caller := std.OriginCaller() if usernameOf(caller) == "" { // TODO: allow with gDefaultAnonFee payment. if !checkAnonFee() { @@ -121,10 +121,10 @@ func CreateRepost(bid BoardID, postid PostID, title string, body string, dstBoar } func DeletePost(bid BoardID, threadid, postid PostID, reason string) { - if !(std.IsOriginCall() || std.PrevRealm().IsUser()) { + if !(std.IsOriginCall() || std.PreviousRealm().IsUser()) { panic("invalid non-user call") } - caller := std.GetOrigCaller() + caller := std.OriginCaller() board := getBoard(bid) if board == nil { panic("board not exist") @@ -153,10 +153,10 @@ func DeletePost(bid BoardID, threadid, postid PostID, reason string) { } func EditPost(bid BoardID, threadid, postid PostID, title, body string) { - if !(std.IsOriginCall() || std.PrevRealm().IsUser()) { + if !(std.IsOriginCall() || std.PreviousRealm().IsUser()) { panic("invalid non-user call") } - caller := std.GetOrigCaller() + caller := std.OriginCaller() board := getBoard(bid) if board == nil { panic("board not exist") diff --git a/examples/gno.land/r/demo/boards/z_12_a_filetest.gno b/examples/gno.land/r/demo/boards/z_12_a_filetest.gno index 909be880efa..baad057b361 100644 --- a/examples/gno.land/r/demo/boards/z_12_a_filetest.gno +++ b/examples/gno.land/r/demo/boards/z_12_a_filetest.gno @@ -20,8 +20,8 @@ func main() { // create a repost via anon user test2 := testutils.TestAddress("test2") - std.TestSetOrigCaller(test2) - std.TestSetOrigSend(std.Coins{{"ugnot", 9000000}}, nil) + std.TestSetOriginCaller(test2) + std.TestSetOriginSend(std.Coins{{"ugnot", 9000000}}, nil) rid := boards.CreateRepost(bid1, pid, "", "Check this out", bid2) println(rid) diff --git a/examples/gno.land/r/demo/boards/z_5_b_filetest.gno b/examples/gno.land/r/demo/boards/z_5_b_filetest.gno index e79da5c3677..d9f3a29e7cb 100644 --- a/examples/gno.land/r/demo/boards/z_5_b_filetest.gno +++ b/examples/gno.land/r/demo/boards/z_5_b_filetest.gno @@ -20,8 +20,8 @@ func main() { // create post via anon user test2 := testutils.TestAddress("test2") - std.TestSetOrigCaller(test2) - std.TestSetOrigSend(std.Coins{{"ugnot", 9000000}}, nil) + std.TestSetOriginCaller(test2) + std.TestSetOriginSend(std.Coins{{"ugnot", 9000000}}, nil) pid := boards.CreateThread(bid, "First Post (title)", "Body of the first post. (body)") println(boards.Render("test_board/" + strconv.Itoa(int(pid)))) diff --git a/examples/gno.land/r/demo/boards/z_5_c_filetest.gno b/examples/gno.land/r/demo/boards/z_5_c_filetest.gno index 723e6a10204..8afad8291ab 100644 --- a/examples/gno.land/r/demo/boards/z_5_c_filetest.gno +++ b/examples/gno.land/r/demo/boards/z_5_c_filetest.gno @@ -20,8 +20,8 @@ func main() { // create post via anon user test2 := testutils.TestAddress("test2") - std.TestSetOrigCaller(test2) - std.TestSetOrigSend(std.Coins{{"ugnot", 101000000}}, nil) + std.TestSetOriginCaller(test2) + std.TestSetOriginSend(std.Coins{{"ugnot", 101000000}}, nil) pid := boards.CreateThread(bid, "First Post (title)", "Body of the first post. (body)") boards.CreateReply(bid, pid, pid, "Reply of the first post") diff --git a/examples/gno.land/r/demo/boards/z_5_d_filetest.gno b/examples/gno.land/r/demo/boards/z_5_d_filetest.gno index 54cfe49eec6..bb115656b41 100644 --- a/examples/gno.land/r/demo/boards/z_5_d_filetest.gno +++ b/examples/gno.land/r/demo/boards/z_5_d_filetest.gno @@ -21,8 +21,8 @@ func main() { // create reply via anon user test2 := testutils.TestAddress("test2") - std.TestSetOrigCaller(test2) - std.TestSetOrigSend(std.Coins{{"ugnot", 9000000}}, nil) + std.TestSetOriginCaller(test2) + std.TestSetOriginSend(std.Coins{{"ugnot", 9000000}}, nil) boards.CreateReply(bid, pid, pid, "Reply of the first post") println(boards.Render("test_board/" + strconv.Itoa(int(pid)))) diff --git a/examples/gno.land/r/demo/btree_dao/btree_dao.gno b/examples/gno.land/r/demo/btree_dao/btree_dao.gno index c90742eb29b..66b857580c1 100644 --- a/examples/gno.land/r/demo/btree_dao/btree_dao.gno +++ b/examples/gno.land/r/demo/btree_dao/btree_dao.gno @@ -57,7 +57,7 @@ func PlantSeed(message string) error { // Returns an error if any validation fails or if NFT minting fails. func plantImpl(userBTree *btree.BTree, seedMessage string) error { // Get the caller's address - userAddress := std.GetOrigCaller() + userAddress := std.OriginCaller() var nftID string var regDetails *RegistrationDetails diff --git a/examples/gno.land/r/demo/btree_dao/btree_dao_test.gno b/examples/gno.land/r/demo/btree_dao/btree_dao_test.gno index 0514f52f7b4..e6ad0c3f732 100644 --- a/examples/gno.land/r/demo/btree_dao/btree_dao_test.gno +++ b/examples/gno.land/r/demo/btree_dao/btree_dao_test.gno @@ -12,7 +12,7 @@ import ( ) func setupTest() { - std.TestSetOrigCaller(std.Address("g1ej0qca5ptsw9kfr64ey8jvfy9eacga6mpj2z0y")) + std.TestSetOriginCaller(std.Address("g1ej0qca5ptsw9kfr64ey8jvfy9eacga6mpj2z0y")) members = btree.New() } diff --git a/examples/gno.land/r/demo/disperse/disperse.gno b/examples/gno.land/r/demo/disperse/disperse.gno index 0dc833dda95..41319992905 100644 --- a/examples/gno.land/r/demo/disperse/disperse.gno +++ b/examples/gno.land/r/demo/disperse/disperse.gno @@ -7,15 +7,15 @@ import ( ) // Get address of Disperse realm -var realmAddr = std.CurrentRealm().Addr() +var realmAddr = std.CurrentRealm().Address() // DisperseUgnot parses receivers and amounts and sends out ugnot // The function will send out the coins to the addresses and return the leftover coins to the caller // if there are any to return func DisperseUgnot(addresses []std.Address, coins std.Coins) { - coinSent := std.GetOrigSend() - caller := std.PrevRealm().Addr() - banker := std.GetBanker(std.BankerTypeOrigSend) + coinSent := std.OriginSend() + caller := std.PreviousRealm().Address() + banker := std.NewBanker(std.BankerTypeOriginSend) if len(addresses) != len(coins) { panic(ErrNumAddrValMismatch) @@ -50,7 +50,7 @@ func DisperseUgnot(addresses []std.Address, coins std.Coins) { // Note that it is necessary to approve the realm to spend the tokens before calling this function // see the corresponding filetests for examples func DisperseGRC20(addresses []std.Address, amounts []uint64, symbols []string) { - caller := std.PrevRealm().Addr() + caller := std.PreviousRealm().Address() if (len(addresses) != len(amounts)) || (len(amounts) != len(symbols)) { panic(ErrArgLenAndSentLenMismatch) diff --git a/examples/gno.land/r/demo/disperse/z_0_filetest.gno b/examples/gno.land/r/demo/disperse/z_0_filetest.gno index ca1e9ea0ce8..695a7f7c2b8 100644 --- a/examples/gno.land/r/demo/disperse/z_0_filetest.gno +++ b/examples/gno.land/r/demo/disperse/z_0_filetest.gno @@ -14,10 +14,10 @@ func main() { disperseAddr := std.DerivePkgAddr("gno.land/r/demo/disperse") mainaddr := std.DerivePkgAddr("gno.land/r/demo/main") - std.TestSetOrigPkgAddr(disperseAddr) - std.TestSetOrigCaller(mainaddr) + std.TestSetOriginPkgAddress(disperseAddr) + std.TestSetOriginCaller(mainaddr) - banker := std.GetBanker(std.BankerTypeRealmSend) + banker := std.NewBanker(std.BankerTypeRealmSend) mainbal := banker.GetCoins(mainaddr) println("main before:", mainbal) diff --git a/examples/gno.land/r/demo/disperse/z_1_filetest.gno b/examples/gno.land/r/demo/disperse/z_1_filetest.gno index 4c27c50749f..a4c0d19b15a 100644 --- a/examples/gno.land/r/demo/disperse/z_1_filetest.gno +++ b/examples/gno.land/r/demo/disperse/z_1_filetest.gno @@ -14,10 +14,10 @@ func main() { disperseAddr := std.DerivePkgAddr("gno.land/r/demo/disperse") mainaddr := std.DerivePkgAddr("gno.land/r/demo/main") - std.TestSetOrigPkgAddr(disperseAddr) - std.TestSetOrigCaller(mainaddr) + std.TestSetOriginPkgAddress(disperseAddr) + std.TestSetOriginCaller(mainaddr) - banker := std.GetBanker(std.BankerTypeRealmSend) + banker := std.NewBanker(std.BankerTypeRealmSend) mainbal := banker.GetCoins(mainaddr) println("main before:", mainbal) diff --git a/examples/gno.land/r/demo/disperse/z_2_filetest.gno b/examples/gno.land/r/demo/disperse/z_2_filetest.gno index 79e8d81e2b1..0e6d9a5cd1a 100644 --- a/examples/gno.land/r/demo/disperse/z_2_filetest.gno +++ b/examples/gno.land/r/demo/disperse/z_2_filetest.gno @@ -14,10 +14,10 @@ func main() { disperseAddr := std.DerivePkgAddr("gno.land/r/demo/disperse") mainaddr := std.DerivePkgAddr("gno.land/r/demo/main") - std.TestSetOrigPkgAddr(disperseAddr) - std.TestSetOrigCaller(mainaddr) + std.TestSetOriginPkgAddress(disperseAddr) + std.TestSetOriginCaller(mainaddr) - banker := std.GetBanker(std.BankerTypeRealmSend) + banker := std.NewBanker(std.BankerTypeRealmSend) banker.SendCoins(mainaddr, disperseAddr, std.Coins{{"ugnot", 100}}) disperse.DisperseUgnotString("g1dmt3sa5ucvecxuhf3j6ne5r0e3z4x7h6c03xc0,g1akeqsvhucjt8gf5yupyzjxsjd29wv8fayng37c", "150,50") diff --git a/examples/gno.land/r/demo/disperse/z_3_filetest.gno b/examples/gno.land/r/demo/disperse/z_3_filetest.gno index 7cb7ffbe71d..4c9ab05728a 100644 --- a/examples/gno.land/r/demo/disperse/z_3_filetest.gno +++ b/examples/gno.land/r/demo/disperse/z_3_filetest.gno @@ -17,10 +17,10 @@ func main() { beneficiary1 := std.Address("g1dmt3sa5ucvecxuhf3j6ne5r0e3z4x7h6c03xc0") beneficiary2 := std.Address("g1akeqsvhucjt8gf5yupyzjxsjd29wv8fayng37c") - std.TestSetOrigPkgAddr(disperseAddr) - std.TestSetOrigCaller(mainaddr) + std.TestSetOriginPkgAddress(disperseAddr) + std.TestSetOriginCaller(mainaddr) - banker := std.GetBanker(std.BankerTypeRealmSend) + banker := std.NewBanker(std.BankerTypeRealmSend) tokens.New("test", "TEST", 4, 0, 0) tokens.Mint("TEST", mainaddr, 200) diff --git a/examples/gno.land/r/demo/disperse/z_4_filetest.gno b/examples/gno.land/r/demo/disperse/z_4_filetest.gno index 4dafb780e83..2cfc9c820d1 100644 --- a/examples/gno.land/r/demo/disperse/z_4_filetest.gno +++ b/examples/gno.land/r/demo/disperse/z_4_filetest.gno @@ -17,10 +17,10 @@ func main() { beneficiary1 := std.Address("g1dmt3sa5ucvecxuhf3j6ne5r0e3z4x7h6c03xc0") beneficiary2 := std.Address("g1akeqsvhucjt8gf5yupyzjxsjd29wv8fayng37c") - std.TestSetOrigPkgAddr(disperseAddr) - std.TestSetOrigCaller(mainaddr) + std.TestSetOriginPkgAddress(disperseAddr) + std.TestSetOriginCaller(mainaddr) - banker := std.GetBanker(std.BankerTypeRealmSend) + banker := std.NewBanker(std.BankerTypeRealmSend) tokens.New("test1", "TEST1", 4, 0, 0) tokens.Mint("TEST1", mainaddr, 200) diff --git a/examples/gno.land/r/demo/foo1155/foo1155.gno b/examples/gno.land/r/demo/foo1155/foo1155.gno index 2bd3b7a84c0..1a14571d236 100644 --- a/examples/gno.land/r/demo/foo1155/foo1155.gno +++ b/examples/gno.land/r/demo/foo1155/foo1155.gno @@ -82,7 +82,7 @@ func BatchTransferFrom(from, to pusers.AddressOrName, batch []grc1155.TokenID, a // Admin func Mint(to pusers.AddressOrName, tid grc1155.TokenID, amount uint64) { - caller := std.GetOrigCaller() + caller := std.OriginCaller() assertIsAdmin(caller) err := foo.SafeMint(users.Resolve(to), tid, amount) if err != nil { @@ -91,7 +91,7 @@ func Mint(to pusers.AddressOrName, tid grc1155.TokenID, amount uint64) { } func MintBatch(to pusers.AddressOrName, batch []grc1155.TokenID, amounts []uint64) { - caller := std.GetOrigCaller() + caller := std.OriginCaller() assertIsAdmin(caller) err := foo.SafeBatchMint(users.Resolve(to), batch, amounts) if err != nil { @@ -100,7 +100,7 @@ func MintBatch(to pusers.AddressOrName, batch []grc1155.TokenID, amounts []uint6 } func Burn(from pusers.AddressOrName, tid grc1155.TokenID, amount uint64) { - caller := std.GetOrigCaller() + caller := std.OriginCaller() assertIsAdmin(caller) err := foo.Burn(users.Resolve(from), tid, amount) if err != nil { @@ -109,7 +109,7 @@ func Burn(from pusers.AddressOrName, tid grc1155.TokenID, amount uint64) { } func BurnBatch(from pusers.AddressOrName, batch []grc1155.TokenID, amounts []uint64) { - caller := std.GetOrigCaller() + caller := std.OriginCaller() assertIsAdmin(caller) err := foo.BatchBurn(users.Resolve(from), batch, amounts) if err != nil { diff --git a/examples/gno.land/r/demo/foo20/foo20.gno b/examples/gno.land/r/demo/foo20/foo20.gno index 917a037d49c..d79cf3b3dc4 100644 --- a/examples/gno.land/r/demo/foo20/foo20.gno +++ b/examples/gno.land/r/demo/foo20/foo20.gno @@ -50,7 +50,7 @@ func TransferFrom(from, to std.Address, amount uint64) { // Faucet is distributing foo20 tokens without restriction (unsafe). // For a real token faucet, you should take care of setting limits are asking payment. func Faucet() { - caller := std.PrevRealm().Addr() + caller := std.PreviousRealm().Address() amount := uint64(1_000 * 10_000) // 1k checkErr(privateLedger.Mint(caller, amount)) } diff --git a/examples/gno.land/r/demo/foo20/foo20_test.gno b/examples/gno.land/r/demo/foo20/foo20_test.gno index d24faef279c..8773114a681 100644 --- a/examples/gno.land/r/demo/foo20/foo20_test.gno +++ b/examples/gno.land/r/demo/foo20/foo20_test.gno @@ -37,7 +37,7 @@ func TestReadOnlyPublicMethods(t *testing.T) { } // bob uses the faucet. - std.TestSetOrigCaller(bob) + std.TestSetOriginCaller(bob) Faucet() // check balances #2. diff --git a/examples/gno.land/r/demo/foo721/foo721.gno b/examples/gno.land/r/demo/foo721/foo721.gno index f7364d4185f..b88647101ca 100644 --- a/examples/gno.land/r/demo/foo721/foo721.gno +++ b/examples/gno.land/r/demo/foo721/foo721.gno @@ -87,7 +87,7 @@ func TransferFrom(from, to pusers.AddressOrName, tid grc721.TokenID) { // Admin func Mint(to pusers.AddressOrName, tid grc721.TokenID) { - caller := std.PrevRealm().Addr() + caller := std.PreviousRealm().Address() assertIsAdmin(caller) err := foo.Mint(users.Resolve(to), tid) if err != nil { @@ -96,7 +96,7 @@ func Mint(to pusers.AddressOrName, tid grc721.TokenID) { } func Burn(tid grc721.TokenID) { - caller := std.PrevRealm().Addr() + caller := std.PreviousRealm().Address() assertIsAdmin(caller) err := foo.Burn(tid) if err != nil { diff --git a/examples/gno.land/r/demo/games/dice_roller/dice_roller.gno b/examples/gno.land/r/demo/games/dice_roller/dice_roller.gno index 4dbbd6c7682..18ead8e5fa3 100644 --- a/examples/gno.land/r/demo/games/dice_roller/dice_roller.gno +++ b/examples/gno.land/r/demo/games/dice_roller/dice_roller.gno @@ -62,7 +62,7 @@ func NewGame(addr std.Address) int { } games.Set(gameId.Next().String(), &game{ - player1: std.PrevRealm().Addr(), + player1: std.PreviousRealm().Address(), player2: addr, }) @@ -79,7 +79,7 @@ func Play(idx int) int { roll := rollDice() // Random the player's dice roll // Play the game and update the player's roll - if err := g.play(std.PrevRealm().Addr(), roll); err != nil { + if err := g.play(std.PreviousRealm().Address(), roll); err != nil { panic(err) } diff --git a/examples/gno.land/r/demo/games/dice_roller/dice_roller_test.gno b/examples/gno.land/r/demo/games/dice_roller/dice_roller_test.gno index 4697b03bf66..0b6d9b06333 100644 --- a/examples/gno.land/r/demo/games/dice_roller/dice_roller_test.gno +++ b/examples/gno.land/r/demo/games/dice_roller/dice_roller_test.gno @@ -27,7 +27,7 @@ func resetGameState() { func TestNewGame(t *testing.T) { resetGameState() - std.TestSetOrigCaller(player1) + std.TestSetOriginCaller(player1) gameID := NewGame(player2) // Verify that the game has been correctly initialized @@ -43,7 +43,7 @@ func TestNewGame(t *testing.T) { func TestPlay(t *testing.T) { resetGameState() - std.TestSetOrigCaller(player1) + std.TestSetOriginCaller(player1) gameID := NewGame(player2) g, err := getGame(gameID) @@ -58,7 +58,7 @@ func TestPlay(t *testing.T) { urequire.Equal(t, 0, g.roll2) // Player 2 hasn't rolled yet // Simulate rolling dice for player 2 - std.TestSetOrigCaller(player2) + std.TestSetOriginCaller(player2) roll2 := Play(gameID) // Verify player 2's roll @@ -71,7 +71,7 @@ func TestPlay(t *testing.T) { func TestPlayAgainstSelf(t *testing.T) { resetGameState() - std.TestSetOrigCaller(player1) + std.TestSetOriginCaller(player1) gameID := NewGame(player1) // Simulate rolling dice twice by the same player @@ -88,11 +88,11 @@ func TestPlayAgainstSelf(t *testing.T) { func TestPlayInvalidPlayer(t *testing.T) { resetGameState() - std.TestSetOrigCaller(player1) + std.TestSetOriginCaller(player1) gameID := NewGame(player1) // Attempt to play as an invalid player - std.TestSetOrigCaller(unknownPlayer) + std.TestSetOriginCaller(unknownPlayer) urequire.PanicsWithMessage(t, "invalid player", func() { Play(gameID) }) @@ -102,7 +102,7 @@ func TestPlayInvalidPlayer(t *testing.T) { func TestPlayAlreadyPlayed(t *testing.T) { resetGameState() - std.TestSetOrigCaller(player1) + std.TestSetOriginCaller(player1) gameID := NewGame(player2) // Player 1 rolls @@ -118,13 +118,13 @@ func TestPlayAlreadyPlayed(t *testing.T) { func TestPlayBeyondGameEnd(t *testing.T) { resetGameState() - std.TestSetOrigCaller(player1) + std.TestSetOriginCaller(player1) gameID := NewGame(player2) // Play for both players - std.TestSetOrigCaller(player1) + std.TestSetOriginCaller(player1) Play(gameID) - std.TestSetOrigCaller(player2) + std.TestSetOriginCaller(player2) Play(gameID) // Check if the game is over @@ -132,7 +132,7 @@ func TestPlayBeyondGameEnd(t *testing.T) { urequire.NoError(t, err) // Attempt to play more should fail - std.TestSetOrigCaller(player1) + std.TestSetOriginCaller(player1) urequire.PanicsWithMessage(t, "game over", func() { Play(gameID) }) diff --git a/examples/gno.land/r/demo/games/shifumi/shifumi.gno b/examples/gno.land/r/demo/games/shifumi/shifumi.gno index 3de09196da1..7ce3eb69653 100644 --- a/examples/gno.land/r/demo/games/shifumi/shifumi.gno +++ b/examples/gno.land/r/demo/games/shifumi/shifumi.gno @@ -63,7 +63,7 @@ func (g *game) winner() int { // NewGame creates a new game where player1 is the caller and player2 the argument. // A new game index is returned. func NewGame(player std.Address) int { - games.Set(id.Next().String(), &game{player1: std.PrevRealm().Addr(), player2: player}) + games.Set(id.Next().String(), &game{player1: std.PreviousRealm().Address(), player2: player}) return int(id) } @@ -74,7 +74,7 @@ func Play(idx, move int) { if !ok { panic("game not found") } - if err := v.(*game).play(std.PrevRealm().Addr(), move); err != nil { + if err := v.(*game).play(std.PreviousRealm().Address(), move); err != nil { panic(err) } } diff --git a/examples/gno.land/r/demo/grc20factory/grc20factory.gno b/examples/gno.land/r/demo/grc20factory/grc20factory.gno index aa91084ab32..1aaee77f2a1 100644 --- a/examples/gno.land/r/demo/grc20factory/grc20factory.gno +++ b/examples/gno.land/r/demo/grc20factory/grc20factory.gno @@ -21,7 +21,7 @@ type instance struct { } func New(name, symbol string, decimals uint, initialMint, faucet uint64) { - caller := std.PrevRealm().Addr() + caller := std.PreviousRealm().Address() NewWithAdmin(name, symbol, decimals, initialMint, faucet, caller) } @@ -76,21 +76,21 @@ func Allowance(symbol string, owner, spender std.Address) uint64 { func Transfer(symbol string, to std.Address, amount uint64) { inst := mustGetInstance(symbol) - caller := std.PrevRealm().Addr() + caller := std.PreviousRealm().Address() teller := inst.ledger.ImpersonateTeller(caller) checkErr(teller.Transfer(to, amount)) } func Approve(symbol string, spender std.Address, amount uint64) { inst := mustGetInstance(symbol) - caller := std.PrevRealm().Addr() + caller := std.PreviousRealm().Address() teller := inst.ledger.ImpersonateTeller(caller) checkErr(teller.Approve(spender, amount)) } func TransferFrom(symbol string, from, to std.Address, amount uint64) { inst := mustGetInstance(symbol) - caller := std.PrevRealm().Addr() + caller := std.PreviousRealm().Address() teller := inst.ledger.ImpersonateTeller(caller) checkErr(teller.TransferFrom(from, to, amount)) } @@ -103,7 +103,7 @@ func Faucet(symbol string) { } // FIXME: add limits? // FIXME: add payment in gnot? - caller := std.PrevRealm().Addr() + caller := std.PreviousRealm().Address() checkErr(inst.ledger.Mint(caller, inst.faucet)) } diff --git a/examples/gno.land/r/demo/grc20factory/grc20factory_test.gno b/examples/gno.land/r/demo/grc20factory/grc20factory_test.gno index 46fc07fabf2..16584e63a1f 100644 --- a/examples/gno.land/r/demo/grc20factory/grc20factory_test.gno +++ b/examples/gno.land/r/demo/grc20factory/grc20factory_test.gno @@ -10,7 +10,7 @@ import ( ) func TestReadOnlyPublicMethods(t *testing.T) { - std.TestSetOrigPkgAddr("gno.land/r/demo/grc20factory") + std.TestSetOriginPkgAddress("gno.land/r/demo/grc20factory") admin := testutils.TestAddress("admin") bob := testutils.TestAddress("bob") carl := testutils.TestAddress("carl") @@ -36,7 +36,7 @@ func TestReadOnlyPublicMethods(t *testing.T) { } // admin creates FOO and BAR. - std.TestSetOrigCaller(admin) + std.TestSetOriginCaller(admin) std.TestSetRealm(std.NewUserRealm(admin)) NewWithAdmin("Foo", "FOO", 3, 1_111_111_000, 5_555, admin) NewWithAdmin("Bar", "BAR", 3, 2_222_000, 6_666, admin) @@ -47,25 +47,25 @@ func TestReadOnlyPublicMethods(t *testing.T) { checkBalances("step2", 1_444_444_000, 1_111_111_000, 333_333_000, 0, 0) // carl uses the faucet. - std.TestSetOrigCaller(carl) + std.TestSetOriginCaller(carl) std.TestSetRealm(std.NewUserRealm(carl)) Faucet("FOO") checkBalances("step3", 1_444_449_555, 1_111_111_000, 333_333_000, 0, 5_555) // admin gives to bob some allowance. - std.TestSetOrigCaller(admin) + std.TestSetOriginCaller(admin) std.TestSetRealm(std.NewUserRealm(admin)) Approve("FOO", bob, 1_000_000) checkBalances("step4", 1_444_449_555, 1_111_111_000, 333_333_000, 1_000_000, 5_555) // bob uses a part of the allowance. - std.TestSetOrigCaller(bob) + std.TestSetOriginCaller(bob) std.TestSetRealm(std.NewUserRealm(bob)) TransferFrom("FOO", admin, carl, 400_000) checkBalances("step5", 1_444_449_555, 1_110_711_000, 333_333_000, 600_000, 405_555) // bob uses a part of the allowance. - std.TestSetOrigCaller(bob) + std.TestSetOriginCaller(bob) std.TestSetRealm(std.NewUserRealm(bob)) TransferFrom("FOO", admin, carl, 600_000) checkBalances("step6", 1_444_449_555, 1_110_111_000, 333_333_000, 0, 1_005_555) diff --git a/examples/gno.land/r/demo/grc20reg/grc20reg.gno b/examples/gno.land/r/demo/grc20reg/grc20reg.gno index ff46ec94860..ba59019985a 100644 --- a/examples/gno.land/r/demo/grc20reg/grc20reg.gno +++ b/examples/gno.land/r/demo/grc20reg/grc20reg.gno @@ -12,7 +12,7 @@ import ( var registry = avl.NewTree() // rlmPath[.slug] -> TokenGetter (slug is optional) func Register(tokenGetter grc20.TokenGetter, slug string) { - rlmPath := std.PrevRealm().PkgPath() + rlmPath := std.PreviousRealm().PkgPath() key := fqname.Construct(rlmPath, slug) registry.Set(key, tokenGetter) std.Emit( diff --git a/examples/gno.land/r/demo/grc20reg/grc20reg_test.gno b/examples/gno.land/r/demo/grc20reg/grc20reg_test.gno index c93365ff7a1..35aad13abcf 100644 --- a/examples/gno.land/r/demo/grc20reg/grc20reg_test.gno +++ b/examples/gno.land/r/demo/grc20reg/grc20reg_test.gno @@ -13,7 +13,7 @@ func TestRegistry(t *testing.T) { std.TestSetRealm(std.NewCodeRealm("gno.land/r/demo/foo")) realmAddr := std.CurrentRealm().PkgPath() token, ledger := grc20.NewToken("TestToken", "TST", 4) - ledger.Mint(std.CurrentRealm().Addr(), 1234567) + ledger.Mint(std.CurrentRealm().Address(), 1234567) tokenGetter := func() *grc20.Token { return token } // register Register(tokenGetter, "") diff --git a/examples/gno.land/r/demo/groups/public.gno b/examples/gno.land/r/demo/groups/public.gno index 33e7dbdcf35..d59b0c2042f 100644 --- a/examples/gno.land/r/demo/groups/public.gno +++ b/examples/gno.land/r/demo/groups/public.gno @@ -19,7 +19,7 @@ func GetGroupIDFromName(name string) (GroupID, bool) { func CreateGroup(name string) GroupID { std.AssertOriginCall() - caller := std.GetOrigCaller() + caller := std.OriginCaller() usernameOf(caller) url := "/r/demo/groups:" + name group := newGroup(url, name, caller) @@ -31,7 +31,7 @@ func CreateGroup(name string) GroupID { func AddMember(gid GroupID, address string, weight int, metadata string) MemberID { std.AssertOriginCall() - caller := std.GetOrigCaller() + caller := std.OriginCaller() usernameOf(caller) group := getGroup(gid) if !group.HasPermission(caller, EditPermission) { @@ -52,7 +52,7 @@ func AddMember(gid GroupID, address string, weight int, metadata string) MemberI func DeleteGroup(gid GroupID) { std.AssertOriginCall() - caller := std.GetOrigCaller() + caller := std.OriginCaller() group := getGroup(gid) if !group.HasPermission(caller, DeletePermission) { panic("unauthorized to delete group") @@ -62,7 +62,7 @@ func DeleteGroup(gid GroupID) { func DeleteMember(gid GroupID, mid MemberID) { std.AssertOriginCall() - caller := std.GetOrigCaller() + caller := std.OriginCaller() group := getGroup(gid) if !group.HasPermission(caller, DeletePermission) { panic("unauthorized to delete member") diff --git a/examples/gno.land/r/demo/groups/z_1_a_filetest.gno b/examples/gno.land/r/demo/groups/z_1_a_filetest.gno index 71da1b966ec..1db5453ba34 100644 --- a/examples/gno.land/r/demo/groups/z_1_a_filetest.gno +++ b/examples/gno.land/r/demo/groups/z_1_a_filetest.gno @@ -16,43 +16,43 @@ var gid groups.GroupID const admin = std.Address("g1manfred47kzduec920z88wfr64ylksmdcedlf5") func main() { - caller := std.GetOrigCaller() // main + caller := std.OriginCaller() // main users.Register("", "gnouser0", "my profile 1") - std.TestSetOrigCaller(admin) + std.TestSetOriginCaller(admin) users.GrantInvites(caller.String() + ":1") // switch back to caller - std.TestSetOrigCaller(caller) + std.TestSetOriginCaller(caller) // invite another addr test1 := testutils.TestAddress("gnouser1") users.Invite(test1.String()) // switch to test1 - std.TestSetOrigCaller(test1) + std.TestSetOriginCaller(test1) users.Register(caller, "gnouser1", "my other profile 1") - std.TestSetOrigCaller(admin) + std.TestSetOriginCaller(admin) users.GrantInvites(caller.String() + ":1") // switch back to caller - std.TestSetOrigCaller(caller) + std.TestSetOriginCaller(caller) // invite another addr test2 := testutils.TestAddress("gnouser2") users.Invite(test2.String()) // switch to test1 - std.TestSetOrigCaller(test2) + std.TestSetOriginCaller(test2) users.Register(caller, "gnouser2", "my other profile 2") - std.TestSetOrigCaller(admin) + std.TestSetOriginCaller(admin) users.GrantInvites(caller.String() + ":1") // switch back to caller - std.TestSetOrigCaller(caller) + std.TestSetOriginCaller(caller) // invite another addr test3 := testutils.TestAddress("gnouser3") users.Invite(test3.String()) // switch to test1 - std.TestSetOrigCaller(test3) + std.TestSetOriginCaller(test3) users.Register(caller, "gnouser3", "my other profile 3") - std.TestSetOrigCaller(caller) + std.TestSetOriginCaller(caller) gid = groups.CreateGroup("test_group") println(gid) diff --git a/examples/gno.land/r/demo/groups/z_1_c_filetest.gno b/examples/gno.land/r/demo/groups/z_1_c_filetest.gno index 6eaabb07cdf..b13c88fe1c8 100644 --- a/examples/gno.land/r/demo/groups/z_1_c_filetest.gno +++ b/examples/gno.land/r/demo/groups/z_1_c_filetest.gno @@ -18,8 +18,8 @@ func main() { // add member via anon user test2 := testutils.TestAddress("test2") - std.TestSetOrigCaller(test2) - std.TestSetOrigSend(std.Coins{{"ugnot", 9000000}}, nil) + std.TestSetOriginCaller(test2) + std.TestSetOriginSend(std.Coins{{"ugnot", 9000000}}, nil) groups.AddMember(gid, test2.String(), 42, "metadata3") } diff --git a/examples/gno.land/r/demo/groups/z_2_a_filetest.gno b/examples/gno.land/r/demo/groups/z_2_a_filetest.gno index 0c482e1b52f..a01b7571d26 100644 --- a/examples/gno.land/r/demo/groups/z_2_a_filetest.gno +++ b/examples/gno.land/r/demo/groups/z_2_a_filetest.gno @@ -16,43 +16,43 @@ var gid groups.GroupID const admin = std.Address("g1manfred47kzduec920z88wfr64ylksmdcedlf5") func main() { - caller := std.GetOrigCaller() // main + caller := std.OriginCaller() // main users.Register("", "gnouser0", "my profile 1") - std.TestSetOrigCaller(admin) + std.TestSetOriginCaller(admin) users.GrantInvites(caller.String() + ":1") // switch back to caller - std.TestSetOrigCaller(caller) + std.TestSetOriginCaller(caller) // invite another addr test1 := testutils.TestAddress("gnouser1") users.Invite(test1.String()) // switch to test1 - std.TestSetOrigCaller(test1) + std.TestSetOriginCaller(test1) users.Register(caller, "gnouser1", "my other profile 1") - std.TestSetOrigCaller(admin) + std.TestSetOriginCaller(admin) users.GrantInvites(caller.String() + ":1") // switch back to caller - std.TestSetOrigCaller(caller) + std.TestSetOriginCaller(caller) // invite another addr test2 := testutils.TestAddress("gnouser2") users.Invite(test2.String()) // switch to test1 - std.TestSetOrigCaller(test2) + std.TestSetOriginCaller(test2) users.Register(caller, "gnouser2", "my other profile 2") - std.TestSetOrigCaller(admin) + std.TestSetOriginCaller(admin) users.GrantInvites(caller.String() + ":1") // switch back to caller - std.TestSetOrigCaller(caller) + std.TestSetOriginCaller(caller) // invite another addr test3 := testutils.TestAddress("gnouser3") users.Invite(test3.String()) // switch to test1 - std.TestSetOrigCaller(test3) + std.TestSetOriginCaller(test3) users.Register(caller, "gnouser3", "my other profile 3") - std.TestSetOrigCaller(caller) + std.TestSetOriginCaller(caller) gid = groups.CreateGroup("test_group") println(gid) diff --git a/examples/gno.land/r/demo/groups/z_2_d_filetest.gno b/examples/gno.land/r/demo/groups/z_2_d_filetest.gno index 3caa726cbd3..ac91caf15b5 100644 --- a/examples/gno.land/r/demo/groups/z_2_d_filetest.gno +++ b/examples/gno.land/r/demo/groups/z_2_d_filetest.gno @@ -20,8 +20,8 @@ func main() { // delete member via anon user test2 := testutils.TestAddress("test2") - std.TestSetOrigCaller(test2) - std.TestSetOrigSend(std.Coins{{"ugnot", 9000000}}, nil) + std.TestSetOriginCaller(test2) + std.TestSetOriginSend(std.Coins{{"ugnot", 9000000}}, nil) groups.DeleteMember(gid, 0) println(groups.Render("")) diff --git a/examples/gno.land/r/demo/groups/z_2_g_filetest.gno b/examples/gno.land/r/demo/groups/z_2_g_filetest.gno index 6230b110c74..88805c2c94a 100644 --- a/examples/gno.land/r/demo/groups/z_2_g_filetest.gno +++ b/examples/gno.land/r/demo/groups/z_2_g_filetest.gno @@ -20,8 +20,8 @@ func main() { // delete group via anon user test2 := testutils.TestAddress("test2") - std.TestSetOrigCaller(test2) - std.TestSetOrigSend(std.Coins{{"ugnot", 9000000}}, nil) + std.TestSetOriginCaller(test2) + std.TestSetOriginSend(std.Coins{{"ugnot", 9000000}}, nil) groups.DeleteGroup(gid) println(groups.Render("")) diff --git a/examples/gno.land/r/demo/keystore/keystore.gno b/examples/gno.land/r/demo/keystore/keystore.gno index 5c76ccd90f8..5edff4ebf25 100644 --- a/examples/gno.land/r/demo/keystore/keystore.gno +++ b/examples/gno.land/r/demo/keystore/keystore.gno @@ -33,14 +33,14 @@ type KeyStore struct { // Set will set a value to a key // requires write-access (original caller must be caller) func Set(k, v string) string { - origOwner := std.GetOrigCaller() + origOwner := std.OriginCaller() return set(origOwner.String(), k, v) } // set (private) will set a key to value // requires write-access (original caller must be caller) func set(owner, k, v string) string { - origOwner := std.GetOrigCaller() + origOwner := std.OriginCaller() if origOwner.String() != owner { return StatusNoWriteAccess } @@ -62,14 +62,14 @@ func set(owner, k, v string) string { // Remove removes a key // requires write-access (original owner must be caller) func Remove(k string) string { - origOwner := std.GetOrigCaller() + origOwner := std.OriginCaller() return remove(origOwner.String(), k) } // remove (private) removes a key // requires write-access (original owner must be caller) func remove(owner, k string) string { - origOwner := std.GetOrigCaller() + origOwner := std.OriginCaller() if origOwner.String() != owner { return StatusNoWriteAccess } @@ -94,7 +94,7 @@ func remove(owner, k string) string { // Get returns a value for a key // read-only func Get(k string) string { - origOwner := std.GetOrigCaller() + origOwner := std.OriginCaller() return remove(origOwner.String(), k) } @@ -116,7 +116,7 @@ func get(owner, k string) string { // Size returns size of database // read-only func Size() string { - origOwner := std.GetOrigCaller() + origOwner := std.OriginCaller() return size(origOwner.String()) } diff --git a/examples/gno.land/r/demo/keystore/keystore_test.gno b/examples/gno.land/r/demo/keystore/keystore_test.gno index 03b61e79663..19d2eea16c1 100644 --- a/examples/gno.land/r/demo/keystore/keystore_test.gno +++ b/examples/gno.land/r/demo/keystore/keystore_test.gno @@ -62,7 +62,7 @@ func TestRender(t *testing.T) { } p = strings.TrimSuffix(p, ":") t.Run(p, func(t *testing.T) { - std.TestSetOrigCaller(tc.caller) + std.TestSetOriginCaller(tc.caller) var act string if len(tc.ps) > 0 && tc.ps[0] == "set" { act = strings.TrimSpace(Set(tc.ps[1], tc.ps[2])) diff --git a/examples/gno.land/r/demo/microblog/microblog.gno b/examples/gno.land/r/demo/microblog/microblog.gno index 1c3cd5e7d68..bfa8ad676d0 100644 --- a/examples/gno.land/r/demo/microblog/microblog.gno +++ b/examples/gno.land/r/demo/microblog/microblog.gno @@ -91,7 +91,7 @@ func NewPost(text string) string { } func Register(name, profile string) string { - caller := std.GetOrigCaller() // main + caller := std.OriginCaller() // main users.Register(caller, name, profile) return "OK" } diff --git a/examples/gno.land/r/demo/microblog/microblog_test.gno b/examples/gno.land/r/demo/microblog/microblog_test.gno index 9ad98d3cbfe..e3c1721b9f7 100644 --- a/examples/gno.land/r/demo/microblog/microblog_test.gno +++ b/examples/gno.land/r/demo/microblog/microblog_test.gno @@ -15,7 +15,7 @@ func TestMicroblog(t *testing.T) { author2 std.Address = testutils.TestAddress("author2") ) - std.TestSetOrigCaller(author1) + std.TestSetOriginCaller(author1) urequire.Equal(t, "404", Render("/wrongpath"), "rendering not giving 404") urequire.NotEqual(t, "404", Render(""), "rendering / should not give 404") @@ -27,7 +27,7 @@ func TestMicroblog(t *testing.T) { _, err = m.GetPage("no such author") urequire.Error(t, err, "silo should not exist") - std.TestSetOrigCaller(author2) + std.TestSetOriginCaller(author2) urequire.NoError(t, m.NewPost("hello, web3"), "could not create post") urequire.NoError(t, m.NewPost("hello again, web3"), "could not create post") diff --git a/examples/gno.land/r/demo/nft/nft.gno b/examples/gno.land/r/demo/nft/nft.gno index f4340d6d2a9..fe328a5be17 100644 --- a/examples/gno.land/r/demo/nft/nft.gno +++ b/examples/gno.land/r/demo/nft/nft.gno @@ -74,7 +74,7 @@ func (grc *token) SafeTransferFrom(from, to std.Address, tid grc721.TokenID) { } func (grc *token) TransferFrom(from, to std.Address, tid grc721.TokenID) { - caller := std.GetCallerAt(2) + caller := std.CallerAt(2) token, ok := grc.getToken(tid) // Throws if `_tokenId` is not a valid NFT. if !ok { @@ -101,7 +101,7 @@ func (grc *token) TransferFrom(from, to std.Address, tid grc721.TokenID) { } func (grc *token) Approve(approved std.Address, tid grc721.TokenID) { - caller := std.GetCallerAt(2) + caller := std.CallerAt(2) token, ok := grc.getToken(tid) // Throws if `_tokenId` is not a valid NFT. if !ok { @@ -121,7 +121,7 @@ func (grc *token) Approve(approved std.Address, tid grc721.TokenID) { // XXX make it work for set of operators. func (grc *token) SetApprovalForAll(operator std.Address, approved bool) { - caller := std.GetCallerAt(2) + caller := std.CallerAt(2) grc.operators.Set(caller.String(), operator) } diff --git a/examples/gno.land/r/demo/nft/z_2_filetest.gno b/examples/gno.land/r/demo/nft/z_2_filetest.gno index 91c48bd5957..1848cd8222e 100644 --- a/examples/gno.land/r/demo/nft/z_2_filetest.gno +++ b/examples/gno.land/r/demo/nft/z_2_filetest.gno @@ -9,7 +9,7 @@ import ( ) func main() { - caller := std.GetCallerAt(1) + caller := std.CallerAt(1) addr1 := testutils.TestAddress("addr1") // addr2 := testutils.TestAddress("addr2") grc721 := nft.GetToken() diff --git a/examples/gno.land/r/demo/nft/z_3_filetest.gno b/examples/gno.land/r/demo/nft/z_3_filetest.gno index d0210c8ba4d..09402b38246 100644 --- a/examples/gno.land/r/demo/nft/z_3_filetest.gno +++ b/examples/gno.land/r/demo/nft/z_3_filetest.gno @@ -9,7 +9,7 @@ import ( ) func main() { - caller := std.GetCallerAt(1) + caller := std.CallerAt(1) addr1 := testutils.TestAddress("addr1") addr2 := testutils.TestAddress("addr2") grc721 := nft.GetToken() diff --git a/examples/gno.land/r/demo/nft/z_4_filetest.gno b/examples/gno.land/r/demo/nft/z_4_filetest.gno index b38ce8ea190..3a167f3c87b 100644 --- a/examples/gno.land/r/demo/nft/z_4_filetest.gno +++ b/examples/gno.land/r/demo/nft/z_4_filetest.gno @@ -9,7 +9,7 @@ import ( ) func main() { - caller := std.GetCallerAt(1) + caller := std.CallerAt(1) addr1 := testutils.TestAddress("addr1") addr2 := testutils.TestAddress("addr2") grc721 := nft.GetToken() diff --git a/examples/gno.land/r/demo/profile/profile.gno b/examples/gno.land/r/demo/profile/profile.gno index 1318e19eaf3..6e0baa10929 100644 --- a/examples/gno.land/r/demo/profile/profile.gno +++ b/examples/gno.land/r/demo/profile/profile.gno @@ -70,7 +70,7 @@ var boolFields = map[string]bool{ // Setters func SetStringField(field, value string) bool { - addr := std.PrevRealm().Addr() + addr := std.PreviousRealm().Address() key := addr.String() + ":" + field updated := fields.Set(key, value) @@ -85,7 +85,7 @@ func SetStringField(field, value string) bool { } func SetIntField(field string, value int) bool { - addr := std.PrevRealm().Addr() + addr := std.PreviousRealm().Address() key := addr.String() + ":" + field updated := fields.Set(key, value) @@ -100,7 +100,7 @@ func SetIntField(field string, value int) bool { } func SetBoolField(field string, value bool) bool { - addr := std.PrevRealm().Addr() + addr := std.PreviousRealm().Address() key := addr.String() + ":" + field updated := fields.Set(key, value) diff --git a/examples/gno.land/r/demo/releases_example/example.gno b/examples/gno.land/r/demo/releases_example/example.gno index a2713687d28..74a306b4251 100644 --- a/examples/gno.land/r/demo/releases_example/example.gno +++ b/examples/gno.land/r/demo/releases_example/example.gno @@ -17,7 +17,7 @@ func init() { } func NewRelease(name, url, notes string) { - caller := std.GetOrigCaller() + caller := std.OriginCaller() if caller != admin { panic("restricted area") } @@ -25,7 +25,7 @@ func NewRelease(name, url, notes string) { } func UpdateAdmin(address std.Address) { - caller := std.GetOrigCaller() + caller := std.OriginCaller() if caller != admin { panic("restricted area") } diff --git a/examples/gno.land/r/demo/tamagotchi/realm.gno b/examples/gno.land/r/demo/tamagotchi/realm.gno index f6d648180ed..4222a9c63b5 100644 --- a/examples/gno.land/r/demo/tamagotchi/realm.gno +++ b/examples/gno.land/r/demo/tamagotchi/realm.gno @@ -16,7 +16,7 @@ func init() { func Reset(optionalName string) string { name := optionalName if name == "" { - height := std.GetHeight() + height := std.ChainHeight() name = ufmt.Sprintf("gnome#%d", height) } diff --git a/examples/gno.land/r/demo/tests/crossrealm_b/crossrealm.gno b/examples/gno.land/r/demo/tests/crossrealm_b/crossrealm.gno index d412b6ee6b1..058c81ed034 100644 --- a/examples/gno.land/r/demo/tests/crossrealm_b/crossrealm.gno +++ b/examples/gno.land/r/demo/tests/crossrealm_b/crossrealm.gno @@ -15,7 +15,7 @@ func (f *fooer) SetS(newVal string) { } func (f *fooer) Foo() { - println("hello " + f.s + " cur=" + std.CurrentRealm().PkgPath() + " prev=" + std.PrevRealm().PkgPath()) + println("hello " + f.s + " cur=" + std.CurrentRealm().PkgPath() + " prev=" + std.PreviousRealm().PkgPath()) } var ( diff --git a/examples/gno.land/r/demo/tests/subtests/subtests.gno b/examples/gno.land/r/demo/tests/subtests/subtests.gno index 6bf43cba5eb..81d133dff38 100644 --- a/examples/gno.land/r/demo/tests/subtests/subtests.gno +++ b/examples/gno.land/r/demo/tests/subtests/subtests.gno @@ -8,8 +8,8 @@ func GetCurrentRealm() std.Realm { return std.CurrentRealm() } -func GetPrevRealm() std.Realm { - return std.PrevRealm() +func GetPreviousRealm() std.Realm { + return std.PreviousRealm() } func Exec(fn func()) { diff --git a/examples/gno.land/r/demo/tests/tests.gno b/examples/gno.land/r/demo/tests/tests.gno index e7fde94ea08..465cc1aeeb3 100644 --- a/examples/gno.land/r/demo/tests/tests.gno +++ b/examples/gno.land/r/demo/tests/tests.gno @@ -21,10 +21,10 @@ func CurrentRealmPath() string { return std.CurrentRealm().PkgPath() } -var initOrigCaller = std.GetOrigCaller() +var initOriginCaller = std.OriginCaller() -func InitOrigCaller() std.Address { - return initOrigCaller +func InitOriginCaller() std.Address { + return initOriginCaller } func CallAssertOriginCall() { @@ -91,12 +91,12 @@ func PrintTestNodes() { println(gTestNode2.Child.Name) } -func GetPrevRealm() std.Realm { - return std.PrevRealm() +func GetPreviousRealm() std.Realm { + return std.PreviousRealm() } -func GetRSubtestsPrevRealm() std.Realm { - return rsubtests.GetPrevRealm() +func GetRSubtestsPreviousRealm() std.Realm { + return rsubtests.GetPreviousRealm() } func Exec(fn func()) { diff --git a/examples/gno.land/r/demo/tests/tests_test.gno b/examples/gno.land/r/demo/tests/tests_test.gno index ccbc6b91265..ac73ac09450 100644 --- a/examples/gno.land/r/demo/tests/tests_test.gno +++ b/examples/gno.land/r/demo/tests/tests_test.gno @@ -42,17 +42,17 @@ func TestAssertOriginCall(t *testing.T) { CallSubtestsAssertOriginCall() } -func TestPrevRealm(t *testing.T) { +func TestPreviousRealm(t *testing.T) { var ( user1Addr = std.DerivePkgAddr("user1.gno") rTestsAddr = std.DerivePkgAddr("gno.land/r/demo/tests") ) - // When a single realm in the frames, PrevRealm returns the user - if addr := GetPrevRealm().Addr(); addr != user1Addr { - t.Errorf("want GetPrevRealm().Addr==%s, got %s", user1Addr, addr) + // When a single realm in the frames, PreviousRealm returns the user + if addr := GetPreviousRealm().Address(); addr != user1Addr { + t.Errorf("want GetPreviousRealm().Addr==%s, got %s", user1Addr, addr) } - // When 2 or more realms in the frames, PrevRealm returns the second to last - if addr := GetRSubtestsPrevRealm().Addr(); addr != rTestsAddr { - t.Errorf("want GetRSubtestsPrevRealm().Addr==%s, got %s", rTestsAddr, addr) + // When 2 or more realms in the frames, PreviousRealm returns the second to last + if addr := GetRSubtestsPreviousRealm().Address(); addr != rTestsAddr { + t.Errorf("want GetRSubtestsPreviousRealm().Addr==%s, got %s", rTestsAddr, addr) } } diff --git a/examples/gno.land/r/demo/tests/z2_filetest.gno b/examples/gno.land/r/demo/tests/z2_filetest.gno index 147d2c12c6c..bad59e0a32b 100644 --- a/examples/gno.land/r/demo/tests/z2_filetest.gno +++ b/examples/gno.land/r/demo/tests/z2_filetest.gno @@ -7,18 +7,18 @@ import ( "gno.land/r/demo/tests" ) -// When a single realm in the frames, PrevRealm returns the user -// When 2 or more realms in the frames, PrevRealm returns the second to last +// When a single realm in the frames, PreviousRealm returns the user +// When 2 or more realms in the frames, PreviousRealm returns the second to last func main() { var ( eoa = testutils.TestAddress("someone") rTestsAddr = std.DerivePkgAddr("gno.land/r/demo/tests") ) - std.TestSetOrigCaller(eoa) - println("tests.GetPrevRealm().Addr(): ", tests.GetPrevRealm().Addr()) - println("tests.GetRSubtestsPrevRealm().Addr(): ", tests.GetRSubtestsPrevRealm().Addr()) + std.TestSetOriginCaller(eoa) + println("tests.GetPreviousRealm().Address(): ", tests.GetPreviousRealm().Address()) + println("tests.GetRSubtestsPreviousRealm().Address(): ", tests.GetRSubtestsPreviousRealm().Address()) } // Output: -// tests.GetPrevRealm().Addr(): g1wdhk6et0dej47h6lta047h6lta047h6lrnerlk -// tests.GetRSubtestsPrevRealm().Addr(): g1gz4ycmx0s6ln2wdrsh4e00l9fsel2wskqa3snq +// tests.GetPreviousRealm().Address(): g1wdhk6et0dej47h6lta047h6lta047h6lrnerlk +// tests.GetRSubtestsPreviousRealm().Address(): g1gz4ycmx0s6ln2wdrsh4e00l9fsel2wskqa3snq diff --git a/examples/gno.land/r/demo/tests/z3_filetest.gno b/examples/gno.land/r/demo/tests/z3_filetest.gno index 5430e7f7151..430486e2818 100644 --- a/examples/gno.land/r/demo/tests/z3_filetest.gno +++ b/examples/gno.land/r/demo/tests/z3_filetest.gno @@ -13,16 +13,16 @@ func main() { eoa = testutils.TestAddress("someone") rTestsAddr = std.DerivePkgAddr("gno.land/r/demo/tests") ) - std.TestSetOrigCaller(eoa) - // Contrarily to z2_filetest.gno we EXPECT GetPrevRealms != eoa (#1704) - if addr := tests.GetPrevRealm().Addr(); addr != eoa { - println("want tests.GetPrevRealm().Addr ==", eoa, "got", addr) + std.TestSetOriginCaller(eoa) + // Contrarily to z2_filetest.gno we EXPECT GetPreviousRealms != eoa (#1704) + if addr := tests.GetPreviousRealm().Address(); addr != eoa { + println("want tests.GetPreviousRealm().Addr ==", eoa, "got", addr) } // When 2 or more realms in the frames, it is also different - if addr := tests.GetRSubtestsPrevRealm().Addr(); addr != rTestsAddr { - println("want GetRSubtestsPrevRealm().Addr ==", rTestsAddr, "got", addr) + if addr := tests.GetRSubtestsPreviousRealm().Address(); addr != rTestsAddr { + println("want GetRSubtestsPreviousRealm().Addr ==", rTestsAddr, "got", addr) } } // Output: -// want tests.GetPrevRealm().Addr == g1wdhk6et0dej47h6lta047h6lta047h6lrnerlk got g1xufrdvnfk6zc9r0nqa23ld3tt2r5gkyvw76q63 +// want tests.GetPreviousRealm().Addr == g1wdhk6et0dej47h6lta047h6lta047h6lrnerlk got g1xufrdvnfk6zc9r0nqa23ld3tt2r5gkyvw76q63 diff --git a/examples/gno.land/r/demo/todolist/todolist_test.gno b/examples/gno.land/r/demo/todolist/todolist_test.gno index 6446732df3e..f6e510bcc03 100644 --- a/examples/gno.land/r/demo/todolist/todolist_test.gno +++ b/examples/gno.land/r/demo/todolist/todolist_test.gno @@ -26,7 +26,7 @@ func TestNewTodoList(t *testing.T) { uassert.Equal(t, title, tdl.Title, "title does not match") uassert.Equal(t, 1, tlid, "tlid does not match") - uassert.Equal(t, tdl.Owner.String(), std.GetOrigCaller().String(), "owner does not match") + uassert.Equal(t, tdl.Owner.String(), std.OriginCaller().String(), "owner does not match") uassert.Equal(t, 0, len(tdl.GetTasks()), "Expected no tasks in the todo list") } diff --git a/examples/gno.land/r/demo/userbook/userbook.gno b/examples/gno.land/r/demo/userbook/userbook.gno index 03027f064b0..412f9410318 100644 --- a/examples/gno.land/r/demo/userbook/userbook.gno +++ b/examples/gno.land/r/demo/userbook/userbook.gno @@ -30,7 +30,7 @@ func init() { func SignUp() string { // Get transaction caller - caller := std.PrevRealm().Addr() + caller := std.PreviousRealm().Address() // Check if the user is already signed up if _, exists := tracker.Get(caller.String()); exists { diff --git a/examples/gno.land/r/demo/users/users.gno b/examples/gno.land/r/demo/users/users.gno index 451afc7bf96..4d578c87d1b 100644 --- a/examples/gno.land/r/demo/users/users.gno +++ b/examples/gno.land/r/demo/users/users.gno @@ -34,16 +34,16 @@ func Register(inviter std.Address, name string, profile string) { // assert CallTx call. std.AssertOriginCall() // assert invited or paid. - caller := std.GetCallerAt(2) - if caller != std.GetOrigCaller() { - panic("should not happen") // because std.AssertOrigCall(). + caller := std.CallerAt(2) + if caller != std.OriginCaller() { + panic("should not happen") // because std.AssertOriginCall(). } - sentCoins := std.GetOrigSend() + sentCoins := std.OriginSend() minCoin := std.NewCoin("ugnot", minFee) if inviter == "" { - // banker := std.GetBanker(std.BankerTypeOrigSend) + // banker := std.NewBanker(std.BankerTypeOriginSend) if len(sentCoins) == 1 && sentCoins[0].IsGTE(minCoin) { if sentCoins[0].Amount > minFee*maxFeeMult { panic("payment must not be greater than " + strconv.Itoa(int(minFee*maxFeeMult))) @@ -118,9 +118,9 @@ func Invite(invitee string) { // assert CallTx call. std.AssertOriginCall() // get caller/inviter. - caller := std.GetCallerAt(2) - if caller != std.GetOrigCaller() { - panic("should not happen") // because std.AssertOrigCall(). + caller := std.CallerAt(2) + if caller != std.OriginCaller() { + panic("should not happen") // because std.AssertOriginCall(). } lines := strings.Split(invitee, "\n") if caller == admin { @@ -157,9 +157,9 @@ func GrantInvites(invites string) { // assert CallTx call. std.AssertOriginCall() // assert admin. - caller := std.GetCallerAt(2) - if caller != std.GetOrigCaller() { - panic("should not happen") // because std.AssertOrigCall(). + caller := std.CallerAt(2) + if caller != std.OriginCaller() { + panic("should not happen") // because std.AssertOriginCall(). } if caller != admin { panic("unauthorized") @@ -208,7 +208,7 @@ func SetMinFee(newMinFee int64) { // assert CallTx call. std.AssertOriginCall() // assert admin caller. - caller := std.GetCallerAt(2) + caller := std.CallerAt(2) if caller != admin { panic("unauthorized") } @@ -221,7 +221,7 @@ func SetMaxFeeMultiple(newMaxFeeMult int64) { // assert CallTx call. std.AssertOriginCall() // assert admin caller. - caller := std.GetCallerAt(2) + caller := std.CallerAt(2) if caller != admin { panic("unauthorized") } @@ -278,7 +278,7 @@ func AdminAddRestrictedName(name string) { // assert CallTx call. std.AssertOriginCall() // get caller - caller := std.GetOrigCaller() + caller := std.OriginCaller() // assert admin if caller != admin { panic("unauthorized") diff --git a/examples/gno.land/r/demo/users/z_0_filetest.gno b/examples/gno.land/r/demo/users/z_0_filetest.gno index cbb2e9209f4..bc06449bf90 100644 --- a/examples/gno.land/r/demo/users/z_0_filetest.gno +++ b/examples/gno.land/r/demo/users/z_0_filetest.gno @@ -7,7 +7,7 @@ import ( ) func main() { - std.TestSetOrigSend(std.Coins{std.NewCoin("dontcare", 1)}, nil) + std.TestSetOriginSend(std.Coins{std.NewCoin("dontcare", 1)}, nil) users.Register("", "gnouser", "my profile") println("done") } diff --git a/examples/gno.land/r/demo/users/z_10_filetest.gno b/examples/gno.land/r/demo/users/z_10_filetest.gno index afeecffcc42..e4a6f714d6b 100644 --- a/examples/gno.land/r/demo/users/z_10_filetest.gno +++ b/examples/gno.land/r/demo/users/z_10_filetest.gno @@ -11,20 +11,20 @@ import ( const admin = std.Address("g1manfred47kzduec920z88wfr64ylksmdcedlf5") func init() { - caller := std.GetOrigCaller() // main + caller := std.OriginCaller() // main test2 := testutils.TestAddress("test2") // as admin, invite gnouser and test2 - std.TestSetOrigCaller(admin) + std.TestSetOriginCaller(admin) users.Invite(caller.String() + "\n" + test2.String()) // register as caller - std.TestSetOrigCaller(caller) + std.TestSetOriginCaller(caller) users.Register(admin, "gnouser", "my profile") } func main() { // register as test2 test2 := testutils.TestAddress("test2") - std.TestSetOrigCaller(test2) + std.TestSetOriginCaller(test2) users.Register(admin, "test222", "my profile 2") println("done") } diff --git a/examples/gno.land/r/demo/users/z_11_filetest.gno b/examples/gno.land/r/demo/users/z_11_filetest.gno index 27c7e9813da..378b58cbfba 100644 --- a/examples/gno.land/r/demo/users/z_11_filetest.gno +++ b/examples/gno.land/r/demo/users/z_11_filetest.gno @@ -11,12 +11,12 @@ import ( const admin = std.Address("g1manfred47kzduec920z88wfr64ylksmdcedlf5") func main() { - caller := std.GetOrigCaller() // main - std.TestSetOrigCaller(admin) + caller := std.OriginCaller() // main + std.TestSetOriginCaller(admin) users.AdminAddRestrictedName("superrestricted") // test restricted name - std.TestSetOrigCaller(caller) + std.TestSetOriginCaller(caller) users.Register("", "superrestricted", "my profile") println("done") } diff --git a/examples/gno.land/r/demo/users/z_11b_filetest.gno b/examples/gno.land/r/demo/users/z_11b_filetest.gno index be508963911..2ff0a66f87c 100644 --- a/examples/gno.land/r/demo/users/z_11b_filetest.gno +++ b/examples/gno.land/r/demo/users/z_11b_filetest.gno @@ -11,14 +11,14 @@ import ( const admin = std.Address("g1manfred47kzduec920z88wfr64ylksmdcedlf5") func main() { - caller := std.GetOrigCaller() // main - std.TestSetOrigCaller(admin) + caller := std.OriginCaller() // main + std.TestSetOriginCaller(admin) // add restricted name users.AdminAddRestrictedName("superrestricted") // grant invite to caller users.Invite(caller.String()) // set back caller - std.TestSetOrigCaller(caller) + std.TestSetOriginCaller(caller) // register restricted name with admin invite users.Register(admin, "superrestricted", "my profile") println("done") diff --git a/examples/gno.land/r/demo/users/z_2_filetest.gno b/examples/gno.land/r/demo/users/z_2_filetest.gno index c1b92790f8b..1436c53ab79 100644 --- a/examples/gno.land/r/demo/users/z_2_filetest.gno +++ b/examples/gno.land/r/demo/users/z_2_filetest.gno @@ -12,18 +12,18 @@ import ( const admin = std.Address("g1manfred47kzduec920z88wfr64ylksmdcedlf5") func main() { - caller := std.GetOrigCaller() // main + caller := std.OriginCaller() // main users.Register("", "gnouser", "my profile") // as admin, grant invites to gnouser - std.TestSetOrigCaller(admin) + std.TestSetOriginCaller(admin) users.GrantInvites(caller.String() + ":1") // switch back to caller - std.TestSetOrigCaller(caller) + std.TestSetOriginCaller(caller) // invite another addr test1 := testutils.TestAddress("test1") users.Invite(test1.String()) // switch to test1 - std.TestSetOrigCaller(test1) + std.TestSetOriginCaller(test1) users.Register(caller, "satoshi", "my other profile") println("done") } diff --git a/examples/gno.land/r/demo/users/z_3_filetest.gno b/examples/gno.land/r/demo/users/z_3_filetest.gno index 5402235e03d..29d082aad62 100644 --- a/examples/gno.land/r/demo/users/z_3_filetest.gno +++ b/examples/gno.land/r/demo/users/z_3_filetest.gno @@ -12,19 +12,19 @@ import ( const admin = std.Address("g1manfred47kzduec920z88wfr64ylksmdcedlf5") func main() { - caller := std.GetOrigCaller() // main + caller := std.OriginCaller() // main users.Register("", "gnouser", "my profile") // as admin, grant invites to gnouser - std.TestSetOrigCaller(admin) + std.TestSetOriginCaller(admin) users.GrantInvites(caller.String() + ":1") // switch back to caller - std.TestSetOrigCaller(caller) + std.TestSetOriginCaller(caller) // invite another addr test1 := testutils.TestAddress("test1") users.Invite(test1.String()) // switch to test1 - std.TestSetOrigCaller(test1) - std.TestSetOrigSend(std.Coins{{"dontcare", 1}}, nil) + std.TestSetOriginCaller(test1) + std.TestSetOriginSend(std.Coins{{"dontcare", 1}}, nil) users.Register(caller, "satoshi", "my other profile") println("done") } diff --git a/examples/gno.land/r/demo/users/z_4_filetest.gno b/examples/gno.land/r/demo/users/z_4_filetest.gno index 613fadf9625..53db4bb2f73 100644 --- a/examples/gno.land/r/demo/users/z_4_filetest.gno +++ b/examples/gno.land/r/demo/users/z_4_filetest.gno @@ -12,20 +12,20 @@ import ( const admin = std.Address("g1manfred47kzduec920z88wfr64ylksmdcedlf5") func main() { - caller := std.GetOrigCaller() // main + caller := std.OriginCaller() // main users.Register("", "gnouser", "my profile") // as admin, grant invites to gnouser - std.TestSetOrigCaller(admin) + std.TestSetOriginCaller(admin) users.GrantInvites(caller.String() + ":1") // switch back to caller - std.TestSetOrigCaller(caller) + std.TestSetOriginCaller(caller) // invite another addr test1 := testutils.TestAddress("test1") test2 := testutils.TestAddress("test2") users.Invite(test1.String()) // switch to test2 (not test1) - std.TestSetOrigCaller(test2) - std.TestSetOrigSend(std.Coins{{"dontcare", 1}}, nil) + std.TestSetOriginCaller(test2) + std.TestSetOriginSend(std.Coins{{"dontcare", 1}}, nil) users.Register(caller, "satoshi", "my other profile") println("done") } diff --git a/examples/gno.land/r/demo/users/z_5_filetest.gno b/examples/gno.land/r/demo/users/z_5_filetest.gno index 6465cc9c378..b02efa90212 100644 --- a/examples/gno.land/r/demo/users/z_5_filetest.gno +++ b/examples/gno.land/r/demo/users/z_5_filetest.gno @@ -12,19 +12,19 @@ import ( const admin = std.Address("g1manfred47kzduec920z88wfr64ylksmdcedlf5") func main() { - caller := std.GetOrigCaller() // main + caller := std.OriginCaller() // main users.Register("", "gnouser", "my profile") // as admin, grant invites to gnouser - std.TestSetOrigCaller(admin) + std.TestSetOriginCaller(admin) users.GrantInvites(caller.String() + ":1") // switch back to caller - std.TestSetOrigCaller(caller) + std.TestSetOriginCaller(caller) // invite another addr test1 := testutils.TestAddress("test1") users.Invite(test1.String()) // switch to test1 - std.TestSetOrigCaller(test1) - std.TestSetOrigSend(std.Coins{{"dontcare", 1}}, nil) + std.TestSetOriginCaller(test1) + std.TestSetOriginSend(std.Coins{{"dontcare", 1}}, nil) users.Register(caller, "satoshi", "my other profile") println(users.Render("")) println("========================================") diff --git a/examples/gno.land/r/demo/users/z_6_filetest.gno b/examples/gno.land/r/demo/users/z_6_filetest.gno index 919088088a2..737f09ee2cd 100644 --- a/examples/gno.land/r/demo/users/z_6_filetest.gno +++ b/examples/gno.land/r/demo/users/z_6_filetest.gno @@ -9,9 +9,9 @@ import ( const admin = std.Address("g1manfred47kzduec920z88wfr64ylksmdcedlf5") func main() { - caller := std.GetOrigCaller() + caller := std.OriginCaller() // as admin, grant invites to unregistered user. - std.TestSetOrigCaller(admin) + std.TestSetOriginCaller(admin) users.GrantInvites(caller.String() + ":1") println("done") } diff --git a/examples/gno.land/r/demo/users/z_7_filetest.gno b/examples/gno.land/r/demo/users/z_7_filetest.gno index 1d3c9e3a917..e2c3e4e6612 100644 --- a/examples/gno.land/r/demo/users/z_7_filetest.gno +++ b/examples/gno.land/r/demo/users/z_7_filetest.gno @@ -12,22 +12,22 @@ import ( const admin = std.Address("g1manfred47kzduec920z88wfr64ylksmdcedlf5") func main() { - caller := std.GetOrigCaller() // main + caller := std.OriginCaller() // main users.Register("", "gnouser", "my profile") // as admin, grant invites to gnouser - std.TestSetOrigCaller(admin) + std.TestSetOriginCaller(admin) users.GrantInvites(caller.String() + ":1") // switch back to caller - std.TestSetOrigCaller(caller) + std.TestSetOriginCaller(caller) // invite another addr test1 := testutils.TestAddress("test1") users.Invite(test1.String()) // switch to test1 - std.TestSetOrigCaller(test1) - std.TestSetOrigSend(std.Coins{{"dontcare", 1}}, nil) + std.TestSetOriginCaller(test1) + std.TestSetOriginSend(std.Coins{{"dontcare", 1}}, nil) users.Register(caller, "satoshi", "my other profile") // as admin, grant invites to gnouser(again) and satoshi. - std.TestSetOrigCaller(admin) + std.TestSetOriginCaller(admin) users.GrantInvites(caller.String() + ":1\n" + test1.String() + ":1") println("done") } diff --git a/examples/gno.land/r/demo/users/z_7b_filetest.gno b/examples/gno.land/r/demo/users/z_7b_filetest.gno index 09c15bb135d..c35b9756d3e 100644 --- a/examples/gno.land/r/demo/users/z_7b_filetest.gno +++ b/examples/gno.land/r/demo/users/z_7b_filetest.gno @@ -12,22 +12,22 @@ import ( const admin = std.Address("g1manfred47kzduec920z88wfr64ylksmdcedlf5") func main() { - caller := std.GetOrigCaller() // main + caller := std.OriginCaller() // main users.Register("", "gnouser", "my profile") // as admin, grant invites to gnouser - std.TestSetOrigCaller(admin) + std.TestSetOriginCaller(admin) users.GrantInvites(caller.String() + ":1\n") // switch back to caller - std.TestSetOrigCaller(caller) + std.TestSetOriginCaller(caller) // invite another addr test1 := testutils.TestAddress("test1") users.Invite(test1.String()) // switch to test1 - std.TestSetOrigCaller(test1) - std.TestSetOrigSend(std.Coins{{"dontcare", 1}}, nil) + std.TestSetOriginCaller(test1) + std.TestSetOriginSend(std.Coins{{"dontcare", 1}}, nil) users.Register(caller, "satoshi", "my other profile") // as admin, grant invites to gnouser(again) and satoshi. - std.TestSetOrigCaller(admin) + std.TestSetOriginCaller(admin) users.GrantInvites(caller.String() + ":1\n" + test1.String() + ":1") println("done") } diff --git a/examples/gno.land/r/demo/users/z_8_filetest.gno b/examples/gno.land/r/demo/users/z_8_filetest.gno index 78fada74a71..56785ae85f1 100644 --- a/examples/gno.land/r/demo/users/z_8_filetest.gno +++ b/examples/gno.land/r/demo/users/z_8_filetest.gno @@ -12,22 +12,22 @@ import ( const admin = std.Address("g1manfred47kzduec920z88wfr64ylksmdcedlf5") func main() { - caller := std.GetOrigCaller() // main + caller := std.OriginCaller() // main users.Register("", "gnouser", "my profile") // as admin, grant invites to gnouser - std.TestSetOrigCaller(admin) + std.TestSetOriginCaller(admin) users.GrantInvites(caller.String() + ":1") // switch back to caller - std.TestSetOrigCaller(caller) + std.TestSetOriginCaller(caller) // invite another addr test1 := testutils.TestAddress("test1") users.Invite(test1.String()) // switch to test1 - std.TestSetOrigCaller(test1) - std.TestSetOrigSend(std.Coins{{"dontcare", 1}}, nil) + std.TestSetOriginCaller(test1) + std.TestSetOriginSend(std.Coins{{"dontcare", 1}}, nil) users.Register(caller, "satoshi", "my other profile") // as admin, grant invites to gnouser(again) and nonexistent user. - std.TestSetOrigCaller(admin) + std.TestSetOriginCaller(admin) test2 := testutils.TestAddress("test2") users.GrantInvites(caller.String() + ":1\n" + test2.String() + ":1") println("done") diff --git a/examples/gno.land/r/demo/users/z_9_filetest.gno b/examples/gno.land/r/demo/users/z_9_filetest.gno index c73c685aebd..d71e19d616d 100644 --- a/examples/gno.land/r/demo/users/z_9_filetest.gno +++ b/examples/gno.land/r/demo/users/z_9_filetest.gno @@ -10,16 +10,16 @@ import ( const admin = std.Address("g1manfred47kzduec920z88wfr64ylksmdcedlf5") func main() { - caller := std.GetOrigCaller() // main + caller := std.OriginCaller() // main test2 := testutils.TestAddress("test2") // as admin, invite gnouser and test2 - std.TestSetOrigCaller(admin) + std.TestSetOriginCaller(admin) users.Invite(caller.String() + "\n" + test2.String()) // register as caller - std.TestSetOrigCaller(caller) + std.TestSetOriginCaller(caller) users.Register(admin, "gnouser", "my profile") // register as test2 - std.TestSetOrigCaller(test2) + std.TestSetOriginCaller(test2) users.Register(admin, "test222", "my profile 2") println("done") } diff --git a/examples/gno.land/r/demo/wugnot/wugnot.gno b/examples/gno.land/r/demo/wugnot/wugnot.gno index d0395fe7e8c..75ce9a76a0a 100644 --- a/examples/gno.land/r/demo/wugnot/wugnot.gno +++ b/examples/gno.land/r/demo/wugnot/wugnot.gno @@ -22,8 +22,8 @@ func init() { } func Deposit() { - caller := std.PrevRealm().Addr() - sent := std.GetOrigSend() + caller := std.PreviousRealm().Address() + sent := std.OriginSend() amount := sent.AmountOf("ugnot") require(uint64(amount) >= ugnotMinDeposit, ufmt.Sprintf("Deposit below minimum: %d/%d ugnot.", amount, ugnotMinDeposit)) @@ -34,13 +34,13 @@ func Deposit() { func Withdraw(amount uint64) { require(amount >= wugnotMinDeposit, ufmt.Sprintf("Deposit below minimum: %d/%d wugnot.", amount, wugnotMinDeposit)) - caller := std.PrevRealm().Addr() - pkgaddr := std.CurrentRealm().Addr() + caller := std.PreviousRealm().Address() + pkgaddr := std.CurrentRealm().Address() callerBal := Token.BalanceOf(caller) require(amount <= callerBal, ufmt.Sprintf("Insufficient balance: %d available, %d needed.", callerBal, amount)) // send swapped ugnots to qcaller - stdBanker := std.GetBanker(std.BankerTypeRealmSend) + stdBanker := std.NewBanker(std.BankerTypeRealmSend) send := std.Coins{{"ugnot", int64(amount)}} stdBanker.SendCoins(pkgaddr, caller, send) checkErr(adm.Burn(caller, amount)) diff --git a/examples/gno.land/r/demo/wugnot/z0_filetest.gno b/examples/gno.land/r/demo/wugnot/z0_filetest.gno index ff2ea86bc0d..6e9fa0da961 100644 --- a/examples/gno.land/r/demo/wugnot/z0_filetest.gno +++ b/examples/gno.land/r/demo/wugnot/z0_filetest.gno @@ -16,7 +16,7 @@ var ( ) func main() { - std.TestSetOrigPkgAddr(addrc) + std.TestSetOriginPkgAddress(addrc) std.TestIssueCoins(addrc, std.Coins{{"ugnot", 100000001}}) // TODO: remove this // issue ugnots @@ -27,8 +27,8 @@ func main() { // println(wugnot.Render("queues")) // println("A -", wugnot.Render("")) - std.TestSetOrigCaller(addr1) - std.TestSetOrigSend(std.Coins{{"ugnot", 123_400}}, nil) + std.TestSetOriginCaller(addr1) + std.TestSetOriginSend(std.Coins{{"ugnot", 123_400}}, nil) wugnot.Deposit() printBalances() wugnot.Withdraw(4242) @@ -38,8 +38,8 @@ func main() { func printBalances() { printSingleBalance := func(name string, addr std.Address) { wugnotBal := wugnot.BalanceOf(addr) - std.TestSetOrigCaller(addr) - robanker := std.GetBanker(std.BankerTypeReadonly) + std.TestSetOriginCaller(addr) + robanker := std.NewBanker(std.BankerTypeReadonly) coins := robanker.GetCoins(addr).AmountOf("ugnot") fmt.Printf("| %-13s | addr=%s | wugnot=%-5d | ugnot=%-9d |\n", name, addr, wugnotBal, coins) diff --git a/examples/gno.land/r/docs/buttons/buttons.gno b/examples/gno.land/r/docs/buttons/buttons.gno index cb050b1bc38..129ffc149e2 100644 --- a/examples/gno.land/r/docs/buttons/buttons.gno +++ b/examples/gno.land/r/docs/buttons/buttons.gno @@ -14,7 +14,7 @@ var ( func UpdateMOTD(newmotd string) { motd = newmotd - lastCaller = std.PrevRealm().Addr() + lastCaller = std.PreviousRealm().Address() } func Render(path string) string { diff --git a/examples/gno.land/r/gnoland/blog/admin.gno b/examples/gno.land/r/gnoland/blog/admin.gno index 87d465449f3..664b905fba8 100644 --- a/examples/gno.land/r/gnoland/blog/admin.gno +++ b/examples/gno.land/r/gnoland/blog/admin.gno @@ -17,7 +17,7 @@ var ( ) func init() { - // adminAddr = std.GetOrigCaller() // FIXME: find a way to use this from the main's genesis. + // adminAddr = std.OriginCaller() // FIXME: find a way to use this from the main's genesis. adminAddr = "g1manfred47kzduec920z88wfr64ylksmdcedlf5" // @moul } @@ -43,7 +43,7 @@ func AdminRemoveModerator(addr std.Address) { func NewPostExecutor(slug, title, body, publicationDate, authors, tags string) dao.Executor { callback := func() error { - addPost(std.PrevRealm().Addr(), slug, title, body, publicationDate, authors, tags) + addPost(std.PreviousRealm().Address(), slug, title, body, publicationDate, authors, tags) return nil } @@ -53,7 +53,7 @@ func NewPostExecutor(slug, title, body, publicationDate, authors, tags string) d func ModAddPost(slug, title, body, publicationDate, authors, tags string) { assertIsModerator() - caller := std.GetOrigCaller() + caller := std.OriginCaller() addPost(caller, slug, title, body, publicationDate, authors, tags) } @@ -120,14 +120,14 @@ func isCommenter(addr std.Address) bool { } func assertIsAdmin() { - caller := std.GetOrigCaller() + caller := std.OriginCaller() if !isAdmin(caller) { panic("access restricted.") } } func assertIsModerator() { - caller := std.GetOrigCaller() + caller := std.OriginCaller() if isAdmin(caller) || isModerator(caller) { return } @@ -135,7 +135,7 @@ func assertIsModerator() { } func assertIsCommenter() { - caller := std.GetOrigCaller() + caller := std.OriginCaller() if isAdmin(caller) || isModerator(caller) || isCommenter(caller) { return } diff --git a/examples/gno.land/r/gnoland/blog/gnoblog.gno b/examples/gno.land/r/gnoland/blog/gnoblog.gno index d2a163543e5..ee8fc01db69 100644 --- a/examples/gno.land/r/gnoland/blog/gnoblog.gno +++ b/examples/gno.land/r/gnoland/blog/gnoblog.gno @@ -15,7 +15,7 @@ func AddComment(postSlug, comment string) { assertIsCommenter() assertNotInPause() - caller := std.GetOrigCaller() + caller := std.OriginCaller() err := b.GetPost(postSlug).AddComment(caller, comment) checkErr(err) } diff --git a/examples/gno.land/r/gnoland/blog/gnoblog_test.gno b/examples/gno.land/r/gnoland/blog/gnoblog_test.gno index d046eb80f42..a486cf33176 100644 --- a/examples/gno.land/r/gnoland/blog/gnoblog_test.gno +++ b/examples/gno.land/r/gnoland/blog/gnoblog_test.gno @@ -7,7 +7,8 @@ import ( ) func TestPackage(t *testing.T) { - std.TestSetOrigCaller(std.Address("g1manfred47kzduec920z88wfr64ylksmdcedlf5")) + std.TestSetOriginCaller(std.Address("g1manfred47kzduec920z88wfr64ylksmdcedlf5")) + // by default, no posts. { got := Render("") diff --git a/examples/gno.land/r/gnoland/events/events_test.gno b/examples/gno.land/r/gnoland/events/events_test.gno index 1d79b754ee4..47d327203d7 100644 --- a/examples/gno.land/r/gnoland/events/events_test.gno +++ b/examples/gno.land/r/gnoland/events/events_test.gno @@ -18,7 +18,7 @@ var ( ) func TestAddEvent(t *testing.T) { - std.TestSetOrigCaller(su) + std.TestSetOriginCaller(su) std.TestSetRealm(suRealm) e1Start := parsedTimeNow.Add(time.Hour * 24 * 5) @@ -61,7 +61,7 @@ func TestAddEvent(t *testing.T) { } func TestAddEventErrors(t *testing.T) { - std.TestSetOrigCaller(su) + std.TestSetOriginCaller(su) std.TestSetRealm(suRealm) _, err := AddEvent("", "sample desc", "gno.land", "gnome land", "2009-02-13T23:31:31Z", "2009-02-13T23:33:31Z") @@ -85,7 +85,7 @@ func TestAddEventErrors(t *testing.T) { } func TestDeleteEvent(t *testing.T) { - std.TestSetOrigCaller(su) + std.TestSetOriginCaller(su) std.TestSetRealm(suRealm) e1Start := parsedTimeNow.Add(time.Hour * 24 * 5) @@ -108,7 +108,7 @@ func TestDeleteEvent(t *testing.T) { } func TestEditEvent(t *testing.T) { - std.TestSetOrigCaller(su) + std.TestSetOriginCaller(su) std.TestSetRealm(suRealm) e1Start := parsedTimeNow.Add(time.Hour * 24 * 5) @@ -138,7 +138,7 @@ func TestEditEvent(t *testing.T) { } func TestInvalidEdit(t *testing.T) { - std.TestSetOrigCaller(su) + std.TestSetOriginCaller(su) std.TestSetRealm(suRealm) uassert.PanicsWithMessage(t, ErrNoSuchID.Error(), func() { @@ -165,7 +165,7 @@ func TestParseTimes(t *testing.T) { } func TestRenderEventWidget(t *testing.T) { - std.TestSetOrigCaller(su) + std.TestSetOriginCaller(su) std.TestSetRealm(suRealm) // No events yet diff --git a/examples/gno.land/r/gnoland/faucet/admin.gno b/examples/gno.land/r/gnoland/faucet/admin.gno index 37108059b74..d991fcd9816 100644 --- a/examples/gno.land/r/gnoland/faucet/admin.gno +++ b/examples/gno.land/r/gnoland/faucet/admin.gno @@ -79,7 +79,7 @@ func AdminRemoveController(addr std.Address) string { } func assertIsAdmin() error { - caller := std.GetOrigCaller() + caller := std.OriginCaller() if caller != gAdminAddr { return errors.New("restricted for admin") } diff --git a/examples/gno.land/r/gnoland/faucet/faucet.gno b/examples/gno.land/r/gnoland/faucet/faucet.gno index 908b86d4aaf..a173c0423ee 100644 --- a/examples/gno.land/r/gnoland/faucet/faucet.gno +++ b/examples/gno.land/r/gnoland/faucet/faucet.gno @@ -42,8 +42,8 @@ func Transfer(to std.Address, send int64) string { gTotalTransferred = gTotalTransferred.Add(sendCoins) gTotalTransfers++ - banker := std.GetBanker(std.BankerTypeRealmSend) - pkgaddr := std.CurrentRealm().Addr() + banker := std.NewBanker(std.BankerTypeRealmSend) + pkgaddr := std.CurrentRealm().Address() banker.SendCoins(pkgaddr, to, sendCoins) return "" } @@ -53,8 +53,8 @@ func GetPerTransferLimit() int64 { } func Render(_ string) string { - banker := std.GetBanker(std.BankerTypeRealmSend) - balance := banker.GetCoins(std.CurrentRealm().Addr()) + banker := std.NewBanker(std.BankerTypeRealmSend) + balance := banker.GetCoins(std.CurrentRealm().Address()) output := gMessage if gInPause { @@ -65,7 +65,7 @@ func Render(_ string) string { output += ufmt.Sprintf("Balance: %s.\n", balance.String()) output += ufmt.Sprintf("Total transfers: %s (in %d times).\n\n", gTotalTransferred.String(), gTotalTransfers) - output += "Package address: " + std.CurrentRealm().Addr().String() + "\n\n" + output += "Package address: " + std.CurrentRealm().Address().String() + "\n\n" output += ufmt.Sprintf("Admin: %s\n\n ", gAdminAddr.String()) output += ufmt.Sprintf("Controllers:\n\n ") @@ -81,7 +81,7 @@ func Render(_ string) string { } func assertIsController() error { - caller := std.GetOrigCaller() + caller := std.OriginCaller() ok := gControllers.Has(caller.String()) if !ok { diff --git a/examples/gno.land/r/gnoland/faucet/faucet_test.gno b/examples/gno.land/r/gnoland/faucet/faucet_test.gno index 5672f317469..ca741ab017f 100644 --- a/examples/gno.land/r/gnoland/faucet/faucet_test.gno +++ b/examples/gno.land/r/gnoland/faucet/faucet_test.gno @@ -33,20 +33,20 @@ func TestPackage(t *testing.T) { // by default, balance is empty, and as a user I cannot call Transfer, or Admin commands. assertBalance(t, test1addr, 0) - std.TestSetOrigCaller(test1addr) + std.TestSetOriginCaller(test1addr) assertErr(t, faucet.Transfer(test1addr, 1000000)) assertErr(t, faucet.AdminAddController(controlleraddr1)) - std.TestSetOrigCaller(controlleraddr1) + std.TestSetOriginCaller(controlleraddr1) assertErr(t, faucet.Transfer(test1addr, 1000000)) // as an admin, add the controller to contract and deposit more 2000gnot to contract - std.TestSetOrigCaller(adminaddr) + std.TestSetOriginCaller(adminaddr) assertNoErr(t, faucet.AdminAddController(controlleraddr1)) assertBalance(t, faucetaddr, 1000000000) // now, send some tokens as controller. - std.TestSetOrigCaller(controlleraddr1) + std.TestSetOriginCaller(controlleraddr1) assertNoErr(t, faucet.Transfer(test1addr, 1000000)) assertBalance(t, test1addr, 1000000) assertNoErr(t, faucet.Transfer(test1addr, 1000000)) @@ -55,13 +55,13 @@ func TestPackage(t *testing.T) { // remove controller // as an admin, remove controller - std.TestSetOrigCaller(adminaddr) + std.TestSetOriginCaller(adminaddr) assertNoErr(t, faucet.AdminRemoveController(controlleraddr1)) - std.TestSetOrigCaller(controlleraddr1) + std.TestSetOriginCaller(controlleraddr1) assertErr(t, faucet.Transfer(test1addr, 1000000)) // duplicate controller - std.TestSetOrigCaller(adminaddr) + std.TestSetOriginCaller(adminaddr) assertNoErr(t, faucet.AdminAddController(controlleraddr1)) assertErr(t, faucet.AdminAddController(controlleraddr1)) // add more than more than allowed controllers @@ -77,13 +77,13 @@ func TestPackage(t *testing.T) { assertErr(t, faucet.AdminAddController(controlleraddr11)) // send more than per transfer limit - std.TestSetOrigCaller(adminaddr) + std.TestSetOriginCaller(adminaddr) faucet.AdminSetTransferLimit(300000000) - std.TestSetOrigCaller(controlleraddr1) + std.TestSetOriginCaller(controlleraddr1) assertErr(t, faucet.Transfer(test1addr, 301000000)) // block transefer from the address not on the controllers list. - std.TestSetOrigCaller(controlleraddr11) + std.TestSetOriginCaller(controlleraddr11) assertErr(t, faucet.Transfer(test1addr, 1000000)) } @@ -105,7 +105,7 @@ func assertNoErr(t *testing.T, err string) { func assertBalance(t *testing.T, addr std.Address, expectedBal int64) { t.Helper() - banker := std.GetBanker(std.BankerTypeReadonly) + banker := std.NewBanker(std.BankerTypeReadonly) coins := banker.GetCoins(addr) got := coins.AmountOf("ugnot") diff --git a/examples/gno.land/r/gnoland/faucet/z2_filetest.gno b/examples/gno.land/r/gnoland/faucet/z2_filetest.gno index d0616b3afcd..1490c46ffc9 100644 --- a/examples/gno.land/r/gnoland/faucet/z2_filetest.gno +++ b/examples/gno.land/r/gnoland/faucet/z2_filetest.gno @@ -20,7 +20,7 @@ func main() { controlleraddr1 = testutils.TestAddress("controller1") controlleraddr2 = testutils.TestAddress("controller2") ) - std.TestSetOrigCaller(adminaddr) + std.TestSetOriginCaller(adminaddr) err := faucet.AdminAddController(controlleraddr1) if err != "" { panic(err) diff --git a/examples/gno.land/r/gnoland/faucet/z3_filetest.gno b/examples/gno.land/r/gnoland/faucet/z3_filetest.gno index 0da06593710..90612aa3548 100644 --- a/examples/gno.land/r/gnoland/faucet/z3_filetest.gno +++ b/examples/gno.land/r/gnoland/faucet/z3_filetest.gno @@ -22,7 +22,7 @@ func main() { testaddr1 = testutils.TestAddress("test1") testaddr2 = testutils.TestAddress("test2") ) - std.TestSetOrigCaller(adminaddr) + std.TestSetOriginCaller(adminaddr) err := faucet.AdminAddController(controlleraddr1) if err != "" { panic(err) @@ -31,12 +31,12 @@ func main() { if err != "" { panic(err) } - std.TestSetOrigCaller(controlleraddr1) + std.TestSetOriginCaller(controlleraddr1) err = faucet.Transfer(testaddr1, 1000000) if err != "" { panic(err) } - std.TestSetOrigCaller(controlleraddr2) + std.TestSetOriginCaller(controlleraddr2) err = faucet.Transfer(testaddr1, 2000000) if err != "" { panic(err) diff --git a/examples/gno.land/r/gnoland/ghverify/contract.gno b/examples/gno.land/r/gnoland/ghverify/contract.gno index 3b8f7fcbbe1..1540e548887 100644 --- a/examples/gno.land/r/gnoland/ghverify/contract.gno +++ b/examples/gno.land/r/gnoland/ghverify/contract.gno @@ -16,7 +16,7 @@ const ( ) var ( - ownerAddress = std.GetOrigCaller() + ownerAddress = std.OriginCaller() oracle *gnorkle.Instance postHandler postGnorkleMessageHandler @@ -70,7 +70,7 @@ func (h postGnorkleMessageHandler) Handle(i *gnorkle.Instance, funcType message. // RequestVerification creates a new static feed with a single task that will // instruct an agent to verify the github handle / gno address pair. func RequestVerification(githubHandle string) { - gnoAddress := string(std.GetOrigCaller()) + gnoAddress := string(std.OriginCaller()) if err := oracle.AddFeeds( static.NewSingleValueFeed( gnoAddress, @@ -102,7 +102,7 @@ func GnorkleEntrypoint(message string) string { // SetOwner transfers ownership of the contract to the given address. func SetOwner(owner std.Address) { - if ownerAddress != std.GetOrigCaller() { + if ownerAddress != std.OriginCaller() { panic("only the owner can set a new owner") } diff --git a/examples/gno.land/r/gnoland/ghverify/contract_test.gno b/examples/gno.land/r/gnoland/ghverify/contract_test.gno index 5c0be0afcb1..3bf6e306fed 100644 --- a/examples/gno.land/r/gnoland/ghverify/contract_test.gno +++ b/examples/gno.land/r/gnoland/ghverify/contract_test.gno @@ -8,7 +8,7 @@ import ( ) func TestVerificationLifecycle(t *testing.T) { - defaultAddress := std.GetOrigCaller() + defaultAddress := std.OriginCaller() user1Address := std.Address(testutils.TestAddress("user 1")) user2Address := std.Address(testutils.TestAddress("user 2")) @@ -19,7 +19,7 @@ func TestVerificationLifecycle(t *testing.T) { } // Make a verification request with the created user. - std.TestSetOrigCaller(user1Address) + std.TestSetOriginCaller(user1Address) RequestVerification("deelawn") // A subsequent request from the same address should panic because there is @@ -44,13 +44,13 @@ func TestVerificationLifecycle(t *testing.T) { } // Make a verification request with the created user. - std.TestSetOrigCaller(user2Address) + std.TestSetOriginCaller(user2Address) RequestVerification("omarsy") // Set the caller back to the whitelisted user and verify that the feed data // returned matches what should have been created by the `RequestVerification` // invocation. - std.TestSetOrigCaller(defaultAddress) + std.TestSetOriginCaller(defaultAddress) result = GnorkleEntrypoint("request") expResult := `[{"id":"` + string(user1Address) + `","type":"0","value_type":"string","tasks":[{"gno_address":"` + string(user1Address) + `","github_handle":"deelawn"}]},` + @@ -61,7 +61,7 @@ func TestVerificationLifecycle(t *testing.T) { } // Try to trigger feed ingestion from the non-authorized user. - std.TestSetOrigCaller(user1Address) + std.TestSetOriginCaller(user1Address) func() { defer func() { if r := recover(); r != nil { @@ -75,7 +75,7 @@ func TestVerificationLifecycle(t *testing.T) { } // Set the caller back to the whitelisted user and transfer contract ownership. - std.TestSetOrigCaller(defaultAddress) + std.TestSetOriginCaller(defaultAddress) SetOwner(defaultAddress) // Now trigger the feed ingestion from the user and new owner and only whitelisted address. diff --git a/examples/gno.land/r/gnoland/home/home.gno b/examples/gno.land/r/gnoland/home/home.gno index 2d1aad8a1a0..1264f5332e4 100644 --- a/examples/gno.land/r/gnoland/home/home.gno +++ b/examples/gno.land/r/gnoland/home/home.gno @@ -149,7 +149,7 @@ func quoteOfTheBlock() ui.Element { "Now, you Gno.", "Come for the Go, Stay for the Gno.", } - height := std.GetHeight() + height := std.ChainHeight() idx := int(height) % len(quotes) qotb := quotes[idx] diff --git a/examples/gno.land/r/gnoland/home/overide_filetest.gno b/examples/gno.land/r/gnoland/home/overide_filetest.gno index be7e33501d6..70c59cbaded 100644 --- a/examples/gno.land/r/gnoland/home/overide_filetest.gno +++ b/examples/gno.land/r/gnoland/home/overide_filetest.gno @@ -8,7 +8,7 @@ import ( ) func main() { - std.TestSetOrigCaller("g1manfred47kzduec920z88wfr64ylksmdcedlf5") + std.TestSetOriginCaller("g1manfred47kzduec920z88wfr64ylksmdcedlf5") home.AdminSetOverride("Hello World!") println(home.Render("")) home.AdminTransferOwnership(testutils.TestAddress("newAdmin")) diff --git a/examples/gno.land/r/gnoland/monit/monit.gno b/examples/gno.land/r/gnoland/monit/monit.gno index be94fbdd2bb..7c74e2f5733 100644 --- a/examples/gno.land/r/gnoland/monit/monit.gno +++ b/examples/gno.land/r/gnoland/monit/monit.gno @@ -29,7 +29,7 @@ var ( func Incr() int { counter++ lastUpdate = time.Now() - lastCaller = std.PrevRealm().Addr() + lastCaller = std.PreviousRealm().Address() wd.Alive() return counter } @@ -40,7 +40,7 @@ func Reset() { Ownable.AssertCallerIsOwner() counter = 0 - lastCaller = std.PrevRealm().Addr() + lastCaller = std.PreviousRealm().Address() lastUpdate = time.Now() wd = watchdog.Watchdog{Duration: 5 * time.Minute} } diff --git a/examples/gno.land/r/gnoland/pages/admin.gno b/examples/gno.land/r/gnoland/pages/admin.gno index 71050f4ef57..963c9161df7 100644 --- a/examples/gno.land/r/gnoland/pages/admin.gno +++ b/examples/gno.land/r/gnoland/pages/admin.gno @@ -14,7 +14,7 @@ var ( ) func init() { - // adminAddr = std.GetOrigCaller() // FIXME: find a way to use this from the main's genesis. + // adminAddr = std.OriginCaller() // FIXME: find a way to use this from the main's genesis. adminAddr = "g1manfred47kzduec920z88wfr64ylksmdcedlf5" // @moul } @@ -41,7 +41,7 @@ func AdminRemoveModerator(addr std.Address) { func ModAddPost(slug, title, body, publicationDate, authors, tags string) { assertIsModerator() - caller := std.GetOrigCaller() + caller := std.OriginCaller() tagList := strings.Split(tags, ",") authorList := strings.Split(authors, ",") @@ -69,14 +69,14 @@ func isModerator(addr std.Address) bool { } func assertIsAdmin() { - caller := std.GetOrigCaller() + caller := std.OriginCaller() if !isAdmin(caller) { panic("access restricted.") } } func assertIsModerator() { - caller := std.GetOrigCaller() + caller := std.OriginCaller() if isAdmin(caller) || isModerator(caller) { return } diff --git a/examples/gno.land/r/gnoland/valopers/v2/valopers.gno b/examples/gno.land/r/gnoland/valopers/v2/valopers.gno index d88ea4b872f..cd2a99bb336 100644 --- a/examples/gno.land/r/gnoland/valopers/v2/valopers.gno +++ b/examples/gno.land/r/gnoland/valopers/v2/valopers.gno @@ -148,7 +148,7 @@ func GovDAOProposal(address std.Address) { ) // Make sure the valoper is the caller - if std.GetOrigCaller() != address { + if std.OriginCaller() != address { panic(errValoperNotCaller) } diff --git a/examples/gno.land/r/gov/dao/bridge/bridge_test.gno b/examples/gno.land/r/gov/dao/bridge/bridge_test.gno index 38b5d4be257..cff93fc497a 100644 --- a/examples/gno.land/r/gov/dao/bridge/bridge_test.gno +++ b/examples/gno.land/r/gov/dao/bridge/bridge_test.gno @@ -47,7 +47,7 @@ func TestBridge_SetDAO(t *testing.T) { } ) - std.TestSetOrigCaller(addr) + std.TestSetOriginCaller(addr) b.Ownable = ownable.NewWithAddress(addr) diff --git a/examples/gno.land/r/leon/hof/hof.gno b/examples/gno.land/r/leon/hof/hof.gno index 96266ffe380..ef20d02d7a7 100644 --- a/examples/gno.land/r/leon/hof/hof.gno +++ b/examples/gno.land/r/leon/hof/hof.gno @@ -56,7 +56,7 @@ func Register() { return } - submission := std.PrevRealm() + submission := std.PreviousRealm() pkgpath := submission.PkgPath() // Must be called from code @@ -73,7 +73,7 @@ func Register() { i := &Item{ id: id, pkgpath: pkgpath, - blockNum: std.GetHeight(), + blockNum: std.ChainHeight(), upvote: avl.NewTree(), downvote: avl.NewTree(), } @@ -91,7 +91,7 @@ func Upvote(pkgpath string) { } item := rawItem.(*Item) - caller := std.PrevRealm().Addr().String() + caller := std.PreviousRealm().Address().String() if item.upvote.Has(caller) { panic(ErrDoubleUpvote) @@ -107,7 +107,7 @@ func Downvote(pkgpath string) { } item := rawItem.(*Item) - caller := std.PrevRealm().Addr().String() + caller := std.PreviousRealm().Address().String() if item.downvote.Has(caller) { panic(ErrDoubleDownvote) diff --git a/examples/gno.land/r/leon/hof/hof_test.gno b/examples/gno.land/r/leon/hof/hof_test.gno index 4d6f70eab88..4e133a6bbe8 100644 --- a/examples/gno.land/r/leon/hof/hof_test.gno +++ b/examples/gno.land/r/leon/hof/hof_test.gno @@ -103,7 +103,7 @@ func TestDownvote(t *testing.T) { func TestDelete(t *testing.T) { userRealm := std.NewUserRealm(admin) std.TestSetRealm(userRealm) - std.TestSetOrigCaller(admin) + std.TestSetOriginCaller(admin) uassert.PanicsWithMessage(t, ErrNoSuchItem.Error(), func() { Delete("nonexistentpkgpath") diff --git a/examples/gno.land/r/leon/home/home.gno b/examples/gno.land/r/leon/home/home.gno index aef261fcd60..6f7fca01c68 100644 --- a/examples/gno.land/r/leon/home/home.gno +++ b/examples/gno.land/r/leon/home/home.gno @@ -52,7 +52,7 @@ TODO import r/gh`, } func UpdatePFP(url, caption string) { - if !config.IsAuthorized(std.PrevRealm().Addr()) { + if !config.IsAuthorized(std.PreviousRealm().Address()) { panic(config.ErrUnauthorized) } @@ -61,7 +61,7 @@ func UpdatePFP(url, caption string) { } func UpdateAboutMe(col1, col2 string) { - if !config.IsAuthorized(std.PrevRealm().Addr()) { + if !config.IsAuthorized(std.PreviousRealm().Address()) { panic(config.ErrUnauthorized) } @@ -71,7 +71,7 @@ func UpdateAboutMe(col1, col2 string) { func renderBlogPosts() string { out := "" - //out += "## Leon's Blog Posts" + // out += "## Leon's Blog Posts" // todo fetch blog posts authored by @leohhhn // and render them @@ -118,7 +118,7 @@ func renderArt() string { func renderGnoFace() string { out := "
\n\n" - out += gnoface.Render(strconv.Itoa(int(std.GetHeight()))) + out += gnoface.Render(strconv.Itoa(int(std.ChainHeight()))) out += "
\n\n" return out @@ -127,7 +127,7 @@ func renderGnoFace() string { func renderMillipede() string { out := "
\n\n" out += "Millipede\n\n" - out += "```\n" + millipede.Draw(int(std.GetHeight())%10+1) + "```\n" + out += "```\n" + millipede.Draw(int(std.ChainHeight())%10+1) + "```\n" out += "
\n\n" return out diff --git a/examples/gno.land/r/matijamarjanovic/home/config.gno b/examples/gno.land/r/matijamarjanovic/home/config.gno index 2a9669c0b58..8a5a4135025 100644 --- a/examples/gno.land/r/matijamarjanovic/home/config.gno +++ b/examples/gno.land/r/matijamarjanovic/home/config.gno @@ -48,7 +48,7 @@ func SetBackup(newAddress std.Address) error { } func checkAuthorized() error { - caller := std.GetOrigCaller() + caller := std.OriginCaller() if caller != mainAddr && caller != backupAddr { return errorUnauthorized } @@ -57,7 +57,7 @@ func checkAuthorized() error { } func AssertAuthorized() { - caller := std.GetOrigCaller() + caller := std.OriginCaller() if caller != mainAddr && caller != backupAddr { panic(errorUnauthorized) } diff --git a/examples/gno.land/r/matijamarjanovic/home/home.gno b/examples/gno.land/r/matijamarjanovic/home/home.gno index 3757324108a..133a5857f2b 100644 --- a/examples/gno.land/r/matijamarjanovic/home/home.gno +++ b/examples/gno.land/r/matijamarjanovic/home/home.gno @@ -71,21 +71,21 @@ func maxOfThree(a, b, c int64) int64 { } func VoteModern() { - ugnotAmount := std.GetOrigSend().AmountOf("ugnot") + ugnotAmount := std.OriginSend().AmountOf("ugnot") votes := ugnotAmount modernVotes += votes updateCurrentTheme() } func VoteClassic() { - ugnotAmount := std.GetOrigSend().AmountOf("ugnot") + ugnotAmount := std.OriginSend().AmountOf("ugnot") votes := ugnotAmount classicVotes += votes updateCurrentTheme() } func VoteMinimal() { - ugnotAmount := std.GetOrigSend().AmountOf("ugnot") + ugnotAmount := std.OriginSend().AmountOf("ugnot") votes := ugnotAmount minimalVotes += votes updateCurrentTheme() @@ -106,10 +106,10 @@ func updateCurrentTheme() { func CollectBalance() { AssertAuthorized() - banker := std.GetBanker(std.BankerTypeRealmSend) + banker := std.NewBanker(std.BankerTypeRealmSend) ownerAddr := Address() - banker.SendCoins(std.CurrentRealm().Addr(), ownerAddr, banker.GetCoins(std.CurrentRealm().Addr())) + banker.SendCoins(std.CurrentRealm().Address(), ownerAddr, banker.GetCoins(std.CurrentRealm().Address())) } func Render(path string) string { diff --git a/examples/gno.land/r/matijamarjanovic/home/home_test.gno b/examples/gno.land/r/matijamarjanovic/home/home_test.gno index 8cc6e6e5608..10e2e6db6fc 100644 --- a/examples/gno.land/r/matijamarjanovic/home/home_test.gno +++ b/examples/gno.land/r/matijamarjanovic/home/home_test.gno @@ -11,7 +11,7 @@ import ( // Helper function to set up test environment func setupTest() { - std.TestSetOrigCaller(std.Address("g1ej0qca5ptsw9kfr64ey8jvfy9eacga6mpj2z0y")) + std.TestSetOriginCaller(std.Address("g1ej0qca5ptsw9kfr64ey8jvfy9eacga6mpj2z0y")) } func TestUpdatePFP(t *testing.T) { @@ -41,7 +41,7 @@ func TestVoteModern(t *testing.T) { coinsSent := std.NewCoins(std.NewCoin("ugnot", 75000000)) coinsSpent := std.NewCoins(std.NewCoin("ugnot", 1)) - std.TestSetOrigSend(coinsSent, coinsSpent) + std.TestSetOriginSend(coinsSent, coinsSpent) VoteModern() uassert.Equal(t, int64(75000000), modernVotes, "Modern votes should be calculated correctly") @@ -55,7 +55,7 @@ func TestVoteClassic(t *testing.T) { coinsSent := std.NewCoins(std.NewCoin("ugnot", 75000000)) coinsSpent := std.NewCoins(std.NewCoin("ugnot", 1)) - std.TestSetOrigSend(coinsSent, coinsSpent) + std.TestSetOriginSend(coinsSent, coinsSpent) VoteClassic() uassert.Equal(t, int64(75000000), classicVotes, "Classic votes should be calculated correctly") @@ -69,7 +69,7 @@ func TestVoteMinimal(t *testing.T) { coinsSent := std.NewCoins(std.NewCoin("ugnot", 75000000)) coinsSpent := std.NewCoins(std.NewCoin("ugnot", 1)) - std.TestSetOrigSend(coinsSent, coinsSpent) + std.TestSetOriginSend(coinsSent, coinsSpent) VoteMinimal() uassert.Equal(t, int64(75000000), minimalVotes, "Minimal votes should be calculated correctly") diff --git a/examples/gno.land/r/morgan/guestbook/guestbook.gno b/examples/gno.land/r/morgan/guestbook/guestbook.gno index be9e9db6133..4930b0af209 100644 --- a/examples/gno.land/r/morgan/guestbook/guestbook.gno +++ b/examples/gno.land/r/morgan/guestbook/guestbook.gno @@ -43,22 +43,22 @@ const ( // Sign signs the guestbook, with the specified message. func Sign(message string) { - prev := std.PrevRealm() + prev := std.PreviousRealm() switch { case !prev.IsUser(): panic(errNotAUser) - case hasSigned.Has(prev.Addr().String()): + case hasSigned.Has(prev.Address().String()): panic(errAlreadySigned) } message = validateMessage(message) guestbook.Set(signatureID.Next().Binary(), Signature{ Message: message, - Author: prev.Addr(), + Author: prev.Address(), // NOTE: time.Now() will yield the "block time", which is deterministic. Time: time.Now(), }) - hasSigned.Set(prev.Addr().String(), struct{}{}) + hasSigned.Set(prev.Address().String(), struct{}{}) } func validateMessage(msg string) string { diff --git a/examples/gno.land/r/moul/config/config.gno b/examples/gno.land/r/moul/config/config.gno index a4f24411747..0302163c3c8 100644 --- a/examples/gno.land/r/moul/config/config.gno +++ b/examples/gno.land/r/moul/config/config.gno @@ -14,7 +14,7 @@ func UpdateAddr(newAddr std.Address) { } func AssertIsAdmin() { - if std.GetOrigCaller() != addr { + if std.OriginCaller() != addr { panic("restricted area") } } diff --git a/examples/gno.land/r/moul/home/z2_filetest.gno b/examples/gno.land/r/moul/home/z2_filetest.gno index f471280d8ef..4ce99f21dfa 100644 --- a/examples/gno.land/r/moul/home/z2_filetest.gno +++ b/examples/gno.land/r/moul/home/z2_filetest.gno @@ -7,7 +7,7 @@ import ( ) func main() { - std.TestSetOrigCaller("g1manfred47kzduec920z88wfr64ylksmdcedlf5") + std.TestSetOriginCaller("g1manfred47kzduec920z88wfr64ylksmdcedlf5") home.AddTodo("aaa") home.AddTodo("bbb") home.AddTodo("ccc") @@ -62,10 +62,10 @@ func main() { // | Key | Value | // | --- | --- | // | `std.CurrentRealm().PkgPath()` | gno.land/r/moul/home | -// | `std.CurrentRealm().Addr()` | g1h8h57ntxadcze3f703skymfzdwa6t3ugf0nq3z | -// | `std.PrevRealm().PkgPath()` | | -// | `std.PrevRealm().Addr()` | g1manfred47kzduec920z88wfr64ylksmdcedlf5 | -// | `std.GetHeight()` | 123 | +// | `std.CurrentRealm().Address()` | g1h8h57ntxadcze3f703skymfzdwa6t3ugf0nq3z | +// | `std.PreviousRealm().PkgPath()` | | +// | `std.PreviousRealm().Address()` | g1manfred47kzduec920z88wfr64ylksmdcedlf5 | +// | `std.ChainHeight()` | 123 | // | `time.Now().Format(time.RFC3339)` | 2009-02-13T23:31:30Z | // // diff --git a/examples/gno.land/r/moul/present/admin.gno b/examples/gno.land/r/moul/present/admin.gno index ab99b1725c5..2c0b93888ae 100644 --- a/examples/gno.land/r/moul/present/admin.gno +++ b/examples/gno.land/r/moul/present/admin.gno @@ -14,7 +14,7 @@ var ( ) func init() { - // adminAddr = std.GetOrigCaller() // FIXME: find a way to use this from the main's genesis. + // adminAddr = std.OriginCaller() // FIXME: find a way to use this from the main's genesis. adminAddr = "g1manfred47kzduec920z88wfr64ylksmdcedlf5" } @@ -41,7 +41,7 @@ func AdminRemoveModerator(addr std.Address) { func ModAddPost(slug, title, body, publicationDate, authors, tags string) { assertIsModerator() - caller := std.GetOrigCaller() + caller := std.OriginCaller() tagList := strings.Split(tags, ",") authorList := strings.Split(authors, ",") @@ -69,14 +69,14 @@ func isModerator(addr std.Address) bool { } func assertIsAdmin() { - caller := std.GetOrigCaller() + caller := std.OriginCaller() if !isAdmin(caller) { panic("access restricted.") } } func assertIsModerator() { - caller := std.GetOrigCaller() + caller := std.OriginCaller() if isAdmin(caller) || isModerator(caller) { return } diff --git a/examples/gno.land/r/n2p5/haystack/haystack_test.gno b/examples/gno.land/r/n2p5/haystack/haystack_test.gno index 52dadf8bf9e..2a25649ff5a 100644 --- a/examples/gno.land/r/n2p5/haystack/haystack_test.gno +++ b/examples/gno.land/r/n2p5/haystack/haystack_test.gno @@ -31,14 +31,14 @@ func TestHaystack(t *testing.T) { n2, _ := genNeedleHex(2) n3, _ := genNeedleHex(3) - std.TestSetOrigCaller(u1) + std.TestSetOriginCaller(u1) urequire.NotPanics(t, func() { Add(n1) }) urequire.PanicsWithMessage(t, haystack.ErrorDuplicateNeedle.Error(), func() { Add(n1) }) - std.TestSetOrigCaller(u2) + std.TestSetOriginCaller(u2) urequire.NotPanics(t, func() { Add(n2) }) urequire.NotPanics(t, func() { Add(n3) }) }) @@ -49,14 +49,14 @@ func TestHaystack(t *testing.T) { n1, h1 := genNeedleHex(4) _, h2 := genNeedleHex(5) - std.TestSetOrigCaller(u1) + std.TestSetOriginCaller(u1) urequire.NotPanics(t, func() { Add(n1) }) urequire.NotPanics(t, func() { result := Get(h1) urequire.Equal(t, n1, result) }) - std.TestSetOrigCaller(u2) + std.TestSetOriginCaller(u2) urequire.NotPanics(t, func() { result := Get(h1) urequire.Equal(t, n1, result) diff --git a/examples/gno.land/r/n2p5/home/home.gno b/examples/gno.land/r/n2p5/home/home.gno index 69b82e86d68..d99ec4d3b7d 100644 --- a/examples/gno.land/r/n2p5/home/home.gno +++ b/examples/gno.land/r/n2p5/home/home.gno @@ -52,7 +52,7 @@ func Render(path string) string { // assertAdmin panics if the caller is not an admin as defined in the config realm. func assertAdmin() { - caller := std.PrevRealm().Addr() + caller := std.PreviousRealm().Address() if !config.IsAdmin(caller) { panic("forbidden: must be admin") } diff --git a/examples/gno.land/r/n2p5/loci/loci.gno b/examples/gno.land/r/n2p5/loci/loci.gno index 36f282e729f..232de1e6459 100644 --- a/examples/gno.land/r/n2p5/loci/loci.gno +++ b/examples/gno.land/r/n2p5/loci/loci.gno @@ -23,7 +23,7 @@ func Set(value string) { panic(err) } store.Set(b) - std.Emit("SetValue", "ForAddr", string(std.PrevRealm().Addr())) + std.Emit("SetValue", "ForAddr", string(std.PreviousRealm().Address())) } // Get retrieves the value stored at the provided address and diff --git a/examples/gno.land/r/nemanya/config/config.gno b/examples/gno.land/r/nemanya/config/config.gno index 795e48c94c1..78fe329d5fe 100644 --- a/examples/gno.land/r/nemanya/config/config.gno +++ b/examples/gno.land/r/nemanya/config/config.gno @@ -52,7 +52,7 @@ func SetBackup(a std.Address) error { } func checkAuthorized() error { - caller := std.PrevRealm().Addr() + caller := std.PreviousRealm().Address() isAuthorized := caller == main || caller == backup if !isAuthorized { diff --git a/examples/gno.land/r/nemanya/home/home.gno b/examples/gno.land/r/nemanya/home/home.gno index 08e24baecfd..34545773f4d 100644 --- a/examples/gno.land/r/nemanya/home/home.gno +++ b/examples/gno.land/r/nemanya/home/home.gno @@ -137,7 +137,7 @@ func renderProjects(projectsMap map[string]Project, title string) string { } func UpdateLink(name, newURL string) { - if !isAuthorized(std.PrevRealm().Addr()) { + if !isAuthorized(std.PreviousRealm().Address()) { panic(config.ErrUnauthorized) } @@ -152,7 +152,7 @@ func UpdateLink(name, newURL string) { } func UpdateAboutMe(text string) { - if !isAuthorized(std.PrevRealm().Addr()) { + if !isAuthorized(std.PreviousRealm().Address()) { panic(config.ErrUnauthorized) } @@ -160,7 +160,7 @@ func UpdateAboutMe(text string) { } func AddGnoProject(name, description, url, imageURL string) { - if !isAuthorized(std.PrevRealm().Addr()) { + if !isAuthorized(std.PreviousRealm().Address()) { panic(config.ErrUnauthorized) } project := Project{ @@ -174,7 +174,7 @@ func AddGnoProject(name, description, url, imageURL string) { } func DeleteGnoProject(projectName string) { - if !isAuthorized(std.PrevRealm().Addr()) { + if !isAuthorized(std.PreviousRealm().Address()) { panic(config.ErrUnauthorized) } @@ -186,7 +186,7 @@ func DeleteGnoProject(projectName string) { } func AddOtherProject(name, description, url, imageURL string) { - if !isAuthorized(std.PrevRealm().Addr()) { + if !isAuthorized(std.PreviousRealm().Address()) { panic(config.ErrUnauthorized) } project := Project{ @@ -200,7 +200,7 @@ func AddOtherProject(name, description, url, imageURL string) { } func RemoveOtherProject(projectName string) { - if !isAuthorized(std.PrevRealm().Addr()) { + if !isAuthorized(std.PreviousRealm().Address()) { panic(config.ErrUnauthorized) } @@ -216,8 +216,8 @@ func isAuthorized(addr std.Address) bool { } func SponsorGnoProject(projectName string) { - address := std.GetOrigCaller() - amount := std.GetOrigSend() + address := std.OriginCaller() + amount := std.OriginSend() if amount.AmountOf("ugnot") == 0 { panic("Donation must include GNOT") @@ -239,8 +239,8 @@ func SponsorGnoProject(projectName string) { } func SponsorOtherProject(projectName string) { - address := std.GetOrigCaller() - amount := std.GetOrigSend() + address := std.OriginCaller() + amount := std.OriginSend() if amount.AmountOf("ugnot") == 0 { panic("Donation must include GNOT") @@ -262,12 +262,12 @@ func SponsorOtherProject(projectName string) { } func Withdraw() string { - if !isAuthorized(std.PrevRealm().Addr()) { + if !isAuthorized(std.PreviousRealm().Address()) { panic(config.ErrUnauthorized) } - banker := std.GetBanker(std.BankerTypeRealmSend) - realmAddress := std.GetOrigPkgAddr() + banker := std.NewBanker(std.BankerTypeRealmSend) + realmAddress := std.OriginPkgAddress() coins := banker.GetCoins(realmAddress) if len(coins) == 0 { diff --git a/examples/gno.land/r/stefann/home/home.gno b/examples/gno.land/r/stefann/home/home.gno index f54721ce37c..53aa0fa5678 100644 --- a/examples/gno.land/r/stefann/home/home.gno +++ b/examples/gno.land/r/stefann/home/home.gno @@ -127,8 +127,8 @@ func UpdateMaxSponsors(newMax int) { } func Donate() { - address := std.GetOrigCaller() - amount := std.GetOrigSend() + address := std.OriginCaller() + amount := std.OriginSend() if amount.AmountOf("ugnot") == 0 { panic("Donation must include GNOT") @@ -146,9 +146,9 @@ func Donate() { travel.currentCityIndex++ sponsorship.DonationsCount++ - banker := std.GetBanker(std.BankerTypeRealmSend) + banker := std.NewBanker(std.BankerTypeRealmSend) ownerAddr := registry.MainAddr() - banker.SendCoins(std.CurrentRealm().Addr(), ownerAddr, banker.GetCoins(std.CurrentRealm().Addr())) + banker.SendCoins(std.CurrentRealm().Address(), ownerAddr, banker.GetCoins(std.CurrentRealm().Address())) } type SponsorSlice []Sponsor diff --git a/examples/gno.land/r/stefann/home/home_test.gno b/examples/gno.land/r/stefann/home/home_test.gno index b8ea88670a6..8fa8337dab4 100644 --- a/examples/gno.land/r/stefann/home/home_test.gno +++ b/examples/gno.land/r/stefann/home/home_test.gno @@ -11,7 +11,7 @@ import ( func TestUpdateAboutMe(t *testing.T) { var owner = std.Address("g1sd5ezmxt4rwpy52u6wl3l3y085n8x0p6nllxm8") - std.TestSetOrigCaller(owner) + std.TestSetOriginCaller(owner) profile.aboutMe = []string{} @@ -32,7 +32,7 @@ func TestUpdateAboutMe(t *testing.T) { func TestUpdateCities(t *testing.T) { var owner = std.Address("g1sd5ezmxt4rwpy52u6wl3l3y085n8x0p6nllxm8") - std.TestSetOrigCaller(owner) + std.TestSetOriginCaller(owner) travel.cities = []City{} @@ -54,7 +54,7 @@ func TestUpdateCities(t *testing.T) { func TestUpdateJarLink(t *testing.T) { var owner = std.Address("g1sd5ezmxt4rwpy52u6wl3l3y085n8x0p6nllxm8") - std.TestSetOrigCaller(owner) + std.TestSetOriginCaller(owner) travel.jarLink = "" @@ -67,7 +67,7 @@ func TestUpdateJarLink(t *testing.T) { func TestUpdateMaxSponsors(t *testing.T) { var owner = std.Address("g1sd5ezmxt4rwpy52u6wl3l3y085n8x0p6nllxm8") - std.TestSetOrigCaller(owner) + std.TestSetOriginCaller(owner) sponsorship.maxSponsors = 0 @@ -87,7 +87,7 @@ func TestUpdateMaxSponsors(t *testing.T) { func TestAddCities(t *testing.T) { var owner = std.Address("g1sd5ezmxt4rwpy52u6wl3l3y085n8x0p6nllxm8") - std.TestSetOrigCaller(owner) + std.TestSetOriginCaller(owner) travel.cities = []City{} @@ -115,7 +115,7 @@ func TestAddCities(t *testing.T) { func TestAddAboutMeRows(t *testing.T) { var owner = std.Address("g1sd5ezmxt4rwpy52u6wl3l3y085n8x0p6nllxm8") - std.TestSetOrigCaller(owner) + std.TestSetOriginCaller(owner) profile.aboutMe = []string{} @@ -140,7 +140,7 @@ func TestAddAboutMeRows(t *testing.T) { func TestDonate(t *testing.T) { var user = testutils.TestAddress("user") - std.TestSetOrigCaller(user) + std.TestSetOriginCaller(user) sponsorship.sponsors = avl.NewTree() sponsorship.DonationsCount = 0 @@ -148,7 +148,7 @@ func TestDonate(t *testing.T) { travel.currentCityIndex = 0 coinsSent := std.NewCoins(std.NewCoin("ugnot", 500)) - std.TestSetOrigSend(coinsSent, std.NewCoins()) + std.TestSetOriginSend(coinsSent, std.NewCoins()) Donate() existingAmount, exists := sponsorship.sponsors.Get(string(user)) @@ -173,7 +173,7 @@ func TestDonate(t *testing.T) { } coinsSent = std.NewCoins(std.NewCoin("ugnot", 300)) - std.TestSetOrigSend(coinsSent, std.NewCoins()) + std.TestSetOriginSend(coinsSent, std.NewCoins()) Donate() existingAmount, exists = sponsorship.sponsors.Get(string(user)) @@ -196,7 +196,7 @@ func TestDonate(t *testing.T) { func TestGetTopSponsors(t *testing.T) { var user = testutils.TestAddress("user") - std.TestSetOrigCaller(user) + std.TestSetOriginCaller(user) sponsorship.sponsors = avl.NewTree() sponsorship.sponsorsCount = 0 @@ -227,7 +227,7 @@ func TestGetTopSponsors(t *testing.T) { func TestGetTotalDonations(t *testing.T) { var user = testutils.TestAddress("user") - std.TestSetOrigCaller(user) + std.TestSetOriginCaller(user) sponsorship.sponsors = avl.NewTree() sponsorship.sponsorsCount = 0 diff --git a/examples/gno.land/r/sys/validators/v2/validators.gno b/examples/gno.land/r/sys/validators/v2/validators.gno index bf42ece4990..538525b754f 100644 --- a/examples/gno.land/r/sys/validators/v2/validators.gno +++ b/examples/gno.land/r/sys/validators/v2/validators.gno @@ -30,7 +30,7 @@ func addValidator(validator validators.Validator) { // Validator added, note the change ch := change{ - blockNum: std.GetHeight(), + blockNum: std.ChainHeight(), validator: val, } @@ -50,7 +50,7 @@ func removeValidator(address std.Address) { // Validator removed, note the change ch := change{ - blockNum: std.GetHeight(), + blockNum: std.ChainHeight(), validator: validators.Validator{ Address: val.Address, PubKey: val.PubKey, diff --git a/examples/gno.land/r/sys/validators/v2/validators_test.gno b/examples/gno.land/r/sys/validators/v2/validators_test.gno index 177d84144cb..dc159a3b957 100644 --- a/examples/gno.land/r/sys/validators/v2/validators_test.gno +++ b/examples/gno.land/r/sys/validators/v2/validators_test.gno @@ -67,7 +67,7 @@ func TestValidators_AddRemove(t *testing.T) { } // Save the beginning height for the removal - initialRemoveHeight := std.GetHeight() + initialRemoveHeight := std.ChainHeight() // Clear any changes changes = avl.NewTree() diff --git a/examples/gno.land/r/ursulovic/home/home.gno b/examples/gno.land/r/ursulovic/home/home.gno index cc420df5e6e..be96ab3f913 100644 --- a/examples/gno.land/r/ursulovic/home/home.gno +++ b/examples/gno.land/r/ursulovic/home/home.gno @@ -74,7 +74,7 @@ func UpdateSelectedImage(url string) { panic("Url is not valid!") } - sentCoins := std.GetOrigSend() + sentCoins := std.OriginSend() if len(sentCoins) != 1 && sentCoins.AmountOf("ugnot") == imageUpdatePrice { panic("Please send exactly " + strconv.Itoa(int(imageUpdatePrice)) + " ugnot") diff --git a/examples/gno.land/r/ursulovic/home/home_test.gno b/examples/gno.land/r/ursulovic/home/home_test.gno index ff3f763d62a..eea71c030e6 100644 --- a/examples/gno.land/r/ursulovic/home/home_test.gno +++ b/examples/gno.land/r/ursulovic/home/home_test.gno @@ -9,7 +9,7 @@ import ( func TestUpdateGithubUrl(t *testing.T) { caller := std.Address("g1d24j8fwnc0w5q427fauyey4gdd30qgu69k6n0x") - std.TestSetOrigCaller(caller) + std.TestSetOriginCaller(caller) newUrl := "https://github.com/example" @@ -22,7 +22,7 @@ func TestUpdateGithubUrl(t *testing.T) { func TestUpdateLinkedinUrl(t *testing.T) { caller := std.Address("g1d24j8fwnc0w5q427fauyey4gdd30qgu69k6n0x") - std.TestSetOrigCaller(caller) + std.TestSetOriginCaller(caller) newUrl := "https://www.linkedin.com/in/example" @@ -35,7 +35,7 @@ func TestUpdateLinkedinUrl(t *testing.T) { func TestUpdateAboutMe(t *testing.T) { caller := std.Address("g1d24j8fwnc0w5q427fauyey4gdd30qgu69k6n0x") - std.TestSetOrigCaller(caller) + std.TestSetOriginCaller(caller) newAboutMe := "This is new description!" @@ -48,12 +48,12 @@ func TestUpdateAboutMe(t *testing.T) { func TestUpdateSelectedImage(t *testing.T) { var user = testutils.TestAddress("user") - std.TestSetOrigCaller(user) + std.TestSetOriginCaller(user) validImageUrl := "https://i.ibb.co/hLtmnX0/beautiful-rain-forest-ang-ka-nature-trail-doi-inthanon-national-park-thailand-36703721.webp" coinsSent := std.NewCoins(std.NewCoin("ugnot", 5000000)) // Update to match the price expected by your function - std.TestSetOrigSend(coinsSent, std.NewCoins()) + std.TestSetOriginSend(coinsSent, std.NewCoins()) UpdateSelectedImage(validImageUrl) @@ -72,7 +72,7 @@ func TestUpdateSelectedImage(t *testing.T) { UpdateSelectedImage(invalidImageUrl) invalidCoins := std.NewCoins(std.NewCoin("ugnot", 1000000)) - std.TestSetOrigSend(invalidCoins, std.NewCoins()) + std.TestSetOriginSend(invalidCoins, std.NewCoins()) defer func() { if r := recover(); r == nil { @@ -85,7 +85,7 @@ func TestUpdateSelectedImage(t *testing.T) { func TestUpdateImagePrice(t *testing.T) { caller := std.Address("g1d24j8fwnc0w5q427fauyey4gdd30qgu69k6n0x") - std.TestSetOrigCaller(caller) + std.TestSetOriginCaller(caller) var newImageUpdatePrice int64 = 3000000 diff --git a/examples/gno.land/r/ursulovic/registry/registry.gno b/examples/gno.land/r/ursulovic/registry/registry.gno index 0bbd6c80df5..f873bc6a120 100644 --- a/examples/gno.land/r/ursulovic/registry/registry.gno +++ b/examples/gno.land/r/ursulovic/registry/registry.gno @@ -50,7 +50,7 @@ func SetBackupAddress(addr std.Address) error { // It will stay here for now, might be useful later func assertAuthorized() { - caller := std.PrevRealm().Addr() + caller := std.PreviousRealm().Address() isAuthorized := caller == mainAddress || caller == backupAddress if !isAuthorized { diff --git a/examples/gno.land/r/x/jeronimo_render_proxy/home/home.gno b/examples/gno.land/r/x/jeronimo_render_proxy/home/home.gno index c73e99cc583..92b277d1b9c 100644 --- a/examples/gno.land/r/x/jeronimo_render_proxy/home/home.gno +++ b/examples/gno.land/r/x/jeronimo_render_proxy/home/home.gno @@ -25,7 +25,7 @@ func Register(fn RenderFn) { } proxyPath := std.CurrentRealm().PkgPath() - callerPath := std.PrevRealm().PkgPath() + callerPath := std.PreviousRealm().PkgPath() if !strings.HasPrefix(callerPath, proxyPath+"/") { panic("caller realm path must start with " + proxyPath) } diff --git a/examples/gno.land/r/x/manfred_upgrade_patterns/upgrade_b/v1/v1.gno b/examples/gno.land/r/x/manfred_upgrade_patterns/upgrade_b/v1/v1.gno index 1298b2539be..170aba1c71a 100644 --- a/examples/gno.land/r/x/manfred_upgrade_patterns/upgrade_b/v1/v1.gno +++ b/examples/gno.land/r/x/manfred_upgrade_patterns/upgrade_b/v1/v1.gno @@ -24,9 +24,9 @@ func SetNextVersion(addr string) { // assert CallTx call. std.AssertOriginCall() // assert admin. - caller := std.GetCallerAt(2) - if caller != std.GetOrigCaller() { - panic("should not happen") // because std.AssertOrigCall(). + caller := std.CallerAt(2) + if caller != std.OriginCaller() { + panic("should not happen") // because std.AssertOriginCall(). } if caller != admin { panic("unauthorized") diff --git a/examples/gno.land/r/x/manfred_upgrade_patterns/upgrade_b/v2/v2.gno b/examples/gno.land/r/x/manfred_upgrade_patterns/upgrade_b/v2/v2.gno index bf30ee1acab..80723ad01f1 100644 --- a/examples/gno.land/r/x/manfred_upgrade_patterns/upgrade_b/v2/v2.gno +++ b/examples/gno.land/r/x/manfred_upgrade_patterns/upgrade_b/v2/v2.gno @@ -28,9 +28,9 @@ func SetNextVersion(addr string) { // assert CallTx call. std.AssertOriginCall() // assert admin. - caller := std.GetCallerAt(2) - if caller != std.GetOrigCaller() { - panic("should not happen") // because std.AssertOrigCall(). + caller := std.CallerAt(2) + if caller != std.OriginCaller() { + panic("should not happen") // because std.AssertOriginCall(). } if caller != admin { panic("unauthorized") diff --git a/examples/gno.land/r/x/manfred_upgrade_patterns/upgrade_c/root/root.gno b/examples/gno.land/r/x/manfred_upgrade_patterns/upgrade_c/root/root.gno index 0a610b0b196..d71f5ec3db5 100644 --- a/examples/gno.land/r/x/manfred_upgrade_patterns/upgrade_c/root/root.gno +++ b/examples/gno.land/r/x/manfred_upgrade_patterns/upgrade_c/root/root.gno @@ -23,7 +23,7 @@ func SetCurrentImpl(pkgpath string) { } func assertIsCurrentImpl() { - if std.PrevRealm().PkgPath() != currentImpl { + if std.PreviousRealm().PkgPath() != currentImpl { panic("unauthorized") } } diff --git a/examples/gno.land/r/x/nir1218_evaluation_proposal/committee.gno b/examples/gno.land/r/x/nir1218_evaluation_proposal/committee.gno index 1ec801bb971..67311d401b3 100644 --- a/examples/gno.land/r/x/nir1218_evaluation_proposal/committee.gno +++ b/examples/gno.land/r/x/nir1218_evaluation_proposal/committee.gno @@ -36,7 +36,7 @@ func (c *Committee) DismissMembers(members []std.Address) []std.Address { func (c *Committee) AddCategory(name string, criteria []string) bool { // TODO error handling - if !c.isMember(std.GetOrigCaller()) { + if !c.isMember(std.OriginCaller()) { return false } category := NewCategory(name, criteria) @@ -45,7 +45,7 @@ func (c *Committee) AddCategory(name string, criteria []string) bool { } func (c *Committee) ApproveCategory(name string, option string) bool { - if !c.isMember(std.GetOrigCaller()) { + if !c.isMember(std.OriginCaller()) { return false } @@ -58,8 +58,8 @@ func (c *Committee) ApproveCategory(name string, option string) bool { return false } - vote := NewVote(std.GetOrigCaller(), option) - category.votes.Set(std.GetOrigCaller().String(), vote) + vote := NewVote(std.OriginCaller(), option) + category.votes.Set(std.OriginCaller().String(), vote) category.Tally() // TODO Add threshold factor for a category approval @@ -81,7 +81,7 @@ func (c *Committee) ApproveCategory(name string, option string) bool { // TODO error handling func (c *Committee) AddContribution(pr *PullRequest, contributor std.Address) (contributionId int, ok bool) { - if !c.isMember(std.GetOrigCaller()) { + if !c.isMember(std.OriginCaller()) { return -1, false } // Check the category of the PR matches a category this committee evaluates @@ -95,7 +95,7 @@ func (c *Committee) AddContribution(pr *PullRequest, contributor std.Address) (c // TODO error handling func (c *Committee) ApproveContribution(id int, option string) bool { - if !c.isMember(std.GetOrigCaller()) { + if !c.isMember(std.OriginCaller()) { return false } @@ -109,7 +109,7 @@ func (c *Committee) ApproveContribution(id int, option string) bool { return false } - vote := NewVote(std.GetOrigCaller(), option) + vote := NewVote(std.OriginCaller(), option) contribution.votes = append(contribution.votes, vote) contribution.Tally() diff --git a/examples/gno.land/r/x/nir1218_evaluation_proposal/committee_test.gno b/examples/gno.land/r/x/nir1218_evaluation_proposal/committee_test.gno index 8a3d16fd7f7..39e7fb6cabf 100644 --- a/examples/gno.land/r/x/nir1218_evaluation_proposal/committee_test.gno +++ b/examples/gno.land/r/x/nir1218_evaluation_proposal/committee_test.gno @@ -36,7 +36,7 @@ func TestCategoryEvaluationCriteria(t *testing.T) { c.DesignateMembers([]std.Address{member}) t.Run("Add First Committee Category and Evaluation Criteria", func(t *testing.T) { - std.TestSetOrigCaller(member) + std.TestSetOriginCaller(member) c.AddCategory(category, criteria) value, exists := c.categories.Get(category) if !exists { @@ -49,7 +49,7 @@ func TestCategoryEvaluationCriteria(t *testing.T) { }) t.Run("Add Second Committee Category and Evaluation Criteria", func(t *testing.T) { - std.TestSetOrigCaller(member) + std.TestSetOriginCaller(member) c.AddCategory(category2, criteria2) value2, exists2 := c.categories.Get(category2) if !exists2 { @@ -62,7 +62,7 @@ func TestCategoryEvaluationCriteria(t *testing.T) { }) t.Run("Approve First Committee Category", func(t *testing.T) { - std.TestSetOrigCaller(member) + std.TestSetOriginCaller(member) approved := c.ApproveCategory(category, VoteYes) if !approved { value, exists := c.categories.Get(category) diff --git a/examples/gno.land/r/x/skip_height_to_skip_time/skiptime_test.gno b/examples/gno.land/r/x/skip_height_to_skip_time/skiptime_test.gno index 52670a5626b..eff6e669be0 100644 --- a/examples/gno.land/r/x/skip_height_to_skip_time/skiptime_test.gno +++ b/examples/gno.land/r/x/skip_height_to_skip_time/skiptime_test.gno @@ -7,7 +7,7 @@ import ( ) func TestSkipHeights(t *testing.T) { - oldHeight := std.GetHeight() + oldHeight := std.ChainHeight() shouldEQ(t, oldHeight, 123) oldNow := time.Now().Unix() @@ -16,7 +16,7 @@ func TestSkipHeights(t *testing.T) { // skip 3 blocks == 15 seconds std.TestSkipHeights(3) - shouldEQ(t, std.GetHeight()-oldHeight, 3) + shouldEQ(t, std.ChainHeight()-oldHeight, 3) shouldEQ(t, time.Now().Unix()-oldNow, 15) } diff --git a/gno.land/genesis/genesis_txs.jsonl b/gno.land/genesis/genesis_txs.jsonl index 9027d51c0ac..24c42220055 100644 --- a/gno.land/genesis/genesis_txs.jsonl +++ b/gno.land/genesis/genesis_txs.jsonl @@ -10,7 +10,7 @@ {"tx": {"msg":[{"@type":"/vm.m_call","caller":"g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj","send":"","pkg_path":"gno.land/r/demo/boards","func":"CreateBoard","args":["testboard"]}],"fee":{"gas_wanted":"2000000","gas_fee":"1000000ugnot"},"signatures":[{"pub_key":{"@type":"/tm.PubKeySecp256k1","value":"A+FhNtsXHjLfSJk1lB8FbiL4mGPjc50Kt81J7EKDnJ2y"},"signature":"vzlSxEFh5jOkaSdv3rsV91v/OJKEF2qSuoCpri1u5tRWq62T7xr3KHRCF5qFnn4aQX/yE8g8f/Y//WPOCUGhJw=="}],"memo":""}} {"tx": {"msg":[{"@type":"/vm.m_call","caller":"g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj","send":"","pkg_path":"gno.land/r/demo/boards","func":"CreateThread","args":["1","Hello World","This is a demo of Gno smart contract programming. This document was\nconstructed by Gno onto a smart contract hosted on the data Realm \nname [\"gno.land/r/demo/boards\"](https://gno.land/r/demo/boards/)\n([github](https://github.com/gnolang/gno/tree/master/examples/gno.land/r/demo/boards)).\n\n## Starting the `gnoland` node node/validator.\n\nNOTE: Where you see `--remote %%REMOTE%%` here, that flag can be replaced\nwith `--remote localhost:26657` for local testnets.\n\n### build gnoland.\n\n```bash\ngit clone git@github.com:gnolang/gno.git\ncd ./gno\nmake \n```\n\n### add test account.\n\n```bash\n./build/gnokey add test1 --recover\n```\n\nUse this mnemonic:\n\u003e source bonus chronic canvas draft south burst lottery vacant surface solve popular case indicate oppose farm nothing bullet exhibit title speed wink action roast\n\n### start gnoland validator node.\n\n```bash\n./build/gnoland\n```\n\n(This can be reset with `make reset`).\n\n### start gnoland web server (optional).\n\n```bash\ngo run ./gnoland/website\n```\n\n## Signing and broadcasting transactions.\n\n### publish the \"gno.land/p/demo/avl\" package.\n\n```bash\n./build/gnokey maketx addpkg test1 --pkgpath \"gno.land/p/demo/avl\" --pkgdir \"examples/gno.land/p/demo/avl\" --deposit 100ugnot --gas-fee 1ugnot --gas-wanted 2000000 \u003e addpkg.avl.unsigned.txt\n./build/gnokey query \"auth/accounts/g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5\"\n./build/gnokey sign test1 --txpath addpkg.avl.unsigned.txt --chainid \"%%CHAINID%%\" --number 0 --sequence 0 \u003e addpkg.avl.signed.txt\n./build/gnokey broadcast addpkg.avl.signed.txt --remote %%REMOTE%%\n```\n\n### publish the \"gno.land/r/demo/boards\" realm package.\n\n```bash\n./build/gnokey maketx addpkg test1 --pkgpath \"gno.land/r/demo/boards\" --pkgdir \"examples/gno.land/r/demo/boards\" --deposit 100ugnot --gas-fee 1ugnot --gas-wanted 300000000 \u003e addpkg.boards.unsigned.txt\n./build/gnokey sign test1 --txpath addpkg.boards.unsigned.txt --chainid \"%%CHAINID%%\" --number 0 --sequence 1 \u003e addpkg.boards.signed.txt\n./build/gnokey broadcast addpkg.boards.signed.txt --remote %%REMOTE%%\n```\n\n### create a board with a smart contract call.\n\n```bash\n./build/gnokey maketx call test1 --pkgpath \"gno.land/r/demo/boards\" --func CreateBoard --args \"testboard\" --gas-fee 1ugnot --gas-wanted 2000000 \u003e createboard.unsigned.txt\n./build/gnokey sign test1 --txpath createboard.unsigned.txt --chainid \"%%CHAINID%%\" --number 0 --sequence 2 \u003e createboard.signed.txt\n./build/gnokey broadcast createboard.signed.txt --remote %%REMOTE%%\n```\nNext, query for the permanent board ID by querying (you need this to create a new post):\n\n```bash\n./build/gnokey query \"vm/qeval\" --data \"gno.land/r/demo/boards.GetBoardIDFromName(\\\"testboard\\\")\"\n```\n\n### create a post of a board with a smart contract call.\n\n```bash\n./build/gnokey maketx call test1 --pkgpath \"gno.land/r/demo/boards\" --func CreatePost --args 1 --args \"Hello World\" --args#file \"./examples/gno.land/r/demo/boards/README.md\" --gas-fee 1ugnot --gas-wanted 2000000 \u003e createpost.unsigned.txt\n./build/gnokey sign test1 --txpath createpost.unsigned.txt --chainid \"%%CHAINID%%\" --number 0 --sequence 3 \u003e createpost.signed.txt\n./build/gnokey broadcast createpost.signed.txt --remote %%REMOTE%%\n```\n\n### create a comment to a post.\n\n```bash\n./build/gnokey maketx call test1 --pkgpath \"gno.land/r/demo/boards\" --func CreateReply --args 1 --args 1 --args \"A comment\" --gas-fee 1ugnot --gas-wanted 2000000 \u003e createcomment.unsigned.txt\n./build/gnokey sign test1 --txpath createcomment.unsigned.txt --chainid \"%%CHAINID%%\" --number 0 --sequence 4 \u003e createcomment.signed.txt\n./build/gnokey broadcast createcomment.signed.txt --remote %%REMOTE%%\n```\n\n```bash\n./build/gnokey query \"vm/qrender\" --data \"gno.land/r/demo/boards:testboard/1\"\n```\n\n### render page with optional path expression.\n\nThe contents of `https://gno.land/r/demo/boards:` and `https://gno.land/r/demo/boards:testboard` are rendered by calling\nthe `Render(path string)` function like so:\n\n```bash\n./build/gnokey query \"vm/qrender\" --data \"gno.land/r/demo/boards:testboard\"\n```\n"]}],"fee":{"gas_wanted":"2000000","gas_fee":"1000000ugnot"},"signatures":[{"pub_key":{"@type":"/tm.PubKeySecp256k1","value":"A+FhNtsXHjLfSJk1lB8FbiL4mGPjc50Kt81J7EKDnJ2y"},"signature":"V43B1waFxhzheW9TfmCpjLdrC4dC1yjUGES5y3J6QsNar6hRpNz4G1thzWmWK7xXhg8u1PCIpxLxGczKQYhuPw=="}],"memo":""}} {"tx": {"msg":[{"@type":"/vm.m_call","caller":"g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj","send":"","pkg_path":"gno.land/r/demo/boards","func":"CreateThread","args":["1","NFT example","NFT's are all the rage these days, for various reasons.\n\nI read over EIP-721 which appears to be the de-facto NFT standard on Ethereum. Then, made a sample implementation of EIP-721 (let's here called GRC-721). The implementation isn't complete, but it demonstrates the main functionality.\n\n - [EIP-721](https://eips.ethereum.org/EIPS/eip-721)\n - [gno.land/r/demo/nft/nft.gno](https://gno.land/r/demo/nft/nft.gno)\n - [zrealm_nft3.gno test](https://github.com/gnolang/gno/blob/master/examples/gno.land/r/demo/nft/z_3_filetest.gno)\n\nIn short, this demonstrates how to implement Ethereum contract interfaces in gno.land; by using only standard Go language features.\n\nPlease leave a comment ([guide](https://gno.land/r/demo/boards:testboard/1)).\n"]}],"fee":{"gas_wanted":"2000000","gas_fee":"1000000ugnot"},"signatures":[{"pub_key":{"@type":"/tm.PubKeySecp256k1","value":"A+FhNtsXHjLfSJk1lB8FbiL4mGPjc50Kt81J7EKDnJ2y"},"signature":"ZXfrTiHxPFQL8uSm+Tv7WXIHPMca9okhm94RAlC6YgNbB1VHQYYpoP4w+cnL3YskVzGrOZxensXa9CAZ+cNNeg=="}],"memo":""}} -{"tx": {"msg":[{"@type":"/vm.m_call","caller":"g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj","send":"","pkg_path":"gno.land/r/demo/boards","func":"CreateThread","args":["1","Simple echo example with coins","This is a simple test realm contract that demonstrates how to use the banker.\n\nSee [gno.land/r/demo/banktest/banktest.gno](/r/demo/banktest/banktest.gno) to see the original contract code.\n\nThis article will go through each line to explain how it works.\n\n```go\npackage banktest\n```\n\nThis package is locally named \"banktest\" (could be anything).\n\n```go\nimport (\n\t\"std\"\n)\n```\n\nThe \"std\" package is defined by the gno code in stdlibs/std/. \u003c/br\u003e\nSelf explanatory; and you'll see more usage from std later.\n\n```go\ntype activity struct {\n\tcaller std.Address\n\tsent std.Coins\n\treturned std.Coins\n\ttime std.Time\n}\n\nfunc (act *activity) String() string {\n\treturn act.caller.String() + \" \" +\n\t\tact.sent.String() + \" sent, \" +\n\t\tact.returned.String() + \" returned, at \" +\n\t\tstd.FormatTimestamp(act.time, \"2006-01-02 3:04pm MST\")\n}\n\nvar latest [10]*activity\n```\n\nThis is just maintaining a list of recent activity to this contract.\nNotice that the \"latest\" variable is defined \"globally\" within\nthe context of the realm with path \"gno.land/r/demo/banktest\".\n\nThis means that calls to functions defined within this package\nare encapsulated within this \"data realm\", where the data is \nmutated based on transactions that can potentially cross many\nrealm and non-realm packge boundaries (in the call stack).\n\n```go\n// Deposit will take the coins (to the realm's pkgaddr) or return them to user.\nfunc Deposit(returnDenom string, returnAmount int64) string {\n\tstd.AssertOriginCall()\n\tcaller := std.GetOrigCaller()\n\tsend := std.Coins{{returnDenom, returnAmount}}\n```\n\nThis is the beginning of the definition of the contract function named\n\"Deposit\". `std.AssertOriginCall() asserts that this function was called by a\ngno transactional Message. The caller is the user who signed off on this\ntransactional message. Send is the amount of deposit sent along with this\nmessage.\n\n```go\n\t// record activity\n\tact := \u0026activity{\n\t\tcaller: caller,\n\t\tsent: std.GetOrigSend(),\n\t\treturned: send,\n\t\ttime: std.GetTimestamp(),\n\t}\n\tfor i := len(latest) - 2; i \u003e= 0; i-- {\n\t\tlatest[i+1] = latest[i] // shift by +1.\n\t}\n\tlatest[0] = act\n```\n\nUpdating the \"latest\" array for viewing at gno.land/r/demo/banktest: (w/ trailing colon).\n\n```go\n\t// return if any.\n\tif returnAmount \u003e 0 {\n```\n\nIf the user requested the return of coins...\n\n```go\n\t\tbanker := std.GetBanker(std.BankerTypeOrigSend)\n```\n\nuse a std.Banker instance to return any deposited coins to the original sender.\n\n```go\n\t\tpkgaddr := std.GetOrigPkgAddr()\n\t\t// TODO: use std.Coins constructors, this isn't generally safe.\n\t\tbanker.SendCoins(pkgaddr, caller, send)\n\t\treturn \"returned!\"\n```\n\nNotice that each realm package has an associated Cosmos address.\n\n\nFinally, the results are rendered via an ABCI query call when you visit [/r/demo/banktest:](/r/demo/banktest:).\n\n```go\nfunc Render(path string) string {\n\t// get realm coins.\n\tbanker := std.GetBanker(std.BankerTypeReadonly)\n\tcoins := banker.GetCoins(std.GetOrigPkgAddr())\n\n\t// render\n\tres := \"\"\n\tres += \"## recent activity\\n\"\n\tres += \"\\n\"\n\tfor _, act := range latest {\n\t\tif act == nil {\n\t\t\tbreak\n\t\t}\n\t\tres += \" * \" + act.String() + \"\\n\"\n\t}\n\tres += \"\\n\"\n\tres += \"## total deposits\\n\"\n\tres += coins.String()\n\treturn res\n}\n```\n\nYou can call this contract yourself, by vistiing [/r/demo/banktest](/r/demo/banktest) and the [quickstart guide](/r/demo/boards:testboard/4).\n"]}],"fee":{"gas_wanted":"2000000","gas_fee":"1000000ugnot"},"signatures":[{"pub_key":{"@type":"/tm.PubKeySecp256k1","value":"A+FhNtsXHjLfSJk1lB8FbiL4mGPjc50Kt81J7EKDnJ2y"},"signature":"iZX/llZlNTdZMLv1goCTgK2bWqzT8enlTq56wMTCpVxJGA0BTvuEM5Nnt9vrnlG6Taqj2GuTrmEnJBkDFTmt9g=="}],"memo":""}} +{"tx": {"msg":[{"@type":"/vm.m_call","caller":"g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj","send":"","pkg_path":"gno.land/r/demo/boards","func":"CreateThread","args":["1","Simple echo example with coins","This is a simple test realm contract that demonstrates how to use the banker.\n\nSee [gno.land/r/demo/banktest/banktest.gno](/r/demo/banktest/banktest.gno) to see the original contract code.\n\nThis article will go through each line to explain how it works.\n\n```go\npackage banktest\n```\n\nThis package is locally named \"banktest\" (could be anything).\n\n```go\nimport (\n\t\"std\"\n)\n```\n\nThe \"std\" package is defined by the gno code in stdlibs/std/. \u003c/br\u003e\nSelf explanatory; and you'll see more usage from std later.\n\n```go\ntype activity struct {\n\tcaller std.Address\n\tsent std.Coins\n\treturned std.Coins\n\ttime std.Time\n}\n\nfunc (act *activity) String() string {\n\treturn act.caller.String() + \" \" +\n\t\tact.sent.String() + \" sent, \" +\n\t\tact.returned.String() + \" returned, at \" +\n\t\tstd.FormatTimestamp(act.time, \"2006-01-02 3:04pm MST\")\n}\n\nvar latest [10]*activity\n```\n\nThis is just maintaining a list of recent activity to this contract.\nNotice that the \"latest\" variable is defined \"globally\" within\nthe context of the realm with path \"gno.land/r/demo/banktest\".\n\nThis means that calls to functions defined within this package\nare encapsulated within this \"data realm\", where the data is \nmutated based on transactions that can potentially cross many\nrealm and non-realm packge boundaries (in the call stack).\n\n```go\n// Deposit will take the coins (to the realm's pkgaddr) or return them to user.\nfunc Deposit(returnDenom string, returnAmount int64) string {\n\tstd.AssertOriginCall()\n\tcaller := std.OriginCaller()\n\tsend := std.Coins{{returnDenom, returnAmount}}\n```\n\nThis is the beginning of the definition of the contract function named\n\"Deposit\". `std.AssertOriginCall() asserts that this function was called by a\ngno transactional Message. The caller is the user who signed off on this\ntransactional message. Send is the amount of deposit sent along with this\nmessage.\n\n```go\n\t// record activity\n\tact := \u0026activity{\n\t\tcaller: caller,\n\t\tsent: std.OriginSend(),\n\t\treturned: send,\n\t\ttime: std.GetTimestamp(),\n\t}\n\tfor i := len(latest) - 2; i \u003e= 0; i-- {\n\t\tlatest[i+1] = latest[i] // shift by +1.\n\t}\n\tlatest[0] = act\n```\n\nUpdating the \"latest\" array for viewing at gno.land/r/demo/banktest: (w/ trailing colon).\n\n```go\n\t// return if any.\n\tif returnAmount \u003e 0 {\n```\n\nIf the user requested the return of coins...\n\n```go\n\t\tbanker := std.NewBanker(std.BankerTypeOriginSend)\n```\n\nuse a std.Banker instance to return any deposited coins to the original sender.\n\n```go\n\t\tpkgaddr := std.OriginPkgAddress()\n\t\t// TODO: use std.Coins constructors, this isn't generally safe.\n\t\tbanker.SendCoins(pkgaddr, caller, send)\n\t\treturn \"returned!\"\n```\n\nNotice that each realm package has an associated Cosmos address.\n\n\nFinally, the results are rendered via an ABCI query call when you visit [/r/demo/banktest:](/r/demo/banktest:).\n\n```go\nfunc Render(path string) string {\n\t// get realm coins.\n\tbanker := std.NewBanker(std.BankerTypeReadonly)\n\tcoins := banker.GetCoins(std.OriginPkgAddress())\n\n\t// render\n\tres := \"\"\n\tres += \"## recent activity\\n\"\n\tres += \"\\n\"\n\tfor _, act := range latest {\n\t\tif act == nil {\n\t\t\tbreak\n\t\t}\n\t\tres += \" * \" + act.String() + \"\\n\"\n\t}\n\tres += \"\\n\"\n\tres += \"## total deposits\\n\"\n\tres += coins.String()\n\treturn res\n}\n```\n\nYou can call this contract yourself, by vistiing [/r/demo/banktest](/r/demo/banktest) and the [quickstart guide](/r/demo/boards:testboard/4).\n"]}],"fee":{"gas_wanted":"2000000","gas_fee":"1000000ugnot"},"signatures":[{"pub_key":{"@type":"/tm.PubKeySecp256k1","value":"A+FhNtsXHjLfSJk1lB8FbiL4mGPjc50Kt81J7EKDnJ2y"},"signature":"iZX/llZlNTdZMLv1goCTgK2bWqzT8enlTq56wMTCpVxJGA0BTvuEM5Nnt9vrnlG6Taqj2GuTrmEnJBkDFTmt9g=="}],"memo":""}} {"tx": {"msg":[{"@type":"/vm.m_call","caller":"g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj","send":"","pkg_path":"gno.land/r/demo/boards","func":"CreateThread","args":["1","TASK: Describe in your words","Describe in an essay (250+ words), on your favorite medium, why you are interested in gno.land and gnolang.\n\nReply here with a URL link to your written piece as a comment, for rewards.\n"]}],"fee":{"gas_wanted":"2000000","gas_fee":"1000000ugnot"},"signatures":[{"pub_key":{"@type":"/tm.PubKeySecp256k1","value":"AmG6kzznyo1uNqWPAYU6wDpsmzQKDaEOrVRaZ08vOyX0"},"signature":"4HBNtrta8HdeHj4JTN56PBTRK8GOe31NMRRXDiyYtjozuyRdWfOGEsGjGgHWcoBUJq6DepBgD4FetdqfhZ6TNQ=="}],"memo":""}} {"tx": {"msg":[{"@type":"/vm.m_call","caller":"g1manfred47kzduec920z88wfr64ylksmdcedlf5","send":"","pkg_path":"gno.land/r/demo/boards","func":"CreateThread","args":["1","Getting Started","This is a demo of Gno smart contract programming. This document was\nconstructed by Gno onto a smart contract hosted on the data Realm\nname [\"gno.land/r/demo/boards\"](https://gno.land/r/demo/boards/)\n([github](https://github.com/gnolang/gno/tree/master/examples/gno.land/r/demo/boards)).\n\n\n\n## Build `gnokey`, create your account, and interact with Gno.\n\nNOTE: Where you see `--remote %%REMOTE%%` here, that flag can be replaced\nwith `--remote localhost:26657` for local testnets.\n\n### Build `gnokey`.\n\n```bash\ngit clone git@github.com:gnolang/gno.git\ncd ./gno\nmake\n```\n\n### Generate a seed/mnemonic code.\n\n```bash\n./build/gnokey generate\n```\n\nNOTE: You can generate 24 words with any good bip39 generator.\n\n### Create a new account using your mnemonic.\n\n```bash\n./build/gnokey add KEYNAME --recover\n```\n\nNOTE: `KEYNAME` is your key identifier, and should be changed.\n\n### Verify that you can see your account locally.\n\n```bash\n./build/gnokey list\n```\n\n## Interact with the blockchain:\n\n### Get your current balance, account number, and sequence number.\n\n```bash\n./build/gnokey query auth/accounts/ACCOUNT_ADDR --remote %%REMOTE%%\n```\n\nNOTE: you can retrieve your `ACCOUNT_ADDR` with `./build/gnokey list`.\n\n### Acquire testnet tokens using the official faucet.\n\nGo to https://gno.land/faucet\n\n### Create a board with a smart contract call.\n\nNOTE: `BOARDNAME` will be the slug of the board, and should be changed.\n\n```bash\n./build/gnokey maketx call KEYNAME --pkgpath \"gno.land/r/demo/boards\" --func \"CreateBoard\" --args \"BOARDNAME\" --gas-fee \"1000000ugnot\" --gas-wanted \"2000000\" --broadcast=true --chainid %%CHAINID%% --remote %%REMOTE%%\n```\n\nInteractive documentation: https://gno.land/r/demo/boards$help\u0026func=CreateBoard\n\nNext, query for the permanent board ID by querying (you need this to create a new post):\n\n```bash\n./build/gnokey query \"vm/qeval\" --data \"gno.land/r/demo/boards.GetBoardIDFromName(\\\"BOARDNAME\\\")\" --remote %%REMOTE%%\n```\n\n### Create a post of a board with a smart contract call.\n\nNOTE: If a board was created successfully, your SEQUENCE_NUMBER would have increased.\n\n```bash\n./build/gnokey maketx call KEYNAME --pkgpath \"gno.land/r/demo/boards\" --func \"CreateThread\" --args BOARD_ID --args \"Hello gno.land\" --args\\#file \"./examples/gno.land/r/demo/boards/example_post.md\" --gas-fee 1000000ugnot --gas-wanted 2000000 --broadcast=true --chainid %%CHAINID%% --remote %%REMOTE%%\n```\n\nInteractive documentation: https://gno.land/r/demo/boards$help\u0026func=CreateThread\n\n### Create a comment to a post.\n\n```bash\n./build/gnokey maketx call KEYNAME --pkgpath \"gno.land/r/demo/boards\" --func \"CreateReply\" --args \"BOARD_ID\" --args \"1\" --args \"1\" --args \"Nice to meet you too.\" --gas-fee 1000000ugnot --gas-wanted 2000000 --broadcast=true --chainid %%CHAINID%% --remote %%REMOTE%%\n```\n\nInteractive documentation: https://gno.land/r/demo/boards$help\u0026func=CreateReply\n\n```bash\n./build/gnokey query \"vm/qrender\" --data \"gno.land/r/demo/boards:BOARDNAME/1\" --remote %%REMOTE%%\n```\n\n### Render page with optional path expression.\n\nThe contents of `https://gno.land/r/demo/boards:` and `https://gno.land/r/demo/boards:gnolang` are rendered by calling\nthe `Render(path string)` function like so:\n\n```bash\n./build/gnokey query \"vm/qrender\" --data \"gno.land/r/demo/boards:gnolang\"\n```\n\n## Starting a local `gnoland` node:\n\n### Add test account.\n\n```bash\n./build/gnokey add test1 --recover\n```\n\nUse this mneonic:\n\u003e source bonus chronic canvas draft south burst lottery vacant surface solve popular case indicate oppose farm nothing bullet exhibit title speed wink action roast\n\n### Start `gnoland` node.\n\n```bash\n./build/gnoland\n```\n\nNOTE: This can be reset with `make reset`\n\n### Publish the \"gno.land/p/demo/avl\" package.\n\n```bash\n./build/gnokey maketx addpkg test1 --pkgpath \"gno.land/p/demo/avl\" --pkgdir \"examples/gno.land/p/demo/avl\" --deposit 100000000ugnot --gas-fee 1000000ugnot --gas-wanted 2000000 --broadcast=true --chainid %%CHAINID%% --remote localhost:26657\n```\n\n### Publish the \"gno.land/r/demo/boards\" realm package.\n\n```bash\n./build/gnokey maketx addpkg test1 --pkgpath \"gno.land/r/demo/boards\" --pkgdir \"examples/gno.land/r/demo/boards\" --deposit 100000000ugnot --gas-fee 1000000ugnot --gas-wanted 300000000 --broadcast=true --chainid %%CHAINID%% --remote localhost:26657\n```\n"]}],"fee":{"gas_wanted":"2000000","gas_fee":"1000000ugnot"},"signatures":[{"pub_key":{"@type":"/tm.PubKeySecp256k1","value":"AnK+a6mcFDjY6b/v6p7r8QFW1M1PgIoQxBgrwOoyY7v3"},"signature":"sHjOGXZEi9wt2FSXFHmkDDoVQyepvFHKRDDU0zgedHYnCYPx5/YndyihsDD5Y2Z7/RgNYBh4JlJwDMGFNStzBQ=="}],"memo":""}} {"tx": {"msg":[{"@type":"/vm.m_call","caller":"g1manfred47kzduec920z88wfr64ylksmdcedlf5","send":"","pkg_path":"gno.land/r/gnoland/blog","func":"ModAddPost","args":["post1","First post","Lorem Ipsum","2022-05-20T13:17:22Z","","tag1,tag2"]}],"fee":{"gas_wanted":"2000000","gas_fee":"1000000ugnot"},"signatures":[{"pub_key":{"@type":"/tm.PubKeySecp256k1","value":"AnK+a6mcFDjY6b/v6p7r8QFW1M1PgIoQxBgrwOoyY7v3"},"signature":"sHjOGXZEi9wt2FSXFHmkDDoVQyepvFHKRDDU0zgedHYnCYPx5/YndyihsDD5Y2Z7/RgNYBh4JlJwDMGFNStzBQ=="}],"memo":""}} diff --git a/gno.land/pkg/integration/testdata/grc20_registry.txtar b/gno.land/pkg/integration/testdata/grc20_registry.txtar index 4377e10a575..ecfab2ea651 100644 --- a/gno.land/pkg/integration/testdata/grc20_registry.txtar +++ b/gno.land/pkg/integration/testdata/grc20_registry.txtar @@ -34,7 +34,7 @@ func TransferByName(name string, to string, amount uint64) string { if pair.name != name { continue } - if std.CurrentRealm().Addr().String() != pair.cb(std.Address(to), amount) { + if std.CurrentRealm().Address().String() != pair.cb(std.Address(to), amount) { return "invalid address, ownership issue :(" } return "same address, success!" @@ -58,6 +58,6 @@ package foo20 import "std" func Transfer(to std.Address, amount uint64) string { - println("transfer from=" + std.PrevRealm().Addr().String() + " to=" + to.String() + " some-amount") - return std.PrevRealm().Addr().String() + println("transfer from=" + std.PreviousRealm().Address().String() + " to=" + to.String() + " some-amount") + return std.PreviousRealm().Address().String() } diff --git a/gno.land/pkg/integration/testdata/grc721_emit.txtar b/gno.land/pkg/integration/testdata/grc721_emit.txtar index 45101b74634..0b90188fd59 100644 --- a/gno.land/pkg/integration/testdata/grc721_emit.txtar +++ b/gno.land/pkg/integration/testdata/grc721_emit.txtar @@ -69,7 +69,7 @@ func TransferFrom(from, to pusers.AddressOrName, tid grc721.TokenID) { // Admin func Mint(to pusers.AddressOrName, tid grc721.TokenID) { - caller := std.PrevRealm().Addr() + caller := std.PreviousRealm().Address() assertIsAdmin(caller) err := foo.Mint(users.Resolve(to), tid) if err != nil { @@ -78,7 +78,7 @@ func Mint(to pusers.AddressOrName, tid grc721.TokenID) { } func Burn(tid grc721.TokenID) { - caller := std.PrevRealm().Addr() + caller := std.PreviousRealm().Address() assertIsAdmin(caller) err := foo.Burn(tid) if err != nil { diff --git a/gno.land/pkg/integration/testdata/initctx.txtar b/gno.land/pkg/integration/testdata/initctx.txtar index 9210268e66f..82e27dba642 100644 --- a/gno.land/pkg/integration/testdata/initctx.txtar +++ b/gno.land/pkg/integration/testdata/initctx.txtar @@ -18,8 +18,8 @@ var orig = std.Address("orig") var prev = std.Address("prev") func init() { - orig = std.GetOrigCaller() - prev = std.PrevRealm().Addr() + orig = std.OriginCaller() + prev = std.PreviousRealm().Address() } func Render(addr string) string { diff --git a/gno.land/pkg/integration/testdata/issue_1786.txtar b/gno.land/pkg/integration/testdata/issue_1786.txtar index 71cd19e7ed7..284ea951e5b 100644 --- a/gno.land/pkg/integration/testdata/issue_1786.txtar +++ b/gno.land/pkg/integration/testdata/issue_1786.txtar @@ -49,7 +49,7 @@ import ( ) func ProxyWrap() { - sent := std.GetOrigSend() + sent := std.OriginSend() ugnotSent := uint64(sent.AmountOf("ugnot")) if ugnotSent == 0 { @@ -58,12 +58,12 @@ func ProxyWrap() { // WRAP IT wugnotAddr := std.DerivePkgAddr("gno.land/r/demo/wugnot") - banker := std.GetBanker(std.BankerTypeRealmSend) - banker.SendCoins(std.CurrentRealm().Addr(), wugnotAddr, std.Coins{{"ugnot", int64(ugnotSent)}}) + banker := std.NewBanker(std.BankerTypeRealmSend) + banker.SendCoins(std.CurrentRealm().Address(), wugnotAddr, std.Coins{{"ugnot", int64(ugnotSent)}}) wugnot.Deposit() // `proxywugnot` has ugnot // SEND WUGNOT: PROXY_WUGNOT -> USER - wugnot.Transfer(std.GetOrigCaller(), ugnotSent) + wugnot.Transfer(std.OriginCaller(), ugnotSent) } func ProxyUnwrap(wugnotAmount uint64) { @@ -72,12 +72,12 @@ func ProxyUnwrap(wugnotAmount uint64) { } // SEND WUGNOT: USER -> PROXY_WUGNOT - wugnot.TransferFrom(std.GetOrigCaller(), std.CurrentRealm().Addr(), wugnotAmount) + wugnot.TransferFrom(std.OriginCaller(), std.CurrentRealm().Address(), wugnotAmount) // UNWRAP IT wugnot.Withdraw(wugnotAmount) // SEND GNOT: PROXY_WUGNOT -> USER - banker := std.GetBanker(std.BankerTypeRealmSend) - banker.SendCoins(std.CurrentRealm().Addr(), std.GetOrigCaller(), std.Coins{{"ugnot", int64(wugnotAmount)}}) + banker := std.NewBanker(std.BankerTypeRealmSend) + banker.SendCoins(std.CurrentRealm().Address(), std.OriginCaller(), std.Coins{{"ugnot", int64(wugnotAmount)}}) } diff --git a/gno.land/pkg/integration/testdata/issue_2283.txtar b/gno.land/pkg/integration/testdata/issue_2283.txtar index 653a4dd79b0..222ca86f2fa 100644 --- a/gno.land/pkg/integration/testdata/issue_2283.txtar +++ b/gno.land/pkg/integration/testdata/issue_2283.txtar @@ -46,7 +46,7 @@ import ( }, { "Name": "feeds_test.gno", - "Body": "package social_feeds\n\nimport (\n\t\"encoding/base64\"\n\t\"fmt\"\n\t\"std\"\n\t\"strconv\"\n\t\"strings\"\n\t\"testing\"\n\n\t\"gno.land/p/demo/avl\"\n\tujson \"gno.land/p/demo/teritori/ujson\"\n\t\"gno.land/p/demo/testutils\"\n\t\"gno.land/r/demo/boards\"\n\t// Fake previous version for testing\n\tfeedsV7 \"gno.land/r/demo/teritori/social_feeds\"\n\t\"gno.land/r/demo/users\"\n)\n\nvar (\n\trootPostID = PostID(0)\n\tpostID1 = PostID(1)\n\tfeedID1 = FeedID(1)\n\tcat1 = uint64(1)\n\tcat2 = uint64(2)\n\tuser = testutils.TestAddress(\"user\")\n\tfilter_all = []uint64{}\n)\n\nfunc getFeed1() *Feed {\n\treturn mustGetFeed(feedID1)\n}\n\nfunc getPost1() *Post {\n\tfeed1 := getFeed1()\n\tpost1 := feed1.MustGetPost(postID1)\n\treturn post1\n}\n\nfunc testCreateFeed(t *testing.T) {\n\tfeedID := CreateFeed(\"teritori1\")\n\tfeed := mustGetFeed(feedID)\n\n\tif feedID != 1 {\n\t\tt.Fatalf(\"expected feedID: 1, got %q.\", feedID)\n\t}\n\n\tif feed.name != \"teritori1\" {\n\t\tt.Fatalf(\"expected feedName: teritori1, got %q.\", feed.name)\n\t}\n}\n\nfunc testCreatePost(t *testing.T) {\n\tmetadata := `{\"gifs\": [], \"files\": [], \"title\": \"\", \"message\": \"testouille\", \"hashtags\": [], \"mentions\": [], \"createdAt\": \"2023-03-29T12:19:04.858Z\", \"updatedAt\": \"2023-03-29T12:19:04.858Z\"}`\n\tpostID := CreatePost(feedID1, rootPostID, cat1, metadata)\n\tfeed := mustGetFeed(feedID1)\n\tpost := feed.MustGetPost(postID)\n\n\tif postID != 1 {\n\t\tt.Fatalf(\"expected postID: 1, got %q.\", postID)\n\t}\n\n\tif post.category != cat1 {\n\t\tt.Fatalf(\"expected categoryID: %q, got %q.\", cat1, post.category)\n\t}\n}\n\nfunc toPostIDsStr(posts []*Post) string {\n\tvar postIDs []string\n\tfor _, post := range posts {\n\t\tpostIDs = append(postIDs, post.id.String())\n\t}\n\n\tpostIDsStr := strings.Join(postIDs, \",\")\n\treturn postIDsStr\n}\n\nfunc testGetPosts(t *testing.T) {\n\tuser := std.Address(\"user\")\n\tstd.TestSetOrigCaller(user)\n\n\tfeedID := CreateFeed(\"teritori10\")\n\tfeed := mustGetFeed(feedID)\n\n\tCreatePost(feedID, rootPostID, cat1, \"post1\")\n\tCreatePost(feedID, rootPostID, cat1, \"post2\")\n\tCreatePost(feedID, rootPostID, cat1, \"post3\")\n\tCreatePost(feedID, rootPostID, cat1, \"post4\")\n\tCreatePost(feedID, rootPostID, cat1, \"post5\")\n\tpostIDToFlagged := CreatePost(feedID, rootPostID, cat1, \"post6\")\n\tpostIDToHide := CreatePost(feedID, rootPostID, cat1, \"post7\")\n\tCreatePost(feedID, rootPostID, cat1, \"post8\")\n\n\tvar posts []*Post\n\tvar postIDsStr string\n\n\t// Query last 3 posts\n\tposts = getPosts(feed, 0, \"\", \"\", []uint64{}, 0, 3)\n\tpostIDsStr = toPostIDsStr(posts)\n\n\tif postIDsStr != \"8,7,6\" {\n\t\tt.Fatalf(\"expected posts order: 8,7,6. Got: %s\", postIDsStr)\n\t}\n\n\t// Query page 2\n\tposts = getPosts(feed, 0, \"\", \"\", []uint64{}, 3, 3)\n\tpostIDsStr = toPostIDsStr(posts)\n\tif postIDsStr != \"5,4,3\" {\n\t\tt.Fatalf(\"expected posts order: 5,4,3. Got: %s\", postIDsStr)\n\t}\n\n\t// Exclude hidden post\n\tHidePostForMe(feed.id, postIDToHide)\n\n\tposts = getPosts(feed, 0, user.String(), \"\", []uint64{}, 0, 3)\n\tpostIDsStr = toPostIDsStr(posts)\n\n\tif postIDsStr != \"8,6,5\" {\n\t\tt.Fatalf(\"expected posts order: 8,6,5. Got: %s\", postIDsStr)\n\t}\n\n\t// Exclude flagged post\n\tFlagPost(feed.id, postIDToFlagged)\n\n\tposts = getPosts(feed, 0, user.String(), \"\", []uint64{}, 0, 3)\n\tpostIDsStr = toPostIDsStr(posts)\n\n\tif postIDsStr != \"8,5,4\" {\n\t\tt.Fatalf(\"expected posts order: 8,5,4. Got: %s\", postIDsStr)\n\t}\n\n\t// Pagination with hidden/flagged posts\n\tposts = getPosts(feed, 0, user.String(), \"\", []uint64{}, 3, 3)\n\tpostIDsStr = toPostIDsStr(posts)\n\n\tif postIDsStr != \"3,2,1\" {\n\t\tt.Fatalf(\"expected posts order: 3,2,1. Got: %s\", postIDsStr)\n\t}\n\n\t// Query out of range\n\tposts = getPosts(feed, 0, user.String(), \"\", []uint64{}, 6, 3)\n\tpostIDsStr = toPostIDsStr(posts)\n\n\tif postIDsStr != \"\" {\n\t\tt.Fatalf(\"expected posts order: ''. Got: %s\", postIDsStr)\n\t}\n}\n\nfunc testReactPost(t *testing.T) {\n\tfeed := getFeed1()\n\tpost := getPost1()\n\n\ticon := \"🥰\"\n\tReactPost(feed.id, post.id, icon, true)\n\n\t// Set reaction\n\treactionCount_, ok := post.reactions.Get(\"🥰\")\n\tif !ok {\n\t\tt.Fatalf(\"expected 🥰 exists\")\n\t}\n\n\treactionCount := reactionCount_.(int)\n\tif reactionCount != 1 {\n\t\tt.Fatalf(\"expected reactionCount: 1, got %q.\", reactionCount)\n\t}\n\n\t// Unset reaction\n\tReactPost(feed.id, post.id, icon, false)\n\t_, exist := post.reactions.Get(\"🥰\")\n\tif exist {\n\t\tt.Fatalf(\"expected 🥰 not exist\")\n\t}\n}\n\nfunc testCreateAndDeleteComment(t *testing.T) {\n\tfeed1 := getFeed1()\n\tpost1 := getPost1()\n\n\tmetadata := `empty_meta_data`\n\n\tcommentID1 := CreatePost(feed1.id, post1.id, cat1, metadata)\n\tcommentID2 := CreatePost(feed1.id, post1.id, cat1, metadata)\n\tcomment2 := feed1.MustGetPost(commentID2)\n\n\tif comment2.id != 3 { // 1 post + 2 comments = 3\n\t\tt.Fatalf(\"expected comment postID: 3, got %q.\", comment2.id)\n\t}\n\n\tif comment2.parentID != post1.id {\n\t\tt.Fatalf(\"expected comment parentID: %q, got %q.\", post1.id, comment2.parentID)\n\t}\n\n\t// Check comment count on parent\n\tif post1.commentsCount != 2 {\n\t\tt.Fatalf(\"expected comments count: 2, got %d.\", post1.commentsCount)\n\t}\n\n\t// Get comments\n\tcomments := GetComments(feed1.id, post1.id, 0, 10)\n\tcommentsParsed := ujson.ParseSlice(comments)\n\n\tif len(commentsParsed) != 2 {\n\t\tt.Fatalf(\"expected encoded comments: 2, got %q.\", commentsParsed)\n\t}\n\n\t// Delete 1 comment\n\tDeletePost(feed1.id, comment2.id)\n\tcomments = GetComments(feed1.id, post1.id, 0, 10)\n\tcommentsParsed = ujson.ParseSlice(comments)\n\n\tif len(commentsParsed) != 1 {\n\t\tt.Fatalf(\"expected encoded comments: 1, got %q.\", commentsParsed)\n\t}\n\n\t// Check comment count on parent\n\tif post1.commentsCount != 1 {\n\t\tt.Fatalf(\"expected comments count: 1, got %d.\", post1.commentsCount)\n\t}\n}\n\nfunc countPosts(feedID FeedID, categories []uint64, limit uint8) int {\n\toffset := uint64(0)\n\n\tpostsStr := GetPosts(feedID, 0, \"\", categories, offset, limit)\n\tif postsStr == \"[]\" {\n\t\treturn 0\n\t}\n\n\tparsedPosts := ujson.ParseSlice(postsStr)\n\tpostsCount := len(parsedPosts)\n\treturn postsCount\n}\n\nfunc countPostsByUser(feedID FeedID, user string) int {\n\toffset := uint64(0)\n\tlimit := uint8(10)\n\n\tpostsStr := GetPosts(feedID, 0, user, []uint64{}, offset, limit)\n\tif postsStr == \"[]\" {\n\t\treturn 0\n\t}\n\n\tparsedPosts := ujson.ParseSlice(postsStr)\n\tpostsCount := len(parsedPosts)\n\treturn postsCount\n}\n\nfunc testFilterByCategories(t *testing.T) {\n\t// // Re-add reaction to test post list\n\t// ReactPost(1, postID, \"🥰\", true)\n\t// ReactPost(1, postID, \"😇\", true)\n\n\tfilter_cat1 := []uint64{1}\n\tfilter_cat1_2 := []uint64{1, 2}\n\tfilter_cat9 := []uint64{9}\n\tfilter_cat1_2_9 := []uint64{1, 2, 9}\n\n\tfeedID2 := CreateFeed(\"teritori2\")\n\tfeed2 := mustGetFeed(feedID2)\n\n\t// Create 2 posts on root with cat1\n\tpostID1 := CreatePost(feed2.id, rootPostID, cat1, \"metadata\")\n\tpostID2 := CreatePost(feed2.id, rootPostID, cat1, \"metadata\")\n\n\t// Create 1 posts on root with cat2\n\tpostID3 := CreatePost(feed2.id, rootPostID, cat2, \"metadata\")\n\n\t// Create comments on post 1\n\tcommentPostID1 := CreatePost(feed2.id, postID1, cat1, \"metadata\")\n\n\t// cat1: Should return max = limit\n\tif count := countPosts(feed2.id, filter_cat1, 1); count != 1 {\n\t\tt.Fatalf(\"expected posts count: 1, got %q.\", count)\n\t}\n\n\t// cat1: Should return max = total\n\tif count := countPosts(feed2.id, filter_cat1, 10); count != 2 {\n\t\tt.Fatalf(\"expected posts count: 2, got %q.\", count)\n\t}\n\n\t// cat 1 + 2: Should return max = limit\n\tif count := countPosts(feed2.id, filter_cat1_2, 2); count != 2 {\n\t\tt.Fatalf(\"expected posts count: 2, got %q.\", count)\n\t}\n\n\t// cat 1 + 2: Should return max = total on both\n\tif count := countPosts(feed2.id, filter_cat1_2, 10); count != 3 {\n\t\tt.Fatalf(\"expected posts count: 3, got %q.\", count)\n\t}\n\n\t// cat 1, 2, 9: Should return total of 1, 2\n\tif count := countPosts(feed2.id, filter_cat1_2_9, 10); count != 3 {\n\t\tt.Fatalf(\"expected posts count: 3, got %q.\", count)\n\t}\n\n\t// cat 9: Should return 0\n\tif count := countPosts(feed2.id, filter_cat9, 10); count != 0 {\n\t\tt.Fatalf(\"expected posts count: 0, got %q.\", count)\n\t}\n\n\t// cat all: should return all\n\tif count := countPosts(feed2.id, filter_all, 10); count != 3 {\n\t\tt.Fatalf(\"expected posts count: 3, got %q.\", count)\n\t}\n\n\t// add comments should not impact the results\n\tCreatePost(feed2.id, postID1, cat1, \"metadata\")\n\tCreatePost(feed2.id, postID2, cat1, \"metadata\")\n\n\tif count := countPosts(feed2.id, filter_all, 10); count != 3 {\n\t\tt.Fatalf(\"expected posts count: 3, got %q.\", count)\n\t}\n\n\t// delete a post should affect the result\n\tDeletePost(feed2.id, postID1)\n\n\tif count := countPosts(feed2.id, filter_all, 10); count != 2 {\n\t\tt.Fatalf(\"expected posts count: 2, got %q.\", count)\n\t}\n}\n\nfunc testTipPost(t *testing.T) {\n\tcreator := testutils.TestAddress(\"creator\")\n\tstd.TestIssueCoins(creator, std.Coins{{\"ugnot\", 100_000_000}})\n\n\t// NOTE: Dont know why the address should be this to be able to call banker (= std.GetCallerAt(1))\n\ttipper := testutils.TestAddress(\"tipper\")\n\tstd.TestIssueCoins(tipper, std.Coins{{\"ugnot\", 50_000_000}})\n\n\tbanker := std.GetBanker(std.BankerTypeReadonly)\n\n\t// Check Original coins of creator/tipper\n\tif coins := banker.GetCoins(creator); coins[0].Amount != 100_000_000 {\n\t\tt.Fatalf(\"expected creator coin count: 100_000_000, got %d.\", coins[0].Amount)\n\t}\n\n\tif coins := banker.GetCoins(tipper); coins[0].Amount != 50_000_000 {\n\t\tt.Fatalf(\"expected tipper coin count: 50_000_000, got %d.\", coins[0].Amount)\n\t}\n\n\t// Creator creates feed, post\n\tstd.TestSetOrigCaller(creator)\n\n\tfeedID3 := CreateFeed(\"teritori3\")\n\tfeed3 := mustGetFeed(feedID3)\n\n\tpostID1 := CreatePost(feed3.id, rootPostID, cat1, \"metadata\")\n\tpost1 := feed3.MustGetPost(postID1)\n\n\t// Tiper tips the ppst\n\tstd.TestSetOrigCaller(tipper)\n\tstd.TestSetOrigSend(std.Coins{{\"ugnot\", 1_000_000}}, nil)\n\tTipPost(feed3.id, post1.id)\n\n\t// Coin must be increased for creator\n\tif coins := banker.GetCoins(creator); coins[0].Amount != 101_000_000 {\n\t\tt.Fatalf(\"expected creator coin after beging tipped: 101_000_000, got %d.\", coins[0].Amount)\n\t}\n\n\t// Total tip amount should increased\n\tif post1.tipAmount != 1_000_000 {\n\t\tt.Fatalf(\"expected total tipAmount: 1_000_000, got %d.\", post1.tipAmount)\n\t}\n\n\t// Add more tip should update this total\n\tstd.TestSetOrigSend(std.Coins{{\"ugnot\", 2_000_000}}, nil)\n\tTipPost(feed3.id, post1.id)\n\n\tif post1.tipAmount != 3_000_000 {\n\t\tt.Fatalf(\"expected total tipAmount: 3_000_000, got %d.\", post1.tipAmount)\n\t}\n}\n\nfunc testFlagPost(t *testing.T) {\n\tflagger := testutils.TestAddress(\"flagger\")\n\n\tfeedID9 := CreateFeed(\"teritori9\")\n\tfeed9 := mustGetFeed(feedID9)\n\n\tCreatePost(feed9.id, rootPostID, cat1, \"metadata1\")\n\tpid := CreatePost(feed9.id, rootPostID, cat1, \"metadata1\")\n\n\t// Flag post\n\tstd.TestSetOrigCaller(flagger)\n\tFlagPost(feed9.id, pid)\n\n\t// Another user flags\n\tanother := testutils.TestAddress(\"another\")\n\tstd.TestSetOrigCaller(another)\n\tFlagPost(feed9.id, pid)\n\n\tflaggedPostsStr := GetFlaggedPosts(feed9.id, 0, 10)\n\tparsed := ujson.ParseSlice(flaggedPostsStr)\n\tif flaggedPostsCount := len(parsed); flaggedPostsCount != 1 {\n\t\tt.Fatalf(\"expected flagged posts: 1, got %d.\", flaggedPostsCount)\n\t}\n}\n\nfunc testFilterUser(t *testing.T) {\n\tuser1 := testutils.TestAddress(\"user1\")\n\tuser2 := testutils.TestAddress(\"user2\")\n\n\t// User1 create 2 posts\n\tstd.TestSetOrigCaller(user1)\n\n\tfeedID4 := CreateFeed(\"teritori4\")\n\tfeed4 := mustGetFeed(feedID4)\n\n\tCreatePost(feed4.id, rootPostID, cat1, `{\"metadata\": \"value\"}`)\n\tCreatePost(feed4.id, rootPostID, cat1, `{\"metadata2\": \"value\"}`)\n\n\t// User2 create 1 post\n\tstd.TestSetOrigCaller(user2)\n\tCreatePost(feed4.id, rootPostID, cat1, `{\"metadata\": \"value\"}`)\n\n\tif count := countPostsByUser(feed4.id, user1.String()); count != 2 {\n\t\tt.Fatalf(\"expected total posts by user1: 2, got %d.\", count)\n\t}\n\n\tif count := countPostsByUser(feed4.id, user2.String()); count != 1 {\n\t\tt.Fatalf(\"expected total posts by user2: 1, got %d.\", count)\n\t}\n\n\tif count := countPostsByUser(feed4.id, \"\"); count != 3 {\n\t\tt.Fatalf(\"expected total posts: 3, got %d.\", count)\n\t}\n}\n\nfunc testHidePostForMe(t *testing.T) {\n\tuser := std.Address(\"user\")\n\tstd.TestSetOrigCaller(user)\n\n\tfeedID8 := CreateFeed(\"teritor8\")\n\tfeed8 := mustGetFeed(feedID8)\n\n\tpostIDToHide := CreatePost(feed8.id, rootPostID, cat1, `{\"metadata\": \"value\"}`)\n\tpostID := CreatePost(feed8.id, rootPostID, cat1, `{\"metadata\": \"value\"}`)\n\n\tif count := countPosts(feed8.id, filter_all, 10); count != 2 {\n\t\tt.Fatalf(\"expected posts count: 2, got %q.\", count)\n\t}\n\n\t// Hide a post for me\n\tHidePostForMe(feed8.id, postIDToHide)\n\n\tif count := countPosts(feed8.id, filter_all, 10); count != 1 {\n\t\tt.Fatalf(\"expected posts count after hidding: 1, got %q.\", count)\n\t}\n\n\t// Query from another user should return full list\n\tanother := std.Address(\"another\")\n\tstd.TestSetOrigCaller(another)\n\n\tif count := countPosts(feed8.id, filter_all, 10); count != 2 {\n\t\tt.Fatalf(\"expected posts count from another: 2, got %q.\", count)\n\t}\n\n\t// UnHide a post for me\n\tstd.TestSetOrigCaller(user)\n\tUnHidePostForMe(feed8.id, postIDToHide)\n\n\tif count := countPosts(feed8.id, filter_all, 10); count != 2 {\n\t\tt.Fatalf(\"expected posts count after unhidding: 2, got %q.\", count)\n\t}\n}\n\nfunc testMigrateFeedData(t *testing.T) string {\n\tfeedID := feedsV7.CreateFeed(\"teritor11\")\n\n\t// Post to test\n\tpostID := feedsV7.CreatePost(feedID, feedsV7.PostID(0), 2, `{\"metadata\": \"value\"}`)\n\tfeedsV7.ReactPost(feedID, postID, \"🇬🇸\", true)\n\n\t// Add comment to post\n\tcommentID := feedsV7.CreatePost(feedID, postID, 2, `{\"comment1\": \"value\"}`)\n\tfeedsV7.ReactPost(feedID, commentID, \"🇬🇸\", true)\n\n\t// // Post with json metadata\n\tfeedsV7.CreatePost(feedID, feedsV7.PostID(0), 2, `{'a':1}`)\n\n\t// Expect: should convert feed data to JSON successfully without error\n\tdataJSON := feedsV7.ExportFeedData(feedID)\n\tif dataJSON == \"\" {\n\t\tt.Fatalf(\"expected feed data exported successfully\")\n\t}\n\n\t// Import data =====================================\n\tImportFeedData(FeedID(uint64(feedID)), dataJSON)\n\n\t// Test public func\n\t// MigrateFromPreviousFeed(feedID)\n}\n\nfunc Test(t *testing.T) {\n\ttestCreateFeed(t)\n\n\ttestCreatePost(t)\n\n\ttestGetPosts(t)\n\n\ttestReactPost(t)\n\n\ttestCreateAndDeleteComment(t)\n\n\ttestFilterByCategories(t)\n\n\ttestTipPost(t)\n\n\ttestFilterUser(t)\n\n\ttestFlagPost(t)\n\n\ttestHidePostForMe(t)\n\n\ttestMigrateFeedData(t)\n}\n" + "Body": "package social_feeds\n\nimport (\n\t\"encoding/base64\"\n\t\"fmt\"\n\t\"std\"\n\t\"strconv\"\n\t\"strings\"\n\t\"testing\"\n\n\t\"gno.land/p/demo/avl\"\n\tujson \"gno.land/p/demo/teritori/ujson\"\n\t\"gno.land/p/demo/testutils\"\n\t\"gno.land/r/demo/boards\"\n\t// Fake previous version for testing\n\tfeedsV7 \"gno.land/r/demo/teritori/social_feeds\"\n\t\"gno.land/r/demo/users\"\n)\n\nvar (\n\trootPostID = PostID(0)\n\tpostID1 = PostID(1)\n\tfeedID1 = FeedID(1)\n\tcat1 = uint64(1)\n\tcat2 = uint64(2)\n\tuser = testutils.TestAddress(\"user\")\n\tfilter_all = []uint64{}\n)\n\nfunc getFeed1() *Feed {\n\treturn mustGetFeed(feedID1)\n}\n\nfunc getPost1() *Post {\n\tfeed1 := getFeed1()\n\tpost1 := feed1.MustGetPost(postID1)\n\treturn post1\n}\n\nfunc testCreateFeed(t *testing.T) {\n\tfeedID := CreateFeed(\"teritori1\")\n\tfeed := mustGetFeed(feedID)\n\n\tif feedID != 1 {\n\t\tt.Fatalf(\"expected feedID: 1, got %q.\", feedID)\n\t}\n\n\tif feed.name != \"teritori1\" {\n\t\tt.Fatalf(\"expected feedName: teritori1, got %q.\", feed.name)\n\t}\n}\n\nfunc testCreatePost(t *testing.T) {\n\tmetadata := `{\"gifs\": [], \"files\": [], \"title\": \"\", \"message\": \"testouille\", \"hashtags\": [], \"mentions\": [], \"createdAt\": \"2023-03-29T12:19:04.858Z\", \"updatedAt\": \"2023-03-29T12:19:04.858Z\"}`\n\tpostID := CreatePost(feedID1, rootPostID, cat1, metadata)\n\tfeed := mustGetFeed(feedID1)\n\tpost := feed.MustGetPost(postID)\n\n\tif postID != 1 {\n\t\tt.Fatalf(\"expected postID: 1, got %q.\", postID)\n\t}\n\n\tif post.category != cat1 {\n\t\tt.Fatalf(\"expected categoryID: %q, got %q.\", cat1, post.category)\n\t}\n}\n\nfunc toPostIDsStr(posts []*Post) string {\n\tvar postIDs []string\n\tfor _, post := range posts {\n\t\tpostIDs = append(postIDs, post.id.String())\n\t}\n\n\tpostIDsStr := strings.Join(postIDs, \",\")\n\treturn postIDsStr\n}\n\nfunc testGetPosts(t *testing.T) {\n\tuser := std.Address(\"user\")\n\tstd.TestSetOriginCaller(user)\n\n\tfeedID := CreateFeed(\"teritori10\")\n\tfeed := mustGetFeed(feedID)\n\n\tCreatePost(feedID, rootPostID, cat1, \"post1\")\n\tCreatePost(feedID, rootPostID, cat1, \"post2\")\n\tCreatePost(feedID, rootPostID, cat1, \"post3\")\n\tCreatePost(feedID, rootPostID, cat1, \"post4\")\n\tCreatePost(feedID, rootPostID, cat1, \"post5\")\n\tpostIDToFlagged := CreatePost(feedID, rootPostID, cat1, \"post6\")\n\tpostIDToHide := CreatePost(feedID, rootPostID, cat1, \"post7\")\n\tCreatePost(feedID, rootPostID, cat1, \"post8\")\n\n\tvar posts []*Post\n\tvar postIDsStr string\n\n\t// Query last 3 posts\n\tposts = getPosts(feed, 0, \"\", \"\", []uint64{}, 0, 3)\n\tpostIDsStr = toPostIDsStr(posts)\n\n\tif postIDsStr != \"8,7,6\" {\n\t\tt.Fatalf(\"expected posts order: 8,7,6. Got: %s\", postIDsStr)\n\t}\n\n\t// Query page 2\n\tposts = getPosts(feed, 0, \"\", \"\", []uint64{}, 3, 3)\n\tpostIDsStr = toPostIDsStr(posts)\n\tif postIDsStr != \"5,4,3\" {\n\t\tt.Fatalf(\"expected posts order: 5,4,3. Got: %s\", postIDsStr)\n\t}\n\n\t// Exclude hidden post\n\tHidePostForMe(feed.id, postIDToHide)\n\n\tposts = getPosts(feed, 0, user.String(), \"\", []uint64{}, 0, 3)\n\tpostIDsStr = toPostIDsStr(posts)\n\n\tif postIDsStr != \"8,6,5\" {\n\t\tt.Fatalf(\"expected posts order: 8,6,5. Got: %s\", postIDsStr)\n\t}\n\n\t// Exclude flagged post\n\tFlagPost(feed.id, postIDToFlagged)\n\n\tposts = getPosts(feed, 0, user.String(), \"\", []uint64{}, 0, 3)\n\tpostIDsStr = toPostIDsStr(posts)\n\n\tif postIDsStr != \"8,5,4\" {\n\t\tt.Fatalf(\"expected posts order: 8,5,4. Got: %s\", postIDsStr)\n\t}\n\n\t// Pagination with hidden/flagged posts\n\tposts = getPosts(feed, 0, user.String(), \"\", []uint64{}, 3, 3)\n\tpostIDsStr = toPostIDsStr(posts)\n\n\tif postIDsStr != \"3,2,1\" {\n\t\tt.Fatalf(\"expected posts order: 3,2,1. Got: %s\", postIDsStr)\n\t}\n\n\t// Query out of range\n\tposts = getPosts(feed, 0, user.String(), \"\", []uint64{}, 6, 3)\n\tpostIDsStr = toPostIDsStr(posts)\n\n\tif postIDsStr != \"\" {\n\t\tt.Fatalf(\"expected posts order: ''. Got: %s\", postIDsStr)\n\t}\n}\n\nfunc testReactPost(t *testing.T) {\n\tfeed := getFeed1()\n\tpost := getPost1()\n\n\ticon := \"🥰\"\n\tReactPost(feed.id, post.id, icon, true)\n\n\t// Set reaction\n\treactionCount_, ok := post.reactions.Get(\"🥰\")\n\tif !ok {\n\t\tt.Fatalf(\"expected 🥰 exists\")\n\t}\n\n\treactionCount := reactionCount_.(int)\n\tif reactionCount != 1 {\n\t\tt.Fatalf(\"expected reactionCount: 1, got %q.\", reactionCount)\n\t}\n\n\t// Unset reaction\n\tReactPost(feed.id, post.id, icon, false)\n\t_, exist := post.reactions.Get(\"🥰\")\n\tif exist {\n\t\tt.Fatalf(\"expected 🥰 not exist\")\n\t}\n}\n\nfunc testCreateAndDeleteComment(t *testing.T) {\n\tfeed1 := getFeed1()\n\tpost1 := getPost1()\n\n\tmetadata := `empty_meta_data`\n\n\tcommentID1 := CreatePost(feed1.id, post1.id, cat1, metadata)\n\tcommentID2 := CreatePost(feed1.id, post1.id, cat1, metadata)\n\tcomment2 := feed1.MustGetPost(commentID2)\n\n\tif comment2.id != 3 { // 1 post + 2 comments = 3\n\t\tt.Fatalf(\"expected comment postID: 3, got %q.\", comment2.id)\n\t}\n\n\tif comment2.parentID != post1.id {\n\t\tt.Fatalf(\"expected comment parentID: %q, got %q.\", post1.id, comment2.parentID)\n\t}\n\n\t// Check comment count on parent\n\tif post1.commentsCount != 2 {\n\t\tt.Fatalf(\"expected comments count: 2, got %d.\", post1.commentsCount)\n\t}\n\n\t// Get comments\n\tcomments := GetComments(feed1.id, post1.id, 0, 10)\n\tcommentsParsed := ujson.ParseSlice(comments)\n\n\tif len(commentsParsed) != 2 {\n\t\tt.Fatalf(\"expected encoded comments: 2, got %q.\", commentsParsed)\n\t}\n\n\t// Delete 1 comment\n\tDeletePost(feed1.id, comment2.id)\n\tcomments = GetComments(feed1.id, post1.id, 0, 10)\n\tcommentsParsed = ujson.ParseSlice(comments)\n\n\tif len(commentsParsed) != 1 {\n\t\tt.Fatalf(\"expected encoded comments: 1, got %q.\", commentsParsed)\n\t}\n\n\t// Check comment count on parent\n\tif post1.commentsCount != 1 {\n\t\tt.Fatalf(\"expected comments count: 1, got %d.\", post1.commentsCount)\n\t}\n}\n\nfunc countPosts(feedID FeedID, categories []uint64, limit uint8) int {\n\toffset := uint64(0)\n\n\tpostsStr := GetPosts(feedID, 0, \"\", categories, offset, limit)\n\tif postsStr == \"[]\" {\n\t\treturn 0\n\t}\n\n\tparsedPosts := ujson.ParseSlice(postsStr)\n\tpostsCount := len(parsedPosts)\n\treturn postsCount\n}\n\nfunc countPostsByUser(feedID FeedID, user string) int {\n\toffset := uint64(0)\n\tlimit := uint8(10)\n\n\tpostsStr := GetPosts(feedID, 0, user, []uint64{}, offset, limit)\n\tif postsStr == \"[]\" {\n\t\treturn 0\n\t}\n\n\tparsedPosts := ujson.ParseSlice(postsStr)\n\tpostsCount := len(parsedPosts)\n\treturn postsCount\n}\n\nfunc testFilterByCategories(t *testing.T) {\n\t// // Re-add reaction to test post list\n\t// ReactPost(1, postID, \"🥰\", true)\n\t// ReactPost(1, postID, \"😇\", true)\n\n\tfilter_cat1 := []uint64{1}\n\tfilter_cat1_2 := []uint64{1, 2}\n\tfilter_cat9 := []uint64{9}\n\tfilter_cat1_2_9 := []uint64{1, 2, 9}\n\n\tfeedID2 := CreateFeed(\"teritori2\")\n\tfeed2 := mustGetFeed(feedID2)\n\n\t// Create 2 posts on root with cat1\n\tpostID1 := CreatePost(feed2.id, rootPostID, cat1, \"metadata\")\n\tpostID2 := CreatePost(feed2.id, rootPostID, cat1, \"metadata\")\n\n\t// Create 1 posts on root with cat2\n\tpostID3 := CreatePost(feed2.id, rootPostID, cat2, \"metadata\")\n\n\t// Create comments on post 1\n\tcommentPostID1 := CreatePost(feed2.id, postID1, cat1, \"metadata\")\n\n\t// cat1: Should return max = limit\n\tif count := countPosts(feed2.id, filter_cat1, 1); count != 1 {\n\t\tt.Fatalf(\"expected posts count: 1, got %q.\", count)\n\t}\n\n\t// cat1: Should return max = total\n\tif count := countPosts(feed2.id, filter_cat1, 10); count != 2 {\n\t\tt.Fatalf(\"expected posts count: 2, got %q.\", count)\n\t}\n\n\t// cat 1 + 2: Should return max = limit\n\tif count := countPosts(feed2.id, filter_cat1_2, 2); count != 2 {\n\t\tt.Fatalf(\"expected posts count: 2, got %q.\", count)\n\t}\n\n\t// cat 1 + 2: Should return max = total on both\n\tif count := countPosts(feed2.id, filter_cat1_2, 10); count != 3 {\n\t\tt.Fatalf(\"expected posts count: 3, got %q.\", count)\n\t}\n\n\t// cat 1, 2, 9: Should return total of 1, 2\n\tif count := countPosts(feed2.id, filter_cat1_2_9, 10); count != 3 {\n\t\tt.Fatalf(\"expected posts count: 3, got %q.\", count)\n\t}\n\n\t// cat 9: Should return 0\n\tif count := countPosts(feed2.id, filter_cat9, 10); count != 0 {\n\t\tt.Fatalf(\"expected posts count: 0, got %q.\", count)\n\t}\n\n\t// cat all: should return all\n\tif count := countPosts(feed2.id, filter_all, 10); count != 3 {\n\t\tt.Fatalf(\"expected posts count: 3, got %q.\", count)\n\t}\n\n\t// add comments should not impact the results\n\tCreatePost(feed2.id, postID1, cat1, \"metadata\")\n\tCreatePost(feed2.id, postID2, cat1, \"metadata\")\n\n\tif count := countPosts(feed2.id, filter_all, 10); count != 3 {\n\t\tt.Fatalf(\"expected posts count: 3, got %q.\", count)\n\t}\n\n\t// delete a post should affect the result\n\tDeletePost(feed2.id, postID1)\n\n\tif count := countPosts(feed2.id, filter_all, 10); count != 2 {\n\t\tt.Fatalf(\"expected posts count: 2, got %q.\", count)\n\t}\n}\n\nfunc testTipPost(t *testing.T) {\n\tcreator := testutils.TestAddress(\"creator\")\n\tstd.TestIssueCoins(creator, std.Coins{{\"ugnot\", 100_000_000}})\n\n\t// NOTE: Dont know why the address should be this to be able to call banker (= std.CallerAt(1))\n\ttipper := testutils.TestAddress(\"tipper\")\n\tstd.TestIssueCoins(tipper, std.Coins{{\"ugnot\", 50_000_000}})\n\n\tbanker := std.NewBanker(std.BankerTypeReadonly)\n\n\t// Check Original coins of creator/tipper\n\tif coins := banker.GetCoins(creator); coins[0].Amount != 100_000_000 {\n\t\tt.Fatalf(\"expected creator coin count: 100_000_000, got %d.\", coins[0].Amount)\n\t}\n\n\tif coins := banker.GetCoins(tipper); coins[0].Amount != 50_000_000 {\n\t\tt.Fatalf(\"expected tipper coin count: 50_000_000, got %d.\", coins[0].Amount)\n\t}\n\n\t// Creator creates feed, post\n\tstd.TestSetOriginCaller(creator)\n\n\tfeedID3 := CreateFeed(\"teritori3\")\n\tfeed3 := mustGetFeed(feedID3)\n\n\tpostID1 := CreatePost(feed3.id, rootPostID, cat1, \"metadata\")\n\tpost1 := feed3.MustGetPost(postID1)\n\n\t// Tiper tips the ppst\n\tstd.TestSetOriginCaller(tipper)\n\tstd.TestSetOriginSend(std.Coins{{\"ugnot\", 1_000_000}}, nil)\n\tTipPost(feed3.id, post1.id)\n\n\t// Coin must be increased for creator\n\tif coins := banker.GetCoins(creator); coins[0].Amount != 101_000_000 {\n\t\tt.Fatalf(\"expected creator coin after beging tipped: 101_000_000, got %d.\", coins[0].Amount)\n\t}\n\n\t// Total tip amount should increased\n\tif post1.tipAmount != 1_000_000 {\n\t\tt.Fatalf(\"expected total tipAmount: 1_000_000, got %d.\", post1.tipAmount)\n\t}\n\n\t// Add more tip should update this total\n\tstd.TestSetOriginSend(std.Coins{{\"ugnot\", 2_000_000}}, nil)\n\tTipPost(feed3.id, post1.id)\n\n\tif post1.tipAmount != 3_000_000 {\n\t\tt.Fatalf(\"expected total tipAmount: 3_000_000, got %d.\", post1.tipAmount)\n\t}\n}\n\nfunc testFlagPost(t *testing.T) {\n\tflagger := testutils.TestAddress(\"flagger\")\n\n\tfeedID9 := CreateFeed(\"teritori9\")\n\tfeed9 := mustGetFeed(feedID9)\n\n\tCreatePost(feed9.id, rootPostID, cat1, \"metadata1\")\n\tpid := CreatePost(feed9.id, rootPostID, cat1, \"metadata1\")\n\n\t// Flag post\n\tstd.TestSetOriginCaller(flagger)\n\tFlagPost(feed9.id, pid)\n\n\t// Another user flags\n\tanother := testutils.TestAddress(\"another\")\n\tstd.TestSetOriginCaller(another)\n\tFlagPost(feed9.id, pid)\n\n\tflaggedPostsStr := GetFlaggedPosts(feed9.id, 0, 10)\n\tparsed := ujson.ParseSlice(flaggedPostsStr)\n\tif flaggedPostsCount := len(parsed); flaggedPostsCount != 1 {\n\t\tt.Fatalf(\"expected flagged posts: 1, got %d.\", flaggedPostsCount)\n\t}\n}\n\nfunc testFilterUser(t *testing.T) {\n\tuser1 := testutils.TestAddress(\"user1\")\n\tuser2 := testutils.TestAddress(\"user2\")\n\n\t// User1 create 2 posts\n\tstd.TestSetOriginCaller(user1)\n\n\tfeedID4 := CreateFeed(\"teritori4\")\n\tfeed4 := mustGetFeed(feedID4)\n\n\tCreatePost(feed4.id, rootPostID, cat1, `{\"metadata\": \"value\"}`)\n\tCreatePost(feed4.id, rootPostID, cat1, `{\"metadata2\": \"value\"}`)\n\n\t// User2 create 1 post\n\tstd.TestSetOriginCaller(user2)\n\tCreatePost(feed4.id, rootPostID, cat1, `{\"metadata\": \"value\"}`)\n\n\tif count := countPostsByUser(feed4.id, user1.String()); count != 2 {\n\t\tt.Fatalf(\"expected total posts by user1: 2, got %d.\", count)\n\t}\n\n\tif count := countPostsByUser(feed4.id, user2.String()); count != 1 {\n\t\tt.Fatalf(\"expected total posts by user2: 1, got %d.\", count)\n\t}\n\n\tif count := countPostsByUser(feed4.id, \"\"); count != 3 {\n\t\tt.Fatalf(\"expected total posts: 3, got %d.\", count)\n\t}\n}\n\nfunc testHidePostForMe(t *testing.T) {\n\tuser := std.Address(\"user\")\n\tstd.TestSetOriginCaller(user)\n\n\tfeedID8 := CreateFeed(\"teritor8\")\n\tfeed8 := mustGetFeed(feedID8)\n\n\tpostIDToHide := CreatePost(feed8.id, rootPostID, cat1, `{\"metadata\": \"value\"}`)\n\tpostID := CreatePost(feed8.id, rootPostID, cat1, `{\"metadata\": \"value\"}`)\n\n\tif count := countPosts(feed8.id, filter_all, 10); count != 2 {\n\t\tt.Fatalf(\"expected posts count: 2, got %q.\", count)\n\t}\n\n\t// Hide a post for me\n\tHidePostForMe(feed8.id, postIDToHide)\n\n\tif count := countPosts(feed8.id, filter_all, 10); count != 1 {\n\t\tt.Fatalf(\"expected posts count after hidding: 1, got %q.\", count)\n\t}\n\n\t// Query from another user should return full list\n\tanother := std.Address(\"another\")\n\tstd.TestSetOriginCaller(another)\n\n\tif count := countPosts(feed8.id, filter_all, 10); count != 2 {\n\t\tt.Fatalf(\"expected posts count from another: 2, got %q.\", count)\n\t}\n\n\t// UnHide a post for me\n\tstd.TestSetOriginCaller(user)\n\tUnHidePostForMe(feed8.id, postIDToHide)\n\n\tif count := countPosts(feed8.id, filter_all, 10); count != 2 {\n\t\tt.Fatalf(\"expected posts count after unhidding: 2, got %q.\", count)\n\t}\n}\n\nfunc testMigrateFeedData(t *testing.T) string {\n\tfeedID := feedsV7.CreateFeed(\"teritor11\")\n\n\t// Post to test\n\tpostID := feedsV7.CreatePost(feedID, feedsV7.PostID(0), 2, `{\"metadata\": \"value\"}`)\n\tfeedsV7.ReactPost(feedID, postID, \"🇬🇸\", true)\n\n\t// Add comment to post\n\tcommentID := feedsV7.CreatePost(feedID, postID, 2, `{\"comment1\": \"value\"}`)\n\tfeedsV7.ReactPost(feedID, commentID, \"🇬🇸\", true)\n\n\t// // Post with json metadata\n\tfeedsV7.CreatePost(feedID, feedsV7.PostID(0), 2, `{'a':1}`)\n\n\t// Expect: should convert feed data to JSON successfully without error\n\tdataJSON := feedsV7.ExportFeedData(feedID)\n\tif dataJSON == \"\" {\n\t\tt.Fatalf(\"expected feed data exported successfully\")\n\t}\n\n\t// Import data =====================================\n\tImportFeedData(FeedID(uint64(feedID)), dataJSON)\n\n\t// Test public func\n\t// MigrateFromPreviousFeed(feedID)\n}\n\nfunc Test(t *testing.T) {\n\ttestCreateFeed(t)\n\n\ttestCreatePost(t)\n\n\ttestGetPosts(t)\n\n\ttestReactPost(t)\n\n\ttestCreateAndDeleteComment(t)\n\n\ttestFilterByCategories(t)\n\n\ttestTipPost(t)\n\n\ttestFilterUser(t)\n\n\ttestFlagPost(t)\n\n\ttestHidePostForMe(t)\n\n\ttestMigrateFeedData(t)\n}\n" }, { "Name": "flags.gno", @@ -66,11 +66,11 @@ import ( }, { "Name": "post.gno", - "Body": "package social_feeds\n\nimport (\n\t\"std\"\n\t\"strconv\"\n\t\"time\"\n\n\t\"gno.land/p/demo/avl\"\n\tujson \"gno.land/p/demo/teritori/ujson\"\n)\n\ntype PostID uint64\n\nfunc (pid PostID) String() string {\n\treturn strconv.Itoa(int(pid))\n}\n\nfunc (pid *PostID) FromJSON(ast *ujson.JSONASTNode) {\n\tval, err := strconv.Atoi(ast.Value)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\t*pid = PostID(val)\n}\n\nfunc (pid PostID) ToJSON() string {\n\treturn strconv.Itoa(int(pid))\n}\n\ntype Reaction struct {\n\ticon string\n\tcount uint64\n}\n\nvar Categories []string = []string{\n\t\"Reaction\",\n\t\"Comment\",\n\t\"Normal\",\n\t\"Article\",\n\t\"Picture\",\n\t\"Audio\",\n\t\"Video\",\n}\n\ntype Post struct {\n\tid PostID\n\tparentID PostID\n\tfeedID FeedID\n\tcategory uint64\n\tmetadata string\n\treactions avl.Tree // icon -> count\n\tcomments avl.Tree // Post.id -> *Post\n\tcreator std.Address\n\ttipAmount uint64\n\tdeleted bool\n\tcommentsCount uint64\n\n\tcreatedAt int64\n\tupdatedAt int64\n\tdeletedAt int64\n}\n\nfunc newPost(feed *Feed, id PostID, creator std.Address, parentID PostID, category uint64, metadata string) *Post {\n\treturn &Post{\n\t\tid: id,\n\t\tparentID: parentID,\n\t\tfeedID: feed.id,\n\t\tcategory: category,\n\t\tmetadata: metadata,\n\t\treactions: avl.Tree{},\n\t\tcreator: creator,\n\t\tcreatedAt: time.Now().Unix(),\n\t}\n}\n\nfunc (post *Post) String() string {\n\treturn post.ToJSON()\n}\n\nfunc (post *Post) Update(category uint64, metadata string) {\n\tpost.category = category\n\tpost.metadata = metadata\n\tpost.updatedAt = time.Now().Unix()\n}\n\nfunc (post *Post) Delete() {\n\tpost.deleted = true\n\tpost.deletedAt = time.Now().Unix()\n}\n\nfunc (post *Post) Tip(from std.Address, to std.Address) {\n\treceivedCoins := std.GetOrigSend()\n\tamount := receivedCoins[0].Amount\n\n\tbanker := std.GetBanker(std.BankerTypeOrigSend)\n\t// banker := std.GetBanker(std.BankerTypeRealmSend)\n\tcoinsToSend := std.Coins{std.Coin{Denom: \"ugnot\", Amount: amount}}\n\tpkgaddr := std.GetOrigPkgAddr()\n\n\tbanker.SendCoins(pkgaddr, to, coinsToSend)\n\n\t// Update tip amount\n\tpost.tipAmount += uint64(amount)\n}\n\n// Always remove reaction if count = 0\nfunc (post *Post) React(icon string, up bool) {\n\tcount_, ok := post.reactions.Get(icon)\n\tcount := 0\n\n\tif ok {\n\t\tcount = count_.(int)\n\t}\n\n\tif up {\n\t\tcount++\n\t} else {\n\t\tcount--\n\t}\n\n\tif count <= 0 {\n\t\tpost.reactions.Remove(icon)\n\t} else {\n\t\tpost.reactions.Set(icon, count)\n\t}\n}\n\nfunc (post *Post) Render() string {\n\treturn post.metadata\n}\n\nfunc (post *Post) FromJSON(jsonData string) {\n\tast := ujson.TokenizeAndParse(jsonData)\n\tast.ParseObject([]*ujson.ParseKV{\n\t\t{Key: \"id\", CustomParser: func(node *ujson.JSONASTNode) {\n\t\t\tpid, _ := strconv.Atoi(node.Value)\n\t\t\tpost.id = PostID(pid)\n\t\t}},\n\t\t{Key: \"parentID\", CustomParser: func(node *ujson.JSONASTNode) {\n\t\t\tpid, _ := strconv.Atoi(node.Value)\n\t\t\tpost.parentID = PostID(pid)\n\t\t}},\n\t\t{Key: \"feedID\", CustomParser: func(node *ujson.JSONASTNode) {\n\t\t\tfid, _ := strconv.Atoi(node.Value)\n\t\t\tpost.feedID = FeedID(fid)\n\t\t}},\n\t\t{Key: \"category\", Value: &post.category},\n\t\t{Key: \"metadata\", Value: &post.metadata},\n\t\t{Key: \"reactions\", CustomParser: func(node *ujson.JSONASTNode) {\n\t\t\treactions := avl.NewTree()\n\t\t\tfor _, child := range node.ObjectChildren {\n\t\t\t\treactionCount := child.Value\n\t\t\t\treactions.Set(child.Key, reactionCount)\n\t\t\t}\n\t\t\tpost.reactions = *reactions\n\t\t}},\n\t\t{Key: \"commentsCount\", Value: &post.commentsCount},\n\t\t{Key: \"creator\", Value: &post.creator},\n\t\t{Key: \"tipAmount\", Value: &post.tipAmount},\n\t\t{Key: \"deleted\", Value: &post.deleted},\n\t\t{Key: \"createdAt\", Value: &post.createdAt},\n\t\t{Key: \"updatedAt\", Value: &post.updatedAt},\n\t\t{Key: \"deletedAt\", Value: &post.deletedAt},\n\t})\n}\n\nfunc (post *Post) ToJSON() string {\n\treactionsKV := []ujson.FormatKV{}\n\tpost.reactions.Iterate(\"\", \"\", func(key string, value interface{}) bool {\n\t\tcount := value.(int)\n\t\tdata := ujson.FormatKV{Key: key, Value: count}\n\t\treactionsKV = append(reactionsKV, data)\n\t\treturn false\n\t})\n\treactions := ujson.FormatObject(reactionsKV)\n\n\tpostJSON := ujson.FormatObject([]ujson.FormatKV{\n\t\t{Key: \"id\", Value: uint64(post.id)},\n\t\t{Key: \"parentID\", Value: uint64(post.parentID)},\n\t\t{Key: \"feedID\", Value: uint64(post.feedID)},\n\t\t{Key: \"category\", Value: post.category},\n\t\t{Key: \"metadata\", Value: post.metadata},\n\t\t{Key: \"reactions\", Value: reactions, Raw: true},\n\t\t{Key: \"creator\", Value: post.creator},\n\t\t{Key: \"tipAmount\", Value: post.tipAmount},\n\t\t{Key: \"deleted\", Value: post.deleted},\n\t\t{Key: \"commentsCount\", Value: post.commentsCount},\n\t\t{Key: \"createdAt\", Value: post.createdAt},\n\t\t{Key: \"updatedAt\", Value: post.updatedAt},\n\t\t{Key: \"deletedAt\", Value: post.deletedAt},\n\t})\n\treturn postJSON\n}\n" + "Body": "package social_feeds\n\nimport (\n\t\"std\"\n\t\"strconv\"\n\t\"time\"\n\n\t\"gno.land/p/demo/avl\"\n\tujson \"gno.land/p/demo/teritori/ujson\"\n)\n\ntype PostID uint64\n\nfunc (pid PostID) String() string {\n\treturn strconv.Itoa(int(pid))\n}\n\nfunc (pid *PostID) FromJSON(ast *ujson.JSONASTNode) {\n\tval, err := strconv.Atoi(ast.Value)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\t*pid = PostID(val)\n}\n\nfunc (pid PostID) ToJSON() string {\n\treturn strconv.Itoa(int(pid))\n}\n\ntype Reaction struct {\n\ticon string\n\tcount uint64\n}\n\nvar Categories []string = []string{\n\t\"Reaction\",\n\t\"Comment\",\n\t\"Normal\",\n\t\"Article\",\n\t\"Picture\",\n\t\"Audio\",\n\t\"Video\",\n}\n\ntype Post struct {\n\tid PostID\n\tparentID PostID\n\tfeedID FeedID\n\tcategory uint64\n\tmetadata string\n\treactions avl.Tree // icon -> count\n\tcomments avl.Tree // Post.id -> *Post\n\tcreator std.Address\n\ttipAmount uint64\n\tdeleted bool\n\tcommentsCount uint64\n\n\tcreatedAt int64\n\tupdatedAt int64\n\tdeletedAt int64\n}\n\nfunc newPost(feed *Feed, id PostID, creator std.Address, parentID PostID, category uint64, metadata string) *Post {\n\treturn &Post{\n\t\tid: id,\n\t\tparentID: parentID,\n\t\tfeedID: feed.id,\n\t\tcategory: category,\n\t\tmetadata: metadata,\n\t\treactions: avl.Tree{},\n\t\tcreator: creator,\n\t\tcreatedAt: time.Now().Unix(),\n\t}\n}\n\nfunc (post *Post) String() string {\n\treturn post.ToJSON()\n}\n\nfunc (post *Post) Update(category uint64, metadata string) {\n\tpost.category = category\n\tpost.metadata = metadata\n\tpost.updatedAt = time.Now().Unix()\n}\n\nfunc (post *Post) Delete() {\n\tpost.deleted = true\n\tpost.deletedAt = time.Now().Unix()\n}\n\nfunc (post *Post) Tip(from std.Address, to std.Address) {\n\treceivedCoins := std.OriginSend()\n\tamount := receivedCoins[0].Amount\n\n\tbanker := std.NewBanker(std.BankerTypeOriginSend)\n\t// banker := std.NewBanker(std.BankerTypeRealmSend)\n\tcoinsToSend := std.Coins{std.Coin{Denom: \"ugnot\", Amount: amount}}\n\tpkgaddr := std.OriginPkgAddress()\n\n\tbanker.SendCoins(pkgaddr, to, coinsToSend)\n\n\t// Update tip amount\n\tpost.tipAmount += uint64(amount)\n}\n\n// Always remove reaction if count = 0\nfunc (post *Post) React(icon string, up bool) {\n\tcount_, ok := post.reactions.Get(icon)\n\tcount := 0\n\n\tif ok {\n\t\tcount = count_.(int)\n\t}\n\n\tif up {\n\t\tcount++\n\t} else {\n\t\tcount--\n\t}\n\n\tif count <= 0 {\n\t\tpost.reactions.Remove(icon)\n\t} else {\n\t\tpost.reactions.Set(icon, count)\n\t}\n}\n\nfunc (post *Post) Render() string {\n\treturn post.metadata\n}\n\nfunc (post *Post) FromJSON(jsonData string) {\n\tast := ujson.TokenizeAndParse(jsonData)\n\tast.ParseObject([]*ujson.ParseKV{\n\t\t{Key: \"id\", CustomParser: func(node *ujson.JSONASTNode) {\n\t\t\tpid, _ := strconv.Atoi(node.Value)\n\t\t\tpost.id = PostID(pid)\n\t\t}},\n\t\t{Key: \"parentID\", CustomParser: func(node *ujson.JSONASTNode) {\n\t\t\tpid, _ := strconv.Atoi(node.Value)\n\t\t\tpost.parentID = PostID(pid)\n\t\t}},\n\t\t{Key: \"feedID\", CustomParser: func(node *ujson.JSONASTNode) {\n\t\t\tfid, _ := strconv.Atoi(node.Value)\n\t\t\tpost.feedID = FeedID(fid)\n\t\t}},\n\t\t{Key: \"category\", Value: &post.category},\n\t\t{Key: \"metadata\", Value: &post.metadata},\n\t\t{Key: \"reactions\", CustomParser: func(node *ujson.JSONASTNode) {\n\t\t\treactions := avl.NewTree()\n\t\t\tfor _, child := range node.ObjectChildren {\n\t\t\t\treactionCount := child.Value\n\t\t\t\treactions.Set(child.Key, reactionCount)\n\t\t\t}\n\t\t\tpost.reactions = *reactions\n\t\t}},\n\t\t{Key: \"commentsCount\", Value: &post.commentsCount},\n\t\t{Key: \"creator\", Value: &post.creator},\n\t\t{Key: \"tipAmount\", Value: &post.tipAmount},\n\t\t{Key: \"deleted\", Value: &post.deleted},\n\t\t{Key: \"createdAt\", Value: &post.createdAt},\n\t\t{Key: \"updatedAt\", Value: &post.updatedAt},\n\t\t{Key: \"deletedAt\", Value: &post.deletedAt},\n\t})\n}\n\nfunc (post *Post) ToJSON() string {\n\treactionsKV := []ujson.FormatKV{}\n\tpost.reactions.Iterate(\"\", \"\", func(key string, value interface{}) bool {\n\t\tcount := value.(int)\n\t\tdata := ujson.FormatKV{Key: key, Value: count}\n\t\treactionsKV = append(reactionsKV, data)\n\t\treturn false\n\t})\n\treactions := ujson.FormatObject(reactionsKV)\n\n\tpostJSON := ujson.FormatObject([]ujson.FormatKV{\n\t\t{Key: \"id\", Value: uint64(post.id)},\n\t\t{Key: \"parentID\", Value: uint64(post.parentID)},\n\t\t{Key: \"feedID\", Value: uint64(post.feedID)},\n\t\t{Key: \"category\", Value: post.category},\n\t\t{Key: \"metadata\", Value: post.metadata},\n\t\t{Key: \"reactions\", Value: reactions, Raw: true},\n\t\t{Key: \"creator\", Value: post.creator},\n\t\t{Key: \"tipAmount\", Value: post.tipAmount},\n\t\t{Key: \"deleted\", Value: post.deleted},\n\t\t{Key: \"commentsCount\", Value: post.commentsCount},\n\t\t{Key: \"createdAt\", Value: post.createdAt},\n\t\t{Key: \"updatedAt\", Value: post.updatedAt},\n\t\t{Key: \"deletedAt\", Value: post.deletedAt},\n\t})\n\treturn postJSON\n}\n" }, { "Name": "public.gno", - "Body": "package social_feeds\n\nimport (\n\t\"std\"\n\t\"strconv\"\n\t\"strings\"\n\n\t\"gno.land/p/demo/avl\"\n\t\"gno.land/p/demo/teritori/flags_index\"\n\t\"gno.land/p/demo/ufmt\"\n)\n\n// Only registered user can create a new feed\n// For the flexibility when testing, allow all user to create feed\nfunc CreateFeed(name string) FeedID {\n\tpkgpath := std.CurrentRealmPath()\n\n\tfid := incGetFeedID()\n\tcaller := std.PrevRealm().Addr()\n\turl := strings.Replace(pkgpath, \"gno.land\", \"\", -1) + \":\" + name\n\tfeed := newFeed(fid, url, name, caller)\n\tfidkey := feedIDKey(fid)\n\tgFeeds.Set(fidkey, feed)\n\tgFeedsByName.Set(name, feed)\n\treturn feed.id\n}\n\n// Anyone can create a post in a existing feed, allow un-registered users also\nfunc CreatePost(fid FeedID, parentID PostID, catetory uint64, metadata string) PostID {\n\tcaller := std.PrevRealm().Addr()\n\n\tfeed := mustGetFeed(fid)\n\tpost := feed.AddPost(caller, parentID, catetory, metadata)\n\treturn post.id\n}\n\n// Only post's owner can edit post\nfunc EditPost(fid FeedID, pid PostID, category uint64, metadata string) {\n\tcaller := std.PrevRealm().Addr()\n\tfeed := mustGetFeed(fid)\n\tpost := feed.MustGetPost(pid)\n\n\tif caller != post.creator {\n\t\tpanic(\"you are not creator of this post\")\n\t}\n\n\tpost.Update(category, metadata)\n}\n\n// Only feed creator/owner can call this\nfunc SetOwner(fid FeedID, newOwner std.Address) {\n\tcaller := std.PrevRealm().Addr()\n\tfeed := mustGetFeed(fid)\n\n\tif caller != feed.creator && caller != feed.owner {\n\t\tpanic(\"you are not creator/owner of this feed\")\n\t}\n\n\tfeed.owner = newOwner\n}\n\n// Only feed creator/owner or post creator can delete the post\nfunc DeletePost(fid FeedID, pid PostID) {\n\tcaller := std.PrevRealm().Addr()\n\tfeed := mustGetFeed(fid)\n\tpost := feed.MustGetPost(pid)\n\n\tif caller != post.creator && caller != feed.creator && caller != feed.owner {\n\t\tpanic(\"you are nor creator of this post neither creator/owner of the feed\")\n\t}\n\n\tpost.Delete()\n\n\t// If post is comment then decrease comments count on parent\n\tif uint64(post.parentID) != 0 {\n\t\tparent := feed.MustGetPost(post.parentID)\n\t\tparent.commentsCount -= 1\n\t}\n}\n\n// Only feed owner can ban the post\nfunc BanPost(fid FeedID, pid PostID, reason string) {\n\tcaller := std.PrevRealm().Addr()\n\tfeed := mustGetFeed(fid)\n\t_ = feed.MustGetPost(pid)\n\n\t// For experimenting, we ban only the post for now\n\t// TODO: recursive delete/ban comments\n\tif caller != feed.owner {\n\t\tpanic(\"you are owner of the feed\")\n\t}\n\n\tfeed.BanPost(pid)\n\n\tfeed.flags.ClearFlagCount(getFlagID(fid, pid))\n}\n\n// Any one can react post\nfunc ReactPost(fid FeedID, pid PostID, icon string, up bool) {\n\tfeed := mustGetFeed(fid)\n\tpost := feed.MustGetPost(pid)\n\n\tpost.React(icon, up)\n}\n\nfunc TipPost(fid FeedID, pid PostID) {\n\tcaller := std.PrevRealm().Addr()\n\tfeed := mustGetFeed(fid)\n\tpost := feed.MustGetPost(pid)\n\n\tpost.Tip(caller, post.creator)\n}\n\n// Get a list of flagged posts\n// NOTE: We can support multi feeds in the future but for now we will have only 1 feed\n// Return stringified list in format: postStr-count,postStr-count\nfunc GetFlaggedPosts(fid FeedID, offset uint64, limit uint8) string {\n\tfeed := mustGetFeed(fid)\n\n\t// Already sorted by count descending\n\tflags := feed.flags.GetFlags(uint64(limit), offset)\n\n\tvar postList []string\n\tfor _, flagCount := range flags {\n\t\tflagID := flagCount.FlagID\n\n\t\tfeedID, postID := parseFlagID(flagID)\n\t\tif feedID != feed.id {\n\t\t\tcontinue\n\t\t}\n\n\t\tpost := feed.GetPost(postID)\n\t\tpostList = append(postList, ufmt.Sprintf(\"%s\", post))\n\t}\n\n\tSEPARATOR := \",\"\n\tres := strings.Join(postList, SEPARATOR)\n\treturn ufmt.Sprintf(\"[%s]\", res)\n}\n\n// NOTE: due to bug of std.PrevRealm().Addr() return \"\" when query so we user this proxy function temporary\n// in waiting of correct behaviour of std.PrevRealm().Addr()\nfunc GetPosts(fid FeedID, parentID PostID, user string, categories []uint64, offset uint64, limit uint8) string {\n\tcaller := std.PrevRealm().Addr()\n\tdata := GetPostsWithCaller(fid, parentID, caller.String(), user, categories, offset, limit)\n\treturn data\n}\n\nfunc GetPostsWithCaller(fid FeedID, parentID PostID, callerAddrStr string, user string, categories []uint64, offset uint64, limit uint8) string {\n\t// Return flagged posts, we process flagged posts differently using FlagIndex\n\tif len(categories) == 1 && categories[0] == uint64(9) {\n\t\treturn GetFlaggedPosts(fid, offset, limit)\n\t}\n\n\t// BUG: normally std.PrevRealm().Addr() should return a value instead of empty\n\t// Fix is in progress on Gno side\n\tfeed := mustGetFeed(fid)\n\tposts := getPosts(feed, parentID, callerAddrStr, user, categories, offset, limit)\n\n\tSEPARATOR := \",\"\n\tvar postListStr []string\n\n\tfor _, post := range posts {\n\t\tpostListStr = append(postListStr, post.String())\n\t}\n\n\tres := strings.Join(postListStr, SEPARATOR)\n\treturn ufmt.Sprintf(\"[%s]\", res)\n}\n\n// user here is: filter by user\nfunc getPosts(feed *Feed, parentID PostID, callerAddrStr string, user string, categories []uint64, offset uint64, limit uint8) []*Post {\n\tcaller := std.Address(callerAddrStr)\n\n\tvar posts []*Post\n\tvar skipped uint64\n\n\t// Create an avlTree for optimizing the check\n\trequestedCategories := avl.NewTree()\n\tfor _, category := range categories {\n\t\tcatStr := strconv.FormatUint(category, 10)\n\t\trequestedCategories.Set(catStr, true)\n\t}\n\n\tfeed.posts.ReverseIterate(\"\", \"\", func(key string, value interface{}) bool {\n\t\tpost := value.(*Post)\n\n\t\tpostCatStr := strconv.FormatUint(post.category, 10)\n\n\t\t// NOTE: this search mechanism is not efficient, only for demo purpose\n\t\tif post.parentID == parentID && post.deleted == false {\n\t\t\tif requestedCategories.Size() > 0 && !requestedCategories.Has(postCatStr) {\n\t\t\t\treturn false\n\t\t\t}\n\n\t\t\tif user != \"\" && std.Address(user) != post.creator {\n\t\t\t\treturn false\n\t\t\t}\n\n\t\t\t// Filter hidden post\n\t\t\tflagID := getFlagID(feed.id, post.id)\n\t\t\tif feed.flags.HasFlagged(flagID, callerAddrStr) {\n\t\t\t\treturn false\n\t\t\t}\n\n\t\t\t// Check if post is in hidden list\n\t\t\tvalue, exists := feed.hiddenPostsByUser.Get(caller.String())\n\t\t\tif exists {\n\t\t\t\thiddenPosts := value.(*avl.Tree)\n\t\t\t\t// If post.id exists in hiddenPosts tree => that post is hidden\n\t\t\t\tif hiddenPosts.Has(post.id.String()) {\n\t\t\t\t\treturn false\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif skipped < offset {\n\t\t\t\tskipped++\n\t\t\t\treturn false\n\t\t\t}\n\n\t\t\tposts = append(posts, post)\n\t\t}\n\n\t\tif len(posts) == int(limit) {\n\t\t\treturn true\n\t\t}\n\n\t\treturn false\n\t})\n\n\treturn posts\n}\n\n// Get comments list\nfunc GetComments(fid FeedID, parentID PostID, offset uint64, limit uint8) string {\n\treturn GetPosts(fid, parentID, \"\", []uint64{}, offset, limit)\n}\n\n// Get Post\nfunc GetPost(fid FeedID, pid PostID) string {\n\tfeed := mustGetFeed(fid)\n\n\tdata, ok := feed.posts.Get(postIDKey(pid))\n\tif !ok {\n\t\tpanic(\"Unable to get post\")\n\t}\n\n\tpost := data.(*Post)\n\treturn post.String()\n}\n\nfunc FlagPost(fid FeedID, pid PostID) {\n\tcaller := std.PrevRealm().Addr()\n\tfeed := mustGetFeed(fid)\n\n\tfeed.FlagPost(caller, pid)\n}\n\nfunc HidePostForMe(fid FeedID, pid PostID) {\n\tcaller := std.PrevRealm().Addr()\n\tfeed := mustGetFeed(fid)\n\n\tfeed.HidePostForUser(caller, pid)\n}\n\nfunc UnHidePostForMe(fid FeedID, pid PostID) {\n\tcaller := std.PrevRealm().Addr()\n\tfeed := mustGetFeed(fid)\n\n\tfeed.UnHidePostForUser(caller, pid)\n}\n\nfunc GetFlags(fid FeedID, limit uint64, offset uint64) string {\n\tfeed := mustGetFeed(fid)\n\n\ttype FlagCount struct {\n\t\tFlagID flags_index.FlagID\n\t\tCount uint64\n\t}\n\n\tflags := feed.flags.GetFlags(limit, offset)\n\n\tvar res []string\n\tfor _, flag := range flags {\n\t\tres = append(res, ufmt.Sprintf(\"%s:%d\", flag.FlagID, flag.Count))\n\t}\n\n\treturn strings.Join(res, \"|\")\n}\n\n// TODO: allow only creator to call\nfunc GetFeedByID(fid FeedID) *Feed {\n\treturn mustGetFeed(fid)\n}\n\n// TODO: allow only admin to call\nfunc ExportFeedData(fid FeedID) string {\n\tfeed := mustGetFeed(fid)\n\tfeedJSON := feed.ToJSON()\n\treturn feedJSON\n}\n\n// TODO: allow only admin to call\nfunc ImportFeedData(fid FeedID, jsonData string) {\n\tfeed := mustGetFeed(fid)\n\tfeed.FromJSON(jsonData)\n}\n\n// func MigrateFromPreviousFeed(fid feedsV7.FeedID) {\n// \t// Get exported data from previous feeds\n// \tjsonData := feedsV7.ExportFeedData(fid)\n// \tImportFeedData(FeedID(uint64(fid)), jsonData)\n// }\n" + "Body": "package social_feeds\n\nimport (\n\t\"std\"\n\t\"strconv\"\n\t\"strings\"\n\n\t\"gno.land/p/demo/avl\"\n\t\"gno.land/p/demo/teritori/flags_index\"\n\t\"gno.land/p/demo/ufmt\"\n)\n\n// Only registered user can create a new feed\n// For the flexibility when testing, allow all user to create feed\nfunc CreateFeed(name string) FeedID {\n\tpkgpath := std.CurrentRealmPath()\n\n\tfid := incGetFeedID()\n\tcaller := std.PreviousRealm().Address()\n\turl := strings.Replace(pkgpath, \"gno.land\", \"\", -1) + \":\" + name\n\tfeed := newFeed(fid, url, name, caller)\n\tfidkey := feedIDKey(fid)\n\tgFeeds.Set(fidkey, feed)\n\tgFeedsByName.Set(name, feed)\n\treturn feed.id\n}\n\n// Anyone can create a post in a existing feed, allow un-registered users also\nfunc CreatePost(fid FeedID, parentID PostID, catetory uint64, metadata string) PostID {\n\tcaller := std.PreviousRealm().Address()\n\n\tfeed := mustGetFeed(fid)\n\tpost := feed.AddPost(caller, parentID, catetory, metadata)\n\treturn post.id\n}\n\n// Only post's owner can edit post\nfunc EditPost(fid FeedID, pid PostID, category uint64, metadata string) {\n\tcaller := std.PreviousRealm().Address()\n\tfeed := mustGetFeed(fid)\n\tpost := feed.MustGetPost(pid)\n\n\tif caller != post.creator {\n\t\tpanic(\"you are not creator of this post\")\n\t}\n\n\tpost.Update(category, metadata)\n}\n\n// Only feed creator/owner can call this\nfunc SetOwner(fid FeedID, newOwner std.Address) {\n\tcaller := std.PreviousRealm().Address()\n\tfeed := mustGetFeed(fid)\n\n\tif caller != feed.creator && caller != feed.owner {\n\t\tpanic(\"you are not creator/owner of this feed\")\n\t}\n\n\tfeed.owner = newOwner\n}\n\n// Only feed creator/owner or post creator can delete the post\nfunc DeletePost(fid FeedID, pid PostID) {\n\tcaller := std.PreviousRealm().Address()\n\tfeed := mustGetFeed(fid)\n\tpost := feed.MustGetPost(pid)\n\n\tif caller != post.creator && caller != feed.creator && caller != feed.owner {\n\t\tpanic(\"you are nor creator of this post neither creator/owner of the feed\")\n\t}\n\n\tpost.Delete()\n\n\t// If post is comment then decrease comments count on parent\n\tif uint64(post.parentID) != 0 {\n\t\tparent := feed.MustGetPost(post.parentID)\n\t\tparent.commentsCount -= 1\n\t}\n}\n\n// Only feed owner can ban the post\nfunc BanPost(fid FeedID, pid PostID, reason string) {\n\tcaller := std.PreviousRealm().Address()\n\tfeed := mustGetFeed(fid)\n\t_ = feed.MustGetPost(pid)\n\n\t// For experimenting, we ban only the post for now\n\t// TODO: recursive delete/ban comments\n\tif caller != feed.owner {\n\t\tpanic(\"you are owner of the feed\")\n\t}\n\n\tfeed.BanPost(pid)\n\n\tfeed.flags.ClearFlagCount(getFlagID(fid, pid))\n}\n\n// Any one can react post\nfunc ReactPost(fid FeedID, pid PostID, icon string, up bool) {\n\tfeed := mustGetFeed(fid)\n\tpost := feed.MustGetPost(pid)\n\n\tpost.React(icon, up)\n}\n\nfunc TipPost(fid FeedID, pid PostID) {\n\tcaller := std.PreviousRealm().Address()\n\tfeed := mustGetFeed(fid)\n\tpost := feed.MustGetPost(pid)\n\n\tpost.Tip(caller, post.creator)\n}\n\n// Get a list of flagged posts\n// NOTE: We can support multi feeds in the future but for now we will have only 1 feed\n// Return stringified list in format: postStr-count,postStr-count\nfunc GetFlaggedPosts(fid FeedID, offset uint64, limit uint8) string {\n\tfeed := mustGetFeed(fid)\n\n\t// Already sorted by count descending\n\tflags := feed.flags.GetFlags(uint64(limit), offset)\n\n\tvar postList []string\n\tfor _, flagCount := range flags {\n\t\tflagID := flagCount.FlagID\n\n\t\tfeedID, postID := parseFlagID(flagID)\n\t\tif feedID != feed.id {\n\t\t\tcontinue\n\t\t}\n\n\t\tpost := feed.GetPost(postID)\n\t\tpostList = append(postList, ufmt.Sprintf(\"%s\", post))\n\t}\n\n\tSEPARATOR := \",\"\n\tres := strings.Join(postList, SEPARATOR)\n\treturn ufmt.Sprintf(\"[%s]\", res)\n}\n\n// NOTE: due to bug of std.PreviousRealm().Address() return \"\" when query so we user this proxy function temporary\n// in waiting of correct behaviour of std.PreviousRealm().Address()\nfunc GetPosts(fid FeedID, parentID PostID, user string, categories []uint64, offset uint64, limit uint8) string {\n\tcaller := std.PreviousRealm().Address()\n\tdata := GetPostsWithCaller(fid, parentID, caller.String(), user, categories, offset, limit)\n\treturn data\n}\n\nfunc GetPostsWithCaller(fid FeedID, parentID PostID, callerAddrStr string, user string, categories []uint64, offset uint64, limit uint8) string {\n\t// Return flagged posts, we process flagged posts differently using FlagIndex\n\tif len(categories) == 1 && categories[0] == uint64(9) {\n\t\treturn GetFlaggedPosts(fid, offset, limit)\n\t}\n\n\t// BUG: normally std.PreviousRealm().Address() should return a value instead of empty\n\t// Fix is in progress on Gno side\n\tfeed := mustGetFeed(fid)\n\tposts := getPosts(feed, parentID, callerAddrStr, user, categories, offset, limit)\n\n\tSEPARATOR := \",\"\n\tvar postListStr []string\n\n\tfor _, post := range posts {\n\t\tpostListStr = append(postListStr, post.String())\n\t}\n\n\tres := strings.Join(postListStr, SEPARATOR)\n\treturn ufmt.Sprintf(\"[%s]\", res)\n}\n\n// user here is: filter by user\nfunc getPosts(feed *Feed, parentID PostID, callerAddrStr string, user string, categories []uint64, offset uint64, limit uint8) []*Post {\n\tcaller := std.Address(callerAddrStr)\n\n\tvar posts []*Post\n\tvar skipped uint64\n\n\t// Create an avlTree for optimizing the check\n\trequestedCategories := avl.NewTree()\n\tfor _, category := range categories {\n\t\tcatStr := strconv.FormatUint(category, 10)\n\t\trequestedCategories.Set(catStr, true)\n\t}\n\n\tfeed.posts.ReverseIterate(\"\", \"\", func(key string, value interface{}) bool {\n\t\tpost := value.(*Post)\n\n\t\tpostCatStr := strconv.FormatUint(post.category, 10)\n\n\t\t// NOTE: this search mechanism is not efficient, only for demo purpose\n\t\tif post.parentID == parentID && post.deleted == false {\n\t\t\tif requestedCategories.Size() > 0 && !requestedCategories.Has(postCatStr) {\n\t\t\t\treturn false\n\t\t\t}\n\n\t\t\tif user != \"\" && std.Address(user) != post.creator {\n\t\t\t\treturn false\n\t\t\t}\n\n\t\t\t// Filter hidden post\n\t\t\tflagID := getFlagID(feed.id, post.id)\n\t\t\tif feed.flags.HasFlagged(flagID, callerAddrStr) {\n\t\t\t\treturn false\n\t\t\t}\n\n\t\t\t// Check if post is in hidden list\n\t\t\tvalue, exists := feed.hiddenPostsByUser.Get(caller.String())\n\t\t\tif exists {\n\t\t\t\thiddenPosts := value.(*avl.Tree)\n\t\t\t\t// If post.id exists in hiddenPosts tree => that post is hidden\n\t\t\t\tif hiddenPosts.Has(post.id.String()) {\n\t\t\t\t\treturn false\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif skipped < offset {\n\t\t\t\tskipped++\n\t\t\t\treturn false\n\t\t\t}\n\n\t\t\tposts = append(posts, post)\n\t\t}\n\n\t\tif len(posts) == int(limit) {\n\t\t\treturn true\n\t\t}\n\n\t\treturn false\n\t})\n\n\treturn posts\n}\n\n// Get comments list\nfunc GetComments(fid FeedID, parentID PostID, offset uint64, limit uint8) string {\n\treturn GetPosts(fid, parentID, \"\", []uint64{}, offset, limit)\n}\n\n// Get Post\nfunc GetPost(fid FeedID, pid PostID) string {\n\tfeed := mustGetFeed(fid)\n\n\tdata, ok := feed.posts.Get(postIDKey(pid))\n\tif !ok {\n\t\tpanic(\"Unable to get post\")\n\t}\n\n\tpost := data.(*Post)\n\treturn post.String()\n}\n\nfunc FlagPost(fid FeedID, pid PostID) {\n\tcaller := std.PreviousRealm().Address()\n\tfeed := mustGetFeed(fid)\n\n\tfeed.FlagPost(caller, pid)\n}\n\nfunc HidePostForMe(fid FeedID, pid PostID) {\n\tcaller := std.PreviousRealm().Address()\n\tfeed := mustGetFeed(fid)\n\n\tfeed.HidePostForUser(caller, pid)\n}\n\nfunc UnHidePostForMe(fid FeedID, pid PostID) {\n\tcaller := std.PreviousRealm().Address()\n\tfeed := mustGetFeed(fid)\n\n\tfeed.UnHidePostForUser(caller, pid)\n}\n\nfunc GetFlags(fid FeedID, limit uint64, offset uint64) string {\n\tfeed := mustGetFeed(fid)\n\n\ttype FlagCount struct {\n\t\tFlagID flags_index.FlagID\n\t\tCount uint64\n\t}\n\n\tflags := feed.flags.GetFlags(limit, offset)\n\n\tvar res []string\n\tfor _, flag := range flags {\n\t\tres = append(res, ufmt.Sprintf(\"%s:%d\", flag.FlagID, flag.Count))\n\t}\n\n\treturn strings.Join(res, \"|\")\n}\n\n// TODO: allow only creator to call\nfunc GetFeedByID(fid FeedID) *Feed {\n\treturn mustGetFeed(fid)\n}\n\n// TODO: allow only admin to call\nfunc ExportFeedData(fid FeedID) string {\n\tfeed := mustGetFeed(fid)\n\tfeedJSON := feed.ToJSON()\n\treturn feedJSON\n}\n\n// TODO: allow only admin to call\nfunc ImportFeedData(fid FeedID, jsonData string) {\n\tfeed := mustGetFeed(fid)\n\tfeed.FromJSON(jsonData)\n}\n\n// func MigrateFromPreviousFeed(fid feedsV7.FeedID) {\n// \t// Get exported data from previous feeds\n// \tjsonData := feedsV7.ExportFeedData(fid)\n// \tImportFeedData(FeedID(uint64(fid)), jsonData)\n// }\n" }, { "Name": "render.gno", diff --git a/gno.land/pkg/integration/testdata/issue_2283_cacheTypes.txtar b/gno.land/pkg/integration/testdata/issue_2283_cacheTypes.txtar index 95bd48c0144..c5f1cf0ed6d 100644 --- a/gno.land/pkg/integration/testdata/issue_2283_cacheTypes.txtar +++ b/gno.land/pkg/integration/testdata/issue_2283_cacheTypes.txtar @@ -40,7 +40,7 @@ stdout OK! }, { "Name": "feeds_test.gno", - "Body": "package social_feeds\n\nimport (\n\t\"encoding/base64\"\n\t\"fmt\"\n\t\"std\"\n\t\"strconv\"\n\t\"strings\"\n\t\"testing\"\n\n\t\"gno.land/p/demo/avl\"\n\tujson \"gno.land/p/demo/teritori/ujson\"\n\t\"gno.land/p/demo/testutils\"\n\t\"gno.land/r/demo/boards\"\n\t// Fake previous version for testing\n\tfeedsV7 \"gno.land/r/demo/teritori/social_feeds\"\n\t\"gno.land/r/demo/users\"\n)\n\nvar (\n\trootPostID = PostID(0)\n\tpostID1 = PostID(1)\n\tfeedID1 = FeedID(1)\n\tcat1 = uint64(1)\n\tcat2 = uint64(2)\n\tuser = testutils.TestAddress(\"user\")\n\tfilter_all = []uint64{}\n)\n\nfunc getFeed1() *Feed {\n\treturn mustGetFeed(feedID1)\n}\n\nfunc getPost1() *Post {\n\tfeed1 := getFeed1()\n\tpost1 := feed1.MustGetPost(postID1)\n\treturn post1\n}\n\nfunc testCreateFeed(t *testing.T) {\n\tfeedID := CreateFeed(\"teritori1\")\n\tfeed := mustGetFeed(feedID)\n\n\tif feedID != 1 {\n\t\tt.Fatalf(\"expected feedID: 1, got %q.\", feedID)\n\t}\n\n\tif feed.name != \"teritori1\" {\n\t\tt.Fatalf(\"expected feedName: teritori1, got %q.\", feed.name)\n\t}\n}\n\nfunc testCreatePost(t *testing.T) {\n\tmetadata := `{\"gifs\": [], \"files\": [], \"title\": \"\", \"message\": \"testouille\", \"hashtags\": [], \"mentions\": [], \"createdAt\": \"2023-03-29T12:19:04.858Z\", \"updatedAt\": \"2023-03-29T12:19:04.858Z\"}`\n\tpostID := CreatePost(feedID1, rootPostID, cat1, metadata)\n\tfeed := mustGetFeed(feedID1)\n\tpost := feed.MustGetPost(postID)\n\n\tif postID != 1 {\n\t\tt.Fatalf(\"expected postID: 1, got %q.\", postID)\n\t}\n\n\tif post.category != cat1 {\n\t\tt.Fatalf(\"expected categoryID: %q, got %q.\", cat1, post.category)\n\t}\n}\n\nfunc toPostIDsStr(posts []*Post) string {\n\tvar postIDs []string\n\tfor _, post := range posts {\n\t\tpostIDs = append(postIDs, post.id.String())\n\t}\n\n\tpostIDsStr := strings.Join(postIDs, \",\")\n\treturn postIDsStr\n}\n\nfunc testGetPosts(t *testing.T) {\n\tuser := std.Address(\"user\")\n\tstd.TestSetOrigCaller(user)\n\n\tfeedID := CreateFeed(\"teritori10\")\n\tfeed := mustGetFeed(feedID)\n\n\tCreatePost(feedID, rootPostID, cat1, \"post1\")\n\tCreatePost(feedID, rootPostID, cat1, \"post2\")\n\tCreatePost(feedID, rootPostID, cat1, \"post3\")\n\tCreatePost(feedID, rootPostID, cat1, \"post4\")\n\tCreatePost(feedID, rootPostID, cat1, \"post5\")\n\tpostIDToFlagged := CreatePost(feedID, rootPostID, cat1, \"post6\")\n\tpostIDToHide := CreatePost(feedID, rootPostID, cat1, \"post7\")\n\tCreatePost(feedID, rootPostID, cat1, \"post8\")\n\n\tvar posts []*Post\n\tvar postIDsStr string\n\n\t// Query last 3 posts\n\tposts = getPosts(feed, 0, \"\", \"\", []uint64{}, 0, 3)\n\tpostIDsStr = toPostIDsStr(posts)\n\n\tif postIDsStr != \"8,7,6\" {\n\t\tt.Fatalf(\"expected posts order: 8,7,6. Got: %s\", postIDsStr)\n\t}\n\n\t// Query page 2\n\tposts = getPosts(feed, 0, \"\", \"\", []uint64{}, 3, 3)\n\tpostIDsStr = toPostIDsStr(posts)\n\tif postIDsStr != \"5,4,3\" {\n\t\tt.Fatalf(\"expected posts order: 5,4,3. Got: %s\", postIDsStr)\n\t}\n\n\t// Exclude hidden post\n\tHidePostForMe(feed.id, postIDToHide)\n\n\tposts = getPosts(feed, 0, user.String(), \"\", []uint64{}, 0, 3)\n\tpostIDsStr = toPostIDsStr(posts)\n\n\tif postIDsStr != \"8,6,5\" {\n\t\tt.Fatalf(\"expected posts order: 8,6,5. Got: %s\", postIDsStr)\n\t}\n\n\t// Exclude flagged post\n\tFlagPost(feed.id, postIDToFlagged)\n\n\tposts = getPosts(feed, 0, user.String(), \"\", []uint64{}, 0, 3)\n\tpostIDsStr = toPostIDsStr(posts)\n\n\tif postIDsStr != \"8,5,4\" {\n\t\tt.Fatalf(\"expected posts order: 8,5,4. Got: %s\", postIDsStr)\n\t}\n\n\t// Pagination with hidden/flagged posts\n\tposts = getPosts(feed, 0, user.String(), \"\", []uint64{}, 3, 3)\n\tpostIDsStr = toPostIDsStr(posts)\n\n\tif postIDsStr != \"3,2,1\" {\n\t\tt.Fatalf(\"expected posts order: 3,2,1. Got: %s\", postIDsStr)\n\t}\n\n\t// Query out of range\n\tposts = getPosts(feed, 0, user.String(), \"\", []uint64{}, 6, 3)\n\tpostIDsStr = toPostIDsStr(posts)\n\n\tif postIDsStr != \"\" {\n\t\tt.Fatalf(\"expected posts order: ''. Got: %s\", postIDsStr)\n\t}\n}\n\nfunc testReactPost(t *testing.T) {\n\tfeed := getFeed1()\n\tpost := getPost1()\n\n\ticon := \"🥰\"\n\tReactPost(feed.id, post.id, icon, true)\n\n\t// Set reaction\n\treactionCount_, ok := post.reactions.Get(\"🥰\")\n\tif !ok {\n\t\tt.Fatalf(\"expected 🥰 exists\")\n\t}\n\n\treactionCount := reactionCount_.(int)\n\tif reactionCount != 1 {\n\t\tt.Fatalf(\"expected reactionCount: 1, got %q.\", reactionCount)\n\t}\n\n\t// Unset reaction\n\tReactPost(feed.id, post.id, icon, false)\n\t_, exist := post.reactions.Get(\"🥰\")\n\tif exist {\n\t\tt.Fatalf(\"expected 🥰 not exist\")\n\t}\n}\n\nfunc testCreateAndDeleteComment(t *testing.T) {\n\tfeed1 := getFeed1()\n\tpost1 := getPost1()\n\n\tmetadata := `empty_meta_data`\n\n\tcommentID1 := CreatePost(feed1.id, post1.id, cat1, metadata)\n\tcommentID2 := CreatePost(feed1.id, post1.id, cat1, metadata)\n\tcomment2 := feed1.MustGetPost(commentID2)\n\n\tif comment2.id != 3 { // 1 post + 2 comments = 3\n\t\tt.Fatalf(\"expected comment postID: 3, got %q.\", comment2.id)\n\t}\n\n\tif comment2.parentID != post1.id {\n\t\tt.Fatalf(\"expected comment parentID: %q, got %q.\", post1.id, comment2.parentID)\n\t}\n\n\t// Check comment count on parent\n\tif post1.commentsCount != 2 {\n\t\tt.Fatalf(\"expected comments count: 2, got %d.\", post1.commentsCount)\n\t}\n\n\t// Get comments\n\tcomments := GetComments(feed1.id, post1.id, 0, 10)\n\tcommentsParsed := ujson.ParseSlice(comments)\n\n\tif len(commentsParsed) != 2 {\n\t\tt.Fatalf(\"expected encoded comments: 2, got %q.\", commentsParsed)\n\t}\n\n\t// Delete 1 comment\n\tDeletePost(feed1.id, comment2.id)\n\tcomments = GetComments(feed1.id, post1.id, 0, 10)\n\tcommentsParsed = ujson.ParseSlice(comments)\n\n\tif len(commentsParsed) != 1 {\n\t\tt.Fatalf(\"expected encoded comments: 1, got %q.\", commentsParsed)\n\t}\n\n\t// Check comment count on parent\n\tif post1.commentsCount != 1 {\n\t\tt.Fatalf(\"expected comments count: 1, got %d.\", post1.commentsCount)\n\t}\n}\n\nfunc countPosts(feedID FeedID, categories []uint64, limit uint8) int {\n\toffset := uint64(0)\n\n\tpostsStr := GetPosts(feedID, 0, \"\", categories, offset, limit)\n\tif postsStr == \"[]\" {\n\t\treturn 0\n\t}\n\n\tparsedPosts := ujson.ParseSlice(postsStr)\n\tpostsCount := len(parsedPosts)\n\treturn postsCount\n}\n\nfunc countPostsByUser(feedID FeedID, user string) int {\n\toffset := uint64(0)\n\tlimit := uint8(10)\n\n\tpostsStr := GetPosts(feedID, 0, user, []uint64{}, offset, limit)\n\tif postsStr == \"[]\" {\n\t\treturn 0\n\t}\n\n\tparsedPosts := ujson.ParseSlice(postsStr)\n\tpostsCount := len(parsedPosts)\n\treturn postsCount\n}\n\nfunc testFilterByCategories(t *testing.T) {\n\t// // Re-add reaction to test post list\n\t// ReactPost(1, postID, \"🥰\", true)\n\t// ReactPost(1, postID, \"😇\", true)\n\n\tfilter_cat1 := []uint64{1}\n\tfilter_cat1_2 := []uint64{1, 2}\n\tfilter_cat9 := []uint64{9}\n\tfilter_cat1_2_9 := []uint64{1, 2, 9}\n\n\tfeedID2 := CreateFeed(\"teritori2\")\n\tfeed2 := mustGetFeed(feedID2)\n\n\t// Create 2 posts on root with cat1\n\tpostID1 := CreatePost(feed2.id, rootPostID, cat1, \"metadata\")\n\tpostID2 := CreatePost(feed2.id, rootPostID, cat1, \"metadata\")\n\n\t// Create 1 posts on root with cat2\n\tpostID3 := CreatePost(feed2.id, rootPostID, cat2, \"metadata\")\n\n\t// Create comments on post 1\n\tcommentPostID1 := CreatePost(feed2.id, postID1, cat1, \"metadata\")\n\n\t// cat1: Should return max = limit\n\tif count := countPosts(feed2.id, filter_cat1, 1); count != 1 {\n\t\tt.Fatalf(\"expected posts count: 1, got %q.\", count)\n\t}\n\n\t// cat1: Should return max = total\n\tif count := countPosts(feed2.id, filter_cat1, 10); count != 2 {\n\t\tt.Fatalf(\"expected posts count: 2, got %q.\", count)\n\t}\n\n\t// cat 1 + 2: Should return max = limit\n\tif count := countPosts(feed2.id, filter_cat1_2, 2); count != 2 {\n\t\tt.Fatalf(\"expected posts count: 2, got %q.\", count)\n\t}\n\n\t// cat 1 + 2: Should return max = total on both\n\tif count := countPosts(feed2.id, filter_cat1_2, 10); count != 3 {\n\t\tt.Fatalf(\"expected posts count: 3, got %q.\", count)\n\t}\n\n\t// cat 1, 2, 9: Should return total of 1, 2\n\tif count := countPosts(feed2.id, filter_cat1_2_9, 10); count != 3 {\n\t\tt.Fatalf(\"expected posts count: 3, got %q.\", count)\n\t}\n\n\t// cat 9: Should return 0\n\tif count := countPosts(feed2.id, filter_cat9, 10); count != 0 {\n\t\tt.Fatalf(\"expected posts count: 0, got %q.\", count)\n\t}\n\n\t// cat all: should return all\n\tif count := countPosts(feed2.id, filter_all, 10); count != 3 {\n\t\tt.Fatalf(\"expected posts count: 3, got %q.\", count)\n\t}\n\n\t// add comments should not impact the results\n\tCreatePost(feed2.id, postID1, cat1, \"metadata\")\n\tCreatePost(feed2.id, postID2, cat1, \"metadata\")\n\n\tif count := countPosts(feed2.id, filter_all, 10); count != 3 {\n\t\tt.Fatalf(\"expected posts count: 3, got %q.\", count)\n\t}\n\n\t// delete a post should affect the result\n\tDeletePost(feed2.id, postID1)\n\n\tif count := countPosts(feed2.id, filter_all, 10); count != 2 {\n\t\tt.Fatalf(\"expected posts count: 2, got %q.\", count)\n\t}\n}\n\nfunc testTipPost(t *testing.T) {\n\tcreator := testutils.TestAddress(\"creator\")\n\tstd.TestIssueCoins(creator, std.Coins{{\"ugnot\", 100_000_000}})\n\n\t// NOTE: Dont know why the address should be this to be able to call banker (= std.GetCallerAt(1))\n\ttipper := testutils.TestAddress(\"tipper\")\n\tstd.TestIssueCoins(tipper, std.Coins{{\"ugnot\", 50_000_000}})\n\n\tbanker := std.GetBanker(std.BankerTypeReadonly)\n\n\t// Check Original coins of creator/tipper\n\tif coins := banker.GetCoins(creator); coins[0].Amount != 100_000_000 {\n\t\tt.Fatalf(\"expected creator coin count: 100_000_000, got %d.\", coins[0].Amount)\n\t}\n\n\tif coins := banker.GetCoins(tipper); coins[0].Amount != 50_000_000 {\n\t\tt.Fatalf(\"expected tipper coin count: 50_000_000, got %d.\", coins[0].Amount)\n\t}\n\n\t// Creator creates feed, post\n\tstd.TestSetOrigCaller(creator)\n\n\tfeedID3 := CreateFeed(\"teritori3\")\n\tfeed3 := mustGetFeed(feedID3)\n\n\tpostID1 := CreatePost(feed3.id, rootPostID, cat1, \"metadata\")\n\tpost1 := feed3.MustGetPost(postID1)\n\n\t// Tiper tips the ppst\n\tstd.TestSetOrigCaller(tipper)\n\tstd.TestSetOrigSend(std.Coins{{\"ugnot\", 1_000_000}}, nil)\n\tTipPost(feed3.id, post1.id)\n\n\t// Coin must be increased for creator\n\tif coins := banker.GetCoins(creator); coins[0].Amount != 101_000_000 {\n\t\tt.Fatalf(\"expected creator coin after beging tipped: 101_000_000, got %d.\", coins[0].Amount)\n\t}\n\n\t// Total tip amount should increased\n\tif post1.tipAmount != 1_000_000 {\n\t\tt.Fatalf(\"expected total tipAmount: 1_000_000, got %d.\", post1.tipAmount)\n\t}\n\n\t// Add more tip should update this total\n\tstd.TestSetOrigSend(std.Coins{{\"ugnot\", 2_000_000}}, nil)\n\tTipPost(feed3.id, post1.id)\n\n\tif post1.tipAmount != 3_000_000 {\n\t\tt.Fatalf(\"expected total tipAmount: 3_000_000, got %d.\", post1.tipAmount)\n\t}\n}\n\nfunc testFlagPost(t *testing.T) {\n\tflagger := testutils.TestAddress(\"flagger\")\n\n\tfeedID9 := CreateFeed(\"teritori9\")\n\tfeed9 := mustGetFeed(feedID9)\n\n\tCreatePost(feed9.id, rootPostID, cat1, \"metadata1\")\n\tpid := CreatePost(feed9.id, rootPostID, cat1, \"metadata1\")\n\n\t// Flag post\n\tstd.TestSetOrigCaller(flagger)\n\tFlagPost(feed9.id, pid)\n\n\t// Another user flags\n\tanother := testutils.TestAddress(\"another\")\n\tstd.TestSetOrigCaller(another)\n\tFlagPost(feed9.id, pid)\n\n\tflaggedPostsStr := GetFlaggedPosts(feed9.id, 0, 10)\n\tparsed := ujson.ParseSlice(flaggedPostsStr)\n\tif flaggedPostsCount := len(parsed); flaggedPostsCount != 1 {\n\t\tt.Fatalf(\"expected flagged posts: 1, got %d.\", flaggedPostsCount)\n\t}\n}\n\nfunc testFilterUser(t *testing.T) {\n\tuser1 := testutils.TestAddress(\"user1\")\n\tuser2 := testutils.TestAddress(\"user2\")\n\n\t// User1 create 2 posts\n\tstd.TestSetOrigCaller(user1)\n\n\tfeedID4 := CreateFeed(\"teritori4\")\n\tfeed4 := mustGetFeed(feedID4)\n\n\tCreatePost(feed4.id, rootPostID, cat1, `{\"metadata\": \"value\"}`)\n\tCreatePost(feed4.id, rootPostID, cat1, `{\"metadata2\": \"value\"}`)\n\n\t// User2 create 1 post\n\tstd.TestSetOrigCaller(user2)\n\tCreatePost(feed4.id, rootPostID, cat1, `{\"metadata\": \"value\"}`)\n\n\tif count := countPostsByUser(feed4.id, user1.String()); count != 2 {\n\t\tt.Fatalf(\"expected total posts by user1: 2, got %d.\", count)\n\t}\n\n\tif count := countPostsByUser(feed4.id, user2.String()); count != 1 {\n\t\tt.Fatalf(\"expected total posts by user2: 1, got %d.\", count)\n\t}\n\n\tif count := countPostsByUser(feed4.id, \"\"); count != 3 {\n\t\tt.Fatalf(\"expected total posts: 3, got %d.\", count)\n\t}\n}\n\nfunc testHidePostForMe(t *testing.T) {\n\tuser := std.Address(\"user\")\n\tstd.TestSetOrigCaller(user)\n\n\tfeedID8 := CreateFeed(\"teritor8\")\n\tfeed8 := mustGetFeed(feedID8)\n\n\tpostIDToHide := CreatePost(feed8.id, rootPostID, cat1, `{\"metadata\": \"value\"}`)\n\tpostID := CreatePost(feed8.id, rootPostID, cat1, `{\"metadata\": \"value\"}`)\n\n\tif count := countPosts(feed8.id, filter_all, 10); count != 2 {\n\t\tt.Fatalf(\"expected posts count: 2, got %q.\", count)\n\t}\n\n\t// Hide a post for me\n\tHidePostForMe(feed8.id, postIDToHide)\n\n\tif count := countPosts(feed8.id, filter_all, 10); count != 1 {\n\t\tt.Fatalf(\"expected posts count after hidding: 1, got %q.\", count)\n\t}\n\n\t// Query from another user should return full list\n\tanother := std.Address(\"another\")\n\tstd.TestSetOrigCaller(another)\n\n\tif count := countPosts(feed8.id, filter_all, 10); count != 2 {\n\t\tt.Fatalf(\"expected posts count from another: 2, got %q.\", count)\n\t}\n\n\t// UnHide a post for me\n\tstd.TestSetOrigCaller(user)\n\tUnHidePostForMe(feed8.id, postIDToHide)\n\n\tif count := countPosts(feed8.id, filter_all, 10); count != 2 {\n\t\tt.Fatalf(\"expected posts count after unhidding: 2, got %q.\", count)\n\t}\n}\n\nfunc testMigrateFeedData(t *testing.T) string {\n\tfeedID := feedsV7.CreateFeed(\"teritor11\")\n\n\t// Post to test\n\tpostID := feedsV7.CreatePost(feedID, feedsV7.PostID(0), 2, `{\"metadata\": \"value\"}`)\n\tfeedsV7.ReactPost(feedID, postID, \"🇬🇸\", true)\n\n\t// Add comment to post\n\tcommentID := feedsV7.CreatePost(feedID, postID, 2, `{\"comment1\": \"value\"}`)\n\tfeedsV7.ReactPost(feedID, commentID, \"🇬🇸\", true)\n\n\t// // Post with json metadata\n\tfeedsV7.CreatePost(feedID, feedsV7.PostID(0), 2, `{'a':1}`)\n\n\t// Expect: should convert feed data to JSON successfully without error\n\tdataJSON := feedsV7.ExportFeedData(feedID)\n\tif dataJSON == \"\" {\n\t\tt.Fatalf(\"expected feed data exported successfully\")\n\t}\n\n\t// Import data =====================================\n\tImportFeedData(FeedID(uint64(feedID)), dataJSON)\n\n\t// Test public func\n\t// MigrateFromPreviousFeed(feedID)\n}\n\nfunc Test(t *testing.T) {\n\ttestCreateFeed(t)\n\n\ttestCreatePost(t)\n\n\ttestGetPosts(t)\n\n\ttestReactPost(t)\n\n\ttestCreateAndDeleteComment(t)\n\n\ttestFilterByCategories(t)\n\n\ttestTipPost(t)\n\n\ttestFilterUser(t)\n\n\ttestFlagPost(t)\n\n\ttestHidePostForMe(t)\n\n\ttestMigrateFeedData(t)\n}\n" + "Body": "package social_feeds\n\nimport (\n\t\"encoding/base64\"\n\t\"fmt\"\n\t\"std\"\n\t\"strconv\"\n\t\"strings\"\n\t\"testing\"\n\n\t\"gno.land/p/demo/avl\"\n\tujson \"gno.land/p/demo/teritori/ujson\"\n\t\"gno.land/p/demo/testutils\"\n\t\"gno.land/r/demo/boards\"\n\t// Fake previous version for testing\n\tfeedsV7 \"gno.land/r/demo/teritori/social_feeds\"\n\t\"gno.land/r/demo/users\"\n)\n\nvar (\n\trootPostID = PostID(0)\n\tpostID1 = PostID(1)\n\tfeedID1 = FeedID(1)\n\tcat1 = uint64(1)\n\tcat2 = uint64(2)\n\tuser = testutils.TestAddress(\"user\")\n\tfilter_all = []uint64{}\n)\n\nfunc getFeed1() *Feed {\n\treturn mustGetFeed(feedID1)\n}\n\nfunc getPost1() *Post {\n\tfeed1 := getFeed1()\n\tpost1 := feed1.MustGetPost(postID1)\n\treturn post1\n}\n\nfunc testCreateFeed(t *testing.T) {\n\tfeedID := CreateFeed(\"teritori1\")\n\tfeed := mustGetFeed(feedID)\n\n\tif feedID != 1 {\n\t\tt.Fatalf(\"expected feedID: 1, got %q.\", feedID)\n\t}\n\n\tif feed.name != \"teritori1\" {\n\t\tt.Fatalf(\"expected feedName: teritori1, got %q.\", feed.name)\n\t}\n}\n\nfunc testCreatePost(t *testing.T) {\n\tmetadata := `{\"gifs\": [], \"files\": [], \"title\": \"\", \"message\": \"testouille\", \"hashtags\": [], \"mentions\": [], \"createdAt\": \"2023-03-29T12:19:04.858Z\", \"updatedAt\": \"2023-03-29T12:19:04.858Z\"}`\n\tpostID := CreatePost(feedID1, rootPostID, cat1, metadata)\n\tfeed := mustGetFeed(feedID1)\n\tpost := feed.MustGetPost(postID)\n\n\tif postID != 1 {\n\t\tt.Fatalf(\"expected postID: 1, got %q.\", postID)\n\t}\n\n\tif post.category != cat1 {\n\t\tt.Fatalf(\"expected categoryID: %q, got %q.\", cat1, post.category)\n\t}\n}\n\nfunc toPostIDsStr(posts []*Post) string {\n\tvar postIDs []string\n\tfor _, post := range posts {\n\t\tpostIDs = append(postIDs, post.id.String())\n\t}\n\n\tpostIDsStr := strings.Join(postIDs, \",\")\n\treturn postIDsStr\n}\n\nfunc testGetPosts(t *testing.T) {\n\tuser := std.Address(\"user\")\n\tstd.TestSetOriginCaller(user)\n\n\tfeedID := CreateFeed(\"teritori10\")\n\tfeed := mustGetFeed(feedID)\n\n\tCreatePost(feedID, rootPostID, cat1, \"post1\")\n\tCreatePost(feedID, rootPostID, cat1, \"post2\")\n\tCreatePost(feedID, rootPostID, cat1, \"post3\")\n\tCreatePost(feedID, rootPostID, cat1, \"post4\")\n\tCreatePost(feedID, rootPostID, cat1, \"post5\")\n\tpostIDToFlagged := CreatePost(feedID, rootPostID, cat1, \"post6\")\n\tpostIDToHide := CreatePost(feedID, rootPostID, cat1, \"post7\")\n\tCreatePost(feedID, rootPostID, cat1, \"post8\")\n\n\tvar posts []*Post\n\tvar postIDsStr string\n\n\t// Query last 3 posts\n\tposts = getPosts(feed, 0, \"\", \"\", []uint64{}, 0, 3)\n\tpostIDsStr = toPostIDsStr(posts)\n\n\tif postIDsStr != \"8,7,6\" {\n\t\tt.Fatalf(\"expected posts order: 8,7,6. Got: %s\", postIDsStr)\n\t}\n\n\t// Query page 2\n\tposts = getPosts(feed, 0, \"\", \"\", []uint64{}, 3, 3)\n\tpostIDsStr = toPostIDsStr(posts)\n\tif postIDsStr != \"5,4,3\" {\n\t\tt.Fatalf(\"expected posts order: 5,4,3. Got: %s\", postIDsStr)\n\t}\n\n\t// Exclude hidden post\n\tHidePostForMe(feed.id, postIDToHide)\n\n\tposts = getPosts(feed, 0, user.String(), \"\", []uint64{}, 0, 3)\n\tpostIDsStr = toPostIDsStr(posts)\n\n\tif postIDsStr != \"8,6,5\" {\n\t\tt.Fatalf(\"expected posts order: 8,6,5. Got: %s\", postIDsStr)\n\t}\n\n\t// Exclude flagged post\n\tFlagPost(feed.id, postIDToFlagged)\n\n\tposts = getPosts(feed, 0, user.String(), \"\", []uint64{}, 0, 3)\n\tpostIDsStr = toPostIDsStr(posts)\n\n\tif postIDsStr != \"8,5,4\" {\n\t\tt.Fatalf(\"expected posts order: 8,5,4. Got: %s\", postIDsStr)\n\t}\n\n\t// Pagination with hidden/flagged posts\n\tposts = getPosts(feed, 0, user.String(), \"\", []uint64{}, 3, 3)\n\tpostIDsStr = toPostIDsStr(posts)\n\n\tif postIDsStr != \"3,2,1\" {\n\t\tt.Fatalf(\"expected posts order: 3,2,1. Got: %s\", postIDsStr)\n\t}\n\n\t// Query out of range\n\tposts = getPosts(feed, 0, user.String(), \"\", []uint64{}, 6, 3)\n\tpostIDsStr = toPostIDsStr(posts)\n\n\tif postIDsStr != \"\" {\n\t\tt.Fatalf(\"expected posts order: ''. Got: %s\", postIDsStr)\n\t}\n}\n\nfunc testReactPost(t *testing.T) {\n\tfeed := getFeed1()\n\tpost := getPost1()\n\n\ticon := \"🥰\"\n\tReactPost(feed.id, post.id, icon, true)\n\n\t// Set reaction\n\treactionCount_, ok := post.reactions.Get(\"🥰\")\n\tif !ok {\n\t\tt.Fatalf(\"expected 🥰 exists\")\n\t}\n\n\treactionCount := reactionCount_.(int)\n\tif reactionCount != 1 {\n\t\tt.Fatalf(\"expected reactionCount: 1, got %q.\", reactionCount)\n\t}\n\n\t// Unset reaction\n\tReactPost(feed.id, post.id, icon, false)\n\t_, exist := post.reactions.Get(\"🥰\")\n\tif exist {\n\t\tt.Fatalf(\"expected 🥰 not exist\")\n\t}\n}\n\nfunc testCreateAndDeleteComment(t *testing.T) {\n\tfeed1 := getFeed1()\n\tpost1 := getPost1()\n\n\tmetadata := `empty_meta_data`\n\n\tcommentID1 := CreatePost(feed1.id, post1.id, cat1, metadata)\n\tcommentID2 := CreatePost(feed1.id, post1.id, cat1, metadata)\n\tcomment2 := feed1.MustGetPost(commentID2)\n\n\tif comment2.id != 3 { // 1 post + 2 comments = 3\n\t\tt.Fatalf(\"expected comment postID: 3, got %q.\", comment2.id)\n\t}\n\n\tif comment2.parentID != post1.id {\n\t\tt.Fatalf(\"expected comment parentID: %q, got %q.\", post1.id, comment2.parentID)\n\t}\n\n\t// Check comment count on parent\n\tif post1.commentsCount != 2 {\n\t\tt.Fatalf(\"expected comments count: 2, got %d.\", post1.commentsCount)\n\t}\n\n\t// Get comments\n\tcomments := GetComments(feed1.id, post1.id, 0, 10)\n\tcommentsParsed := ujson.ParseSlice(comments)\n\n\tif len(commentsParsed) != 2 {\n\t\tt.Fatalf(\"expected encoded comments: 2, got %q.\", commentsParsed)\n\t}\n\n\t// Delete 1 comment\n\tDeletePost(feed1.id, comment2.id)\n\tcomments = GetComments(feed1.id, post1.id, 0, 10)\n\tcommentsParsed = ujson.ParseSlice(comments)\n\n\tif len(commentsParsed) != 1 {\n\t\tt.Fatalf(\"expected encoded comments: 1, got %q.\", commentsParsed)\n\t}\n\n\t// Check comment count on parent\n\tif post1.commentsCount != 1 {\n\t\tt.Fatalf(\"expected comments count: 1, got %d.\", post1.commentsCount)\n\t}\n}\n\nfunc countPosts(feedID FeedID, categories []uint64, limit uint8) int {\n\toffset := uint64(0)\n\n\tpostsStr := GetPosts(feedID, 0, \"\", categories, offset, limit)\n\tif postsStr == \"[]\" {\n\t\treturn 0\n\t}\n\n\tparsedPosts := ujson.ParseSlice(postsStr)\n\tpostsCount := len(parsedPosts)\n\treturn postsCount\n}\n\nfunc countPostsByUser(feedID FeedID, user string) int {\n\toffset := uint64(0)\n\tlimit := uint8(10)\n\n\tpostsStr := GetPosts(feedID, 0, user, []uint64{}, offset, limit)\n\tif postsStr == \"[]\" {\n\t\treturn 0\n\t}\n\n\tparsedPosts := ujson.ParseSlice(postsStr)\n\tpostsCount := len(parsedPosts)\n\treturn postsCount\n}\n\nfunc testFilterByCategories(t *testing.T) {\n\t// // Re-add reaction to test post list\n\t// ReactPost(1, postID, \"🥰\", true)\n\t// ReactPost(1, postID, \"😇\", true)\n\n\tfilter_cat1 := []uint64{1}\n\tfilter_cat1_2 := []uint64{1, 2}\n\tfilter_cat9 := []uint64{9}\n\tfilter_cat1_2_9 := []uint64{1, 2, 9}\n\n\tfeedID2 := CreateFeed(\"teritori2\")\n\tfeed2 := mustGetFeed(feedID2)\n\n\t// Create 2 posts on root with cat1\n\tpostID1 := CreatePost(feed2.id, rootPostID, cat1, \"metadata\")\n\tpostID2 := CreatePost(feed2.id, rootPostID, cat1, \"metadata\")\n\n\t// Create 1 posts on root with cat2\n\tpostID3 := CreatePost(feed2.id, rootPostID, cat2, \"metadata\")\n\n\t// Create comments on post 1\n\tcommentPostID1 := CreatePost(feed2.id, postID1, cat1, \"metadata\")\n\n\t// cat1: Should return max = limit\n\tif count := countPosts(feed2.id, filter_cat1, 1); count != 1 {\n\t\tt.Fatalf(\"expected posts count: 1, got %q.\", count)\n\t}\n\n\t// cat1: Should return max = total\n\tif count := countPosts(feed2.id, filter_cat1, 10); count != 2 {\n\t\tt.Fatalf(\"expected posts count: 2, got %q.\", count)\n\t}\n\n\t// cat 1 + 2: Should return max = limit\n\tif count := countPosts(feed2.id, filter_cat1_2, 2); count != 2 {\n\t\tt.Fatalf(\"expected posts count: 2, got %q.\", count)\n\t}\n\n\t// cat 1 + 2: Should return max = total on both\n\tif count := countPosts(feed2.id, filter_cat1_2, 10); count != 3 {\n\t\tt.Fatalf(\"expected posts count: 3, got %q.\", count)\n\t}\n\n\t// cat 1, 2, 9: Should return total of 1, 2\n\tif count := countPosts(feed2.id, filter_cat1_2_9, 10); count != 3 {\n\t\tt.Fatalf(\"expected posts count: 3, got %q.\", count)\n\t}\n\n\t// cat 9: Should return 0\n\tif count := countPosts(feed2.id, filter_cat9, 10); count != 0 {\n\t\tt.Fatalf(\"expected posts count: 0, got %q.\", count)\n\t}\n\n\t// cat all: should return all\n\tif count := countPosts(feed2.id, filter_all, 10); count != 3 {\n\t\tt.Fatalf(\"expected posts count: 3, got %q.\", count)\n\t}\n\n\t// add comments should not impact the results\n\tCreatePost(feed2.id, postID1, cat1, \"metadata\")\n\tCreatePost(feed2.id, postID2, cat1, \"metadata\")\n\n\tif count := countPosts(feed2.id, filter_all, 10); count != 3 {\n\t\tt.Fatalf(\"expected posts count: 3, got %q.\", count)\n\t}\n\n\t// delete a post should affect the result\n\tDeletePost(feed2.id, postID1)\n\n\tif count := countPosts(feed2.id, filter_all, 10); count != 2 {\n\t\tt.Fatalf(\"expected posts count: 2, got %q.\", count)\n\t}\n}\n\nfunc testTipPost(t *testing.T) {\n\tcreator := testutils.TestAddress(\"creator\")\n\tstd.TestIssueCoins(creator, std.Coins{{\"ugnot\", 100_000_000}})\n\n\t// NOTE: Dont know why the address should be this to be able to call banker (= std.CallerAt(1))\n\ttipper := testutils.TestAddress(\"tipper\")\n\tstd.TestIssueCoins(tipper, std.Coins{{\"ugnot\", 50_000_000}})\n\n\tbanker := std.NewBanker(std.BankerTypeReadonly)\n\n\t// Check Original coins of creator/tipper\n\tif coins := banker.GetCoins(creator); coins[0].Amount != 100_000_000 {\n\t\tt.Fatalf(\"expected creator coin count: 100_000_000, got %d.\", coins[0].Amount)\n\t}\n\n\tif coins := banker.GetCoins(tipper); coins[0].Amount != 50_000_000 {\n\t\tt.Fatalf(\"expected tipper coin count: 50_000_000, got %d.\", coins[0].Amount)\n\t}\n\n\t// Creator creates feed, post\n\tstd.TestSetOriginCaller(creator)\n\n\tfeedID3 := CreateFeed(\"teritori3\")\n\tfeed3 := mustGetFeed(feedID3)\n\n\tpostID1 := CreatePost(feed3.id, rootPostID, cat1, \"metadata\")\n\tpost1 := feed3.MustGetPost(postID1)\n\n\t// Tiper tips the ppst\n\tstd.TestSetOriginCaller(tipper)\n\tstd.TestSetOriginSend(std.Coins{{\"ugnot\", 1_000_000}}, nil)\n\tTipPost(feed3.id, post1.id)\n\n\t// Coin must be increased for creator\n\tif coins := banker.GetCoins(creator); coins[0].Amount != 101_000_000 {\n\t\tt.Fatalf(\"expected creator coin after beging tipped: 101_000_000, got %d.\", coins[0].Amount)\n\t}\n\n\t// Total tip amount should increased\n\tif post1.tipAmount != 1_000_000 {\n\t\tt.Fatalf(\"expected total tipAmount: 1_000_000, got %d.\", post1.tipAmount)\n\t}\n\n\t// Add more tip should update this total\n\tstd.TestSetOriginSend(std.Coins{{\"ugnot\", 2_000_000}}, nil)\n\tTipPost(feed3.id, post1.id)\n\n\tif post1.tipAmount != 3_000_000 {\n\t\tt.Fatalf(\"expected total tipAmount: 3_000_000, got %d.\", post1.tipAmount)\n\t}\n}\n\nfunc testFlagPost(t *testing.T) {\n\tflagger := testutils.TestAddress(\"flagger\")\n\n\tfeedID9 := CreateFeed(\"teritori9\")\n\tfeed9 := mustGetFeed(feedID9)\n\n\tCreatePost(feed9.id, rootPostID, cat1, \"metadata1\")\n\tpid := CreatePost(feed9.id, rootPostID, cat1, \"metadata1\")\n\n\t// Flag post\n\tstd.TestSetOriginCaller(flagger)\n\tFlagPost(feed9.id, pid)\n\n\t// Another user flags\n\tanother := testutils.TestAddress(\"another\")\n\tstd.TestSetOriginCaller(another)\n\tFlagPost(feed9.id, pid)\n\n\tflaggedPostsStr := GetFlaggedPosts(feed9.id, 0, 10)\n\tparsed := ujson.ParseSlice(flaggedPostsStr)\n\tif flaggedPostsCount := len(parsed); flaggedPostsCount != 1 {\n\t\tt.Fatalf(\"expected flagged posts: 1, got %d.\", flaggedPostsCount)\n\t}\n}\n\nfunc testFilterUser(t *testing.T) {\n\tuser1 := testutils.TestAddress(\"user1\")\n\tuser2 := testutils.TestAddress(\"user2\")\n\n\t// User1 create 2 posts\n\tstd.TestSetOriginCaller(user1)\n\n\tfeedID4 := CreateFeed(\"teritori4\")\n\tfeed4 := mustGetFeed(feedID4)\n\n\tCreatePost(feed4.id, rootPostID, cat1, `{\"metadata\": \"value\"}`)\n\tCreatePost(feed4.id, rootPostID, cat1, `{\"metadata2\": \"value\"}`)\n\n\t// User2 create 1 post\n\tstd.TestSetOriginCaller(user2)\n\tCreatePost(feed4.id, rootPostID, cat1, `{\"metadata\": \"value\"}`)\n\n\tif count := countPostsByUser(feed4.id, user1.String()); count != 2 {\n\t\tt.Fatalf(\"expected total posts by user1: 2, got %d.\", count)\n\t}\n\n\tif count := countPostsByUser(feed4.id, user2.String()); count != 1 {\n\t\tt.Fatalf(\"expected total posts by user2: 1, got %d.\", count)\n\t}\n\n\tif count := countPostsByUser(feed4.id, \"\"); count != 3 {\n\t\tt.Fatalf(\"expected total posts: 3, got %d.\", count)\n\t}\n}\n\nfunc testHidePostForMe(t *testing.T) {\n\tuser := std.Address(\"user\")\n\tstd.TestSetOriginCaller(user)\n\n\tfeedID8 := CreateFeed(\"teritor8\")\n\tfeed8 := mustGetFeed(feedID8)\n\n\tpostIDToHide := CreatePost(feed8.id, rootPostID, cat1, `{\"metadata\": \"value\"}`)\n\tpostID := CreatePost(feed8.id, rootPostID, cat1, `{\"metadata\": \"value\"}`)\n\n\tif count := countPosts(feed8.id, filter_all, 10); count != 2 {\n\t\tt.Fatalf(\"expected posts count: 2, got %q.\", count)\n\t}\n\n\t// Hide a post for me\n\tHidePostForMe(feed8.id, postIDToHide)\n\n\tif count := countPosts(feed8.id, filter_all, 10); count != 1 {\n\t\tt.Fatalf(\"expected posts count after hidding: 1, got %q.\", count)\n\t}\n\n\t// Query from another user should return full list\n\tanother := std.Address(\"another\")\n\tstd.TestSetOriginCaller(another)\n\n\tif count := countPosts(feed8.id, filter_all, 10); count != 2 {\n\t\tt.Fatalf(\"expected posts count from another: 2, got %q.\", count)\n\t}\n\n\t// UnHide a post for me\n\tstd.TestSetOriginCaller(user)\n\tUnHidePostForMe(feed8.id, postIDToHide)\n\n\tif count := countPosts(feed8.id, filter_all, 10); count != 2 {\n\t\tt.Fatalf(\"expected posts count after unhidding: 2, got %q.\", count)\n\t}\n}\n\nfunc testMigrateFeedData(t *testing.T) string {\n\tfeedID := feedsV7.CreateFeed(\"teritor11\")\n\n\t// Post to test\n\tpostID := feedsV7.CreatePost(feedID, feedsV7.PostID(0), 2, `{\"metadata\": \"value\"}`)\n\tfeedsV7.ReactPost(feedID, postID, \"🇬🇸\", true)\n\n\t// Add comment to post\n\tcommentID := feedsV7.CreatePost(feedID, postID, 2, `{\"comment1\": \"value\"}`)\n\tfeedsV7.ReactPost(feedID, commentID, \"🇬🇸\", true)\n\n\t// // Post with json metadata\n\tfeedsV7.CreatePost(feedID, feedsV7.PostID(0), 2, `{'a':1}`)\n\n\t// Expect: should convert feed data to JSON successfully without error\n\tdataJSON := feedsV7.ExportFeedData(feedID)\n\tif dataJSON == \"\" {\n\t\tt.Fatalf(\"expected feed data exported successfully\")\n\t}\n\n\t// Import data =====================================\n\tImportFeedData(FeedID(uint64(feedID)), dataJSON)\n\n\t// Test public func\n\t// MigrateFromPreviousFeed(feedID)\n}\n\nfunc Test(t *testing.T) {\n\ttestCreateFeed(t)\n\n\ttestCreatePost(t)\n\n\ttestGetPosts(t)\n\n\ttestReactPost(t)\n\n\ttestCreateAndDeleteComment(t)\n\n\ttestFilterByCategories(t)\n\n\ttestTipPost(t)\n\n\ttestFilterUser(t)\n\n\ttestFlagPost(t)\n\n\ttestHidePostForMe(t)\n\n\ttestMigrateFeedData(t)\n}\n" }, { "Name": "flags.gno", @@ -60,11 +60,11 @@ stdout OK! }, { "Name": "post.gno", - "Body": "package social_feeds\n\nimport (\n\t\"std\"\n\t\"strconv\"\n\t\"time\"\n\n\t\"gno.land/p/demo/avl\"\n\tujson \"gno.land/p/demo/teritori/ujson\"\n)\n\ntype PostID uint64\n\nfunc (pid PostID) String() string {\n\treturn strconv.Itoa(int(pid))\n}\n\nfunc (pid *PostID) FromJSON(ast *ujson.JSONASTNode) {\n\tval, err := strconv.Atoi(ast.Value)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\t*pid = PostID(val)\n}\n\nfunc (pid PostID) ToJSON() string {\n\treturn strconv.Itoa(int(pid))\n}\n\ntype Reaction struct {\n\ticon string\n\tcount uint64\n}\n\nvar Categories []string = []string{\n\t\"Reaction\",\n\t\"Comment\",\n\t\"Normal\",\n\t\"Article\",\n\t\"Picture\",\n\t\"Audio\",\n\t\"Video\",\n}\n\ntype Post struct {\n\tid PostID\n\tparentID PostID\n\tfeedID FeedID\n\tcategory uint64\n\tmetadata string\n\treactions avl.Tree // icon -> count\n\tcomments avl.Tree // Post.id -> *Post\n\tcreator std.Address\n\ttipAmount uint64\n\tdeleted bool\n\tcommentsCount uint64\n\n\tcreatedAt int64\n\tupdatedAt int64\n\tdeletedAt int64\n}\n\nfunc newPost(feed *Feed, id PostID, creator std.Address, parentID PostID, category uint64, metadata string) *Post {\n\treturn &Post{\n\t\tid: id,\n\t\tparentID: parentID,\n\t\tfeedID: feed.id,\n\t\tcategory: category,\n\t\tmetadata: metadata,\n\t\treactions: avl.Tree{},\n\t\tcreator: creator,\n\t\tcreatedAt: time.Now().Unix(),\n\t}\n}\n\nfunc (post *Post) String() string {\n\treturn post.ToJSON()\n}\n\nfunc (post *Post) Update(category uint64, metadata string) {\n\tpost.category = category\n\tpost.metadata = metadata\n\tpost.updatedAt = time.Now().Unix()\n}\n\nfunc (post *Post) Delete() {\n\tpost.deleted = true\n\tpost.deletedAt = time.Now().Unix()\n}\n\nfunc (post *Post) Tip(from std.Address, to std.Address) {\n\treceivedCoins := std.GetOrigSend()\n\tamount := receivedCoins[0].Amount\n\n\tbanker := std.GetBanker(std.BankerTypeOrigSend)\n\t// banker := std.GetBanker(std.BankerTypeRealmSend)\n\tcoinsToSend := std.Coins{std.Coin{Denom: \"ugnot\", Amount: amount}}\n\tpkgaddr := std.GetOrigPkgAddr()\n\n\tbanker.SendCoins(pkgaddr, to, coinsToSend)\n\n\t// Update tip amount\n\tpost.tipAmount += uint64(amount)\n}\n\n// Always remove reaction if count = 0\nfunc (post *Post) React(icon string, up bool) {\n\tcount_, ok := post.reactions.Get(icon)\n\tcount := 0\n\n\tif ok {\n\t\tcount = count_.(int)\n\t}\n\n\tif up {\n\t\tcount++\n\t} else {\n\t\tcount--\n\t}\n\n\tif count <= 0 {\n\t\tpost.reactions.Remove(icon)\n\t} else {\n\t\tpost.reactions.Set(icon, count)\n\t}\n}\n\nfunc (post *Post) Render() string {\n\treturn post.metadata\n}\n\nfunc (post *Post) FromJSON(jsonData string) {\n\tast := ujson.TokenizeAndParse(jsonData)\n\tast.ParseObject([]*ujson.ParseKV{\n\t\t{Key: \"id\", CustomParser: func(node *ujson.JSONASTNode) {\n\t\t\tpid, _ := strconv.Atoi(node.Value)\n\t\t\tpost.id = PostID(pid)\n\t\t}},\n\t\t{Key: \"parentID\", CustomParser: func(node *ujson.JSONASTNode) {\n\t\t\tpid, _ := strconv.Atoi(node.Value)\n\t\t\tpost.parentID = PostID(pid)\n\t\t}},\n\t\t{Key: \"feedID\", CustomParser: func(node *ujson.JSONASTNode) {\n\t\t\tfid, _ := strconv.Atoi(node.Value)\n\t\t\tpost.feedID = FeedID(fid)\n\t\t}},\n\t\t{Key: \"category\", Value: &post.category},\n\t\t{Key: \"metadata\", Value: &post.metadata},\n\t\t{Key: \"reactions\", CustomParser: func(node *ujson.JSONASTNode) {\n\t\t\treactions := avl.NewTree()\n\t\t\tfor _, child := range node.ObjectChildren {\n\t\t\t\treactionCount := child.Value\n\t\t\t\treactions.Set(child.Key, reactionCount)\n\t\t\t}\n\t\t\tpost.reactions = *reactions\n\t\t}},\n\t\t{Key: \"commentsCount\", Value: &post.commentsCount},\n\t\t{Key: \"creator\", Value: &post.creator},\n\t\t{Key: \"tipAmount\", Value: &post.tipAmount},\n\t\t{Key: \"deleted\", Value: &post.deleted},\n\t\t{Key: \"createdAt\", Value: &post.createdAt},\n\t\t{Key: \"updatedAt\", Value: &post.updatedAt},\n\t\t{Key: \"deletedAt\", Value: &post.deletedAt},\n\t})\n}\n\nfunc (post *Post) ToJSON() string {\n\treactionsKV := []ujson.FormatKV{}\n\tpost.reactions.Iterate(\"\", \"\", func(key string, value interface{}) bool {\n\t\tcount := value.(int)\n\t\tdata := ujson.FormatKV{Key: key, Value: count}\n\t\treactionsKV = append(reactionsKV, data)\n\t\treturn false\n\t})\n\treactions := ujson.FormatObject(reactionsKV)\n\n\tpostJSON := ujson.FormatObject([]ujson.FormatKV{\n\t\t{Key: \"id\", Value: uint64(post.id)},\n\t\t{Key: \"parentID\", Value: uint64(post.parentID)},\n\t\t{Key: \"feedID\", Value: uint64(post.feedID)},\n\t\t{Key: \"category\", Value: post.category},\n\t\t{Key: \"metadata\", Value: post.metadata},\n\t\t{Key: \"reactions\", Value: reactions, Raw: true},\n\t\t{Key: \"creator\", Value: post.creator},\n\t\t{Key: \"tipAmount\", Value: post.tipAmount},\n\t\t{Key: \"deleted\", Value: post.deleted},\n\t\t{Key: \"commentsCount\", Value: post.commentsCount},\n\t\t{Key: \"createdAt\", Value: post.createdAt},\n\t\t{Key: \"updatedAt\", Value: post.updatedAt},\n\t\t{Key: \"deletedAt\", Value: post.deletedAt},\n\t})\n\treturn postJSON\n}\n" + "Body": "package social_feeds\n\nimport (\n\t\"std\"\n\t\"strconv\"\n\t\"time\"\n\n\t\"gno.land/p/demo/avl\"\n\tujson \"gno.land/p/demo/teritori/ujson\"\n)\n\ntype PostID uint64\n\nfunc (pid PostID) String() string {\n\treturn strconv.Itoa(int(pid))\n}\n\nfunc (pid *PostID) FromJSON(ast *ujson.JSONASTNode) {\n\tval, err := strconv.Atoi(ast.Value)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\t*pid = PostID(val)\n}\n\nfunc (pid PostID) ToJSON() string {\n\treturn strconv.Itoa(int(pid))\n}\n\ntype Reaction struct {\n\ticon string\n\tcount uint64\n}\n\nvar Categories []string = []string{\n\t\"Reaction\",\n\t\"Comment\",\n\t\"Normal\",\n\t\"Article\",\n\t\"Picture\",\n\t\"Audio\",\n\t\"Video\",\n}\n\ntype Post struct {\n\tid PostID\n\tparentID PostID\n\tfeedID FeedID\n\tcategory uint64\n\tmetadata string\n\treactions avl.Tree // icon -> count\n\tcomments avl.Tree // Post.id -> *Post\n\tcreator std.Address\n\ttipAmount uint64\n\tdeleted bool\n\tcommentsCount uint64\n\n\tcreatedAt int64\n\tupdatedAt int64\n\tdeletedAt int64\n}\n\nfunc newPost(feed *Feed, id PostID, creator std.Address, parentID PostID, category uint64, metadata string) *Post {\n\treturn &Post{\n\t\tid: id,\n\t\tparentID: parentID,\n\t\tfeedID: feed.id,\n\t\tcategory: category,\n\t\tmetadata: metadata,\n\t\treactions: avl.Tree{},\n\t\tcreator: creator,\n\t\tcreatedAt: time.Now().Unix(),\n\t}\n}\n\nfunc (post *Post) String() string {\n\treturn post.ToJSON()\n}\n\nfunc (post *Post) Update(category uint64, metadata string) {\n\tpost.category = category\n\tpost.metadata = metadata\n\tpost.updatedAt = time.Now().Unix()\n}\n\nfunc (post *Post) Delete() {\n\tpost.deleted = true\n\tpost.deletedAt = time.Now().Unix()\n}\n\nfunc (post *Post) Tip(from std.Address, to std.Address) {\n\treceivedCoins := std.OriginSend()\n\tamount := receivedCoins[0].Amount\n\n\tbanker := std.NewBanker(std.BankerTypeOriginSend)\n\t// banker := std.NewBanker(std.BankerTypeRealmSend)\n\tcoinsToSend := std.Coins{std.Coin{Denom: \"ugnot\", Amount: amount}}\n\tpkgaddr := std.OriginPkgAddress()\n\n\tbanker.SendCoins(pkgaddr, to, coinsToSend)\n\n\t// Update tip amount\n\tpost.tipAmount += uint64(amount)\n}\n\n// Always remove reaction if count = 0\nfunc (post *Post) React(icon string, up bool) {\n\tcount_, ok := post.reactions.Get(icon)\n\tcount := 0\n\n\tif ok {\n\t\tcount = count_.(int)\n\t}\n\n\tif up {\n\t\tcount++\n\t} else {\n\t\tcount--\n\t}\n\n\tif count <= 0 {\n\t\tpost.reactions.Remove(icon)\n\t} else {\n\t\tpost.reactions.Set(icon, count)\n\t}\n}\n\nfunc (post *Post) Render() string {\n\treturn post.metadata\n}\n\nfunc (post *Post) FromJSON(jsonData string) {\n\tast := ujson.TokenizeAndParse(jsonData)\n\tast.ParseObject([]*ujson.ParseKV{\n\t\t{Key: \"id\", CustomParser: func(node *ujson.JSONASTNode) {\n\t\t\tpid, _ := strconv.Atoi(node.Value)\n\t\t\tpost.id = PostID(pid)\n\t\t}},\n\t\t{Key: \"parentID\", CustomParser: func(node *ujson.JSONASTNode) {\n\t\t\tpid, _ := strconv.Atoi(node.Value)\n\t\t\tpost.parentID = PostID(pid)\n\t\t}},\n\t\t{Key: \"feedID\", CustomParser: func(node *ujson.JSONASTNode) {\n\t\t\tfid, _ := strconv.Atoi(node.Value)\n\t\t\tpost.feedID = FeedID(fid)\n\t\t}},\n\t\t{Key: \"category\", Value: &post.category},\n\t\t{Key: \"metadata\", Value: &post.metadata},\n\t\t{Key: \"reactions\", CustomParser: func(node *ujson.JSONASTNode) {\n\t\t\treactions := avl.NewTree()\n\t\t\tfor _, child := range node.ObjectChildren {\n\t\t\t\treactionCount := child.Value\n\t\t\t\treactions.Set(child.Key, reactionCount)\n\t\t\t}\n\t\t\tpost.reactions = *reactions\n\t\t}},\n\t\t{Key: \"commentsCount\", Value: &post.commentsCount},\n\t\t{Key: \"creator\", Value: &post.creator},\n\t\t{Key: \"tipAmount\", Value: &post.tipAmount},\n\t\t{Key: \"deleted\", Value: &post.deleted},\n\t\t{Key: \"createdAt\", Value: &post.createdAt},\n\t\t{Key: \"updatedAt\", Value: &post.updatedAt},\n\t\t{Key: \"deletedAt\", Value: &post.deletedAt},\n\t})\n}\n\nfunc (post *Post) ToJSON() string {\n\treactionsKV := []ujson.FormatKV{}\n\tpost.reactions.Iterate(\"\", \"\", func(key string, value interface{}) bool {\n\t\tcount := value.(int)\n\t\tdata := ujson.FormatKV{Key: key, Value: count}\n\t\treactionsKV = append(reactionsKV, data)\n\t\treturn false\n\t})\n\treactions := ujson.FormatObject(reactionsKV)\n\n\tpostJSON := ujson.FormatObject([]ujson.FormatKV{\n\t\t{Key: \"id\", Value: uint64(post.id)},\n\t\t{Key: \"parentID\", Value: uint64(post.parentID)},\n\t\t{Key: \"feedID\", Value: uint64(post.feedID)},\n\t\t{Key: \"category\", Value: post.category},\n\t\t{Key: \"metadata\", Value: post.metadata},\n\t\t{Key: \"reactions\", Value: reactions, Raw: true},\n\t\t{Key: \"creator\", Value: post.creator},\n\t\t{Key: \"tipAmount\", Value: post.tipAmount},\n\t\t{Key: \"deleted\", Value: post.deleted},\n\t\t{Key: \"commentsCount\", Value: post.commentsCount},\n\t\t{Key: \"createdAt\", Value: post.createdAt},\n\t\t{Key: \"updatedAt\", Value: post.updatedAt},\n\t\t{Key: \"deletedAt\", Value: post.deletedAt},\n\t})\n\treturn postJSON\n}\n" }, { "Name": "public.gno", - "Body": "package social_feeds\n\nimport (\n\t\"std\"\n\t\"strconv\"\n\t\"strings\"\n\n\t\"gno.land/p/demo/avl\"\n\t\"gno.land/p/demo/teritori/flags_index\"\n\t\"gno.land/p/demo/ufmt\"\n)\n\n// Only registered user can create a new feed\n// For the flexibility when testing, allow all user to create feed\nfunc CreateFeed(name string) FeedID {\n\tpkgpath := std.CurrentRealmPath()\n\n\tfid := incGetFeedID()\n\tcaller := std.PrevRealm().Addr()\n\turl := strings.Replace(pkgpath, \"gno.land\", \"\", -1) + \":\" + name\n\tfeed := newFeed(fid, url, name, caller)\n\tfidkey := feedIDKey(fid)\n\tgFeeds.Set(fidkey, feed)\n\tgFeedsByName.Set(name, feed)\n\treturn feed.id\n}\n\n// Anyone can create a post in a existing feed, allow un-registered users also\nfunc CreatePost(fid FeedID, parentID PostID, catetory uint64, metadata string) PostID {\n\tcaller := std.PrevRealm().Addr()\n\n\tfeed := mustGetFeed(fid)\n\tpost := feed.AddPost(caller, parentID, catetory, metadata)\n\treturn post.id\n}\n\n// Only post's owner can edit post\nfunc EditPost(fid FeedID, pid PostID, category uint64, metadata string) {\n\tcaller := std.PrevRealm().Addr()\n\tfeed := mustGetFeed(fid)\n\tpost := feed.MustGetPost(pid)\n\n\tif caller != post.creator {\n\t\tpanic(\"you are not creator of this post\")\n\t}\n\n\tpost.Update(category, metadata)\n}\n\n// Only feed creator/owner can call this\nfunc SetOwner(fid FeedID, newOwner std.Address) {\n\tcaller := std.PrevRealm().Addr()\n\tfeed := mustGetFeed(fid)\n\n\tif caller != feed.creator && caller != feed.owner {\n\t\tpanic(\"you are not creator/owner of this feed\")\n\t}\n\n\tfeed.owner = newOwner\n}\n\n// Only feed creator/owner or post creator can delete the post\nfunc DeletePost(fid FeedID, pid PostID) {\n\tcaller := std.PrevRealm().Addr()\n\tfeed := mustGetFeed(fid)\n\tpost := feed.MustGetPost(pid)\n\n\tif caller != post.creator && caller != feed.creator && caller != feed.owner {\n\t\tpanic(\"you are nor creator of this post neither creator/owner of the feed\")\n\t}\n\n\tpost.Delete()\n\n\t// If post is comment then decrease comments count on parent\n\tif uint64(post.parentID) != 0 {\n\t\tparent := feed.MustGetPost(post.parentID)\n\t\tparent.commentsCount -= 1\n\t}\n}\n\n// Only feed owner can ban the post\nfunc BanPost(fid FeedID, pid PostID, reason string) {\n\tcaller := std.PrevRealm().Addr()\n\tfeed := mustGetFeed(fid)\n\t_ = feed.MustGetPost(pid)\n\n\t// For experimenting, we ban only the post for now\n\t// TODO: recursive delete/ban comments\n\tif caller != feed.owner {\n\t\tpanic(\"you are owner of the feed\")\n\t}\n\n\tfeed.BanPost(pid)\n\n\tfeed.flags.ClearFlagCount(getFlagID(fid, pid))\n}\n\n// Any one can react post\nfunc ReactPost(fid FeedID, pid PostID, icon string, up bool) {\n\tfeed := mustGetFeed(fid)\n\tpost := feed.MustGetPost(pid)\n\n\tpost.React(icon, up)\n}\n\nfunc TipPost(fid FeedID, pid PostID) {\n\tcaller := std.PrevRealm().Addr()\n\tfeed := mustGetFeed(fid)\n\tpost := feed.MustGetPost(pid)\n\n\tpost.Tip(caller, post.creator)\n}\n\n// Get a list of flagged posts\n// NOTE: We can support multi feeds in the future but for now we will have only 1 feed\n// Return stringified list in format: postStr-count,postStr-count\nfunc GetFlaggedPosts(fid FeedID, offset uint64, limit uint8) string {\n\tfeed := mustGetFeed(fid)\n\n\t// Already sorted by count descending\n\tflags := feed.flags.GetFlags(uint64(limit), offset)\n\n\tvar postList []string\n\tfor _, flagCount := range flags {\n\t\tflagID := flagCount.FlagID\n\n\t\tfeedID, postID := parseFlagID(flagID)\n\t\tif feedID != feed.id {\n\t\t\tcontinue\n\t\t}\n\n\t\tpost := feed.GetPost(postID)\n\t\tpostList = append(postList, ufmt.Sprintf(\"%s\", post))\n\t}\n\n\tSEPARATOR := \",\"\n\tres := strings.Join(postList, SEPARATOR)\n\treturn ufmt.Sprintf(\"[%s]\", res)\n}\n\n// NOTE: due to bug of std.PrevRealm().Addr() return \"\" when query so we user this proxy function temporary\n// in waiting of correct behaviour of std.PrevRealm().Addr()\nfunc GetPosts(fid FeedID, parentID PostID, user string, categories []uint64, offset uint64, limit uint8) string {\n\tcaller := std.PrevRealm().Addr()\n\tdata := GetPostsWithCaller(fid, parentID, caller.String(), user, categories, offset, limit)\n\treturn data\n}\n\nfunc GetPostsWithCaller(fid FeedID, parentID PostID, callerAddrStr string, user string, categories []uint64, offset uint64, limit uint8) string {\n\t// Return flagged posts, we process flagged posts differently using FlagIndex\n\tif len(categories) == 1 && categories[0] == uint64(9) {\n\t\treturn GetFlaggedPosts(fid, offset, limit)\n\t}\n\n\t// BUG: normally std.PrevRealm().Addr() should return a value instead of empty\n\t// Fix is in progress on Gno side\n\tfeed := mustGetFeed(fid)\n\tposts := getPosts(feed, parentID, callerAddrStr, user, categories, offset, limit)\n\n\tSEPARATOR := \",\"\n\tvar postListStr []string\n\n\tfor _, post := range posts {\n\t\tpostListStr = append(postListStr, post.String())\n\t}\n\n\tres := strings.Join(postListStr, SEPARATOR)\n\treturn ufmt.Sprintf(\"[%s]\", res)\n}\n\n// user here is: filter by user\nfunc getPosts(feed *Feed, parentID PostID, callerAddrStr string, user string, categories []uint64, offset uint64, limit uint8) []*Post {\n\tcaller := std.Address(callerAddrStr)\n\n\tvar posts []*Post\n\tvar skipped uint64\n\n\t// Create an avlTree for optimizing the check\n\trequestedCategories := avl.NewTree()\n\tfor _, category := range categories {\n\t\tcatStr := strconv.FormatUint(category, 10)\n\t\trequestedCategories.Set(catStr, true)\n\t}\n\n\tfeed.posts.ReverseIterate(\"\", \"\", func(key string, value interface{}) bool {\n\t\tpost := value.(*Post)\n\n\t\tpostCatStr := strconv.FormatUint(post.category, 10)\n\n\t\t// NOTE: this search mechanism is not efficient, only for demo purpose\n\t\tif post.parentID == parentID && post.deleted == false {\n\t\t\tif requestedCategories.Size() > 0 && !requestedCategories.Has(postCatStr) {\n\t\t\t\treturn false\n\t\t\t}\n\n\t\t\tif user != \"\" && std.Address(user) != post.creator {\n\t\t\t\treturn false\n\t\t\t}\n\n\t\t\t// Filter hidden post\n\t\t\tflagID := getFlagID(feed.id, post.id)\n\t\t\tif feed.flags.HasFlagged(flagID, callerAddrStr) {\n\t\t\t\treturn false\n\t\t\t}\n\n\t\t\t// Check if post is in hidden list\n\t\t\tvalue, exists := feed.hiddenPostsByUser.Get(caller.String())\n\t\t\tif exists {\n\t\t\t\thiddenPosts := value.(*avl.Tree)\n\t\t\t\t// If post.id exists in hiddenPosts tree => that post is hidden\n\t\t\t\tif hiddenPosts.Has(post.id.String()) {\n\t\t\t\t\treturn false\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif skipped < offset {\n\t\t\t\tskipped++\n\t\t\t\treturn false\n\t\t\t}\n\n\t\t\tposts = append(posts, post)\n\t\t}\n\n\t\tif len(posts) == int(limit) {\n\t\t\treturn true\n\t\t}\n\n\t\treturn false\n\t})\n\n\treturn posts\n}\n\n// Get comments list\nfunc GetComments(fid FeedID, parentID PostID, offset uint64, limit uint8) string {\n\treturn GetPosts(fid, parentID, \"\", []uint64{}, offset, limit)\n}\n\n// Get Post\nfunc GetPost(fid FeedID, pid PostID) string {\n\tfeed := mustGetFeed(fid)\n\n\tdata, ok := feed.posts.Get(postIDKey(pid))\n\tif !ok {\n\t\tpanic(\"Unable to get post\")\n\t}\n\n\tpost := data.(*Post)\n\treturn post.String()\n}\n\nfunc FlagPost(fid FeedID, pid PostID) {\n\tcaller := std.PrevRealm().Addr()\n\tfeed := mustGetFeed(fid)\n\n\tfeed.FlagPost(caller, pid)\n}\n\nfunc HidePostForMe(fid FeedID, pid PostID) {\n\tcaller := std.PrevRealm().Addr()\n\tfeed := mustGetFeed(fid)\n\n\tfeed.HidePostForUser(caller, pid)\n}\n\nfunc UnHidePostForMe(fid FeedID, pid PostID) {\n\tcaller := std.PrevRealm().Addr()\n\tfeed := mustGetFeed(fid)\n\n\tfeed.UnHidePostForUser(caller, pid)\n}\n\nfunc GetFlags(fid FeedID, limit uint64, offset uint64) string {\n\tfeed := mustGetFeed(fid)\n\n\ttype FlagCount struct {\n\t\tFlagID flags_index.FlagID\n\t\tCount uint64\n\t}\n\n\tflags := feed.flags.GetFlags(limit, offset)\n\n\tvar res []string\n\tfor _, flag := range flags {\n\t\tres = append(res, ufmt.Sprintf(\"%s:%d\", flag.FlagID, flag.Count))\n\t}\n\n\treturn strings.Join(res, \"|\")\n}\n\n// TODO: allow only creator to call\nfunc GetFeedByID(fid FeedID) *Feed {\n\treturn mustGetFeed(fid)\n}\n\n// TODO: allow only admin to call\nfunc ExportFeedData(fid FeedID) string {\n\tfeed := mustGetFeed(fid)\n\tfeedJSON := feed.ToJSON()\n\treturn feedJSON\n}\n\n// TODO: allow only admin to call\nfunc ImportFeedData(fid FeedID, jsonData string) {\n\tfeed := mustGetFeed(fid)\n\tfeed.FromJSON(jsonData)\n}\n\n// func MigrateFromPreviousFeed(fid feedsV7.FeedID) {\n// \t// Get exported data from previous feeds\n// \tjsonData := feedsV7.ExportFeedData(fid)\n// \tImportFeedData(FeedID(uint64(fid)), jsonData)\n// }\n" + "Body": "package social_feeds\n\nimport (\n\t\"std\"\n\t\"strconv\"\n\t\"strings\"\n\n\t\"gno.land/p/demo/avl\"\n\t\"gno.land/p/demo/teritori/flags_index\"\n\t\"gno.land/p/demo/ufmt\"\n)\n\n// Only registered user can create a new feed\n// For the flexibility when testing, allow all user to create feed\nfunc CreateFeed(name string) FeedID {\n\tpkgpath := std.CurrentRealmPath()\n\n\tfid := incGetFeedID()\n\tcaller := std.PreviousRealm().Address()\n\turl := strings.Replace(pkgpath, \"gno.land\", \"\", -1) + \":\" + name\n\tfeed := newFeed(fid, url, name, caller)\n\tfidkey := feedIDKey(fid)\n\tgFeeds.Set(fidkey, feed)\n\tgFeedsByName.Set(name, feed)\n\treturn feed.id\n}\n\n// Anyone can create a post in a existing feed, allow un-registered users also\nfunc CreatePost(fid FeedID, parentID PostID, catetory uint64, metadata string) PostID {\n\tcaller := std.PreviousRealm().Address()\n\n\tfeed := mustGetFeed(fid)\n\tpost := feed.AddPost(caller, parentID, catetory, metadata)\n\treturn post.id\n}\n\n// Only post's owner can edit post\nfunc EditPost(fid FeedID, pid PostID, category uint64, metadata string) {\n\tcaller := std.PreviousRealm().Address()\n\tfeed := mustGetFeed(fid)\n\tpost := feed.MustGetPost(pid)\n\n\tif caller != post.creator {\n\t\tpanic(\"you are not creator of this post\")\n\t}\n\n\tpost.Update(category, metadata)\n}\n\n// Only feed creator/owner can call this\nfunc SetOwner(fid FeedID, newOwner std.Address) {\n\tcaller := std.PreviousRealm().Address()\n\tfeed := mustGetFeed(fid)\n\n\tif caller != feed.creator && caller != feed.owner {\n\t\tpanic(\"you are not creator/owner of this feed\")\n\t}\n\n\tfeed.owner = newOwner\n}\n\n// Only feed creator/owner or post creator can delete the post\nfunc DeletePost(fid FeedID, pid PostID) {\n\tcaller := std.PreviousRealm().Address()\n\tfeed := mustGetFeed(fid)\n\tpost := feed.MustGetPost(pid)\n\n\tif caller != post.creator && caller != feed.creator && caller != feed.owner {\n\t\tpanic(\"you are nor creator of this post neither creator/owner of the feed\")\n\t}\n\n\tpost.Delete()\n\n\t// If post is comment then decrease comments count on parent\n\tif uint64(post.parentID) != 0 {\n\t\tparent := feed.MustGetPost(post.parentID)\n\t\tparent.commentsCount -= 1\n\t}\n}\n\n// Only feed owner can ban the post\nfunc BanPost(fid FeedID, pid PostID, reason string) {\n\tcaller := std.PreviousRealm().Address()\n\tfeed := mustGetFeed(fid)\n\t_ = feed.MustGetPost(pid)\n\n\t// For experimenting, we ban only the post for now\n\t// TODO: recursive delete/ban comments\n\tif caller != feed.owner {\n\t\tpanic(\"you are owner of the feed\")\n\t}\n\n\tfeed.BanPost(pid)\n\n\tfeed.flags.ClearFlagCount(getFlagID(fid, pid))\n}\n\n// Any one can react post\nfunc ReactPost(fid FeedID, pid PostID, icon string, up bool) {\n\tfeed := mustGetFeed(fid)\n\tpost := feed.MustGetPost(pid)\n\n\tpost.React(icon, up)\n}\n\nfunc TipPost(fid FeedID, pid PostID) {\n\tcaller := std.PreviousRealm().Address()\n\tfeed := mustGetFeed(fid)\n\tpost := feed.MustGetPost(pid)\n\n\tpost.Tip(caller, post.creator)\n}\n\n// Get a list of flagged posts\n// NOTE: We can support multi feeds in the future but for now we will have only 1 feed\n// Return stringified list in format: postStr-count,postStr-count\nfunc GetFlaggedPosts(fid FeedID, offset uint64, limit uint8) string {\n\tfeed := mustGetFeed(fid)\n\n\t// Already sorted by count descending\n\tflags := feed.flags.GetFlags(uint64(limit), offset)\n\n\tvar postList []string\n\tfor _, flagCount := range flags {\n\t\tflagID := flagCount.FlagID\n\n\t\tfeedID, postID := parseFlagID(flagID)\n\t\tif feedID != feed.id {\n\t\t\tcontinue\n\t\t}\n\n\t\tpost := feed.GetPost(postID)\n\t\tpostList = append(postList, ufmt.Sprintf(\"%s\", post))\n\t}\n\n\tSEPARATOR := \",\"\n\tres := strings.Join(postList, SEPARATOR)\n\treturn ufmt.Sprintf(\"[%s]\", res)\n}\n\n// NOTE: due to bug of std.PreviousRealm().Address() return \"\" when query so we user this proxy function temporary\n// in waiting of correct behaviour of std.PreviousRealm().Address()\nfunc GetPosts(fid FeedID, parentID PostID, user string, categories []uint64, offset uint64, limit uint8) string {\n\tcaller := std.PreviousRealm().Address()\n\tdata := GetPostsWithCaller(fid, parentID, caller.String(), user, categories, offset, limit)\n\treturn data\n}\n\nfunc GetPostsWithCaller(fid FeedID, parentID PostID, callerAddrStr string, user string, categories []uint64, offset uint64, limit uint8) string {\n\t// Return flagged posts, we process flagged posts differently using FlagIndex\n\tif len(categories) == 1 && categories[0] == uint64(9) {\n\t\treturn GetFlaggedPosts(fid, offset, limit)\n\t}\n\n\t// BUG: normally std.PreviousRealm().Address() should return a value instead of empty\n\t// Fix is in progress on Gno side\n\tfeed := mustGetFeed(fid)\n\tposts := getPosts(feed, parentID, callerAddrStr, user, categories, offset, limit)\n\n\tSEPARATOR := \",\"\n\tvar postListStr []string\n\n\tfor _, post := range posts {\n\t\tpostListStr = append(postListStr, post.String())\n\t}\n\n\tres := strings.Join(postListStr, SEPARATOR)\n\treturn ufmt.Sprintf(\"[%s]\", res)\n}\n\n// user here is: filter by user\nfunc getPosts(feed *Feed, parentID PostID, callerAddrStr string, user string, categories []uint64, offset uint64, limit uint8) []*Post {\n\tcaller := std.Address(callerAddrStr)\n\n\tvar posts []*Post\n\tvar skipped uint64\n\n\t// Create an avlTree for optimizing the check\n\trequestedCategories := avl.NewTree()\n\tfor _, category := range categories {\n\t\tcatStr := strconv.FormatUint(category, 10)\n\t\trequestedCategories.Set(catStr, true)\n\t}\n\n\tfeed.posts.ReverseIterate(\"\", \"\", func(key string, value interface{}) bool {\n\t\tpost := value.(*Post)\n\n\t\tpostCatStr := strconv.FormatUint(post.category, 10)\n\n\t\t// NOTE: this search mechanism is not efficient, only for demo purpose\n\t\tif post.parentID == parentID && post.deleted == false {\n\t\t\tif requestedCategories.Size() > 0 && !requestedCategories.Has(postCatStr) {\n\t\t\t\treturn false\n\t\t\t}\n\n\t\t\tif user != \"\" && std.Address(user) != post.creator {\n\t\t\t\treturn false\n\t\t\t}\n\n\t\t\t// Filter hidden post\n\t\t\tflagID := getFlagID(feed.id, post.id)\n\t\t\tif feed.flags.HasFlagged(flagID, callerAddrStr) {\n\t\t\t\treturn false\n\t\t\t}\n\n\t\t\t// Check if post is in hidden list\n\t\t\tvalue, exists := feed.hiddenPostsByUser.Get(caller.String())\n\t\t\tif exists {\n\t\t\t\thiddenPosts := value.(*avl.Tree)\n\t\t\t\t// If post.id exists in hiddenPosts tree => that post is hidden\n\t\t\t\tif hiddenPosts.Has(post.id.String()) {\n\t\t\t\t\treturn false\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif skipped < offset {\n\t\t\t\tskipped++\n\t\t\t\treturn false\n\t\t\t}\n\n\t\t\tposts = append(posts, post)\n\t\t}\n\n\t\tif len(posts) == int(limit) {\n\t\t\treturn true\n\t\t}\n\n\t\treturn false\n\t})\n\n\treturn posts\n}\n\n// Get comments list\nfunc GetComments(fid FeedID, parentID PostID, offset uint64, limit uint8) string {\n\treturn GetPosts(fid, parentID, \"\", []uint64{}, offset, limit)\n}\n\n// Get Post\nfunc GetPost(fid FeedID, pid PostID) string {\n\tfeed := mustGetFeed(fid)\n\n\tdata, ok := feed.posts.Get(postIDKey(pid))\n\tif !ok {\n\t\tpanic(\"Unable to get post\")\n\t}\n\n\tpost := data.(*Post)\n\treturn post.String()\n}\n\nfunc FlagPost(fid FeedID, pid PostID) {\n\tcaller := std.PreviousRealm().Address()\n\tfeed := mustGetFeed(fid)\n\n\tfeed.FlagPost(caller, pid)\n}\n\nfunc HidePostForMe(fid FeedID, pid PostID) {\n\tcaller := std.PreviousRealm().Address()\n\tfeed := mustGetFeed(fid)\n\n\tfeed.HidePostForUser(caller, pid)\n}\n\nfunc UnHidePostForMe(fid FeedID, pid PostID) {\n\tcaller := std.PreviousRealm().Address()\n\tfeed := mustGetFeed(fid)\n\n\tfeed.UnHidePostForUser(caller, pid)\n}\n\nfunc GetFlags(fid FeedID, limit uint64, offset uint64) string {\n\tfeed := mustGetFeed(fid)\n\n\ttype FlagCount struct {\n\t\tFlagID flags_index.FlagID\n\t\tCount uint64\n\t}\n\n\tflags := feed.flags.GetFlags(limit, offset)\n\n\tvar res []string\n\tfor _, flag := range flags {\n\t\tres = append(res, ufmt.Sprintf(\"%s:%d\", flag.FlagID, flag.Count))\n\t}\n\n\treturn strings.Join(res, \"|\")\n}\n\n// TODO: allow only creator to call\nfunc GetFeedByID(fid FeedID) *Feed {\n\treturn mustGetFeed(fid)\n}\n\n// TODO: allow only admin to call\nfunc ExportFeedData(fid FeedID) string {\n\tfeed := mustGetFeed(fid)\n\tfeedJSON := feed.ToJSON()\n\treturn feedJSON\n}\n\n// TODO: allow only admin to call\nfunc ImportFeedData(fid FeedID, jsonData string) {\n\tfeed := mustGetFeed(fid)\n\tfeed.FromJSON(jsonData)\n}\n\n// func MigrateFromPreviousFeed(fid feedsV7.FeedID) {\n// \t// Get exported data from previous feeds\n// \tjsonData := feedsV7.ExportFeedData(fid)\n// \tImportFeedData(FeedID(uint64(fid)), jsonData)\n// }\n" }, { "Name": "render.gno", diff --git a/gno.land/pkg/integration/testdata/prevrealm.txtar b/gno.land/pkg/integration/testdata/prevrealm.txtar index 31f0ca336ba..73340d9b44d 100644 --- a/gno.land/pkg/integration/testdata/prevrealm.txtar +++ b/gno.land/pkg/integration/testdata/prevrealm.txtar @@ -1,4 +1,4 @@ -# This tests ensure the consistency of the std.PrevRealm function, in the +# This tests ensure the consistency of the std.PreviousRealm function, in the # following situations: # # @@ -16,8 +16,8 @@ # | 10 | | | myrlm.B() | r/foo | # | 11 | | through /p/demo/bar | bar.A() | user address | # | 12 | | | bar.B() | user address | -# | 13 | MsgCall | wallet direct | std.PrevRealm() | user address | -# | 14 | MsgRun | wallet direct | std.PrevRealm() | user address | +# | 13 | MsgCall | wallet direct | std.PreviousRealm() | user address | +# | 14 | MsgRun | wallet direct | std.PreviousRealm() | user address | # Init ## deploy myrlm @@ -82,11 +82,11 @@ stdout ${test1_user_addr} gnokey maketx run -gas-fee 100000ugnot -gas-wanted 12000000 -broadcast -chainid tendermint_test test1 $WORK/run/barB.gno stdout ${test1_user_addr} -## 13. MsgCall -> std.PrevRealm(): user address -## gnokey maketx call -pkgpath std -func PrevRealm -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 +## 13. MsgCall -> std.PreviousRealm(): user address +## gnokey maketx call -pkgpath std -func PreviousRealm -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 ## stdout ${test1_user_addr} -## 14. MsgRun -> std.PrevRealm(): user address +## 14. MsgRun -> std.PreviousRealm(): user address gnokey maketx run -gas-fee 100000ugnot -gas-wanted 12000000 -broadcast -chainid tendermint_test test1 $WORK/run/baz.gno stdout ${test1_user_addr} @@ -96,7 +96,7 @@ package myrlm import "std" func A() string { - return std.PrevRealm().Addr().String() + return std.PreviousRealm().Address().String() } func B() string { @@ -120,7 +120,7 @@ package bar import "std" func A() string { - return std.PrevRealm().Addr().String() + return std.PreviousRealm().Address().String() } func B() string { @@ -180,5 +180,5 @@ package main import "std" func main() { - println(std.PrevRealm().Addr().String()) + println(std.PreviousRealm().Address().String()) } diff --git a/gno.land/pkg/integration/testdata/realm_banker_issued_coin_denom.txtar b/gno.land/pkg/integration/testdata/realm_banker_issued_coin_denom.txtar index a55604267ae..a95f7e6f93d 100644 --- a/gno.land/pkg/integration/testdata/realm_banker_issued_coin_denom.txtar +++ b/gno.land/pkg/integration/testdata/realm_banker_issued_coin_denom.txtar @@ -79,12 +79,12 @@ import ( ) func Mint(addr std.Address, denom string, amount int64) { - banker := std.GetBanker(std.BankerTypeRealmIssue) + banker := std.NewBanker(std.BankerTypeRealmIssue) banker.IssueCoin(addr, std.CurrentRealm().CoinDenom(denom), amount) } func Burn(addr std.Address, denom string, amount int64) { - banker := std.GetBanker(std.BankerTypeRealmIssue) + banker := std.NewBanker(std.BankerTypeRealmIssue) banker.RemoveCoin(addr, std.CurrentRealm().CoinDenom(denom), amount) } @@ -97,12 +97,12 @@ import ( ) func Mint(addr std.Address, denom string, amount int64) { - banker := std.GetBanker(std.BankerTypeRealmIssue) + banker := std.NewBanker(std.BankerTypeRealmIssue) banker.IssueCoin(addr, std.CurrentRealm().CoinDenom(denom), amount) } func Burn(addr std.Address, denom string, amount int64) { - banker := std.GetBanker(std.BankerTypeRealmIssue) + banker := std.NewBanker(std.BankerTypeRealmIssue) banker.RemoveCoin(addr, std.CurrentRealm().CoinDenom(denom), amount) } @@ -114,11 +114,11 @@ import ( ) func Mint(addr std.Address, denom string, amount int64) { - banker := std.GetBanker(std.BankerTypeRealmIssue) + banker := std.NewBanker(std.BankerTypeRealmIssue) banker.IssueCoin(addr, denom, amount) } func Burn(addr std.Address, denom string, amount int64) { - banker := std.GetBanker(std.BankerTypeRealmIssue) + banker := std.NewBanker(std.BankerTypeRealmIssue) banker.RemoveCoin(addr, denom, amount) } diff --git a/gno.land/pkg/sdk/vm/handler_test.go b/gno.land/pkg/sdk/vm/handler_test.go index 0d238deed1f..903e390e6b7 100644 --- a/gno.land/pkg/sdk/vm/handler_test.go +++ b/gno.land/pkg/sdk/vm/handler_test.go @@ -120,8 +120,8 @@ import "std" import "time" var _ = time.RFC3339 -func caller() std.Address { return std.GetOrigCaller() } -var GetHeight = std.GetHeight +func caller() std.Address { return std.OriginCaller() } +var GetHeight = std.ChainHeight var sl = []int{1,2,3,4,5} func fn() func(string) string { return Echo } type myStruct struct{a int} diff --git a/gno.land/pkg/sdk/vm/keeper.go b/gno.land/pkg/sdk/vm/keeper.go index bf16cd44243..08b88a143e3 100644 --- a/gno.land/pkg/sdk/vm/keeper.go +++ b/gno.land/pkg/sdk/vm/keeper.go @@ -265,13 +265,13 @@ func (vm *VMKeeper) checkNamespacePermission(ctx sdk.Context, creator crypto.Add // Parse and run the files, construct *PV. pkgAddr := gno.DerivePkgAddr(pkgPath) msgCtx := stdlibs.ExecContext{ - ChainID: ctx.ChainID(), - ChainDomain: chainDomain, - Height: ctx.BlockHeight(), - Timestamp: ctx.BlockTime().Unix(), - OrigCaller: creator.Bech32(), - OrigSendSpent: new(std.Coins), - OrigPkgAddr: pkgAddr.Bech32(), + ChainID: ctx.ChainID(), + ChainDomain: chainDomain, + Height: ctx.BlockHeight(), + Timestamp: ctx.BlockTime().Unix(), + OriginCaller: creator.Bech32(), + OriginSendSpent: new(std.Coins), + OriginPkgAddr: pkgAddr.Bech32(), // XXX: should we remove the banker ? Banker: NewSDKBanker(vm, ctx), Params: NewSDKParams(vm, ctx), @@ -370,17 +370,17 @@ func (vm *VMKeeper) AddPackage(ctx sdk.Context, msg MsgAddPackage) (err error) { // Parse and run the files, construct *PV. msgCtx := stdlibs.ExecContext{ - ChainID: ctx.ChainID(), - ChainDomain: chainDomain, - Height: ctx.BlockHeight(), - Timestamp: ctx.BlockTime().Unix(), - OrigCaller: creator.Bech32(), - OrigSend: deposit, - OrigSendSpent: new(std.Coins), - OrigPkgAddr: pkgAddr.Bech32(), - Banker: NewSDKBanker(vm, ctx), - Params: NewSDKParams(vm, ctx), - EventLogger: ctx.EventLogger(), + ChainID: ctx.ChainID(), + ChainDomain: chainDomain, + Height: ctx.BlockHeight(), + Timestamp: ctx.BlockTime().Unix(), + OriginCaller: creator.Bech32(), + OriginSend: deposit, + OriginSendSpent: new(std.Coins), + OriginPkgAddr: pkgAddr.Bech32(), + Banker: NewSDKBanker(vm, ctx), + Params: NewSDKParams(vm, ctx), + EventLogger: ctx.EventLogger(), } // Parse and run the files, construct *PV. m2 := gno.NewMachineWithOptions( @@ -461,17 +461,17 @@ func (vm *VMKeeper) Call(ctx sdk.Context, msg MsgCall) (res string, err error) { // could it be safely partially memoized? chainDomain := vm.getChainDomainParam(ctx) msgCtx := stdlibs.ExecContext{ - ChainID: ctx.ChainID(), - ChainDomain: chainDomain, - Height: ctx.BlockHeight(), - Timestamp: ctx.BlockTime().Unix(), - OrigCaller: caller.Bech32(), - OrigSend: send, - OrigSendSpent: new(std.Coins), - OrigPkgAddr: pkgAddr.Bech32(), - Banker: NewSDKBanker(vm, ctx), - Params: NewSDKParams(vm, ctx), - EventLogger: ctx.EventLogger(), + ChainID: ctx.ChainID(), + ChainDomain: chainDomain, + Height: ctx.BlockHeight(), + Timestamp: ctx.BlockTime().Unix(), + OriginCaller: caller.Bech32(), + OriginSend: send, + OriginSendSpent: new(std.Coins), + OriginPkgAddr: pkgAddr.Bech32(), + Banker: NewSDKBanker(vm, ctx), + Params: NewSDKParams(vm, ctx), + EventLogger: ctx.EventLogger(), } // Construct machine and evaluate. m := gno.NewMachineWithOptions( @@ -576,17 +576,17 @@ func (vm *VMKeeper) Run(ctx sdk.Context, msg MsgRun) (res string, err error) { // Parse and run the files, construct *PV. msgCtx := stdlibs.ExecContext{ - ChainID: ctx.ChainID(), - ChainDomain: chainDomain, - Height: ctx.BlockHeight(), - Timestamp: ctx.BlockTime().Unix(), - OrigCaller: caller.Bech32(), - OrigSend: send, - OrigSendSpent: new(std.Coins), - OrigPkgAddr: pkgAddr.Bech32(), - Banker: NewSDKBanker(vm, ctx), - Params: NewSDKParams(vm, ctx), - EventLogger: ctx.EventLogger(), + ChainID: ctx.ChainID(), + ChainDomain: chainDomain, + Height: ctx.BlockHeight(), + Timestamp: ctx.BlockTime().Unix(), + OriginCaller: caller.Bech32(), + OriginSend: send, + OriginSendSpent: new(std.Coins), + OriginPkgAddr: pkgAddr.Bech32(), + Banker: NewSDKBanker(vm, ctx), + Params: NewSDKParams(vm, ctx), + EventLogger: ctx.EventLogger(), } buf := new(bytes.Buffer) @@ -733,13 +733,13 @@ func (vm *VMKeeper) QueryEval(ctx sdk.Context, pkgPath string, expr string) (res ChainDomain: chainDomain, Height: ctx.BlockHeight(), Timestamp: ctx.BlockTime().Unix(), - // OrigCaller: caller, - // OrigSend: send, - // OrigSendSpent: nil, - OrigPkgAddr: pkgAddr.Bech32(), - Banker: NewSDKBanker(vm, ctx), // safe as long as ctx is a fork to be discarded. - Params: NewSDKParams(vm, ctx), - EventLogger: ctx.EventLogger(), + // OriginCaller: caller, + // OriginSend: send, + // OriginSendSpent: nil, + OriginPkgAddr: pkgAddr.Bech32(), + Banker: NewSDKBanker(vm, ctx), // safe as long as ctx is a fork to be discarded. + Params: NewSDKParams(vm, ctx), + EventLogger: ctx.EventLogger(), } m := gno.NewMachineWithOptions( gno.MachineOptions{ @@ -790,13 +790,13 @@ func (vm *VMKeeper) QueryEvalString(ctx sdk.Context, pkgPath string, expr string ChainDomain: chainDomain, Height: ctx.BlockHeight(), Timestamp: ctx.BlockTime().Unix(), - // OrigCaller: caller, - // OrigSend: jsend, - // OrigSendSpent: nil, - OrigPkgAddr: pkgAddr.Bech32(), - Banker: NewSDKBanker(vm, ctx), // safe as long as ctx is a fork to be discarded. - Params: NewSDKParams(vm, ctx), - EventLogger: ctx.EventLogger(), + // OriginCaller: caller, + // OriginSend: jsend, + // OriginSendSpent: nil, + OriginPkgAddr: pkgAddr.Bech32(), + Banker: NewSDKBanker(vm, ctx), // safe as long as ctx is a fork to be discarded. + Params: NewSDKParams(vm, ctx), + EventLogger: ctx.EventLogger(), } m := gno.NewMachineWithOptions( gno.MachineOptions{ diff --git a/gno.land/pkg/sdk/vm/keeper_test.go b/gno.land/pkg/sdk/vm/keeper_test.go index f8144988c44..243b2712632 100644 --- a/gno.land/pkg/sdk/vm/keeper_test.go +++ b/gno.land/pkg/sdk/vm/keeper_test.go @@ -106,7 +106,7 @@ func Echo() string {return "hello world"}`, } // Sending total send amount succeeds. -func TestVMKeeperOrigSend1(t *testing.T) { +func TestVMKeeperOriginSend1(t *testing.T) { env := setupTestEnv() ctx := env.vmk.MakeGnoTransactionStore(env.ctx) @@ -128,10 +128,10 @@ func init() { } func Echo(msg string) string { - addr := std.GetOrigCaller() - pkgAddr := std.GetOrigPkgAddr() - send := std.GetOrigSend() - banker := std.GetBanker(std.BankerTypeOrigSend) + addr := std.OriginCaller() + pkgAddr := std.OriginPkgAddress() + send := std.OriginSend() + banker := std.NewBanker(std.BankerTypeOriginSend) banker.SendCoins(pkgAddr, addr, send) // send back return "echo:"+msg }`}, @@ -151,7 +151,7 @@ func Echo(msg string) string { } // Sending too much fails -func TestVMKeeperOrigSend2(t *testing.T) { +func TestVMKeeperOriginSend2(t *testing.T) { env := setupTestEnv() ctx := env.vmk.MakeGnoTransactionStore(env.ctx) @@ -172,14 +172,14 @@ import "std" var admin std.Address func init() { - admin = std.GetOrigCaller() + admin = std.OriginCaller() } func Echo(msg string) string { - addr := std.GetOrigCaller() - pkgAddr := std.GetOrigPkgAddr() - send := std.GetOrigSend() - banker := std.GetBanker(std.BankerTypeOrigSend) + addr := std.OriginCaller() + pkgAddr := std.OriginPkgAddress() + send := std.OriginSend() + banker := std.NewBanker(std.BankerTypeOriginSend) banker.SendCoins(pkgAddr, addr, send) // send back return "echo:"+msg } @@ -205,7 +205,7 @@ func GetAdmin() string { } // Sending more than tx send fails. -func TestVMKeeperOrigSend3(t *testing.T) { +func TestVMKeeperOriginSend3(t *testing.T) { env := setupTestEnv() ctx := env.vmk.MakeGnoTransactionStore(env.ctx) @@ -227,10 +227,10 @@ func init() { } func Echo(msg string) string { - addr := std.GetOrigCaller() - pkgAddr := std.GetOrigPkgAddr() + addr := std.OriginCaller() + pkgAddr := std.OriginPkgAddress() send := std.Coins{{"ugnot", 10000000}} - banker := std.GetBanker(std.BankerTypeOrigSend) + banker := std.NewBanker(std.BankerTypeOriginSend) banker.SendCoins(pkgAddr, addr, send) // send back return "echo:"+msg }`}, @@ -271,10 +271,10 @@ func init() { } func Echo(msg string) string { - addr := std.GetOrigCaller() - pkgAddr := std.GetOrigPkgAddr() + addr := std.OriginCaller() + pkgAddr := std.OriginPkgAddress() send := std.Coins{{"ugnot", 10000000}} - banker := std.GetBanker(std.BankerTypeRealmSend) + banker := std.NewBanker(std.BankerTypeRealmSend) banker.SendCoins(pkgAddr, addr, send) // send back return "echo:"+msg }`}, @@ -315,10 +315,10 @@ func init() { } func Echo(msg string) string { - addr := std.GetOrigCaller() - pkgAddr := std.GetOrigPkgAddr() + addr := std.OriginCaller() + pkgAddr := std.OriginPkgAddress() send := std.Coins{{"ugnot", 10000000}} - banker := std.GetBanker(std.BankerTypeRealmSend) + banker := std.NewBanker(std.BankerTypeRealmSend) banker.SendCoins(pkgAddr, addr, send) // send back return "echo:"+msg }`}, @@ -390,8 +390,8 @@ func Do() string { assert.Equal(t, int64(1337), bar) } -// Assign admin as OrigCaller on deploying the package. -func TestVMKeeperOrigCallerInit(t *testing.T) { +// Assign admin as OriginCaller on deploying the package. +func TestVMKeeperOriginCallerInit(t *testing.T) { env := setupTestEnv() ctx := env.vmk.MakeGnoTransactionStore(env.ctx) @@ -412,14 +412,14 @@ import "std" var admin std.Address func init() { - admin = std.GetOrigCaller() + admin = std.OriginCaller() } func Echo(msg string) string { - addr := std.GetOrigCaller() - pkgAddr := std.GetOrigPkgAddr() - send := std.GetOrigSend() - banker := std.GetBanker(std.BankerTypeOrigSend) + addr := std.OriginCaller() + pkgAddr := std.OriginPkgAddress() + send := std.OriginSend() + banker := std.NewBanker(std.BankerTypeOriginSend) banker.SendCoins(pkgAddr, addr, send) // send back return "echo:"+msg } @@ -500,7 +500,7 @@ package main import "std" func main() { - addr := std.GetOrigCaller() + addr := std.OriginCaller() println("hello world!", addr) } `}, diff --git a/gnovm/pkg/gnolang/gonative.go b/gnovm/pkg/gnolang/gonative.go index 85fc8b70051..f93ae06f1d3 100644 --- a/gnovm/pkg/gnolang/gonative.go +++ b/gnovm/pkg/gnolang/gonative.go @@ -275,7 +275,7 @@ func Go2GnoNativeValue(alloc *Allocator, rv reflect.Value) (tv TypedValue) { return go2GnoValue(alloc, rv) } -// NOTE: used by imports_test.go TestSetOrigCaller. +// NOTE: used by imports_test.go TestSetOriginCaller. func Gno2GoValue(tv *TypedValue, rv reflect.Value) (ret reflect.Value) { return gno2GoValue(tv, rv) } diff --git a/gnovm/pkg/test/test.go b/gnovm/pkg/test/test.go index d06540761d7..fc4814aa478 100644 --- a/gnovm/pkg/test/test.go +++ b/gnovm/pkg/test/test.go @@ -51,17 +51,17 @@ func Context(pkgPath string, send std.Coins) *teststd.TestExecContext { }, } ctx := stdlibs.ExecContext{ - ChainID: "dev", - ChainDomain: "tests.gno.land", - Height: DefaultHeight, - Timestamp: DefaultTimestamp, - OrigCaller: DefaultCaller, - OrigPkgAddr: pkgAddr.Bech32(), - OrigSend: send, - OrigSendSpent: new(std.Coins), - Banker: banker, - Params: newTestParams(), - EventLogger: sdk.NewEventLogger(), + ChainID: "dev", + ChainDomain: "tests.gno.land", + Height: DefaultHeight, + Timestamp: DefaultTimestamp, + OriginCaller: DefaultCaller, + OriginPkgAddr: pkgAddr.Bech32(), + OriginSend: send, + OriginSendSpent: new(std.Coins), + Banker: banker, + Params: newTestParams(), + EventLogger: sdk.NewEventLogger(), } return &teststd.TestExecContext{ ExecContext: ctx, diff --git a/gnovm/pkg/transpiler/transpiler_test.go b/gnovm/pkg/transpiler/transpiler_test.go index 2a0707f7f79..38b241587b0 100644 --- a/gnovm/pkg/transpiler/transpiler_test.go +++ b/gnovm/pkg/transpiler/transpiler_test.go @@ -389,11 +389,11 @@ func otherFunc() { package std func AssertOriginCall() -func origCaller() string +func originCaller() string func testfunc() { AssertOriginCall() - println(origCaller()) + println(originCaller()) } `, expectedOutput: ` @@ -404,7 +404,7 @@ package std func testfunc() { AssertOriginCall(nil) - println(X_origCaller(nil)) + println(X_originCaller(nil)) } `, }, diff --git a/gnovm/stdlibs/generated.go b/gnovm/stdlibs/generated.go index 6bd45de3589..f00ce51b551 100644 --- a/gnovm/stdlibs/generated.go +++ b/gnovm/stdlibs/generated.go @@ -450,14 +450,14 @@ var nativeFuncs = [...]NativeFunc{ }, { "std", - "GetChainID", + "ChainID", []gno.FieldTypeExpr{}, []gno.FieldTypeExpr{ {Name: gno.N("r0"), Type: gno.X("string")}, }, true, func(m *gno.Machine) { - r0 := libs_std.GetChainID( + r0 := libs_std.ChainID( m, ) @@ -470,14 +470,14 @@ var nativeFuncs = [...]NativeFunc{ }, { "std", - "GetChainDomain", + "ChainDomain", []gno.FieldTypeExpr{}, []gno.FieldTypeExpr{ {Name: gno.N("r0"), Type: gno.X("string")}, }, true, func(m *gno.Machine) { - r0 := libs_std.GetChainDomain( + r0 := libs_std.ChainDomain( m, ) @@ -490,14 +490,14 @@ var nativeFuncs = [...]NativeFunc{ }, { "std", - "GetHeight", + "ChainHeight", []gno.FieldTypeExpr{}, []gno.FieldTypeExpr{ {Name: gno.N("r0"), Type: gno.X("int64")}, }, true, func(m *gno.Machine) { - r0 := libs_std.GetHeight( + r0 := libs_std.ChainHeight( m, ) @@ -510,7 +510,7 @@ var nativeFuncs = [...]NativeFunc{ }, { "std", - "origSend", + "originSend", []gno.FieldTypeExpr{}, []gno.FieldTypeExpr{ {Name: gno.N("r0"), Type: gno.X("[]string")}, @@ -518,7 +518,7 @@ var nativeFuncs = [...]NativeFunc{ }, true, func(m *gno.Machine) { - r0, r1 := libs_std.X_origSend( + r0, r1 := libs_std.X_originSend( m, ) @@ -536,14 +536,14 @@ var nativeFuncs = [...]NativeFunc{ }, { "std", - "origCaller", + "originCaller", []gno.FieldTypeExpr{}, []gno.FieldTypeExpr{ {Name: gno.N("r0"), Type: gno.X("string")}, }, true, func(m *gno.Machine) { - r0 := libs_std.X_origCaller( + r0 := libs_std.X_originCaller( m, ) @@ -556,14 +556,14 @@ var nativeFuncs = [...]NativeFunc{ }, { "std", - "origPkgAddr", + "originPkgAddr", []gno.FieldTypeExpr{}, []gno.FieldTypeExpr{ {Name: gno.N("r0"), Type: gno.X("string")}, }, true, func(m *gno.Machine) { - r0 := libs_std.X_origPkgAddr( + r0 := libs_std.X_originPkgAddr( m, ) diff --git a/gnovm/stdlibs/std/banker.gno b/gnovm/stdlibs/std/banker.gno index 4c20e8d4b61..9db914e6a4f 100644 --- a/gnovm/stdlibs/std/banker.gno +++ b/gnovm/stdlibs/std/banker.gno @@ -5,7 +5,7 @@ import ( "strings" ) -// Realm functions can call std.GetBanker(options) to get +// Realm functions can call std.NewBanker(options) to get // a banker instance. Banker objects cannot be persisted, // but can be passed onto other functions to be transacted // on. A banker instance can be passed onto other realm @@ -28,7 +28,7 @@ type Banker interface { } // BankerType represents the "permission level" requested for a banker, -// retrievable through [GetBanker]. +// retrievable through [NewBanker]. type BankerType uint8 // Available types of banker. @@ -36,7 +36,7 @@ const ( // Can only read state. BankerTypeReadonly BankerType = iota // Can only send from tx send. - BankerTypeOrigSend + BankerTypeOriginSend // Can send from all realm coins. BankerTypeRealmSend // Can issue and remove realm coins. @@ -49,8 +49,8 @@ func (b BankerType) String() string { switch b { case BankerTypeReadonly: return "BankerTypeReadonly" - case BankerTypeOrigSend: - return "BankerTypeOrigSend" + case BankerTypeOriginSend: + return "BankerTypeOriginSend" case BankerTypeRealmSend: return "BankerTypeRealmSend" case BankerTypeRealmIssue: @@ -63,22 +63,22 @@ func (b BankerType) String() string { //---------------------------------------- // adapter for native banker -// GetBanker returns a new Banker, with its capabilities matching the given +// NewBanker returns a new Banker, with its capabilities matching the given // [BankerType]. -func GetBanker(bt BankerType) Banker { +func NewBanker(bt BankerType) Banker { assertCallerIsRealm() if bt >= maxBanker { panic("invalid banker type") } var pkgAddr Address - if bt == BankerTypeOrigSend { - pkgAddr = GetOrigPkgAddr() - if pkgAddr != CurrentRealm().Addr() { - panic("banker with type BankerTypeOrigSend can only be instantiated by the origin package") + if bt == BankerTypeOriginSend { + pkgAddr = OriginPkgAddress() + if pkgAddr != CurrentRealm().Address() { + panic("banker with type BankerTypeOriginSend can only be instantiated by the origin package") } } else if bt == BankerTypeRealmSend || bt == BankerTypeRealmIssue { - pkgAddr = CurrentRealm().Addr() + pkgAddr = CurrentRealm().Address() } return banker{ bt, diff --git a/gnovm/stdlibs/std/banker.go b/gnovm/stdlibs/std/banker.go index c57ba8529ed..ee02b0cfad0 100644 --- a/gnovm/stdlibs/std/banker.go +++ b/gnovm/stdlibs/std/banker.go @@ -25,7 +25,7 @@ const ( // Can only read state. btReadonly uint8 = iota //nolint // Can only send from tx send. - btOrigSend + btOriginSend // Can send from all realm coins. btRealmSend // Can issue and remove realm coins. @@ -45,19 +45,19 @@ func X_bankerSendCoins(m *gno.Machine, bt uint8, fromS, toS string, denoms []str from, to := crypto.Bech32Address(fromS), crypto.Bech32Address(toS) switch bt { - case btOrigSend: + case btOriginSend: // indirection allows us to "commit" in a second phase - spent := (*ctx.OrigSendSpent).Add(amt) - if !ctx.OrigSend.IsAllGTE(spent) { + spent := (*ctx.OriginSendSpent).Add(amt) + if !ctx.OriginSend.IsAllGTE(spent) { m.Panic(typedString( fmt.Sprintf( `cannot send "%v", limit "%v" exceeded with "%v" already spent`, - amt, ctx.OrigSend, *ctx.OrigSendSpent), + amt, ctx.OriginSend, *ctx.OriginSendSpent), )) return } ctx.Banker.SendCoins(from, to, amt) - *ctx.OrigSendSpent = spent + *ctx.OriginSendSpent = spent case btRealmSend, btRealmIssue: ctx.Banker.SendCoins(from, to, amt) default: diff --git a/gnovm/stdlibs/std/context.go b/gnovm/stdlibs/std/context.go index a8ef500c346..37d246b0f1a 100644 --- a/gnovm/stdlibs/std/context.go +++ b/gnovm/stdlibs/std/context.go @@ -8,18 +8,18 @@ import ( ) type ExecContext struct { - ChainID string - ChainDomain string - Height int64 - Timestamp int64 // seconds - TimestampNano int64 // nanoseconds, only used for testing. - OrigCaller crypto.Bech32Address - OrigPkgAddr crypto.Bech32Address - OrigSend std.Coins - OrigSendSpent *std.Coins // mutable - Banker BankerInterface - Params ParamsInterface - EventLogger *sdk.EventLogger + ChainID string + ChainDomain string + Height int64 + Timestamp int64 // seconds + TimestampNano int64 // nanoseconds, only used for testing. + OriginCaller crypto.Bech32Address + OriginPkgAddr crypto.Bech32Address + OriginSend std.Coins + OriginSendSpent *std.Coins // mutable + Banker BankerInterface + Params ParamsInterface + EventLogger *sdk.EventLogger } // GetContext returns the execution context. diff --git a/gnovm/stdlibs/std/emit_event.go b/gnovm/stdlibs/std/emit_event.go index 10b00d62cfc..6e8f00ee3e8 100644 --- a/gnovm/stdlibs/std/emit_event.go +++ b/gnovm/stdlibs/std/emit_event.go @@ -18,7 +18,7 @@ func X_emit(m *gno.Machine, typ string, attrs []string) { } _, pkgPath := currentRealm(m) - fnIdent := getPrevFunctionNameFromTarget(m, "Emit") + fnIdent := getPreviousFunctionNameFromTarget(m, "Emit") ctx := GetContext(m) diff --git a/gnovm/stdlibs/std/frame.gno b/gnovm/stdlibs/std/frame.gno index 1709f8cb8b5..bcffa458043 100644 --- a/gnovm/stdlibs/std/frame.gno +++ b/gnovm/stdlibs/std/frame.gno @@ -5,7 +5,7 @@ type Realm struct { pkgPath string } -func (r Realm) Addr() Address { +func (r Realm) Address() Address { return r.addr } diff --git a/gnovm/stdlibs/std/native.gno b/gnovm/stdlibs/std/native.gno index 9cf8808a07e..732cdcef6cf 100644 --- a/gnovm/stdlibs/std/native.gno +++ b/gnovm/stdlibs/std/native.gno @@ -10,12 +10,12 @@ func AssertOriginCall() // injected // MsgRun. func IsOriginCall() bool // injected -func GetChainID() string // injected -func GetChainDomain() string // injected -func GetHeight() int64 // injected +func ChainID() string // injected +func ChainDomain() string // injected +func ChainHeight() int64 // injected -func GetOrigSend() Coins { - den, amt := origSend() +func OriginSend() Coins { + den, amt := originSend() coins := make(Coins, len(den)) for i := range coins { coins[i] = Coin{Denom: den[i], Amount: amt[i]} @@ -23,8 +23,8 @@ func GetOrigSend() Coins { return coins } -func GetOrigCaller() Address { - return Address(origCaller()) +func OriginCaller() Address { + return Address(originCaller()) } func CurrentRealm() Realm { @@ -32,23 +32,23 @@ func CurrentRealm() Realm { return Realm{Address(addr), path} } -func PrevRealm() Realm { +func PreviousRealm() Realm { addr, path := getRealm(1) return Realm{Address(addr), path} } -func GetOrigPkgAddr() Address { - return Address(origPkgAddr()) +func OriginPkgAddress() Address { + return Address(originPkgAddr()) } -func GetCallerAt(n int) Address { +func CallerAt(n int) Address { return Address(callerAt(n)) } // Variations which don't use named types. -func origSend() (denoms []string, amounts []int64) -func origCaller() string -func origPkgAddr() string +func originSend() (denoms []string, amounts []int64) +func originCaller() string +func originPkgAddr() string func callerAt(n int) string func getRealm(height int) (address string, pkgPath string) func assertCallerIsRealm() diff --git a/gnovm/stdlibs/std/native.go b/gnovm/stdlibs/std/native.go index 9e398e907a2..9e61d69e8d7 100644 --- a/gnovm/stdlibs/std/native.go +++ b/gnovm/stdlibs/std/native.go @@ -22,29 +22,29 @@ func IsOriginCall(m *gno.Machine) bool { return n <= 2 && isMsgCall } -func GetChainID(m *gno.Machine) string { +func ChainID(m *gno.Machine) string { return GetContext(m).ChainID } -func GetChainDomain(m *gno.Machine) string { +func ChainDomain(m *gno.Machine) string { return GetContext(m).ChainDomain } -func GetHeight(m *gno.Machine) int64 { +func ChainHeight(m *gno.Machine) int64 { return GetContext(m).Height } -// getPrevFunctionNameFromTarget returns the last called function name (identifier) from the call stack. -func getPrevFunctionNameFromTarget(m *gno.Machine, targetFunc string) string { - targetIndex := findTargetFuncIndex(m, targetFunc) +// getPreviousFunctionNameFromTarget returns the last called function name (identifier) from the call stack. +func getPreviousFunctionNameFromTarget(m *gno.Machine, targetFunc string) string { + targetIndex := findTargetFunctionIndex(m, targetFunc) if targetIndex == -1 { return "" } - return findPrevFuncName(m, targetIndex) + return findPreviousFunctionName(m, targetIndex) } -// findTargetFuncIndex finds and returns the index of the target function in the call stack. -func findTargetFuncIndex(m *gno.Machine, targetFunc string) int { +// findTargetFunctionIndex finds and returns the index of the target function in the call stack. +func findTargetFunctionIndex(m *gno.Machine, targetFunc string) int { for i := len(m.Frames) - 1; i >= 0; i-- { currFunc := m.Frames[i].Func if currFunc != nil && currFunc.Name == gno.Name(targetFunc) { @@ -54,8 +54,8 @@ func findTargetFuncIndex(m *gno.Machine, targetFunc string) int { return -1 } -// findPrevFuncName returns the function name before the given index in the call stack. -func findPrevFuncName(m *gno.Machine, targetIndex int) string { +// findPreviousFunctionName returns the function name before the given index in the call stack. +func findPreviousFunctionName(m *gno.Machine, targetIndex int) string { for i := targetIndex - 1; i >= 0; i-- { currFunc := m.Frames[i].Func if currFunc != nil { @@ -66,25 +66,25 @@ func findPrevFuncName(m *gno.Machine, targetIndex int) string { panic("function name not found") } -func X_origSend(m *gno.Machine) (denoms []string, amounts []int64) { - os := GetContext(m).OrigSend +func X_originSend(m *gno.Machine) (denoms []string, amounts []int64) { + os := GetContext(m).OriginSend return ExpandCoins(os) } -func X_origCaller(m *gno.Machine) string { - return string(GetContext(m).OrigCaller) +func X_originCaller(m *gno.Machine) string { + return string(GetContext(m).OriginCaller) } -func X_origPkgAddr(m *gno.Machine) string { - return string(GetContext(m).OrigPkgAddr) +func X_originPkgAddr(m *gno.Machine) string { + return string(GetContext(m).OriginPkgAddr) } func X_callerAt(m *gno.Machine, n int) string { if n <= 0 { - m.Panic(typedString("GetCallerAt requires positive arg")) + m.Panic(typedString("CallerAt requires positive arg")) return "" } - // Add 1 to n to account for the GetCallerAt (gno fn) frame. + // Add 1 to n to account for the CallerAt (gno fn) frame. n++ if n > m.NumFrames() { // NOTE: the last frame's LastPackage @@ -94,9 +94,9 @@ func X_callerAt(m *gno.Machine, n int) string { return "" } if n == m.NumFrames() { - // This makes it consistent with GetOrigCaller. + // This makes it consistent with OriginCaller. ctx := GetContext(m) - return string(ctx.OrigCaller) + return string(ctx.OriginCaller) } return string(m.MustLastCallFrame(n).LastPackage.GetPkgAddr().Bech32()) } @@ -131,8 +131,8 @@ func X_getRealm(m *gno.Machine, height int) (address, pkgPath string) { } } - // Fallback case: return OrigCaller. - return string(ctx.OrigCaller), "" + // Fallback case: return OriginCaller. + return string(ctx.OriginCaller), "" } // currentRealm retrieves the current realm's address and pkgPath. diff --git a/gnovm/stdlibs/std/native_test.go b/gnovm/stdlibs/std/native_test.go index 851785575d7..e509b990d00 100644 --- a/gnovm/stdlibs/std/native_test.go +++ b/gnovm/stdlibs/std/native_test.go @@ -9,11 +9,11 @@ import ( "github.com/gnolang/gno/tm2/pkg/crypto" ) -func TestPrevRealmIsOrigin(t *testing.T) { +func TestPreviousRealmIsOrigin(t *testing.T) { var ( user = gno.DerivePkgAddr("user1.gno").Bech32() ctx = ExecContext{ - OrigCaller: user, + OriginCaller: user, } msgCallFrame = &gno.Frame{LastPackage: &gno.PackageValue{PkgPath: "main"}} msgRunFrame = &gno.Frame{LastPackage: &gno.PackageValue{PkgPath: "gno.land/r/g1337/run"}} diff --git a/gnovm/tests/files/std10.gno b/gnovm/tests/files/std10.gno index 7caf534c5ca..b549387feaa 100644 --- a/gnovm/tests/files/std10.gno +++ b/gnovm/tests/files/std10.gno @@ -7,8 +7,8 @@ func main() { // assert panic is recoverable println(recover()) }() - std.GetCallerAt(0) + std.CallerAt(0) } // Output: -// GetCallerAt requires positive arg +// CallerAt requires positive arg diff --git a/gnovm/tests/files/std11.gno b/gnovm/tests/files/std11.gno index ce02fa11ec3..70668fe443b 100644 --- a/gnovm/tests/files/std11.gno +++ b/gnovm/tests/files/std11.gno @@ -7,7 +7,7 @@ func main() { // assert panic is recoverable println(recover()) }() - std.GetCallerAt(42) + std.CallerAt(42) } // Output: diff --git a/gnovm/tests/files/std2.gno b/gnovm/tests/files/std2.gno index fe218f8b34a..71865fdf97d 100644 --- a/gnovm/tests/files/std2.gno +++ b/gnovm/tests/files/std2.gno @@ -3,7 +3,7 @@ package main import "std" func main() { - caller := std.GetOrigCaller() + caller := std.OriginCaller() println(caller) } diff --git a/gnovm/tests/files/std3.gno b/gnovm/tests/files/std3.gno index e8d4bc31a12..a95c7395664 100644 --- a/gnovm/tests/files/std3.gno +++ b/gnovm/tests/files/std3.gno @@ -6,8 +6,8 @@ import ( ) func main() { - caller := std.GetOrigCaller() - caller2 := std.GetOrigCaller() + caller := std.OriginCaller() + caller2 := std.OriginCaller() cmp := bytes.Compare([]byte(caller), []byte(caller2)) println(cmp) } diff --git a/gnovm/tests/files/std4.gno b/gnovm/tests/files/std4.gno index d09bc6251c0..aef32507b08 100644 --- a/gnovm/tests/files/std4.gno +++ b/gnovm/tests/files/std4.gno @@ -5,7 +5,7 @@ import ( ) func main() { - caller1 := std.GetCallerAt(1) + caller1 := std.CallerAt(1) println(caller1) } diff --git a/gnovm/tests/files/std5.gno b/gnovm/tests/files/std5.gno index 2f9e98bb4ec..6ca5e893167 100644 --- a/gnovm/tests/files/std5.gno +++ b/gnovm/tests/files/std5.gno @@ -5,9 +5,9 @@ import ( ) func main() { - caller1 := std.GetCallerAt(1) + caller1 := std.CallerAt(1) println(caller1) - caller2 := std.GetCallerAt(2) + caller2 := std.CallerAt(2) println(caller2) } @@ -15,7 +15,7 @@ func main() { // panic: frame not found // callerAt(n) // gonative:std.callerAt -// std.GetCallerAt(2) +// std.CallerAt(2) // std/native.gno:45 // main() // main/files/std5.gno:10 diff --git a/gnovm/tests/files/std6.gno b/gnovm/tests/files/std6.gno index 20943f47d28..27c64503b13 100644 --- a/gnovm/tests/files/std6.gno +++ b/gnovm/tests/files/std6.gno @@ -3,9 +3,9 @@ package main import "std" func inner() { - caller1 := std.GetCallerAt(1) + caller1 := std.CallerAt(1) println(caller1) - caller2 := std.GetCallerAt(2) + caller2 := std.CallerAt(2) println(caller2) } diff --git a/gnovm/tests/files/std7.gno b/gnovm/tests/files/std7.gno index 9d602cc2039..ce767fe59e9 100644 --- a/gnovm/tests/files/std7.gno +++ b/gnovm/tests/files/std7.gno @@ -7,11 +7,11 @@ import ( ) func inner() { - caller1 := std.GetCallerAt(1) + caller1 := std.CallerAt(1) println(caller1) - caller2 := std.GetCallerAt(2) + caller2 := std.CallerAt(2) println(caller2) - caller3 := std.GetCallerAt(3) + caller3 := std.CallerAt(3) println(caller3) } diff --git a/gnovm/tests/files/std8.gno b/gnovm/tests/files/std8.gno index dfc2b8ca5fd..fb7c861e538 100644 --- a/gnovm/tests/files/std8.gno +++ b/gnovm/tests/files/std8.gno @@ -7,13 +7,13 @@ import ( ) func inner() { - caller1 := std.GetCallerAt(1) + caller1 := std.CallerAt(1) println(caller1) - caller2 := std.GetCallerAt(2) + caller2 := std.CallerAt(2) println(caller2) - caller3 := std.GetCallerAt(3) + caller3 := std.CallerAt(3) println(caller3) - caller4 := std.GetCallerAt(4) + caller4 := std.CallerAt(4) println(caller4) } @@ -25,7 +25,7 @@ func main() { // panic: frame not found // callerAt(n) // gonative:std.callerAt -// std.GetCallerAt(4) +// std.CallerAt(4) // std/native.gno:45 // fn() // main/files/std8.gno:16 diff --git a/gnovm/tests/files/zrealm_crossrealm11.gno b/gnovm/tests/files/zrealm_crossrealm11.gno index 5936743ddc6..29295e99d10 100644 --- a/gnovm/tests/files/zrealm_crossrealm11.gno +++ b/gnovm/tests/files/zrealm_crossrealm11.gno @@ -9,8 +9,8 @@ import ( rtests "gno.land/r/demo/tests" ) -func getPrevRealm() std.Realm { - return std.PrevRealm() +func getPreviousRealm() std.Realm { + return std.PreviousRealm() } func Exec(fn func()) { @@ -29,7 +29,7 @@ func main() { } assertRealm := func(r std.Realm) { - pkgPath := callersByAddr[r.Addr()] + pkgPath := callersByAddr[r.Address()] if r.IsUser() && pkgPath != "user1.gno" { panic(ufmt.Sprintf("ERROR: expected: 'user1.gno', got:'%s'", pkgPath)) } else if !r.IsUser() && pkgPath != r.PkgPath() { @@ -43,51 +43,51 @@ func main() { }{ { callStackAdd: "", - callerFn: std.PrevRealm, + callerFn: std.PreviousRealm, }, { - callStackAdd: " -> r/crossrealm_test.getPrevRealm", - callerFn: getPrevRealm, + callStackAdd: " -> r/crossrealm_test.getPreviousRealm", + callerFn: getPreviousRealm, }, { callStackAdd: " -> p/demo/tests", - callerFn: ptests.GetPrevRealm, + callerFn: ptests.GetPreviousRealm, }, { callStackAdd: " -> p/demo/tests -> p/demo/tests/subtests", - callerFn: ptests.GetPSubtestsPrevRealm, + callerFn: ptests.GetPSubtestsPreviousRealm, }, { callStackAdd: " -> r/demo/tests", - callerFn: rtests.GetPrevRealm, + callerFn: rtests.GetPreviousRealm, }, { callStackAdd: " -> r/demo/tests -> r/demo/tests/subtests", - callerFn: rtests.GetRSubtestsPrevRealm, + callerFn: rtests.GetRSubtestsPreviousRealm, }, } println("---") // needed to have space prefixes - printColumns("STACK", "std.PrevRealm") + printColumns("STACK", "std.PreviousRealm") printColumns("-----", "------------------") baseCallStack := "user1.gno -> r/crossrealm_test.main" for i, tt := range tests { - printColumns(baseCallStack+tt.callStackAdd, callersByAddr[tt.callerFn().Addr()]) + printColumns(baseCallStack+tt.callStackAdd, callersByAddr[tt.callerFn().Address()]) Exec(func() { r := tt.callerFn() assertRealm(r) - printColumns(baseCallStack+" -> r/crossrealm_test.Exec"+tt.callStackAdd, callersByAddr[r.Addr()]) + printColumns(baseCallStack+" -> r/crossrealm_test.Exec"+tt.callStackAdd, callersByAddr[r.Address()]) }) rtests.Exec(func() { r := tt.callerFn() assertRealm(r) - printColumns(baseCallStack+" -> r/demo/tests.Exec"+tt.callStackAdd, callersByAddr[r.Addr()]) + printColumns(baseCallStack+" -> r/demo/tests.Exec"+tt.callStackAdd, callersByAddr[r.Address()]) }) ptests.Exec(func() { r := tt.callerFn() assertRealm(r) - printColumns(baseCallStack+" -> p/demo/tests.Exec"+tt.callStackAdd, callersByAddr[r.Addr()]) + printColumns(baseCallStack+" -> p/demo/tests.Exec"+tt.callStackAdd, callersByAddr[r.Address()]) }) } } @@ -111,16 +111,16 @@ func printColumns(left, right string) { // Output: // --- -// STACK = std.PrevRealm +// STACK = std.PreviousRealm // ----- = ------------------ // user1.gno -> r/crossrealm_test.main = user1.gno // user1.gno -> r/crossrealm_test.main -> r/crossrealm_test.Exec = user1.gno // user1.gno -> r/crossrealm_test.main -> r/demo/tests.Exec = gno.land/r/demo/tests // user1.gno -> r/crossrealm_test.main -> p/demo/tests.Exec = user1.gno -// user1.gno -> r/crossrealm_test.main -> r/crossrealm_test.getPrevRealm = user1.gno -// user1.gno -> r/crossrealm_test.main -> r/crossrealm_test.Exec -> r/crossrealm_test.getPrevRealm = user1.gno -// user1.gno -> r/crossrealm_test.main -> r/demo/tests.Exec -> r/crossrealm_test.getPrevRealm = gno.land/r/demo/tests -// user1.gno -> r/crossrealm_test.main -> p/demo/tests.Exec -> r/crossrealm_test.getPrevRealm = user1.gno +// user1.gno -> r/crossrealm_test.main -> r/crossrealm_test.getPreviousRealm = user1.gno +// user1.gno -> r/crossrealm_test.main -> r/crossrealm_test.Exec -> r/crossrealm_test.getPreviousRealm = user1.gno +// user1.gno -> r/crossrealm_test.main -> r/demo/tests.Exec -> r/crossrealm_test.getPreviousRealm = gno.land/r/demo/tests +// user1.gno -> r/crossrealm_test.main -> p/demo/tests.Exec -> r/crossrealm_test.getPreviousRealm = user1.gno // user1.gno -> r/crossrealm_test.main -> p/demo/tests = user1.gno // user1.gno -> r/crossrealm_test.main -> r/crossrealm_test.Exec -> p/demo/tests = user1.gno // user1.gno -> r/crossrealm_test.main -> r/demo/tests.Exec -> p/demo/tests = gno.land/r/demo/tests diff --git a/gnovm/tests/files/zrealm_crossrealm12.gno b/gnovm/tests/files/zrealm_crossrealm12.gno index f2f229cd5de..5ae4d69879a 100644 --- a/gnovm/tests/files/zrealm_crossrealm12.gno +++ b/gnovm/tests/files/zrealm_crossrealm12.gno @@ -21,13 +21,13 @@ func main() { for _, test := range tests { r := test.fn() - if std.DerivePkgAddr(r.PkgPath()) != r.Addr() { + if std.DerivePkgAddr(r.PkgPath()) != r.Address() { panic(fmt.Sprintf("ERROR: expected: %v, got: %v", - std.DerivePkgAddr(r.PkgPath()), r.Addr(), + std.DerivePkgAddr(r.PkgPath()), r.Address(), )) } - println(r.PkgPath(), r.Addr()) + println(r.PkgPath(), r.Address()) } } diff --git a/gnovm/tests/files/zrealm_crossrealm13.gno b/gnovm/tests/files/zrealm_crossrealm13.gno index 4daeb6de366..53504d095ec 100644 --- a/gnovm/tests/files/zrealm_crossrealm13.gno +++ b/gnovm/tests/files/zrealm_crossrealm13.gno @@ -7,15 +7,15 @@ import ( func main() { PrintRealm() println(pad("CurrentRealm:"), std.CurrentRealm()) - println(pad("PrevRealm:"), std.PrevRealm()) + println(pad("PreviousRealm:"), std.PreviousRealm()) std.TestSetRealm(std.NewUserRealm("g1user")) PrintRealm() println(pad("CurrentRealm:"), std.CurrentRealm()) - println(pad("PrevRealm:"), std.PrevRealm()) + println(pad("PreviousRealm:"), std.PreviousRealm()) std.TestSetRealm(std.NewCodeRealm("gno.land/r/demo/users")) PrintRealm() println(pad("CurrentRealm:"), std.CurrentRealm()) - println(pad("PrevRealm:"), std.PrevRealm()) + println(pad("PreviousRealm:"), std.PreviousRealm()) } func pad(s string) string { @@ -27,7 +27,7 @@ func pad(s string) string { func PrintRealm() { println(pad("PrintRealm: CurrentRealm:"), std.CurrentRealm()) - println(pad("PrintRealm: PrevRealm:"), std.PrevRealm()) + println(pad("PrintRealm: PreviousRealm:"), std.PreviousRealm()) } // Because this is the context of a package, using PrintRealm() @@ -35,14 +35,14 @@ func PrintRealm() { // Output: // PrintRealm: CurrentRealm: (struct{("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm" std.Address),("" string)} std.Realm) -// PrintRealm: PrevRealm: (struct{("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm" std.Address),("" string)} std.Realm) +// PrintRealm: PreviousRealm: (struct{("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm" std.Address),("" string)} std.Realm) // CurrentRealm: (struct{("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm" std.Address),("" string)} std.Realm) -// PrevRealm: (struct{("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm" std.Address),("" string)} std.Realm) +// PreviousRealm: (struct{("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm" std.Address),("" string)} std.Realm) // PrintRealm: CurrentRealm: (struct{("g1user" std.Address),("" string)} std.Realm) -// PrintRealm: PrevRealm: (struct{("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm" std.Address),("" string)} std.Realm) +// PrintRealm: PreviousRealm: (struct{("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm" std.Address),("" string)} std.Realm) // CurrentRealm: (struct{("g1user" std.Address),("" string)} std.Realm) -// PrevRealm: (struct{("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm" std.Address),("" string)} std.Realm) +// PreviousRealm: (struct{("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm" std.Address),("" string)} std.Realm) // PrintRealm: CurrentRealm: (struct{("g17m4ga9t9dxn8uf06p3cahdavzfexe33ecg8v2s" std.Address),("gno.land/r/demo/users" string)} std.Realm) -// PrintRealm: PrevRealm: (struct{("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm" std.Address),("" string)} std.Realm) +// PrintRealm: PreviousRealm: (struct{("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm" std.Address),("" string)} std.Realm) // CurrentRealm: (struct{("g17m4ga9t9dxn8uf06p3cahdavzfexe33ecg8v2s" std.Address),("gno.land/r/demo/users" string)} std.Realm) -// PrevRealm: (struct{("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm" std.Address),("" string)} std.Realm) +// PreviousRealm: (struct{("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm" std.Address),("" string)} std.Realm) diff --git a/gnovm/tests/files/zrealm_crossrealm13a.gno b/gnovm/tests/files/zrealm_crossrealm13a.gno index 2fc37804fce..0434a0b6538 100644 --- a/gnovm/tests/files/zrealm_crossrealm13a.gno +++ b/gnovm/tests/files/zrealm_crossrealm13a.gno @@ -8,15 +8,15 @@ import ( func main() { PrintRealm() println(pad("CurrentRealm:"), std.CurrentRealm()) - println(pad("PrevRealm:"), std.PrevRealm()) + println(pad("PreviousRealm:"), std.PreviousRealm()) std.TestSetRealm(std.NewUserRealm("g1user")) PrintRealm() println(pad("CurrentRealm:"), std.CurrentRealm()) - println(pad("PrevRealm:"), std.PrevRealm()) + println(pad("PreviousRealm:"), std.PreviousRealm()) std.TestSetRealm(std.NewCodeRealm("gno.land/r/demo/users")) PrintRealm() println(pad("CurrentRealm:"), std.CurrentRealm()) - println(pad("PrevRealm:"), std.PrevRealm()) + println(pad("PreviousRealm:"), std.PreviousRealm()) } func pad(s string) string { @@ -28,19 +28,19 @@ func pad(s string) string { func PrintRealm() { println(pad("PrintRealm: CurrentRealm:"), std.CurrentRealm()) - println(pad("PrintRealm: PrevRealm:"), std.PrevRealm()) + println(pad("PrintRealm: PreviousRealm:"), std.PreviousRealm()) } // Output: // PrintRealm: CurrentRealm: (struct{("g1r0mlnkc05z0fv49km99z60qnp95tengyqfdr02" std.Address),("gno.land/r/demo/groups" string)} std.Realm) -// PrintRealm: PrevRealm: (struct{("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm" std.Address),("" string)} std.Realm) +// PrintRealm: PreviousRealm: (struct{("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm" std.Address),("" string)} std.Realm) // CurrentRealm: (struct{("g1r0mlnkc05z0fv49km99z60qnp95tengyqfdr02" std.Address),("gno.land/r/demo/groups" string)} std.Realm) -// PrevRealm: (struct{("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm" std.Address),("" string)} std.Realm) +// PreviousRealm: (struct{("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm" std.Address),("" string)} std.Realm) // PrintRealm: CurrentRealm: (struct{("g1r0mlnkc05z0fv49km99z60qnp95tengyqfdr02" std.Address),("gno.land/r/demo/groups" string)} std.Realm) -// PrintRealm: PrevRealm: (struct{("g1user" std.Address),("" string)} std.Realm) +// PrintRealm: PreviousRealm: (struct{("g1user" std.Address),("" string)} std.Realm) // CurrentRealm: (struct{("g1user" std.Address),("" string)} std.Realm) -// PrevRealm: (struct{("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm" std.Address),("" string)} std.Realm) +// PreviousRealm: (struct{("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm" std.Address),("" string)} std.Realm) // PrintRealm: CurrentRealm: (struct{("g1r0mlnkc05z0fv49km99z60qnp95tengyqfdr02" std.Address),("gno.land/r/demo/groups" string)} std.Realm) -// PrintRealm: PrevRealm: (struct{("g17m4ga9t9dxn8uf06p3cahdavzfexe33ecg8v2s" std.Address),("gno.land/r/demo/users" string)} std.Realm) +// PrintRealm: PreviousRealm: (struct{("g17m4ga9t9dxn8uf06p3cahdavzfexe33ecg8v2s" std.Address),("gno.land/r/demo/users" string)} std.Realm) // CurrentRealm: (struct{("g17m4ga9t9dxn8uf06p3cahdavzfexe33ecg8v2s" std.Address),("gno.land/r/demo/users" string)} std.Realm) -// PrevRealm: (struct{("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm" std.Address),("" string)} std.Realm) +// PreviousRealm: (struct{("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm" std.Address),("" string)} std.Realm) diff --git a/gnovm/tests/files/zrealm_initctx.gno b/gnovm/tests/files/zrealm_initctx.gno index 2fda65e7681..4fc05a6e59c 100644 --- a/gnovm/tests/files/zrealm_initctx.gno +++ b/gnovm/tests/files/zrealm_initctx.gno @@ -10,8 +10,8 @@ var addr = std.Address("test") var addrInit = std.Address("addrInit") func init() { - addr = std.GetOrigCaller() - addrInit = tests.InitOrigCaller() + addr = std.OriginCaller() + addrInit = tests.InitOriginCaller() } func main() { diff --git a/gnovm/tests/files/zrealm_natbind0.gno b/gnovm/tests/files/zrealm_natbind0.gno index 6f8045107dc..fb5a47afe66 100644 --- a/gnovm/tests/files/zrealm_natbind0.gno +++ b/gnovm/tests/files/zrealm_natbind0.gno @@ -8,7 +8,7 @@ import ( var node interface{} func init() { - node = std.GetHeight + node = std.ChainHeight } func main() { @@ -17,7 +17,7 @@ func main() { // to convert the types to builtin go/gno identifiers). f := node.(func() int64) println(f()) - node = std.GetChainID + node = std.ChainID g := node.(func() string) println(g()) } diff --git a/gnovm/tests/files/zrealm_natbind1_stdlibs.gno b/gnovm/tests/files/zrealm_natbind1_stdlibs.gno index f44b6ab4fcf..2011624b186 100644 --- a/gnovm/tests/files/zrealm_natbind1_stdlibs.gno +++ b/gnovm/tests/files/zrealm_natbind1_stdlibs.gno @@ -6,7 +6,7 @@ import ( ) func main() { - println(std.GetChainDomain()) + println(std.ChainDomain()) } // Output: diff --git a/gnovm/tests/files/zrealm_std0.gno b/gnovm/tests/files/zrealm_std0.gno index 3f6bdae2537..fff6d6882b8 100644 --- a/gnovm/tests/files/zrealm_std0.gno +++ b/gnovm/tests/files/zrealm_std0.gno @@ -6,7 +6,7 @@ import ( ) func main() { - caller := std.GetOrigCaller() + caller := std.OriginCaller() println(caller) } diff --git a/gnovm/tests/files/zrealm_std1.gno b/gnovm/tests/files/zrealm_std1.gno index d75a2c60b71..8206b7b4097 100644 --- a/gnovm/tests/files/zrealm_std1.gno +++ b/gnovm/tests/files/zrealm_std1.gno @@ -8,14 +8,14 @@ import ( var aset *std.AddressList func init() { - caller := std.GetOrigCaller() + caller := std.OriginCaller() aset = std.NewAddressList() aset.AddAddress(caller) } func main() { println(*aset) - caller := std.GetOrigCaller() + caller := std.OriginCaller() err := aset.AddAddress(caller) println("error:", err) has := aset.HasAddress(caller) diff --git a/gnovm/tests/files/zrealm_std2.gno b/gnovm/tests/files/zrealm_std2.gno index 810210c6160..15d137bf556 100644 --- a/gnovm/tests/files/zrealm_std2.gno +++ b/gnovm/tests/files/zrealm_std2.gno @@ -9,14 +9,14 @@ import ( var aset std.AddressSet func init() { - caller := std.GetOrigCaller() + caller := std.OriginCaller() aset = std.NewAddressList() aset.AddAddress(caller) } func main() { println(*(aset.(*std.AddressList))) - caller := std.GetOrigCaller() + caller := std.OriginCaller() err := aset.AddAddress(caller) println("error:", err) has := aset.HasAddress(caller) diff --git a/gnovm/tests/files/zrealm_std6.gno b/gnovm/tests/files/zrealm_std6.gno index 17a79c1d43b..b2ab6432d13 100644 --- a/gnovm/tests/files/zrealm_std6.gno +++ b/gnovm/tests/files/zrealm_std6.gno @@ -6,7 +6,7 @@ import ( ) var ( - realmAddr std.Address = std.GetOrigPkgAddr() + realmAddr std.Address = std.OriginPkgAddress() ) func main() { diff --git a/gnovm/tests/integ/context/context.gno b/gnovm/tests/integ/context/context.gno index 92a9cc632b7..58274b8e5d4 100644 --- a/gnovm/tests/integ/context/context.gno +++ b/gnovm/tests/integ/context/context.gno @@ -7,5 +7,5 @@ import ( func Context() { // This requires a Context to work; it will fail ugly if the Context isn't available. - fmt.Printf("Context worked: %d\n", std.GetHeight()) + fmt.Printf("Context worked: %d\n", std.ChainHeight()) } diff --git a/gnovm/tests/stdlibs/generated.go b/gnovm/tests/stdlibs/generated.go index 4445d2467e8..d32156c363f 100644 --- a/gnovm/tests/stdlibs/generated.go +++ b/gnovm/tests/stdlibs/generated.go @@ -117,7 +117,7 @@ var nativeFuncs = [...]NativeFunc{ }, { "std", - "testSetOrigCaller", + "testSetOriginCaller", []gno.FieldTypeExpr{ {Name: gno.N("p0"), Type: gno.X("string")}, }, @@ -132,14 +132,14 @@ var nativeFuncs = [...]NativeFunc{ gno.Gno2GoValue(b.GetPointerTo(nil, gno.NewValuePathBlock(1, 0, "")).TV, rp0) - testlibs_std.X_testSetOrigCaller( + testlibs_std.X_testSetOriginCaller( m, p0) }, }, { "std", - "testSetOrigPkgAddr", + "testSetOriginPkgAddr", []gno.FieldTypeExpr{ {Name: gno.N("p0"), Type: gno.X("string")}, }, @@ -154,7 +154,7 @@ var nativeFuncs = [...]NativeFunc{ gno.Gno2GoValue(b.GetPointerTo(nil, gno.NewValuePathBlock(1, 0, "")).TV, rp0) - testlibs_std.X_testSetOrigPkgAddr( + testlibs_std.X_testSetOriginPkgAddr( m, p0) }, @@ -187,7 +187,7 @@ var nativeFuncs = [...]NativeFunc{ }, { "std", - "testSetOrigSend", + "testSetOriginSend", []gno.FieldTypeExpr{ {Name: gno.N("p0"), Type: gno.X("[]string")}, {Name: gno.N("p1"), Type: gno.X("[]int64")}, @@ -214,7 +214,7 @@ var nativeFuncs = [...]NativeFunc{ gno.Gno2GoValue(b.GetPointerTo(nil, gno.NewValuePathBlock(1, 2, "")).TV, rp2) gno.Gno2GoValue(b.GetPointerTo(nil, gno.NewValuePathBlock(1, 3, "")).TV, rp3) - testlibs_std.X_testSetOrigSend( + testlibs_std.X_testSetOriginSend( m, p0, p1, p2, p3) }, diff --git a/gnovm/tests/stdlibs/std/std.gno b/gnovm/tests/stdlibs/std/std.gno index dcb5a64dbb3..46b73ef99ea 100644 --- a/gnovm/tests/stdlibs/std/std.gno +++ b/gnovm/tests/stdlibs/std/std.gno @@ -4,20 +4,20 @@ func AssertOriginCall() // injected func IsOriginCall() bool // injected func TestSkipHeights(count int64) // injected -func TestSetOrigCaller(addr Address) { testSetOrigCaller(string(addr)) } -func TestSetOrigPkgAddr(addr Address) { testSetOrigPkgAddr(string(addr)) } +func TestSetOriginCaller(addr Address) { testSetOriginCaller(string(addr)) } +func TestSetOriginPkgAddress(addr Address) { testSetOriginPkgAddr(string(addr)) } // TestSetRealm sets the realm for the current frame. // After calling TestSetRealm, calling CurrentRealm() in the test function will yield the value of -// rlm, while if a realm function is called, using PrevRealm() will yield rlm. +// rlm, while if a realm function is called, using PreviousRealm() will yield rlm. func TestSetRealm(rlm Realm) { testSetRealm(string(rlm.addr), rlm.pkgPath) } -func TestSetOrigSend(sent, spent Coins) { +func TestSetOriginSend(sent, spent Coins) { sentDenom, sentAmt := sent.expandNative() spentDenom, spentAmt := spent.expandNative() - testSetOrigSend(sentDenom, sentAmt, spentDenom, spentAmt) + testSetOriginSend(sentDenom, sentAmt, spentDenom, spentAmt) } func TestIssueCoins(addr Address, coins Coins) { @@ -25,14 +25,14 @@ func TestIssueCoins(addr Address, coins Coins) { testIssueCoins(string(addr), denom, amt) } -// GetCallerAt calls callerAt, which we overwrite +// CallerAt calls callerAt, which we overwrite func callerAt(n int) string // native bindings -func testSetOrigCaller(s string) -func testSetOrigPkgAddr(s string) +func testSetOriginCaller(s string) +func testSetOriginPkgAddr(s string) func testSetRealm(addr, pkgPath string) -func testSetOrigSend( +func testSetOriginSend( sentDenom []string, sentAmt []int64, spentDenom []string, spentAmt []int64) func testIssueCoins(addr string, denom []string, amt []int64) diff --git a/gnovm/tests/stdlibs/std/std.go b/gnovm/tests/stdlibs/std/std.go index 675194b252f..e83c35a0787 100644 --- a/gnovm/tests/stdlibs/std/std.go +++ b/gnovm/tests/stdlibs/std/std.go @@ -14,7 +14,7 @@ import ( type TestExecContext struct { std.ExecContext - // These are used to set up the result of CurrentRealm() and PrevRealm(). + // These are used to set up the result of CurrentRealm() and PreviousRealm(). RealmFrames map[*gno.Frame]RealmOverride } @@ -71,10 +71,10 @@ func TestSkipHeights(m *gno.Machine, count int64) { func X_callerAt(m *gno.Machine, n int) string { if n <= 0 { - m.Panic(typedString("GetCallerAt requires positive arg")) + m.Panic(typedString("CallerAt requires positive arg")) return "" } - // Add 1 to n to account for the GetCallerAt (gno fn) frame. + // Add 1 to n to account for the CallerAt (gno fn) frame. n++ if n > m.NumFrames()-1 { // NOTE: the last frame's LastPackage @@ -84,22 +84,22 @@ func X_callerAt(m *gno.Machine, n int) string { return "" } if n == m.NumFrames()-1 { - // This makes it consistent with GetOrigCaller and TestSetOrigCaller. + // This makes it consistent with OriginCaller and TestSetOriginCaller. ctx := m.Context.(*TestExecContext) - return string(ctx.OrigCaller) + return string(ctx.OriginCaller) } return string(m.MustLastCallFrame(n).LastPackage.GetPkgAddr().Bech32()) } -func X_testSetOrigCaller(m *gno.Machine, addr string) { +func X_testSetOriginCaller(m *gno.Machine, addr string) { ctx := m.Context.(*TestExecContext) - ctx.OrigCaller = crypto.Bech32Address(addr) + ctx.OriginCaller = crypto.Bech32Address(addr) m.Context = ctx } -func X_testSetOrigPkgAddr(m *gno.Machine, addr string) { +func X_testSetOriginPkgAddr(m *gno.Machine, addr string) { ctx := m.Context.(*TestExecContext) - ctx.OrigPkgAddr = crypto.Bech32Address(addr) + ctx.OriginPkgAddr = crypto.Bech32Address(addr) m.Context = ctx } @@ -160,22 +160,22 @@ func X_getRealm(m *gno.Machine, height int) (address string, pkgPath string) { } } - // Fallback case: return OrigCaller. - return string(ctx.OrigCaller), "" + // Fallback case: return OriginCaller. + return string(ctx.OriginCaller), "" } func X_isRealm(m *gno.Machine, pkgPath string) bool { return gno.IsRealmPath(pkgPath) } -func X_testSetOrigSend(m *gno.Machine, +func X_testSetOriginSend(m *gno.Machine, sentDenom []string, sentAmt []int64, spentDenom []string, spentAmt []int64, ) { ctx := m.Context.(*TestExecContext) - ctx.OrigSend = std.CompactCoins(sentDenom, sentAmt) + ctx.OriginSend = std.CompactCoins(sentDenom, sentAmt) spent := std.CompactCoins(spentDenom, spentAmt) - ctx.OrigSendSpent = &spent + ctx.OriginSendSpent = &spent m.Context = ctx }