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

Extend txlink, ?help, and Wallet Connect to Support maketx run #3283

Open
moul opened this issue Dec 6, 2024 · 5 comments
Open

Extend txlink, ?help, and Wallet Connect to Support maketx run #3283

moul opened this issue Dec 6, 2024 · 5 comments
Labels
help wanted Want to contribute? We recommend these issues.

Comments

@moul
Copy link
Member

moul commented Dec 6, 2024

Extend p/txlink, the ?help page, and wallet connect support to handle maketx run, enabling advanced calls with complex types and logic. This eliminates boilerplate and supports direct interactions, like working with DAOs and reusable scripts.

Example

Here’s an example of a Go script showcasing this feature:

// `maketx run -file .`
package main

import "gno.land/r/boards2"
import "gno.land/r/moul/proptmpl"

func main() {
	boards2.GetBoard("boardName").GetDAO().Propose(
		"proposal title",
		// EDIT BELOW: Add proposal logic
		proptmpl.ProposalTemplate("arg1", "arg2"),
		})
}

With something like this generated in the Render() func of boards2.

[create a proposal for this board](/r/boards2$help&run=package+main%0Aimport+%22gno.land/r/boards2%22%0A%0Afunc+main()%7B%0A++++board+%3A%3D+boards2.GetBoard(%22boardName%22)%0A++++dao+%3A%3D+board.GetDAO()%0A++++dao.Propose(func()%7B%0A++++++++//+Proposal+logic+here%0A++++%7D)%0A%7D)

Probably generated with:

import "gno.land/p/moul/txlink"

txlink.Run(`package main
import ...`)

Goals

  1. txlink:

    • Keep links concise but support multiline syntax for readability.
  2. ?help Page:

    • Display prefilled editable code for users.
    • Bonus: Syntax highlighting and clear comments like // EDIT BELOW to guide edits.
  3. Wallets:

    • Support reviewing and editing the script before execution.

Let’s discuss and align on implementation details.

cc @leohhhn @zivkovicmilos @jinoosss @jefft0 @jeronimoalbi @thehowl

@moul moul added the help wanted Want to contribute? We recommend these issues. label Dec 6, 2024
@moul
Copy link
Member Author

moul commented Dec 6, 2024

A key consideration is whether txlink should include the realm path in the URL for context or always use top-level links. Additionally, we need to decide whether to prefill guessable parts (like package main, primary import and func main() {) to keep URLs concise, or require full code explicitly, resulting in longer but clearer URLs.

Exploration examples:

txlink.Run(`boards2.GetBoard("boardName").GetDAO().Propose(
	"proposal title",
	ProposalTemplate("arg1", "arg2"),
)

@moul
Copy link
Member Author

moul commented Dec 6, 2024

Here's an example illustrating how maketx run enables contracts to stay agnostic of r/sys/users, allowing interactions by resolving usernames to addresses externally:

package main

import "r/sys/users"
import "r/foo20"

func main() {
    recipient := users.Resolve("@moul")
    foo20.Transfer(recipient, 1337)
}

A smart wallet could resolve @moul through a query, cache it if needed, and then call the top-level function with the resolved std.Address. Gnoweb should check, like gno.land, whether r/sys/users is enabled on the chain. If it is, Gnoweb could transparently support username resolution for each maketx call that takes an std.Address.

@moul
Copy link
Member Author

moul commented Dec 6, 2024

Another thing to consider when we want the equivalent of maketx run is allowing the passing of freshly created anonymous functions or closures. It should be easy to call AddPackage with a random package name, such as r/moul/scripts/abc12659ajsldkg, using just an init() function.

txlink.AddPackage(txlink.ScriptPath(), `
package main

import "gno.land/r/boards2"

func init() {
	boards2.GetBoard("boardName").GetDAO().Propose(
		"proposal title",
		func() {
			// EDIT BELOW: Add proposal logic
			// ...
		})
}`)

@jinoosss
Copy link
Member

jinoosss commented Dec 6, 2024

This feature can be a great experience for users.
There is consideration for a similar feature in the Adena wallet.

There are a few things to consider

  1. If it's going to be utilized as a link, you need to consider the maximum length of the URL allowed.
    : We may need to consider encoding or URL shortening.

  2. It must be in a form that the wallet can parse in order to validate and submit it.
    : If it is parsable, it can be simulated or syntax checked.

@moul
Copy link
Member Author

moul commented Dec 6, 2024

We should focus on creating a great gnoweb experience by developing hyperlinks that provide sufficient data for gnoweb to generate CLI documentation.

Then, Adena and other wallets should simply follow gnoweb's lead.

-> #2602

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Want to contribute? We recommend these issues.
Projects
Status: Triage
Development

No branches or pull requests

2 participants