Skip to content

Commit

Permalink
fix: In MsgSend, use Coin. Add expo API function makeSendTx (#191)
Browse files Browse the repository at this point in the history
The gnoclient API uses `MsgSend` where the amount is an [array of
`Coin`](https://github.com/gnolang/gno/blob/287c22ec830a1408f1d3de6319602640d841c7cc/tm2/pkg/sdk/bank/msgs.go#L17).
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). 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
#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);
```

---------

Signed-off-by: Jeff Thompson <[email protected]>
  • Loading branch information
jefft0 authored Oct 25, 2024
1 parent 53473b6 commit f47f15d
Show file tree
Hide file tree
Showing 12 changed files with 239 additions and 201 deletions.
121 changes: 57 additions & 64 deletions api/gen/csharp/Gnonativetypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,41 +99,42 @@ static Gnon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CgxIZWxsb1JlcXVlc3QSEgoEbmFtZRgBIAEoCVIETmFtZSIrCg1I",
"ZWxsb1Jlc3BvbnNlEhoKCGdyZWV0aW5nGAEgASgJUghHcmVldGluZyIoChJI",
"ZWxsb1N0cmVhbVJlcXVlc3QSEgoEbmFtZRgBIAEoCVIETmFtZSIxChNIZWxs",
"b1N0cmVhbVJlc3BvbnNlEhoKCGdyZWV0aW5nGAEgASgJUghHcmVldGluZyIw",
"ChhHTk9OQVRJVkVUWVBFU19CeXRlc0xpc3QSFAoFVmFsdWUYASADKAxSBVZh",
"bHVlQilaJ2dpdGh1Yi5jb20vZ25vbGFuZy9nbm9uYXRpdmUvYXBpL2dlbi9n",
"b2IGcHJvdG8z"));
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
new pbr::FileDescriptor[] { },
new pbr::GeneratedClrTypeInfo(null, null, new pbr::GeneratedClrTypeInfo[] {
Expand Down Expand Up @@ -187,7 +188,7 @@ static GnonativetypesReflection() {
new pbr::GeneratedClrTypeInfo(typeof(global::Land.Gno.Gnonative.V1.MsgCall), global::Land.Gno.Gnonative.V1.MsgCall.Parser, new[]{ "PackagePath", "Fnc", "Args", "Send" }, null, null, null, null),
new pbr::GeneratedClrTypeInfo(typeof(global::Land.Gno.Gnonative.V1.CallRequest), global::Land.Gno.Gnonative.V1.CallRequest.Parser, new[]{ "GasFee", "GasWanted", "Memo", "CallerAddress", "Msgs" }, null, null, null, null),
new pbr::GeneratedClrTypeInfo(typeof(global::Land.Gno.Gnonative.V1.CallResponse), global::Land.Gno.Gnonative.V1.CallResponse.Parser, new[]{ "Result" }, null, null, null, null),
new pbr::GeneratedClrTypeInfo(typeof(global::Land.Gno.Gnonative.V1.MsgSend), global::Land.Gno.Gnonative.V1.MsgSend.Parser, new[]{ "ToAddress", "Send" }, null, null, null, null),
new pbr::GeneratedClrTypeInfo(typeof(global::Land.Gno.Gnonative.V1.MsgSend), global::Land.Gno.Gnonative.V1.MsgSend.Parser, new[]{ "ToAddress", "Amount" }, null, null, null, null),
new pbr::GeneratedClrTypeInfo(typeof(global::Land.Gno.Gnonative.V1.SendRequest), global::Land.Gno.Gnonative.V1.SendRequest.Parser, new[]{ "GasFee", "GasWanted", "Memo", "CallerAddress", "Msgs" }, null, null, null, null),
new pbr::GeneratedClrTypeInfo(typeof(global::Land.Gno.Gnonative.V1.SendResponse), global::Land.Gno.Gnonative.V1.SendResponse.Parser, null, null, null, null, null),
new pbr::GeneratedClrTypeInfo(typeof(global::Land.Gno.Gnonative.V1.MsgRun), global::Land.Gno.Gnonative.V1.MsgRun.Parser, new[]{ "Package", "Send" }, null, null, null, null),
Expand Down Expand Up @@ -3165,6 +3166,9 @@ public Coin Clone() {
/// <summary>Field number for the "denom" field.</summary>
public const int DenomFieldNumber = 1;
private string denom_ = "";
/// <summary>
/// Example: "ugnot"
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public string Denom {
Expand Down Expand Up @@ -10961,7 +10965,7 @@ public MsgSend() {
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public MsgSend(MsgSend other) : this() {
toAddress_ = other.toAddress_;
send_ = other.send_;
amount_ = other.amount_.Clone();
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
}

Expand All @@ -10987,19 +10991,18 @@ public MsgSend Clone() {
}
}

/// <summary>Field number for the "send" field.</summary>
public const int SendFieldNumber = 2;
private string send_ = "";
/// <summary>Field number for the "amount" field.</summary>
public const int AmountFieldNumber = 2;
private static readonly pb::FieldCodec<global::Land.Gno.Gnonative.V1.Coin> _repeated_amount_codec
= pb::FieldCodec.ForMessage(18, global::Land.Gno.Gnonative.V1.Coin.Parser);
private readonly pbc::RepeatedField<global::Land.Gno.Gnonative.V1.Coin> amount_ = new pbc::RepeatedField<global::Land.Gno.Gnonative.V1.Coin>();
/// <summary>
/// Example: "1000ugnot"
/// Example: [ {Denom: "ugnot", Amount: 1000} ]
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public string Send {
get { return send_; }
set {
send_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
public pbc::RepeatedField<global::Land.Gno.Gnonative.V1.Coin> Amount {
get { return amount_; }
}

[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
Expand All @@ -11018,7 +11021,7 @@ public bool Equals(MsgSend other) {
return true;
}
if (ToAddress != other.ToAddress) return false;
if (Send != other.Send) return false;
if(!amount_.Equals(other.amount_)) return false;
return Equals(_unknownFields, other._unknownFields);
}

Expand All @@ -11027,7 +11030,7 @@ public bool Equals(MsgSend other) {
public override int GetHashCode() {
int hash = 1;
if (ToAddress.Length != 0) hash ^= ToAddress.GetHashCode();
if (Send.Length != 0) hash ^= Send.GetHashCode();
hash ^= amount_.GetHashCode();
if (_unknownFields != null) {
hash ^= _unknownFields.GetHashCode();
}
Expand All @@ -11050,10 +11053,7 @@ public void WriteTo(pb::CodedOutputStream output) {
output.WriteRawTag(10);
output.WriteBytes(ToAddress);
}
if (Send.Length != 0) {
output.WriteRawTag(18);
output.WriteString(Send);
}
amount_.WriteTo(output, _repeated_amount_codec);
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
Expand All @@ -11068,10 +11068,7 @@ public void WriteTo(pb::CodedOutputStream output) {
output.WriteRawTag(10);
output.WriteBytes(ToAddress);
}
if (Send.Length != 0) {
output.WriteRawTag(18);
output.WriteString(Send);
}
amount_.WriteTo(ref output, _repeated_amount_codec);
if (_unknownFields != null) {
_unknownFields.WriteTo(ref output);
}
Expand All @@ -11085,9 +11082,7 @@ public int CalculateSize() {
if (ToAddress.Length != 0) {
size += 1 + pb::CodedOutputStream.ComputeBytesSize(ToAddress);
}
if (Send.Length != 0) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(Send);
}
size += amount_.CalculateSize(_repeated_amount_codec);
if (_unknownFields != null) {
size += _unknownFields.CalculateSize();
}
Expand All @@ -11103,9 +11098,7 @@ public void MergeFrom(MsgSend other) {
if (other.ToAddress.Length != 0) {
ToAddress = other.ToAddress;
}
if (other.Send.Length != 0) {
Send = other.Send;
}
amount_.Add(other.amount_);
_unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
}

Expand All @@ -11130,7 +11123,7 @@ public void MergeFrom(pb::CodedInputStream input) {
break;
}
case 18: {
Send = input.ReadString();
amount_.AddEntriesFrom(input, _repeated_amount_codec);
break;
}
}
Expand All @@ -11157,7 +11150,7 @@ public void MergeFrom(pb::CodedInputStream input) {
break;
}
case 18: {
Send = input.ReadString();
amount_.AddEntriesFrom(ref input, _repeated_amount_codec);
break;
}
}
Expand Down
8 changes: 5 additions & 3 deletions api/gen/es/gnonativetypes_pb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,8 @@ export declare class KeyInfo extends Message<KeyInfo> {
*/
export declare class Coin extends Message<Coin> {
/**
* Example: "ugnot"
*
* @generated from field: string denom = 1;
*/
denom: string;
Expand Down Expand Up @@ -1361,11 +1363,11 @@ export declare class MsgSend extends Message<MsgSend> {
toAddress: Uint8Array;

/**
* Example: "1000ugnot"
* Example: [ {Denom: "ugnot", Amount: 1000} ]
*
* @generated from field: string send = 2;
* @generated from field: repeated land.gno.gnonative.v1.Coin amount = 2;
*/
send: string;
amount: Coin[];

constructor(data?: PartialMessage<MsgSend>);

Expand Down
2 changes: 1 addition & 1 deletion api/gen/es/gnonativetypes_pb.js
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ export const MsgSend = proto3.makeMessageType(
"land.gno.gnonative.v1.MsgSend",
() => [
{ no: 1, name: "to_address", kind: "scalar", T: 12 /* ScalarType.BYTES */ },
{ no: 2, name: "send", kind: "scalar", T: 9 /* ScalarType.STRING */ },
{ no: 2, name: "amount", kind: "message", T: Coin, repeated: true },
],
);

Expand Down
Loading

0 comments on commit f47f15d

Please sign in to comment.