Skip to content

Commit

Permalink
chore: remove Get prefixes from GetCallerAt, GetOrigSend, GetOrigCaller
Browse files Browse the repository at this point in the history
  • Loading branch information
hthieu1110 committed Dec 19, 2024
1 parent 018ef43 commit c57797d
Show file tree
Hide file tree
Showing 85 changed files with 218 additions and 218 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ func Bid() {
panic("Exceeded auction end block")
}

sentCoins := std.GetOrigSend()
sentCoins := std.OrigSend()
if len(sentCoins) != 1 {
panic("Send only one type of coin")
}
Expand All @@ -23,7 +23,7 @@ func Bid() {
}

// Update the top bidder address
highestBidder = std.GetOrigCaller()
highestBidder = std.OrigCaller()
// Update the top bid amount
highestBid = sentAmount
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
func Withdraw() {
// Query the return amount to non-highest bidders
amount, _ := pendingReturns.Get(std.GetOrigCaller().String())
amount, _ := pendingReturns.Get(std.OrigCaller().String())

if amount > 0 {
// If there's an amount, reset the amount first,
pendingReturns.Set(std.GetOrigCaller().String(), 0)
pendingReturns.Set(std.OrigCaller().String(), 0)

// Return the exceeded amount
banker := std.GetBanker(std.BankerTypeRealmSend)
pkgAddr := std.GetOrigPkgAddr()

banker.SendCoins(pkgAddr, std.GetOrigCaller(), std.Coins{{"ugnot", amount.(int64)}})
banker.SendCoins(pkgAddr, std.OrigCaller(), std.Coins{{"ugnot", amount.(int64)}})
}
}
2 changes: 1 addition & 1 deletion docs/assets/how-to-guides/write-simple-dapp/poll-2.gno
Original file line number Diff line number Diff line change
Expand Up @@ -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.OrigCaller()

// get specific Poll from AVL tree
pollRaw, exists := polls.Get(id)
Expand Down
8 changes: 4 additions & 4 deletions docs/concepts/effective-gno.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,10 @@ var (

func init() {
created = time.Now()
// std.GetOrigCaller in the context of realm initialisation is,
// std.OrigCaller 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.OrigCaller()
// list is already initialized, so it will already contain "foo", "bar" and
// the current time as existing items.
list = append(list, admin.String())
Expand Down Expand Up @@ -498,10 +498,10 @@ One strategy is to look at the caller with `std.PrevRealm()`, 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.OrigCaller()`, 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.OrigCaller`.

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
Expand Down
10 changes: 5 additions & 5 deletions docs/how-to-guides/porting-solidity-to-gno.md
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ func Bid() {
panic("Exceeded auction end block")
}

sentCoins := std.GetOrigSend()
sentCoins := std.OrigSend()
if len(sentCoins) != 1 {
panic("Send only one type of coin")
}
Expand All @@ -373,7 +373,7 @@ func Bid() {
}

// Update the top bidder address
highestBidder = std.GetOrigCaller()
highestBidder = std.OrigCaller()
// Update the top bid amount
highestBid = sentAmount
}
Expand Down Expand Up @@ -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.OrigCaller().String())

if amount > 0 {
// If there's an amount, reset the amount first,
pendingReturns.Set(std.GetOrigCaller().String(), 0)
pendingReturns.Set(std.OrigCaller().String(), 0)

// Return the exceeded amount
banker := std.GetBanker(std.BankerTypeRealmSend)
pkgAddr := std.GetOrigPkgAddr()

banker.SendCoins(pkgAddr, std.GetOrigCaller(), std.Coins{{"ugnot", amount.(int64)}})
banker.SendCoins(pkgAddr, std.OrigCaller(), std.Coins{{"ugnot", amount.(int64)}})
}
}
```
Expand Down
2 changes: 1 addition & 1 deletion docs/how-to-guides/write-simple-dapp.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.OrigCaller()

// get specific Poll from AVL tree
pollRaw, exists := polls.Get(id)
Expand Down
12 changes: 6 additions & 6 deletions docs/reference/stdlibs/std/chain.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,27 +77,27 @@ height := std.GetHeight()
```
---

## GetOrigSend
## OrigSend
```go
func GetOrigSend() Coins
func OrigSend() Coins
```
Returns the `Coins` that were sent along with the calling transaction.

#### Usage
```go
coinsSent := std.GetOrigSend()
coinsSent := std.OrigSend()
```
---

## GetOrigCaller
## OrigCaller
```go
func GetOrigCaller() Address
func OrigCaller() Address
```
Returns the original signer of the transaction.

#### Usage
```go
caller := std.GetOrigCaller()
caller := std.OrigCaller()
```
---

Expand Down
2 changes: 1 addition & 1 deletion examples/gno.land/p/demo/gnorkle/gnorkle/instance.gno
Original file line number Diff line number Diff line change
Expand Up @@ -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.OrigCaller())

funcType, msg := message.ParseFunc(msg)

