-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapi.ts
More file actions
119 lines (113 loc) · 3.13 KB
/
Copy pathapi.ts
File metadata and controls
119 lines (113 loc) · 3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import {
HttpApi,
HttpApiEndpoint,
HttpApiGroup,
HttpApiSchema,
HttpApiSecurity,
OpenApi,
} from "@effect/platform"
import { Schema } from "@effect/schema"
const security = HttpApiSecurity.apiKey({
in: "header",
key: "x-api-key",
})
class TimeoutError extends Schema.TaggedClass<TimeoutError>()(
"TimeoutError",
{},
) { }
class AuthorizationError extends Schema.TaggedClass<AuthorizationError>()(
"AuthorizationError",
{},
) { }
export const OrganizationApi = HttpApiGroup.make("organization").pipe(
HttpApiGroup.add(
HttpApiEndpoint.post("add-metadata", "/add-metadata").pipe(
HttpApiEndpoint.setSuccess(Schema.Struct({ status: Schema.String })),
HttpApiEndpoint.setPayload(
Schema.Struct({
address: Schema.String,
contractName: Schema.String,
tokenSymbol: Schema.optional(Schema.String),
decimals: Schema.optional(Schema.Number),
type: Schema.String,
chainID: Schema.Number,
}),
),
OpenApi.annotate({
description: "Manully add contract metadata to the database",
}),
),
),
HttpApiGroup.add(
HttpApiEndpoint.post("add-abi", "/add-abi").pipe(
HttpApiEndpoint.setSuccess(Schema.Struct({ status: Schema.String })),
HttpApiEndpoint.setPayload(
Schema.Struct({
address: Schema.String,
abi: Schema.String,
chain: Schema.Number,
}),
),
OpenApi.annotate({
description: "Manully add a contract ABI to the database",
}),
),
),
HttpApiGroup.addError(AuthorizationError, { status: 401 }),
OpenApi.annotate({ security }),
)
export const TransactionApi = HttpApiGroup.make("transaction").pipe(
HttpApiGroup.add(
HttpApiEndpoint.get("decode", "/decode/:chain/:hash").pipe(
HttpApiEndpoint.setPath(
Schema.Struct({
chain: Schema.NumberFromString,
hash: Schema.String,
}),
),
OpenApi.annotate({
description: "Decode transaction",
}),
),
),
HttpApiGroup.add(
HttpApiEndpoint.get("interpret", "/interpret/:chain/:hash").pipe(
HttpApiEndpoint.setPath(
Schema.Struct({
chain: Schema.NumberFromString,
hash: Schema.String,
}),
),
OpenApi.annotate({
title: "Interpret transaction",
}),
),
),
)
const GlobalRoute = HttpApiGroup.make("global").pipe(
HttpApiGroup.add(
HttpApiEndpoint.get("supported-chains", "/supported-chains").pipe(
HttpApiEndpoint.setSuccess(
Schema.Struct({
chains: Schema.Array(
Schema.Struct({
chainId: Schema.Number,
name: Schema.String,
}),
),
}),
),
OpenApi.annotate({
description: "List supported chains and their ids",
}),
),
),
)
// NOTE: We use this now only for openapi generation
export class Api extends HttpApi.empty.pipe(
HttpApi.addGroup(GlobalRoute),
HttpApi.addGroup(OrganizationApi),
HttpApi.addGroup(TransactionApi),
HttpApi.addError(TimeoutError, { status: 408 }),
OpenApi.annotate({ title: "Loop Decoder REST API" }),
) { }