gno icon indicating copy to clipboard operation
gno copied to clipboard

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

Open moul opened this issue 1 year ago • 7 comments

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 avatar Dec 06 '24 08:12 moul

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 avatar Dec 06 '24 09:12 moul

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 avatar Dec 06 '24 09:12 moul

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
			// ...
		})
}`)

moul avatar Dec 06 '24 09:12 moul

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

  • https://github.com/onbloc/adena-wallet/issues/302

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.

jinoosss avatar Dec 06 '24 10:12 jinoosss

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.

-> https://github.com/gnolang/gno/issues/2602

moul avatar Dec 06 '24 11:12 moul

Counter-proposal: what if there were some code blocks, say with ```gno-run, such that:

  • Adena could understand them and allow the user to make the transaction
  • The playground could also be used as an in-page editor to then make the transaction?

I see using MsgRun as being generally unsafe for non-technical users, so I would advise against making its usability much simpler; I'd still want to make it clear to the user that they're running code that wasn't written by them or the realm they're using, and they should understand what they're doing.

thehowl avatar Dec 20 '24 21:12 thehowl

This issue is stale because it has been open 6 months with no activity. Remove stale label or comment or this will be closed in 3 months.

github-actions[bot] avatar Jun 19 '25 02:06 github-actions[bot]