File tree 2 files changed +77
-9
lines changed
routes/[network]/api/readonly/[contract]/[action]/[[data]]
2 files changed +77
-9
lines changed Original file line number Diff line number Diff line change
1
+ export const stringableTypes = [
2
+ 'string' ,
3
+ 'string?' ,
4
+ 'bool' ,
5
+ 'bool?' ,
6
+ 'asset' ,
7
+ 'asset?' ,
8
+ 'extended_asset' ,
9
+ 'extended_asset?' ,
10
+ 'bytes' ,
11
+ 'bytes?' ,
12
+ 'checksum160' ,
13
+ 'checksum160?' ,
14
+ 'checksum256' ,
15
+ 'checksum256?' ,
16
+ 'checksum512' ,
17
+ 'checksum512?' ,
18
+ 'name' ,
19
+ 'name?' ,
20
+ 'publickey' ,
21
+ 'publickey?' ,
22
+ 'signature' ,
23
+ 'signature?' ,
24
+ 'symbol' ,
25
+ 'symbol?' ,
26
+ 'symbol_code' ,
27
+ 'symbol_code?' ,
28
+ 'time_point' ,
29
+ 'time_point?' ,
30
+ 'time_point_sec' ,
31
+ 'time_point_sec?' ,
32
+ 'block_timestamp_type' ,
33
+ 'block_timestamp_type?' ,
34
+ 'int8' ,
35
+ 'int8?' ,
36
+ 'int16' ,
37
+ 'int16?' ,
38
+ 'int32' ,
39
+ 'int32?' ,
40
+ 'int64' ,
41
+ 'int64?' ,
42
+ 'int128' ,
43
+ 'int128?' ,
44
+ 'uint8' ,
45
+ 'uint8?' ,
46
+ 'uint16' ,
47
+ 'uint16?' ,
48
+ 'uint32' ,
49
+ 'uint32?' ,
50
+ 'uint64' ,
51
+ 'uint64?' ,
52
+ 'uint128' ,
53
+ 'uint128?' ,
54
+ 'varint' ,
55
+ 'varint?' ,
56
+ 'varuint' ,
57
+ 'varuint?' ,
58
+ 'float32' ,
59
+ 'float32?' ,
60
+ 'float64' ,
61
+ 'float64?' ,
62
+ 'float128' ,
63
+ 'float128?'
64
+ ] ;
Original file line number Diff line number Diff line change 1
- import { json } from '@sveltejs/kit' ;
1
+ import { json , text } from '@sveltejs/kit' ;
2
2
3
3
import { ContractKit } from '@wharfkit/contract' ;
4
4
import { Name , Serializer , Transaction } from '@wharfkit/antelope' ;
5
5
import type { RequestEvent } from './$types' ;
6
+ import { stringableTypes } from '$lib/types/string' ;
6
7
7
8
export async function GET ( { locals : { network } , params } : RequestEvent ) {
8
9
const contractKit = new ContractKit ( {
@@ -33,12 +34,15 @@ export async function GET({ locals: { network }, params }: RequestEvent) {
33
34
throw new Error ( `Return type for ${ name } not defined in the ABI.` ) ;
34
35
}
35
36
36
- return json (
37
- Serializer . decode ( {
38
- data : hexData ,
39
- type : returnType . result_type ,
40
- abi : contract . abi
41
- } ) ,
42
- { status : 200 }
43
- ) ;
37
+ const decoded = Serializer . decode ( {
38
+ data : hexData ,
39
+ type : returnType . result_type ,
40
+ abi : contract . abi
41
+ } ) ;
42
+
43
+ if ( stringableTypes . includes ( returnType . result_type ) ) {
44
+ return text ( String ( decoded ) , { status : 200 } ) ;
45
+ } else {
46
+ return json ( decoded , { status : 200 } ) ;
47
+ }
44
48
}
You can’t perform that action at this time.
0 commit comments