Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat: add r/demo/atomicswap #2510

Open
wants to merge 106 commits into
base: master
Choose a base branch
from
Open

Conversation

moul
Copy link
Member

@moul moul commented Jul 5, 2024

  • implement
  • unit test / txtar
  • question: ugnot or grc20 or both? Maybe it’s time to encourage using wugnot.
    -> both, with a callback mechanism.
  • question: p+r or just r?
    -> just r, and a single file. let's do it more!
  • make the API gnokey compatible + add Render.

Depends on #3397 (cherry-picked)
Depends on #2529 (cherry-picked)
Depends on #2549 (cherry-picked)
Depends on #2551
Closes #2549

@moul moul self-assigned this Jul 5, 2024
@github-actions github-actions bot added the 🧾 package/realm Tag used for new Realms or Packages. label Jul 5, 2024
Signed-off-by: moul <[email protected]>
@github-actions github-actions bot added the 📦 🤖 gnovm Issues or PRs gnovm related label Jul 5, 2024
Signed-off-by: moul <[email protected]>
Copy link

codecov bot commented Jul 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

📢 Thoughts on this report? Let us know!

@moul
Copy link
Member Author

moul commented Jul 5, 2024

I think i'll try to be more grc20-centric for my demos. In involves writing some helpers to show how to actually come with gnot tokens, wrap then with wugnot. But also writing more and more grc20 examples: stupid ones, testing-purpose ones, etc.

@moul moul marked this pull request as ready for review July 6, 2024 20:26
@moul moul requested review from thehowl and a team as code owners July 6, 2024 20:26
gnovm/stdlibs/std/coins.gno Outdated Show resolved Hide resolved
albttx pushed a commit that referenced this pull request Jan 10, 2025
- [x] Switch to storing a `type XXX func() grc20.Token` instead of a
`grc20.Token` directly.
-  [x] Implement `grc20reg`.  
- [x] Add new tests in `gnovm/tests` to demonstrate the current VM's
management of the cross-realm feature and support potential changes in
#2743.
- [x] Create a demo in `atomicswap` or a similar application.
(#2510 (comment))
-  [x] Try using a `Token.Getter()` helper.  (Works! f99654e)
- [ ] Demonstrate how to manage "disappearing" functions during garbage
collection by checking if the function pointer is nil or non-resolvable.

Alternative to #2516  
NOT(!) depending on #2743

---------

Signed-off-by: moul <[email protected]>
moul added 2 commits January 10, 2025 18:14
Signed-off-by: moul <[email protected]>
Signed-off-by: moul <[email protected]>
@moul moul requested review from leohhhn, n0izn0iz and notJoon and removed request for mvertes, thehowl and a team January 10, 2025 18:25
@moul
Copy link
Member Author

moul commented Jan 10, 2025

Ready for review.

@moul moul removed the don't merge Please don't merge this functionality temporarily label Jan 10, 2025
Copy link
Contributor

@leohhhn leohhhn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a few comments, otherwise I will try it out after merging.

I will also port my k=x*y minidex next to this so we can have it as an example.

func NewCustomCoinSwap(recipient std.Address, hashlock string, timelock time.Time) (int, *Swap) {
sender := std.PrevRealm().Addr()
sent := std.GetOrigSend()
require(len(sent) != 0, "at least one coin needs to be sent")
Copy link
Contributor

@leohhhn leohhhn Jan 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is Solidity's style. While I appreciate the conciseness, do you think we should stick to the Go idiomatic way of checking for errors? ie if err:= ...; err!=nil {panic(err)}

Not sure what should be the way forward.

Copy link
Member Author

@moul moul Jan 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is Go too, not very famous, and usually found only in mains or "scripts." I believe it will become more common in Gno realms.

For instance, here is a Go package I wrote several years ago because I was accustomed to having this helper in all my mains: https://pkg.go.dev/moul.io/u#CheckErr

examples/gno.land/r/demo/atomicswap/atomicswap.gno Outdated Show resolved Hide resolved
Comment on lines +108 to +114
} else { // by id
swap, ok := swaps.Get(path)
if !ok {
return "404"
}
return swap.(*Swap).String()
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can be written without the else block enclosing the code

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I won't fix it myself since I prefer this version to resemble a "switch case" with clear responsibilities. However, if someone believes it's important enough, feel free to send a suggestion that I will approve.

examples/gno.land/r/demo/atomicswap/atomicswap.gno Outdated Show resolved Hide resolved
gno.land/pkg/integration/testdata/atomicswap.txtar Outdated Show resolved Hide resolved
Signed-off-by: moul <[email protected]>
@moul moul enabled auto-merge (squash) January 15, 2025 15:31
@moul moul requested a review from n2p5 January 15, 2025 21:16
Copy link
Contributor

@n0izn0iz n0izn0iz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used this realm in an atomic swap experiment with a cosmwasm contract on the other side and it worked good :)

Copy link
Contributor

@n2p5 n2p5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 ⛰️ gno.land Issues or PRs gno.land package related 📦 🤖 gnovm Issues or PRs gnovm related 🧾 package/realm Tag used for new Realms or Packages.
Projects
Status: In Progress
Status: 🙏🏻 To Delegate
Status: No status
Status: In Review
Development

Successfully merging this pull request may close these issues.

6 participants