Skip to content

feat: r/coins balance checker #3899

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

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

Conversation

notJoon
Copy link
Member

@notJoon notJoon commented Mar 10, 2025

Description

Implemented the token inquiry function. Currently, only the feature to check coins at a specific address is provided, and the function to check the total quantity is not yet supported.

Example Usage:

  • /r/gnoland/coins:ugnot - shows the total supply of ugnot
  • /r/gnoland/coins:ugnot/g1... - shows the ugnot balance of a specific address

Related

@github-actions github-actions bot added 🧾 package/realm Tag used for new Realms or Packages. 📦 ⛰️ gno.land Issues or PRs gno.land package related labels Mar 10, 2025
@Gno2D2 Gno2D2 requested a review from a team March 10, 2025 04:21
@Gno2D2
Copy link
Collaborator

Gno2D2 commented Mar 10, 2025

🛠 PR Checks Summary

🔴 Must not contain the "don't merge" label

Manual Checks (for Reviewers):
  • IGNORE the bot requirements for this PR (force green CI check)
Read More

🤖 This bot helps streamline PR reviews by verifying automated checks and providing guidance for contributors and reviewers.

✅ Automated Checks (for Contributors):

🟢 Maintainers must be able to edit this pull request (more info)
🔴 Must not contain the "don't merge" label
🟢 Pending initial approval by a review team member, or review from tech-staff

☑️ Contributor Actions:
  1. Fix any issues flagged by automated checks.
  2. Follow the Contributor Checklist to ensure your PR is ready for review.
    • Add new tests, or document why they are unnecessary.
    • Provide clear examples/screenshots, if necessary.
    • Update documentation, if required.
    • Ensure no breaking changes, or include BREAKING CHANGE notes.
    • Link related issues/PRs, where applicable.
☑️ Reviewer Actions:
  1. Complete manual checks for the PR, including the guidelines and additional checks if applicable.
📚 Resources:
Debug
Automated Checks
Maintainers must be able to edit this pull request (more info)

If

🟢 Condition met
└── 🟢 And
    ├── 🟢 The base branch matches this pattern: ^master$
    └── 🟢 The pull request was created from a fork (head branch repo: notJoon/gno-core)

Then

🟢 Requirement satisfied
└── 🟢 Maintainer can modify this pull request

Must not contain the "don't merge" label

If

🟢 Condition met
└── 🟢 A label matches this pattern: don't merge (label: don't merge)

Then

🔴 Requirement not satisfied
└── 🔴 On no pull request

Pending initial approval by a review team member, or review from tech-staff

If

🟢 Condition met
└── 🟢 And
    ├── 🟢 The base branch matches this pattern: ^master$
    └── 🟢 Not (🔴 Pull request author is a member of the team: tech-staff)

Then

🟢 Requirement satisfied
└── 🟢 If
    ├── 🟢 Condition
    │   └── 🟢 Or
    │       ├── 🟢 At least 1 user(s) of the organization reviewed the pull request (with state "APPROVED")
    │       ├── 🟢 At least 1 user(s) of the team tech-staff reviewed pull request
    │       └── 🔴 This pull request is a draft
    └── 🟢 Then
        └── 🟢 And
            ├── 🟢 Not (🔴 This label is applied to pull request: review/triage-pending)
            └── 🟢 At least 1 user(s) of the team tech-staff reviewed pull request

Manual Checks
**IGNORE** the bot requirements for this PR (force green CI check)

If

🟢 Condition met
└── 🟢 On every pull request

Can be checked by

  • Any user with comment edit permission

Copy link

codecov bot commented Mar 10, 2025

Codecov Report

Attention: Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
gnovm/tests/stdlibs/std/std.go 0.00% 3 Missing ⚠️

📢 Thoughts on this report? Let us know!

@github-actions github-actions bot added the 📦 🤖 gnovm Issues or PRs gnovm related label Mar 10, 2025
@Kouteki Kouteki moved this from Triage to In Progress in 🧙‍♂️gno.land core team Mar 10, 2025
@leohhhn
Copy link
Contributor

leohhhn commented Mar 10, 2025

If you add TotalSupply in this PR, just linking this PR as well for the docs: #2661

@moul
Copy link
Member

moul commented Mar 10, 2025

can we stop using the term "airdrop" for this feature (PR title, and a unit test having the term in the title); this PR isn't an airdrop checker, but a balance checker.

)

