/
constants.js
255 lines (228 loc) · 6.1 KB
/
constants.js
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
/*
* Copyright (C) 2019-2024 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const NANOSECONDS_PER_MILLISECOND = 10n ** 6n;
const MAX_INT32 = 2147483647;
const MAX_LONG = 2n ** 63n - 1n;
const ONE_DAY_IN_NS = 86_400_000_000_000n;
const ZERO_UINT256 = '0x0000000000000000000000000000000000000000000000000000000000000000';
const AUTO_RENEW_PERIOD_MULTIPLE = BigInt(1e9);
const DECIMALS_IN_HBARS = 8;
const EMPTY_STRING = '';
const EVM_ADDRESS_LENGTH = 20;
const apiPrefix = '/api/v1';
// url query filer keys
const filterKeys = {
ACCOUNT_BALANCE: 'account.balance',
ACCOUNT_ID: 'account.id',
ACCOUNT_PUBLICKEY: 'account.publickey',
BALANCE: 'balance',
BLOCK_HASH: 'block.hash',
BLOCK_NUMBER: 'block.number',
CONTRACTID: 'contractid',
CONTRACT_ID: 'contract.id',
CREDIT_TYPE: 'type',
ENCODING: 'encoding',
ENTITY_PUBLICKEY: 'publickey',
FILE_ID: 'file.id',
FROM: 'from',
ID_OR_ALIAS_OR_EVM_ADDRESS: 'idOrAliasOrEvmAddress',
INDEX: 'index',
INTERNAL: 'internal',
LIMIT: 'limit',
NODE_ID: 'node.id',
NONCE: 'nonce',
ORDER: 'order',
Q: 'q',
RESULT: 'result',
SCHEDULED: 'scheduled',
SCHEDULEID: 'scheduleid',
SCHEDULE_ID: 'schedule.id',
SEQUENCE_NUMBER: 'sequencenumber',
SERIAL_NUMBER: 'serialnumber',
SPENDER_ID: 'spender.id',
TIMESTAMP: 'timestamp',
TOKENID: 'tokenid',
TOKEN_ID: 'token.id',
TOKEN_TYPE: 'type',
TOPIC0: 'topic0',
TOPIC1: 'topic1',
TOPIC2: 'topic2',
TOPIC3: 'topic3',
TOPIC_ID: 'topic.id',
TRANSACTION_INDEX: 'transaction.index',
TRANSACTION_TYPE: 'transactiontype',
TRANSACTIONS: 'transactions',
HASH_OR_NUMBER: 'hashOrNumber',
SLOT: 'slot',
};
const entityTypes = {
ACCOUNT: 'ACCOUNT',
CONTRACT: 'CONTRACT',
FILE: 'FILE',
TOKEN: 'TOKEN',
TOPIC: 'TOPIC',
SCHEDULE: 'SCHEDULE',
};
const EvmAddressType = {
// evm address without shard and realm and with 0x prefix
NO_SHARD_REALM: 0,
// evm address with shard and realm as optionals
OPTIONAL_SHARD_REALM: 1,
// can be either a NO_SHARD_REALM or OPTIONAL_SHARD_REALM
ANY: 2,
};
const keyTypes = {
ECDSA_SECP256K1: 'ECDSA_SECP256K1',
ED25519: 'ED25519',
PROTOBUF: 'ProtobufEncoded',
};
const requestIdLabel = 'requestId';
const requestPathLabel = 'requestPath';
const requestStartTime = 'requestStartTime';
const responseContentType = 'responseContentType';
const responseDataLabel = 'responseData';
const orderFilterValues = {
ASC: 'asc',
DESC: 'desc',
};
// topic messages filter options
const characterEncoding = {
BASE64: 'base64',
UTF8: 'utf-8',
};
const networkSupplyQuery = {
CIRCULATING: 'circulating',
TOTALCOINS: 'totalcoins',
};
const networkSupplyCurrencyFormatType = {
TINYBARS: 'TINYBARS', // output circulating or total coins in tinybars
HBARS: 'HBARS', // output circulating or total coins in hbars (rounded to nearest integer)
BOTH: 'BOTH', // default; output circulating or total coins in fractional hbars (with a decimal point between hbars and remaining tinybars)
};
const transactionResultFilter = {
SUCCESS: 'success',
FAIL: 'fail',
};
const cryptoTransferType = {
CREDIT: 'credit',
DEBIT: 'debit',
};
const cloudProviders = {
S3: 'S3',
GCP: 'GCP',
};
const defaultCloudProviderEndpoints = {
[cloudProviders.S3]: 'https://s3.amazonaws.com',
[cloudProviders.GCP]: 'https://storage.googleapis.com',
};
const networks = {
DEMO: 'DEMO',
MAINNET: 'MAINNET',
TESTNET: 'TESTNET',
PREVIEWNET: 'PREVIEWNET',
OTHER: 'OTHER',
};
const defaultBucketNames = {
[networks.DEMO]: 'hedera-demo-streams',
[networks.MAINNET]: 'hedera-mainnet-streams',
[networks.TESTNET]: 'hedera-testnet-streams-2024-02',
[networks.PREVIEWNET]: 'hedera-preview-testnet-streams',
[networks.OTHER]: null,
};
const recordStreamPrefix = 'recordstreams/record';
const tokenTypeFilter = {
ALL: 'all',
FUNGIBLE_COMMON: 'fungible_common',
NON_FUNGIBLE_UNIQUE: 'non_fungible_unique',
};
const zeroRandomPageCostQueryHint = 'set local random_page_cost = 0';
export class StatusCode {
constructor(code, message) {
this.code = code;
this.message = message;
}
isClientError() {
return this.code >= 400 && this.code < 500;
}
toString() {
return `${this.code} ${this.message}`;
}
}
const httpStatusCodes = {
BAD_GATEWAY: new StatusCode(502, 'Bad gateway'),
BAD_REQUEST: new StatusCode(400, 'Bad request'),
INTERNAL_ERROR: new StatusCode(500, 'Internal error'),
NO_CONTENT: new StatusCode(204, 'No content'),
NOT_FOUND: new StatusCode(404, 'Not found'),
OK: new StatusCode(200, 'OK'),
PARTIAL_CONTENT: new StatusCode(206, 'Partial mirror node'),
SERVICE_UNAVAILABLE: new StatusCode(503, 'Service unavailable'),
};
const queryParamOperators = {
eq: 'eq',
ne: 'ne',
lt: 'lt',
lte: 'lte',
gt: 'gt',
gte: 'gte',
};
const queryParamOperatorPatterns = {
gt: /^>$/,
gte: /^>=$/,
gtorgte: /^>[=]?$/,
eq: /^=$/,
lt: /^<$/,
lte: /^<=$/,
ltorlte: /^<[=]?$/,
ne: /^!=$/,
};
export {
AUTO_RENEW_PERIOD_MULTIPLE,
DECIMALS_IN_HBARS,
EMPTY_STRING,
EVM_ADDRESS_LENGTH,
NANOSECONDS_PER_MILLISECOND,
MAX_INT32,
MAX_LONG,
ONE_DAY_IN_NS,
ZERO_UINT256,
apiPrefix,
characterEncoding,
cloudProviders,
cryptoTransferType,
defaultBucketNames,
defaultCloudProviderEndpoints,
entityTypes,
filterKeys,
httpStatusCodes,
keyTypes,
networks,
networkSupplyCurrencyFormatType,
networkSupplyQuery,
orderFilterValues,
queryParamOperators,
queryParamOperatorPatterns,
recordStreamPrefix,
requestIdLabel,
requestPathLabel,
requestStartTime,
responseContentType,
responseDataLabel,
tokenTypeFilter,
transactionResultFilter,
zeroRandomPageCostQueryHint,
EvmAddressType,
};