Expand Down
20 changes: 10 additions & 10 deletions examples/gno.land/p/demo/grc/grc1155/basic_grc1155_token.gno
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (s *basicGRC1155Token) SetApprovalForAll(operator std.Address, approved boo
return ErrInvalidAddress
}

caller := std.GetOrigCaller()
caller := std.OrigCaller()
return s.setApprovalForAll(caller, operator, approved)
}

Expand All @@ -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.OrigCaller()
if !s.IsApprovedForAll(caller, from) {
return ErrCallerIsNotOwnerOrApproved
}
Expand All @@ -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.OrigCaller()
if !s.IsApprovedForAll(caller, from) {
return ErrCallerIsNotOwnerOrApproved
}
Expand All @@ -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.OrigCaller()

err := s.mintBatch(to, []TokenID{tid}, []uint64{amount})
if err != nil {
Expand All @@ -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.OrigCaller()

err := s.mintBatch(to, batch, amounts)
if err != nil {
Expand All @@ -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.OrigCaller()

err := s.burnBatch(from, []TokenID{tid}, []uint64{amount})
if err != nil {
Expand All @@ -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.OrigCaller()

err := s.burnBatch(from, batch, amounts)
if err != nil {
Expand Down Expand Up @@ -225,7 +225,7 @@ func (s *basicGRC1155Token) safeBatchTransferFrom(from, to std.Address, batch []
return ErrCannotTransferToSelf
}

caller := std.GetOrigCaller()
caller := std.OrigCaller()
s.beforeTokenTransfer(caller, from, to, batch, amounts)

for i := 0; i < len(batch); i++ {
Expand Down Expand Up @@ -265,7 +265,7 @@ func (s *basicGRC1155Token) mintBatch(to std.Address, batch []TokenID, amounts [
return ErrInvalidAddress
}

caller := std.GetOrigCaller()
caller := std.OrigCaller()
s.beforeTokenTransfer(caller, zeroAddress, to, batch, amounts)

for i := 0; i < len(batch); i++ {
Expand Down Expand Up @@ -294,7 +294,7 @@ func (s *basicGRC1155Token) burnBatch(from std.Address, batch []TokenID, amounts
return ErrInvalidAddress
}

caller := std.GetOrigCaller()
caller := std.OrigCaller()
s.beforeTokenTransfer(caller, from, zeroAddress, batch, amounts)

for i := 0; i < len(batch); i++ {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.OrigCaller()
addr := std.Address("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")

isApprovedForAll := dummy.IsApprovedForAll(caller, addr)
Expand All @@ -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.OrigCaller()
addr := std.Address("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")

tid := TokenID("1")
Expand Down Expand Up @@ -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.OrigCaller()
addr := std.Address("g1var589z07ppjsjd24ukm4uguzwdt0tw7g47cgm")

tid1 := TokenID("1")
Expand Down
2 changes: 1 addition & 1 deletion examples/gno.land/p/demo/microblog/microblog.gno
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (m *Microblog) GetPages() []*Page {
}

func (m *Microblog) NewPost(text string) error {
author := std.GetOrigCaller()
author := std.OrigCaller()
_, found := m.Pages.Get(author.String())
if !found {
// make a new page for the new author
Expand Down
6 changes: 3 additions & 3 deletions examples/gno.land/p/demo/simpledao/dao.gno
Original file line number Diff line number Diff line change
Expand Up @@ -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.OrigSend() // Get the sent coins, if any
canCoverFee = sentCoins.AmountOf("ugnot") >= minProposalFee.Amount
)

Expand Down Expand Up @@ -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.OrigSend() // Get the sent coins, if any
canCoverFee = sentCoins.AmountOf("ugnot") >= minExecuteFee.Amount
)

Expand Down Expand Up @@ -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.OrigCaller()
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.OrigSend()

if amount.AmountOf("ugnot") != ls.amount {
return ErrAmt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.OrigSend()

if amount.AmountOf("ugnot") != rs.amount {
return ErrAmt
Expand Down
2 changes: 1 addition & 1 deletion examples/gno.land/p/demo/todolist/todolist.gno
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func NewTodoList(title string) *TodoList {
return &TodoList{
Title: title,
Tasks: avl.NewTree(),
Owner: std.GetOrigCaller(),
Owner: std.OrigCaller(),
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/gno.land/p/demo/todolist/todolist_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -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.OrigCaller().String(), todoList.GetTodolistOwner().String())
}

func TestNewTask(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions examples/gno.land/r/demo/banktest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.OrigCaller()
send := std.Coins{{returnDenom, returnAmount}}
```
Expand All @@ -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.OrigSend(),
returned: send,
time: time.Now(),
}
Expand Down
4 changes: 2 additions & 2 deletions examples/gno.land/r/demo/banktest/banktest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -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.OrigCaller()
send := std.Coins{{returnDenom, returnAmount}}
// record activity
act := &activity{
caller: caller,
sent: std.GetOrigSend(),
sent: std.OrigSend(),
returned: send,
time: time.Now(),
}
Expand Down
Loading

0 comments on commit c57797d

Please sign in to comment.