// TotalSupply returns the total supply of the specified denomination
func TotalSupply(banker std.Banker, denom string) int64 {
Copy link
Member

Choose a reason for hiding this comment

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

can we have this API instead, and always use a readonly banker?

Suggested change
func TotalSupply(banker std.Banker, denom string) int64 {
func TotalSupply(denom string) int64 {

Copy link
Member Author

@notJoon notJoon Mar 11, 2025

Choose a reason for hiding this comment

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

Modified it so that the banker object is created inside the function. I also considered placing the banker globally, but it seemed better to restrict the object's lifetime to within the function (It's also purer than global).
695412e

}

func renderHomepage() string {
return `# Gno.land Coins
Copy link
Member

Choose a reason for hiding this comment

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

homepage should give some information, and provide default links so that we can try the features with just a few clicks.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is currently a placeholder. It is must be updated later.

## Total Supply
` + std.NewCoin(denom, totalSupply).String() + `

[Back to Home](/r/gnoland/coins:)
Copy link
Member

Choose a reason for hiding this comment

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

back is already available in the navigation breadcrumb.

Copy link
Member Author

Choose a reason for hiding this comment

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

removed 695412e

Comment on lines 109 to 110
[Back to Coin Info](/r/gnoland/coins:` + denom + `)
[Back to Home](/r/gnoland/coins:)
Copy link
Member

Choose a reason for hiding this comment

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

remove this, we should use the navigation breadcrumb for this.

Copy link
Member Author

Choose a reason for hiding this comment

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

}

for _, tt := range tests {
banker := std.NewBanker(std.BankerTypeRealmIssue)
Copy link
Member

Choose a reason for hiding this comment

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

why do we need to initialize a banker from this realm?

(if there is a good reason, why not a readonly one?)

Copy link
Member Author

Choose a reason for hiding this comment

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

In std.BankerTypeReadonly mode, issuing coins are blocked, so I use std.BankerTypeRealmIssue mode only when setting up the test environment.

I think there won't be any issues because the inside of the TotalSupply or AddressBalance functions are set to read-only (modified to create a banker internally). please correct me, if I wrong.

Comment on lines 50 to 52
for _, acc := range accounts {
if acc == nil {
continue
Copy link
Member

@moul moul Mar 10, 2025

Choose a reason for hiding this comment

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

Not scalable. We need to find a more efficient solution, or we should refrain from offering this feature for now.

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 modified this function to process in a single loop. This is what I could think of for now. What do you think?

0d751b6

Copy link
Member

Choose a reason for hiding this comment

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

This needs a change in the underlying banker module, so that it keeps track of the available tokens, rather than iterating on the accounts here.

Copy link
Member

@moul moul left a comment

Choose a reason for hiding this comment

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

check comments.

@notJoon notJoon changed the title feat: Implement banker.TotalSupply and r/coins balance checker feat: r/coins balance checker Apr 3, 2025
@notJoon
Copy link
Member Author

notJoon commented Apr 14, 2025

@notJoon

Let's split this PR in to the balance checker and the banker edits. Either way we'd like to merge the balance checker soon, and let's just leave todo's regarding the total supply.

bfee6be

@moul
Copy link
Member

moul commented Apr 14, 2025

@notJoon, this is still not good. Please do not modify the tm2 code at all in this PR; just examples/.

@notJoon
Copy link
Member Author

notJoon commented Apr 14, 2025

this is still not good. Please do not modify the tm2 code at all in this PR; just examples/.

@moul
It seems we have different understandings of the implementation method. I originally understood that this functionality would be implemented using "banker-related workflows" and std.NewBanker as mentioned in the comments and the Render function in original PR. That's why I implemented the TotalCoin function before, and when I referred to the previous review, I understood we were moving in this direction.

If possible, could you clarify the implementation direction for the r/coins package? Currently, besides the examples, the only modified part is the mock function for testing TotalCoin. If this also needs to be reverted, I think r/coins will remain just a placeholder, and I don't get it how will be implemented and used.

If we're not using banker, using grc20's token-related functions seems like the most possible alternative option.

I should have confirmed this before starting, but it seems something went wrong from the beginning. I would appreciate your confirmation on this. Thank you.

@moul
Copy link
Member

moul commented Apr 14, 2025

r/coins needs to display balances (using banker). Most of this PR code focuses on total supply, which is more complex and not urgently needed (we'll address that later). For now, r/coins should concentrate on displaying the user balance for a specific coin.

There should be a .gno file for the realm that includes only a Render function, along with a few helpers and some unit tests.

Initial specifications can be found at https://github.com/gnolang/gno/pull/3826/files. Please ignore the total supply, as it is not yet supported.

@leohhhn leohhhn self-requested a review April 14, 2025 18:18
@notJoon
Copy link
Member Author

notJoon commented Apr 16, 2025

@moul I've made modifications like this, what do you think? I've modified it to exclude the total supply and only provide the balance inquiry function for specific addresses.

1978a90

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.

Looks good; we can make the rendering better in the next iteration.

Comment on lines 42 to 47
router.HandleFunc("{denom}", func(res *mux.ResponseWriter, req *mux.Request) {
// denom := req.GetVar("denom")
// banker := std.NewBanker(std.BankerTypeReadonly)
// res.Write(renderAddressBalance(banker, denom, denom))
panic("not supported yet")
})
Copy link
Contributor

@leohhhn leohhhn Apr 22, 2025

Choose a reason for hiding this comment

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

I think this would error and make the user experience a bit worse; maybe a better option is to simply write out "page coming soon" or similar.

Copy link
Member Author

Choose a reason for hiding this comment

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

Comment on lines 91 to 93
func formatBalance(coin std.Coin) string {
return "Balance: " + strconv.Itoa(int(coin.Amount)) + " " + coin.Denom
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: you can use std.Coin.String()

Copy link
Member Author

@notJoon notJoon Apr 23, 2025

Choose a reason for hiding this comment

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

This can also reduce function calls and package usage. That's a very good suggestion.
16ed599

@notJoon notJoon requested a review from leohhhn April 23, 2025 03:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
don't merge Please don't merge this functionality temporarily 📦 🌐 tendermint v2 Issues or PRs tm2 related 📦 ⛰️ 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: In Progress
Status: In Review
Development

Successfully merging this pull request may close these issues.

8 participants