@@ -5,6 +5,7 @@ import { HexString } from "aptos";
5
5
import stringify from "json-stable-stringify" ;
6
6
import { StructInfoType } from "./parserRepo" ;
7
7
import { ActualStringClass } from "./nativeFuncs" ;
8
+ import { AccountAddress } from "aptos/dist/transaction_builder/aptos_types" ;
8
9
9
10
export function abortCode ( code : any ) {
10
11
if ( code instanceof U64 ) {
@@ -256,15 +257,24 @@ export function payloadArg(val: any) {
256
257
return val . value . toString ( ) ;
257
258
}
258
259
else {
259
- throw new Error ( "Only expect U8, U64, or U128 for integer types" ) ;
260
+ throw new Error ( "Only expect U8, U64, or U128 for UnsignedInt types" ) ;
260
261
}
261
262
}
263
+ else if ( Array . isArray ( val ) && val . every ( v => v instanceof U8 ) ) {
264
+ // For U8[]
265
+ return u8ArrayArg ( val ) ;
266
+ }
262
267
else if ( val instanceof HexString ) {
263
268
return val . toShortString ( ) ;
264
269
}
265
- else if ( typeof val === 'boolean' ) {
270
+ else if ( [ 'boolean' , 'string' , 'number' , 'bigint' ] . includes ( typeof val ) ) {
271
+ // 1. return as it is for js primitive types
272
+ // 2. to make sure function payloadArg is idempotent when called more than once
266
273
return val
267
274
}
275
+ else if ( val instanceof AccountAddress ) {
276
+ return val ;
277
+ }
268
278
else if ( val . typeTag instanceof StructTag ) {
269
279
const tag = val . typeTag as StructTag ;
270
280
if ( tag . address . toShortString ( ) === '0x1' && tag . module === 'string' && tag . name === 'String' ) {
@@ -277,7 +287,7 @@ export function payloadArg(val: any) {
277
287
}
278
288
}
279
289
else {
280
- throw new Error ( `Unexpected value type: ${ typeof val } ` ) ;
290
+ throw new Error ( `Unexpected value ${ val } ` ) ;
281
291
}
282
292
}
283
293
0 commit comments