@@ -29,6 +29,7 @@ import {
2929 ALGORAND_ADDRESS_BYTE_LENGTH ,
3030 ALGORAND_CHECKSUM_BYTE_LENGTH ,
3131 BITS_IN_BYTE ,
32+ UINT512_SIZE ,
3233 UINT64_SIZE ,
3334} from '../constants'
3435import { lazyContext } from '../context-helpers/internal-context'
@@ -441,7 +442,7 @@ export class StaticArrayImpl<TItem extends ARC4Encoded, TLength extends number>
441442 const childTypes = Array ( arraySize ) . fill ( genericArgs . elementType )
442443 let i = 0
443444 let size = 0
444- if ( genericArgs . elementType . name === 'Bool' ) {
445+ if ( [ 'Bool' , 'boolean' ] . includes ( genericArgs . elementType . name ) ) {
445446 while ( i < childTypes . length ) {
446447 const after = findBoolTypes ( childTypes , i , 1 )
447448 const boolNum = after + 1
@@ -716,7 +717,7 @@ export class TupleImpl<TTuple extends [ARC4Encoded, ...ARC4Encoded[]]> extends T
716717
717718 while ( i < genericArgs . length ) {
718719 const childType = genericArgs [ i ]
719- if ( childType . name === 'Bool' ) {
720+ if ( [ 'Bool' , 'boolean' ] . includes ( childType . name ) ) {
720721 const after = findBoolTypes ( genericArgs , i , 1 )
721722 const boolNum = after + 1
722723 size += Math . floor ( boolNum / BITS_IN_BYTE )
@@ -821,6 +822,27 @@ export class StructImpl<T extends StructConstraint> extends (Struct<StructConstr
821822 const genericArgs = Object . values ( t . genericArgs as Record < string , TypeInfo > )
822823 return `(${ genericArgs . map ( getArc4TypeName ) . join ( ',' ) } )`
823824 }
825+
826+ static getMaxBytesLength ( typeInfo : TypeInfo ) : number {
827+ const genericArgs = Object . values ( typeInfo . genericArgs as Record < string , TypeInfo > )
828+ let i = 0
829+ let size = 0
830+
831+ while ( i < genericArgs . length ) {
832+ const childType = genericArgs [ i ]
833+ if ( [ 'Bool' , 'boolean' ] . includes ( childType . name ) ) {
834+ const after = findBoolTypes ( genericArgs , i , 1 )
835+ const boolNum = after + 1
836+ size += Math . floor ( boolNum / BITS_IN_BYTE )
837+ size += boolNum % BITS_IN_BYTE ? 1 : 0
838+ i += after
839+ } else {
840+ size += getMaxLengthOfStaticContentType ( childType )
841+ }
842+ i += 1
843+ }
844+ return size
845+ }
824846}
825847
826848export class DynamicBytesImpl extends DynamicBytes {
@@ -981,7 +1003,7 @@ const decode = (value: Uint8Array, childTypes: TypeInfo[]) => {
9811003 dynamicSegments . push ( [ dynamicIndex , - 1 ] )
9821004 valuePartitions . push ( new Uint8Array ( ) )
9831005 arrayIndex += ABI_LENGTH_SIZE
984- } else if ( childType . name === 'Bool' ) {
1006+ } else if ( [ 'Bool' , 'boolean' ] . includes ( childType . name ) ) {
9851007 const before = findBoolTypes ( childTypes , i , - 1 )
9861008 let after = findBoolTypes ( childTypes , i , 1 )
9871009
@@ -1043,7 +1065,7 @@ const findBoolTypes = (values: TypeInfo[], index: number, delta: number): number
10431065 const length = values . length
10441066 while ( true ) {
10451067 const curr = index + delta * until
1046- if ( values [ curr ] . name === 'Bool' ) {
1068+ if ( [ 'Bool' , 'boolean' ] . includes ( values [ curr ] . name ) ) {
10471069 if ( ( curr != length - 1 && delta > 0 ) || ( curr > 0 && delta < 0 ) ) {
10481070 until += 1
10491071 } else {
@@ -1059,6 +1081,12 @@ const findBoolTypes = (values: TypeInfo[], index: number, delta: number): number
10591081
10601082const getMaxLengthOfStaticContentType = ( type : TypeInfo ) : number => {
10611083 switch ( trimGenericTypeName ( type . name ) ) {
1084+ case 'uint64' :
1085+ return UINT64_SIZE / BITS_IN_BYTE
1086+ case 'biguint' :
1087+ return UINT512_SIZE / BITS_IN_BYTE
1088+ case 'boolean' :
1089+ return 1
10621090 case 'Address' :
10631091 return AddressImpl . getMaxBytesLength ( type )
10641092 case 'Byte' :
@@ -1073,6 +1101,8 @@ const getMaxLengthOfStaticContentType = (type: TypeInfo): number => {
10731101 return StaticBytesImpl . getMaxBytesLength ( type )
10741102 case 'Tuple' :
10751103 return TupleImpl . getMaxBytesLength ( type )
1104+ case 'Struct' :
1105+ return StructImpl . getMaxBytesLength ( type )
10761106 }
10771107 throw new CodeError ( `unsupported type ${ type . name } ` )
10781108}
@@ -1324,3 +1354,8 @@ export const getArc4Encoded = (value: DeliberateAny): ARC4Encoded => {
13241354
13251355 throw new CodeError ( `Unsupported type for encoding: ${ typeof value } ` )
13261356}
1357+
1358+ export const arc4EncodedLengthImpl = ( typeInfoString : string ) : uint64 => {
1359+ const typeInfo = JSON . parse ( typeInfoString )
1360+ return getMaxLengthOfStaticContentType ( typeInfo )
1361+ }
0 commit comments