Skip to content

Commit 877695e

Browse files
committed
Determine if the decoded type is stringable, and if so just return text
1 parent a682938 commit 877695e

File tree

2 files changed

+77
-9
lines changed

2 files changed

+77
-9
lines changed

src/lib/types/string.ts

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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+
];

src/routes/[network]/api/readonly/[contract]/[action]/[[data]]/+server.ts

+13-9
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { json } from '@sveltejs/kit';
1+
import { json, text } from '@sveltejs/kit';
22

33
import { ContractKit } from '@wharfkit/contract';
44
import { Name, Serializer, Transaction } from '@wharfkit/antelope';
55
import type { RequestEvent } from './$types';
6+
import { stringableTypes } from '$lib/types/string';
67

78
export async function GET({ locals: { network }, params }: RequestEvent) {
89
const contractKit = new ContractKit({
@@ -33,12 +34,15 @@ export async function GET({ locals: { network }, params }: RequestEvent) {
3334
throw new Error(`Return type for ${name} not defined in the ABI.`);
3435
}
3536

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+
}
4448
}

0 commit comments

Comments
 (0)