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 txlink builder and send special arg #3948

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

Conversation

alexiscolin
Copy link
Member

@alexiscolin alexiscolin commented Mar 15, 2025

Related to #3919, this PR introduces a new streamlined way to build transaction links in gno, with built-in support for send values.

New Builder Pattern:

// Create transaction links with a fluent interface
txlink.NewLink("MyFunc").
    AddArg("key", "value").
    AddArgs("k1", "v1", "k2", "v2").
    SetSend("1000000ugnot").
    URL()

Added multiple ways to specify send values:

  • Via builder pattern: SetSend("1000000ugnot")
  • Via direct call: Call("MyFunc", ".send", "1000000ugnot")

The new builder pattern uses the same Realm logic as the previous one

  • Support for current realm (relative paths)
  • Support for local realm paths
  • Support for fully qualified paths

Priority Rules:

As a refinement, implemented clear priority rules for send values:

  • Last AddSend call wins

Test Coverage

Added comprehensive test suite covering:

  • Basic builder functionality
  • Realm handling
  • URL encoding
  • Send values (all methods)
  • Empty/special values
  • Error cases

@alexiscolin alexiscolin requested a review from leohhhn March 15, 2025 16:08
@github-actions github-actions bot added the 🧾 package/realm Tag used for new Realms or Packages. label Mar 15, 2025
@Gno2D2 Gno2D2 requested a review from a team March 15, 2025 16:09
@Gno2D2 Gno2D2 added the review/triage-pending PRs opened by external contributors that are waiting for the 1st review label Mar 15, 2025
@Gno2D2
Copy link
Collaborator

Gno2D2 commented Mar 15, 2025

🛠 PR Checks Summary

All Automated Checks passed. ✅

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)
🟢 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: alexiscolin/gno)

Then

🟢 Requirement satisfied
└── 🟢 Maintainer can modify this 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
        └── 🟢 Not (🔴 This label is applied to pull request: review/triage-pending)

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

@alexiscolin alexiscolin changed the title Feat/add send txlink feat: add send txlink Mar 15, 2025
Copy link

codecov bot commented Mar 15, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

📢 Thoughts on this report? Let us know!

@alexiscolin alexiscolin changed the title feat: add send txlink feat: add txlink builder and .send special arg Mar 15, 2025
@alexiscolin alexiscolin changed the title feat: add txlink builder and .send special arg feat: add txlink builder and send special arg Mar 15, 2025
@leohhhn leohhhn requested a review from moul March 17, 2025 12:41
@leohhhn leohhhn linked an issue Mar 17, 2025 that may be closed by this pull request
@Gno2D2 Gno2D2 removed the review/triage-pending PRs opened by external contributors that are waiting for the 1st review label Mar 17, 2025
}

// AddArg adds a key-value argument pair. Returns the builder for chaining.
func (b *TxBuilder) AddArg(key, value string) *TxBuilder {
Copy link
Member

Choose a reason for hiding this comment

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

I'm usually against this pattern, but in this specific case, it may be interesting to consider making the value any, and then trying to convert basic types to a string. wdyt?

Suggested change
func (b *TxBuilder) AddArg(key, value string) *TxBuilder {
func (b *TxBuilder) AddArg(key, value any) *TxBuilder {

Copy link
Member Author

@alexiscolin alexiscolin Mar 18, 2025

Choose a reason for hiding this comment

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

Yeah it's not recommended but but might be more flexible and easy to use. @leohhhn since you used this packages way more than me, do you think it could be helpful?

Copy link
Contributor

@leohhhn leohhhn Mar 18, 2025

Choose a reason for hiding this comment

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

I'm more for typed approaches; pretty sure someone will try to jam in a struct or slice or other invalid input; we can have this approach when we also allow a pattern like std.Emit(&mystruct)

@alexiscolin alexiscolin requested a review from moul March 18, 2025 16:46
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.

lgtm

Co-authored-by: Leon Hudak <[email protected]>
@leohhhn
Copy link
Contributor

leohhhn commented Mar 20, 2025

Can you modify the render of r/gnoland/users/v1 to add the .send arg being 1 GNOT? Just for a testable example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🧾 package/realm Tag used for new Realms or Packages.
Projects
Status: In Progress
Status: Triage
Development

Successfully merging this pull request may close these issues.

[gnoweb] Allow -send value to be set via txlink
4 participants