@@ -5,6 +5,7 @@ import { HexString } from "aptos";
55import stringify from "json-stable-stringify" ;
66import { StructInfoType } from "./parserRepo" ;
77import { ActualStringClass } from "./nativeFuncs" ;
8+ import { AccountAddress } from "aptos/dist/transaction_builder/aptos_types" ;
89
910export function abortCode ( code : any ) {
1011 if ( code instanceof U64 ) {
@@ -256,15 +257,24 @@ export function payloadArg(val: any) {
256257 return val . value . toString ( ) ;
257258 }
258259 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" ) ;
260261 }
261262 }
263+ else if ( Array . isArray ( val ) && val . every ( v => v instanceof U8 ) ) {
264+ // For U8[]
265+ return u8ArrayArg ( val ) ;
266+ }
262267 else if ( val instanceof HexString ) {
263268 return val . toShortString ( ) ;
264269 }
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
266273 return val
267274 }
275+ else if ( val instanceof AccountAddress ) {
276+ return val ;
277+ }
268278 else if ( val . typeTag instanceof StructTag ) {
269279 const tag = val . typeTag as StructTag ;
270280 if ( tag . address . toShortString ( ) === '0x1' && tag . module === 'string' && tag . name === 'String' ) {
@@ -277,7 +287,7 @@ export function payloadArg(val: any) {
277287 }
278288 }
279289 else {
280- throw new Error ( `Unexpected value type: ${ typeof val } ` ) ;
290+ throw new Error ( `Unexpected value ${ val } ` ) ;
281291 }
282292}
283293
0 commit comments