Skip to content

Commit

Permalink
fix: Hacky fix of null args list marshaling issue (#46)
Browse files Browse the repository at this point in the history
* fix: Hacky fix of null args list marshaling issue

* Run prettier

---------

Co-authored-by: Milos Zivkovic <[email protected]>
  • Loading branch information
clockworkgr and zivkovicmilos authored Sep 22, 2023
1 parent 2c0c9be commit 0d54ec4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
4 changes: 2 additions & 2 deletions proto/gno/vm.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ syntax = "proto3";

package gno.vm;

import "google/protobuf/struct.proto";


// MsgCall is the method invocation tx message,
// denoted as "m_call"
Expand All @@ -16,7 +16,7 @@ message MsgCall {
// the function name being invoked
string func = 4;
// the function arguments
google.protobuf.Value args = 5; // null | string[]
repeated string args = 5; // null | string[]
}

// MsgAddPackage is the package deployment tx message,
Expand Down
27 changes: 17 additions & 10 deletions src/proto/gno/vm.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable */
import Long from 'long';
import _m0 from 'protobufjs/minimal';
import { Value } from '../google/protobuf/struct';

export const protobufPackage = 'gno.vm';

Expand All @@ -19,7 +18,7 @@ export interface MsgCall {
/** the function name being invoked */
func: string;
/** the function arguments */
args?: any | undefined;
args: string[] | null;
}

/**
Expand Down Expand Up @@ -60,7 +59,7 @@ export interface MemFile {
}

function createBaseMsgCall(): MsgCall {
return { caller: '', send: '', pkg_path: '', func: '', args: undefined };
return { caller: '', send: '', pkg_path: '', func: '', args: null };
}

export const MsgCall = {
Expand All @@ -80,8 +79,10 @@ export const MsgCall = {
if (message.func !== '') {
writer.uint32(34).string(message.func);
}
if (message.args !== undefined) {
Value.encode(Value.wrap(message.args), writer.uint32(42).fork()).ldelim();
if (message.args) {
for (const v of message.args) {
writer.uint32(42).string(v!);
}
}
return writer;
},
Expand Down Expand Up @@ -126,8 +127,10 @@ export const MsgCall = {
if (tag !== 42) {
break;
}

message.args = Value.unwrap(Value.decode(reader, reader.uint32()));
if (!message.args) {
message.args = [];
}
message.args.push(reader.string());
continue;
}
if ((tag & 7) === 4 || tag === 0) {
Expand All @@ -144,7 +147,9 @@ export const MsgCall = {
send: isSet(object.send) ? String(object.send) : '',
pkg_path: isSet(object.pkg_path) ? String(object.pkg_path) : '',
func: isSet(object.func) ? String(object.func) : '',
args: isSet(object?.args) ? object.args : undefined,
args: Array.isArray(object?.args)
? object.args.map((e: any) => String(e))
: null,
};
},

Expand All @@ -162,8 +167,10 @@ export const MsgCall = {
if (message.func !== '') {
obj.func = message.func;
}
if (message.args !== undefined) {
if (message.args?.length) {
obj.args = message.args;
} else {
obj.args = null;
}
return obj;
},
Expand All @@ -177,7 +184,7 @@ export const MsgCall = {
message.send = object.send ?? '';
message.pkg_path = object.pkg_path ?? '';
message.func = object.func ?? '';
message.args = object.args ?? undefined;
message.args = object.args?.map((e) => e) || null;
return message;
},
};
Expand Down
4 changes: 2 additions & 2 deletions src/wallet/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export class GnoWallet extends Wallet {
callMethod = async <K extends keyof BroadcastTransactionMap>(
path: string,
method: string,
args: string[],
args: string[] | null,
endpoint: K,
funds?: Map<string, number>,
fee?: TxFee
Expand All @@ -178,7 +178,7 @@ export class GnoWallet extends Wallet {
send: amount,
pkg_path: path,
func: method,
args: args.length === 0 ? null : args,
args: args ? (args.length === 0 ? null : args) : null,
};

// Construct the transfer transaction
Expand Down

0 comments on commit 0d54ec4

Please sign in to comment.