8
8
CairoEnum ,
9
9
ParsedStruct ,
10
10
Uint256 ,
11
- Uint ,
12
11
} from '../../types' ;
13
12
import { CairoUint256 } from '../cairoDataTypes/uint256' ;
14
13
import { CairoUint512 } from '../cairoDataTypes/uint512' ;
@@ -72,80 +71,84 @@ function decodeBaseTypes(
72
71
73
72
case isTypeUint ( type ) :
74
73
switch ( true ) {
75
- case CairoUint256 . isAbiType ( type ) :
76
- console . log ( 'got 256 uint value' ) ;
74
+ case CairoUint256 . isAbiType ( type ) : {
77
75
const low = it . next ( ) . value ;
78
76
const high = it . next ( ) . value ;
79
77
80
78
const ret = new CairoUint256 ( low , high ) ;
81
- let configConstructor = config ?. [ 'core::integer::u256' ] ;
79
+ const configConstructor = config ?. [ 'core::integer::u256' ] ;
82
80
if ( configConstructor ) {
83
81
return configConstructor ( ret ) ;
84
82
}
83
+
85
84
return ret ;
85
+ }
86
86
87
- case CairoUint512 . isAbiType ( type ) :
87
+ case CairoUint512 . isAbiType ( type ) : {
88
88
const limb0 = it . next ( ) . value ;
89
89
const limb1 = it . next ( ) . value ;
90
90
const limb2 = it . next ( ) . value ;
91
91
const limb3 = it . next ( ) . value ;
92
92
93
93
return new CairoUint512 ( limb0 , limb1 , limb2 , limb3 ) . toBigInt ( ) ;
94
+ }
94
95
95
- default :
96
+ default : {
96
97
temp = it . next ( ) . value ;
97
98
const configType = getUintType ( type ) ;
98
99
if ( configType ) {
99
100
const UintConstructor = config ?. [ configType ] ;
100
101
if ( UintConstructor ) {
101
102
return UintConstructor ( temp ) ;
102
- } else {
103
- return BigInt ( temp ) ;
104
103
}
104
+ return BigInt ( temp ) ;
105
105
}
106
+ }
106
107
}
107
108
109
+ return BigInt ( temp ) ;
110
+
108
111
case isTypeEthAddress ( type ) :
109
112
temp = it . next ( ) . value ;
110
113
return BigInt ( temp ) ;
111
114
112
- case isTypeContractAddress ( type ) :
115
+ case isTypeContractAddress ( type ) : {
113
116
temp = it . next ( ) . value ;
114
117
temp = toHex ( temp ) ;
115
118
const configConstructor = config ?. [ type ] ;
116
119
if ( configConstructor ) {
117
120
return configConstructor ( temp ) ;
118
- } else {
119
- return BigInt ( temp ) ;
120
121
}
122
+ return BigInt ( temp ) ;
123
+ }
121
124
122
125
case isTypeBytes31 ( type ) :
123
126
temp = it . next ( ) . value ;
124
127
return decodeShortString ( temp ) ;
125
128
126
- case isTypeSecp256k1Point ( type ) :
129
+ case isTypeSecp256k1Point ( type ) : {
127
130
const xLow = removeHexPrefix ( it . next ( ) . value ) . padStart ( 32 , '0' ) ;
128
131
const xHigh = removeHexPrefix ( it . next ( ) . value ) . padStart ( 32 , '0' ) ;
129
132
const yLow = removeHexPrefix ( it . next ( ) . value ) . padStart ( 32 , '0' ) ;
130
133
const yHigh = removeHexPrefix ( it . next ( ) . value ) . padStart ( 32 , '0' ) ;
131
134
const pubK = BigInt ( addHexPrefix ( xHigh + xLow + yHigh + yLow ) ) ;
132
135
133
136
return pubK ;
137
+ }
134
138
135
- case isTypeFelt ( type ) :
139
+ case isTypeFelt ( type ) : {
136
140
temp = String ( it . next ( ) . value ) ;
137
- console . log ( 'Original temp = ' , temp ) ;
138
141
const configFeltConstructor = config ?. [ 'core::felt252' ] ;
139
142
if ( configFeltConstructor ) {
140
143
if ( configFeltConstructor === String ) return decodeShortString ( temp ) ;
141
- else return configFeltConstructor ( temp ) ;
144
+ return configFeltConstructor ( temp ) ;
142
145
}
143
146
144
147
// Default
145
148
return BigInt ( temp ) ;
149
+ }
146
150
147
151
default :
148
- console . log ( 'went to default block for ' ) ;
149
152
temp = it . next ( ) . value ;
150
153
return BigInt ( temp ) ;
151
154
}
@@ -294,14 +297,12 @@ function decodeCalldataValue(
294
297
parsedDataArr . push ( val ) ;
295
298
}
296
299
}
297
- console . log ( 'Returning array: ' , parsedDataArr ) ;
298
300
const configConstructor = config ?. [ element . name ] ;
299
301
if ( configConstructor ) {
300
302
const concatenatedString = parsedDataArr . join ( '' ) ;
301
303
return concatenatedString ;
302
- } else {
303
- return parsedDataArr ;
304
304
}
305
+ return parsedDataArr ;
305
306
}
306
307
307
308
// base type
@@ -326,9 +327,10 @@ export default function decodeCalldataField(
326
327
const { name, type } = input ;
327
328
328
329
switch ( true ) {
329
- case isLen ( name ) :
330
+ case isLen ( name ) : {
330
331
const temp = calldataIterator . next ( ) . value ;
331
332
return BigInt ( temp ) ;
333
+ }
332
334
333
335
case ( structs && type in structs ) || isTypeTuple ( type ) :
334
336
return decodeCalldataValue ( calldataIterator , input , structs , enums , config ) ;
@@ -341,8 +343,11 @@ export default function decodeCalldataField(
341
343
if ( isCairo1Type ( type ) ) {
342
344
return decodeCalldataValue ( calldataIterator , input , structs , enums , config ) ;
343
345
}
346
+ break ;
344
347
345
348
default :
346
349
return decodeBaseTypes ( type , calldataIterator , config ) ;
347
350
}
351
+
352
+ return null ;
348
353
}
0 commit comments