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

fix: In MsgSend, use Coin. Add expo API function makeSendTx #191

Merged
merged 4 commits into from
Oct 25, 2024

Conversation

jefft0
Copy link
Contributor

@jefft0 jefft0 commented Oct 25, 2024

The gnoclient API uses MsgSend where the amount is an array of Coin. A Coin is a struct with separate fields for Denom and Amount. However, the Gno Native Kit API uses a string such as "1000ugnot" (from the original version of gnoclient). We want to track the current gnoclient API. This PR has four commits:

  1. Change the Protobuf MsgSend to use an array of Coin for the Amount. (The Protobuf Coin type was already defined.) Run make regenerate to make the native interfaces. Update gnoNativeService.Send to use the Coin struct. Run npm install @gnolang/gnonative to install the new API on buf.build.
  2. In expo, update package.json to use the updated bufbuild_es types. Update send to take an array of Coin.
  3. In expo, for making individual transactions we already have makeCallTx. Add makeSendTx.
  4. In expo, in makeCallTx and makeSendTx, the callerAddress should not be optional. (This should have been fixed for makeCallTx in PR fix: Remove deprecated API methods. Require caller address. #184 .)

This was tested by making a local expo NPM package and installing locally in Gnokey Mobile. The following test code sends 100 ugnot to an address.

      const test_addr = await gnonative.addressFromBech32("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5");
      const tx = await gnonative.makeSendTx(test_addr, [new Coin({denom: "ugnot", amount: BigInt(100)})], "1ugnot", BigInt(10000000), keyInfo.address);
      const signedTx = await gnonative.signTx(tx.txJson, keyInfo.address);
      await gnonative.broadcastTxCommit(signedTx.signedTxJson);

@jefft0 jefft0 requested a review from D4ryl00 October 25, 2024 10:38
… be optional.

Should have been fixed in gnolang#184 .

Signed-off-by: Jeff Thompson <[email protected]>
Copy link
Contributor

@D4ryl00 D4ryl00 left a comment

Choose a reason for hiding this comment

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

LGTM

@jefft0 jefft0 merged commit f47f15d into gnolang:main Oct 25, 2024
@jefft0 jefft0 deleted the fix/MsgSend-use-Coin branch October 25, 2024 16:08
Copy link

🎉 This PR is included in version 3.0.5 🎉

The release is available on:

Your semantic-release bot 📦🚀

jefft0 added a commit that referenced this pull request Oct 30, 2024
The gnoclient API uses `MsgCall` where the send amount is an [array of
`Coin`](https://github.com/gnolang/gno/blob/287c22ec830a1408f1d3de6319602640d841c7cc/gno.land/pkg/sdk/vm/msgs.go#L87).
A `Coin` is a struct with [separate fields for Denom and
Amount.](https://github.com/gnolang/gno/blob/287c22ec830a1408f1d3de6319602640d841c7cc/tm2/pkg/std/coin.go#L19)
However, the Gno Native Kit API uses a string such as "1000ugnot" (from
the original version of gnoclient). Similar to PR
#191 for `MsgSend`, we want to
track the current gnoclient API. This PR has three commits:

1. Update go.mod to use the latest gnokey-mobile. This allows gnonative
to compile after updating to the latest gnolang/gno.
2. Change the Protobuf `MsgCall` to use an array of `Coin` for the Send
amount. (The Protobuf `Coin` type was already defined.) Run `make
regenerate` to make the native interfaces. Update
`gnoNativeService.convertCallRequest` to use the `Coin` struct, similar
to the previous change to
[convertSendRequest](https://github.com/gnolang/gnonative/blob/c0f18fd181ae3bc2159090c5199f4725216f9800/service/api.go#L591-L594).
Run `npm install @gnolang/gnonative` to install the new API on
buf.build.
3. In expo, update package.json to use the updated bufbuild_es types.
Update `call` and `makeCallTx` to take an array of `Coin`.

BREAKING CHANGE: The only code which currently uses the Send amount in
MsgCall is where [gnokey-mobile calls
"Register"](https://github.com/gnolang/gnokey-mobile/blob/f1dc64684f110f71c0465c6a815b2f1b745800e9/mobile/redux/features/signupSlice.ts#L218).
After we merge this PR, we will update gnokey-mobile.

---------

Signed-off-by: Jeff Thompson <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants