-
Notifications
You must be signed in to change notification settings - Fork 15
/
HederaSchemas.ts
821 lines (712 loc) · 30.6 KB
/
HederaSchemas.ts
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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
/*-
*
* Hedera Mirror Node Explorer
*
* Copyright (C) 2021 - 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.
*
*/
// ---------------------------------------------------------------------------------------------------------------------
// Account
// ---------------------------------------------------------------------------------------------------------------------
import {EntityID} from "@/utils/EntityID";
import {makeDefaultNodeDescription} from "@/schemas/HederaUtils";
export interface AccountsResponse {
accounts: AccountInfo[] | undefined
links: Links | undefined
}
export interface AccountInfo {
account: string | null // Network entity ID in the format of shard.realm.num
auto_renew_period: number | null
balance: Balance | null
created_timestamp: string | null
deleted: boolean | null
expiry_timestamp: string | null
key : Key | null
max_automatic_token_associations: number | null
memo: string | null
receiver_sig_required: boolean | null
alias: string | null // RFC4648 no-padding base32 encoded account alias
ethereum_nonce: number | null
evm_address: string | null // A network entity encoded as an EVM address in hex.
decline_reward: boolean | null // Whether the account declines receiving a staking reward
staked_account_id: string | null // The account to which this account is staking
staked_node_id: number | null // The id of the node to which this account is staking
stake_period_start : string | null // The staking period during which either the staking settings for this account
// changed (such as starting staking or changing stakedNode) or the most recent
// reward was earned, whichever is later. If this account is not currently
// staked to a node, then the value is null
pending_reward: number | undefined // The pending reward in tinybars the account will receive in the next
// reward payout. Note the value is updated at the end of each staking period
// and there may be delay to reflect the changes in the past staking period.
}
export interface AccountBalanceTransactions extends AccountInfo {
transactions?: Array<Transaction>
links?: Links
}
export interface Balance {
timestamp: string | null
balance: number | null
tokens: TokenBalance[]
}
export interface TokenBalance {
token_id: string | null // Network entity ID in the format of shard.realm.num
balance: number
}
export interface TokenRelationshipResponse {
tokens: Array<TokenRelationship>,
links: Links
}
export interface TokenRelationship {
automatic_association: boolean,
balance: number,
created_timestamp: string,
freeze_status: string, // [ NOT_APPLICABLE, FROZEN, UNFROZEN ]
kyc_status: string, // [ NOT_APPLICABLE, GRANTED, REVOKED ]
token_id: string | null,
}
export interface CryptoAllowancesResponse {
allowances: Array<CryptoAllowance>,
links: Links
}
export interface CryptoAllowance {
amount_granted: number, // The granted amount of the spender's allowance in tinybars.
owner: string | null, // Network entity ID in the format of shard.realm.num
spender: string | null, // Network entity ID in the format of shard.realm.num
timestamp: TimestampRange
}
export interface TokenAllowancesResponse {
allowances: Array<TokenAllowance>,
links: Links
}
export interface TokenAllowance extends CryptoAllowance {
token_id: string | null, // Network entity ID in the format of shard.realm.num
}
// ---------------------------------------------------------------------------------------------------------------------
// Balance
// ---------------------------------------------------------------------------------------------------------------------
export interface BalancesResponse {
timestamp: string | null | undefined
balances: Array<AccountBalance> | undefined
links: Links | undefined
}
export interface AccountBalance {
account: string | null // Network entity ID in the format of shard.realm.num
balance: number
tokens: Array<TokenBalance>
}
// ---------------------------------------------------------------------------------------------------------------------
// Transaction
// ---------------------------------------------------------------------------------------------------------------------
export interface TransactionResponse {
transactions: Array<Transaction> | undefined
links: Links | undefined
}
export interface NftTransactionHistory {
transactions: Array<NftTransactionTransfer> | undefined
links: Links | undefined
}
export interface TransactionByIdResponse {
transactions: Array<TransactionDetail> | undefined
}
export interface Transaction {
bytes: string | null
charged_tx_fee: number
consensus_timestamp: string
entity_id: string | null // Network entity ID in the format of shard.realm.num
max_fee: string
memo_base64: string | null // To be checked
name: TransactionType
nft_transfers: NftTransfer[]
node: string | null // Network entity ID in the format of shard.realm.num
nonce: number
parent_consensus_timestamp: string | null
result: string
scheduled: boolean
staking_reward_transfers: StakingRewardTransfer[]
token_transfers: TokenTransfer[]
transaction_hash: string
transaction_id: string
transfers: Transfer[]
valid_duration_seconds: string
valid_start_timestamp: string
}
export interface NftTransactionTransfer {
consensus_timestamp: string | undefined
nonce: number | undefined
transaction_id: string | undefined
type: TransactionType | undefined
is_approval: false
receiver_account_id: string | null | undefined // account ID in the format of shard.realm.num
sender_account_id: string | null | undefined // account ID in the format of shard.realm.num
}
export interface TransactionDetail extends Transaction {
nft_transfers: NftTransfer[]
assessed_custom_fees: CustomFee[]
}
export interface NftTransfer {
receiver_account_id: string | null | undefined // Network entity ID in the format of shard.realm.num
sender_account_id: string | null | undefined // Network entity ID in the format of shard.realm.num
is_approval: boolean
serial_number: number
token_id: string | null // Network entity ID in the format of shard.realm.num}
}
export function compareNftTransfer(t1: NftTransfer, t2: NftTransfer): number {
let result = compareString(t1.sender_account_id, t2.sender_account_id)
if (result == 0) {
result = compareString(t1.token_id, t2.token_id)
}
if (result == 0) {
result = compareString(t1.receiver_account_id, t2.receiver_account_id)
}
if (result == 0) {
result = compareNumber(t1.serial_number, t2.serial_number)
}
return result
}
export interface Transfer {
account: string | null // Network entity ID in the format of shard.realm.num
amount: number
is_approval: boolean | undefined
}
export interface TokenTransfer extends Transfer {
token_id: string | null // Network entity ID in the format of shard.realm.num
}
export interface StakingRewardTransfer {
account: string | null // Network entity ID in the format of shard.realm.num
amount: number
}
export interface CustomFee {
amount: number | undefined
collector_account_id: string | undefined // Network entity ID in the format of shard.realm.num
effective_payer_account_ids: string[] | undefined
token_id: string | null | undefined // Network entity ID in the format of shard.realm.num
}
export enum TransactionType {
CONSENSUSCREATETOPIC = "CONSENSUSCREATETOPIC",
CONSENSUSDELETETOPIC = "CONSENSUSDELETETOPIC",
CONSENSUSSUBMITMESSAGE = "CONSENSUSSUBMITMESSAGE",
CONSENSUSUPDATETOPIC = "CONSENSUSUPDATETOPIC",
CONTRACTCALL = "CONTRACTCALL",
CONTRACTCREATEINSTANCE = "CONTRACTCREATEINSTANCE",
CONTRACTDELETEINSTANCE = "CONTRACTDELETEINSTANCE",
CONTRACTUPDATEINSTANCE = "CONTRACTUPDATEINSTANCE",
CRYPTOADDLIVEHASH = "CRYPTOADDLIVEHASH",
CRYPTOCREATEACCOUNT = "CRYPTOCREATEACCOUNT",
CRYPTODELETE = "CRYPTODELETE",
CRYPTODELETELIVEHASH = "CRYPTODELETELIVEHASH",
CRYPTOTRANSFER = "CRYPTOTRANSFER",
CRYPTOUPDATEACCOUNT = "CRYPTOUPDATEACCOUNT",
CRYPTOAPPROVEALLOWANCE = "CRYPTOAPPROVEALLOWANCE",
CRYPTODELETEALLOWANCE = "CRYPTODELETEALLOWANCE",
FILEAPPEND = "FILEAPPEND",
FILECREATE = "FILECREATE",
FILEDELETE = "FILEDELETE",
FILEUPDATE = "FILEUPDATE",
FREEZE = "FREEZE",
SCHEDULECREATE = "SCHEDULECREATE",
SCHEDULEDELETE = "SCHEDULEDELETE",
SCHEDULESIGN = "SCHEDULESIGN",
SYSTEMDELETE = "SYSTEMDELETE",
SYSTEMUNDELETE = "SYSTEMUNDELETE",
TOKENASSOCIATE = "TOKENASSOCIATE",
TOKENBURN = "TOKENBURN",
TOKENCREATION = "TOKENCREATION",
TOKENDELETION = "TOKENDELETION",
TOKENDISSOCIATE = "TOKENDISSOCIATE",
TOKENFEESCHEDULEUPDATE = "TOKENFEESCHEDULEUPDATE",
TOKENFREEZE = "TOKENFREEZE",
TOKENGRANTKYC = "TOKENGRANTKYC",
TOKENMINT = "TOKENMINT",
TOKENPAUSE = "TOKENPAUSE",
TOKENREVOKEKYC = "TOKENREVOKEKYC",
TOKENUNFREEZE = "TOKENUNFREEZE",
TOKENUNPAUSE = "TOKENUNPAUSE",
TOKENUPDATE = "TOKENUPDATE",
TOKENWIPE = "TOKENWIPE",
UNCHECKEDSUBMIT = "UNCHECKEDSUBMIT",
ETHEREUMTRANSACTION = "ETHEREUMTRANSACTION",
NODESTAKEUPDATE = "NODESTAKEUPDATE",
UTILPRNG = "UTILPRNG"
}
export enum TransactionResult {
SUCCESS = "success",
FAILURE = "fail"
}
export function compareTransferByAccount(t1: Transfer | StakingRewardTransfer, t2: Transfer | StakingRewardTransfer): number {
let result: number
const account1 = t1.account
const account2 = t2.account
if (account1 != null && account2 != null) {
const accountId1 = EntityID.parse(account1)
const accountId2 = EntityID.parse(account2)
if (accountId1 != null && accountId2 != null) {
result = accountId1.compareAccountID(accountId2)
} else {
result = account1.localeCompare(account2);
}
} else if (account1 != null){
result = +1
} else if (account2 != null) {
result = -1
} else {
result = 0
}
return result
}
export function compareTokenTransferByTokenId(t1: TokenTransfer, t2: TokenTransfer): number {
return compareString(t1.token_id, t2.token_id)
}
// ---------------------------------------------------------------------------------------------------------------------
// Token
// ---------------------------------------------------------------------------------------------------------------------
export interface TokensResponse {
tokens: Token[] | undefined
links: Links | undefined
}
export interface Token {
token_id: string | null
symbol: string
admin_key: Key | null
type: string
}
export interface TokenInfo {
admin_key: Key | null
auto_renew_account: string | null // Network entity ID in the format of shard.realm.num
auto_renew_period: number | null
created_timestamp: string
decimals: string
deleted: boolean | null
expiry_timestamp: string | null
fee_schedule_key: Key | null
freeze_default: boolean
freeze_key: Key | null
initial_supply: string
kyc_key: Key | null
max_supply: string
modified_timestamp: string
name: string
memo: string
pause_key: Key | null
pause_status: string // NOT_APPLICABLE, PAUSED, UNPAUSED
supply_key: Key | null
supply_type: string // FINITE, INFINITE
symbol: string
token_id: string | null // Network entity ID in the format of shard.realm.num
total_supply: string
treasury_account_id: string | null // Network entity ID in the format of shard.realm.num
type: string // FUNGIBLE_COMMON, NON_FUNGIBLE_UNIQUE
wipe_key: Key | null
custom_fees: CustomFees
}
export interface CustomFees {
created_timestamp: string | undefined
fixed_fees: FixedFee[] | undefined // Network entity ID in the format of shard.realm.num
fractional_fees: FractionalFee[] | undefined
royalty_fees: RoyaltyFee[] | null | undefined // Network entity ID in the format of shard.realm.num
}
export interface FixedFee {
amount: number | undefined
collector_account_id: string | undefined // Network entity ID in the format of shard.realm.num
denominating_token_id: string | undefined // Network entity ID in the format of shard.realm.num
}
export interface FractionalFee {
amount: FractionAmount | undefined
collector_account_id: string | undefined // Network entity ID in the format of shard.realm.num
denominating_token_id: string | undefined // Network entity ID in the format of shard.realm.num
maximum: number | undefined
mininum: number | undefined
net_of_transfers: boolean | undefined
}
export interface RoyaltyFee {
amount: FractionAmount | undefined
collector_account_id: string | undefined // Network entity ID in the format of shard.realm.num
fallback_fee: FallbackFee | undefined // Network entity ID in the format of shard.realm.num
}
export interface FallbackFee {
amount: number | undefined
denominating_token_id: string | undefined // Network entity ID in the format of shard.realm.num
}
export interface FractionAmount {
numerator: number | undefined
denominator: number | undefined
}
export interface TokenBalancesResponse {
timestamp: string | null | undefined
balances: TokenDistribution[] | undefined
links: Links | undefined
}
export interface TokenDistribution {
account: string | null // Network entity ID in the format of shard.realm.num
balance: number
}
// ---------------------------------------------------------------------------------------------------------------------
// Nft
// ---------------------------------------------------------------------------------------------------------------------
export interface Nfts {
nfts: Nft[] | undefined
links: Links | undefined
}
export interface Nft {
account_id: string | null | undefined // Network entity ID in the format of shard.realm.num
created_timestamp: string | null | undefined
delegating_spender: string | null | undefined
deleted: boolean
metadata: string | undefined
modified_timestamp: string | null | undefined
serial_number: number | undefined
spender_id: string | null | undefined
token_id: string | null | undefined // Network entity ID in the format of shard.realm.num
}
// ---------------------------------------------------------------------------------------------------------------------
// TopicMessagesResponse
// ---------------------------------------------------------------------------------------------------------------------
export interface TopicMessagesResponse {
messages: Array<TopicMessage> | undefined
links: Links | undefined
}
export interface TopicMessage {
chunk_info: ChunkInfo | null,
consensus_timestamp: string,
topic_id: string | null,
message: string,
running_hash: string,
running_hash_version: number,
sequence_number: number
}
export interface ChunkInfo {
initial_transaction_id: TransactionId,
number: number,
total: number
}
export interface TransactionId {
account_id: string | null,
nonce: number | null,
scheduled: boolean | null,
transaction_valid_start: string
}
// ---------------------------------------------------------------------------------------------------------------------
// Contract
// ---------------------------------------------------------------------------------------------------------------------
export interface ContractsResponse {
contracts: Contract[] | undefined
links: Links | undefined
}
export interface Contract {
admin_key: Key | null
auto_renew_account: string | null // Network entity ID in the format of shard.realm.num
auto_renew_period: number | null
contract_id: string | null // Network entity ID in the format of shard.realm.num
created_timestamp: string | null
deleted: boolean
evm_address: string
expiration_timestamp: string | null
file_id: string | null | undefined // Network entity ID in the format of shard.realm.num
max_automatic_token_associations: number | null
memo: string
nonce: number | undefined
obtainer_id: string | null // Network entity ID in the format of shard.realm.num
permanent_removal: boolean | null
proxy_account_id: string | null // Network entity ID in the format of shard.realm.num
timestamp: TimestampRange // timestamp range the entity is valid for
}
export interface ContractResponse extends Contract {
bytecode: string | null
runtime_bytecode: string | null
}
export interface TimestampRange {
from: string | undefined // The inclusive from timestamp in seconds
to: string | null | undefined // The exclusive to timestamp in seconds
}
export interface ContractResultsResponse {
results: Array<ContractResult> | undefined
links: Links | undefined
}
export interface ContractResult {
access_list: string | null
address: string | null
amount: number | null
block_gas_used: number | null // integer
block_hash: string | null
block_number: number | null // integer
bloom: string | null
call_result: string | null
chain_id: string | null
contract_id: string | null
created_contract_ids: Array<string> | null
error_message: string | null
failed_initcode: string
from: string
function_parameters: string
gas_limit: number
gas_price: string | null
gas_used: number | null
gas_consumed: number | null
hash: string | null
max_fee_per_gas: string | null
max_priority_fee_per_gas: string | null
nonce: number | null // integer
r: string | null
result: string
s: string | null
status: string
timestamp: string
to: string | null
transaction_index: number | null // integer
type: number | null // The type of the wrapped ethereum transaction, 0 (Pre-Eip1559) or 2 (Post-Eip1559)
v: number | null
}
export interface ContractResultDetails extends ContractResult {
logs: ContractLog[] | undefined
state_changes: ContractResultStateChange[]
}
export interface ContractResultLog {
address: string | undefined
bloom: string | null | undefined
contract_id: string | null | undefined
data: string | null | undefined
index: number | undefined // integer
topics: string[] | undefined
}
export interface ContractLog extends ContractResultLog {
block_hash: string | undefined,
block_number: number | undefined,
root_contract_id: string | null | undefined,
timestamp: string | undefined,
transaction_hash: string | undefined,
transaction_index: number | null | undefined, //integer
}
export interface ContractResultsLogResponse {
logs: ContractLog[],
links: Links | undefined
}
export interface ContractResultStateChange {
address: string | undefined
contract_id: string | null | undefined
slot: string | undefined
value_read: string | undefined
value_written: string | null | undefined
}
export interface ContractActionsResponse {
actions: Array<ContractAction> | undefined
links: Links | undefined
}
export interface ContractAction {
call_depth: number | undefined,
call_operation_type: string | undefined,
call_type: string | undefined,
caller: string | null | undefined, // Network entity ID in the format of shard.realm.num
caller_type: string | undefined, // enum EntityType
from: string | undefined,
gas: number | undefined,
gas_used: number | undefined,
index: number | undefined,
input: string | null | undefined,
recipient: string | null | undefined,
recipient_type: string | null | undefined, // enum EntityType
result_data: string | null | undefined,
result_data_type: string | undefined, // enum ResultDataType
timestamp: string | undefined,
to: string | null | undefined,
value: number | undefined
}
export enum EntityType {
ACCOUNT = "ACCOUNT",
CONTRACT = "CONTRACT"
}
export enum ResultDataType {
OUTPUT = "OUTPUT",
REVERT_REASON = "REVERT_REASON",
ERROR = "ERROR"
}
// ---------------------------------------------------------------------------------------------------------------------
// Node
// ---------------------------------------------------------------------------------------------------------------------
export interface NetworkNodesResponse {
nodes: NetworkNode[] | undefined
links: Links | undefined
}
export interface NetworkNode {
description: string | null | undefined
file_id: string | null | undefined // Network entity ID in the format of shard.realm.num
memo: string | undefined
node_id: number | undefined
node_account_id: string | null | undefined // Network entity ID in the format of shard.realm.num
node_cert_hash: string | null | undefined
public_key: string | null | undefined // hex encoded X509 RSA public key used to sign stream files
service_endpoints: ServiceEndPoint[] | undefined
timestamp: TimestampRange | undefined
max_stake: number | null // The maximum stake (rewarded or not rewarded) this node can have as consensus weight
min_stake: number | null // The minimum stake (rewarded or not rewarded) this node must reach before having non-zero consensus weight
stake: number | null // The node consensus weight at the beginning of the staking period
stake_not_rewarded: number | null // The sum (balance + stakedToMe) for all accounts staked to this node with declineReward=true at the beginning of the staking period
stake_rewarded: number | null // The sum (balance + staked) for all accounts staked to the node that are not declining rewards at the beginning of the staking period
staking_period: TimestampRange | null
reward_rate_start: number | null
}
export interface ServiceEndPoint {
ip_address_v4: string
port: number
}
export function makeShortNodeDescription(description: string): string {
const separator = description.indexOf('|') ?? -1
return (separator !== -1) ? (description.slice(0, separator) ?? null) : description
}
export function makeNodeSelectorDescription(node: NetworkNode): string {
const percentFormatter = new Intl.NumberFormat("en-US", {
style: 'percent',
maximumFractionDigits: 1
})
const unclampedStakeAmount = (node.stake_rewarded ?? 0) + (node.stake_not_rewarded ?? 0)
const percentMin = node.min_stake ? unclampedStakeAmount / node.min_stake : 0
const percentMax = node.max_stake ? (node.stake_rewarded ?? 0) / node.max_stake : 0
let result = node.node_id
+ ' - '
+ (node.description ?? makeDefaultNodeDescription(node.node_id ?? null))
if (percentMin !== 0 && percentMin < 1) {
result += " - Not Rewarding (total stake is " + percentFormatter.format(percentMin) + " of min)"
} else if (percentMax !== 0) {
result += " - Rewarding (staked for reward is " + percentFormatter.format(percentMax) + " of max)"
}
return result
}
// ---------------------------------------------------------------------------------------------------------------------
// Network
// ---------------------------------------------------------------------------------------------------------------------
export interface NetworkExchangeRateSetResponse{
current_rate: ExchangeRate,
next_rate: ExchangeRate,
timestamp: string
}
export interface ExchangeRate {
cent_equivalent: number,
expiration_time: number,
hbar_equivalent: number
}
export interface NetworkSupplyResponse {
released_supply: string | undefined // The network's released supply of hbars in tinybars
timestamp: string | undefined // The consensus timestamp at which the released supply was valid
total_supply: string | undefined // The network's total supply of hbars in tinybars
}
export interface NetworkStake {
max_stake_rewarded: number, // The maximum amount of tinybar that can be staked for reward while still
// achieving the maximum per-hbar reward rate
max_staking_reward_rate_per_hbar: number, // The maximum reward rate, in tinybars per whole hbar, that any account can receive in a day
max_total_reward: number, // The total tinybars to be paid as staking rewards in the ending period,
// after applying the settings for the 0.0.800 balance threshold and the maximum stake rewarded
node_reward_fee_fraction: number, // The fraction between zero and one of the network and service fees paid to the node reward account 0.0.801
reserved_staking_rewards: number, // The amount of the staking reward funds of account 0.0.800 reserved to
// pay pending rewards that have been earned but not collected
reward_balance_threshold: number, // The unreserved tinybar balance of account 0.0.800 required to achieve the maximum per-hbar reward rate
stake_total: number, // The total amount staked to the network in tinybars the start of the current staking period
staking_period: TimestampRange, // The timestamp range of the staking period
staking_period_duration: number, // The number of minutes in a staking period
staking_periods_stored: number, // The number of staking periods for which the reward is stored for each node
staking_reward_fee_fraction: number, // The fraction between zero and one of the network and service fees paid
// to the staking reward account 0.0.800
staking_reward_rate: number, // The total number of tinybars to be distributed as staking rewards each period
staking_start_threshold: number, // The minimum balance of staking reward account 0.0.800 required to active rewards
unreserved_staking_reward_balance: number // The unreserved balance of account 0.0.800 at the close of the just-ending period;
// this value is used to compute the HIP-782 balance ratio
}
// ---------------------------------------------------------------------------------------------------------------------
// Block
// ---------------------------------------------------------------------------------------------------------------------
export interface BlocksResponse {
blocks: Array<Block> | undefined
links: Links | undefined
}
export interface Block {
count: number | undefined // integer - minimum 0
gas_used: number | null | undefined // integer - minimum 0
hapi_version: string | undefined
hash: string | undefined
logs_bloom: string | null | undefined // pattern ^0x[0-9a-fA-F]{512}$
name: string | undefined
number: number | undefined
previous_hash: string | undefined
size: number | null | undefined // integer
timestamp: TimestampRange | undefined
}
export interface TimestampRange {
from: string | undefined // pattern: ^\d{1,10}(\.\d{1,9})?$
to: string | null | undefined // pattern: ^\d{1,10}(\.\d{1,9})?$
}
// ---------------------------------------------------------------------------------------------------------------------
// StakingRewardTransfer
// ---------------------------------------------------------------------------------------------------------------------
export interface StakingRewardsResponse {
rewards: Array<StakingReward> | undefined
links: Links | undefined
}
export interface StakingReward {
account_id: string|null
amount: number
timestamp: string
}
// ---------------------------------------------------------------------------------------------------------------------
// Misc
// ---------------------------------------------------------------------------------------------------------------------
export interface Key {
_type: KeyType | undefined
key: string | undefined
}
export enum KeyType {
ECDSA_SECP256K1 = "ECDSA_SECP256K1",
ED25519 = "ED25519",
ProtobufEncoded = "ProtobufEncoded"
}
export interface Links {
next: string | null | undefined
}
export const infiniteDuration = 31556888202959784
// ---------------------------------------------------------------------------------------------------------------------
// Private
// ---------------------------------------------------------------------------------------------------------------------
function compareString(s1: string|null|undefined, s2: string|null|undefined): number {
let result: number
if (s1 && s2) {
result = s1.localeCompare(s2)
} else if (s1) {
// s2 is null or undefined
result = +1
} else if (s2) {
// s1 is null or undefined
result = -1
} else {
result = 0
}
return result
}
function compareNumber(n1: number|null|undefined, n2: number|null|undefined): number {
let result: number
if (n1 && n2) {
if (n1 < n2) {
result = -1
} else if (n1 > n2) {
result = +1
} else {
result = 0
}
} else if (n1) {
// n2 is null or undefined
result = +1
} else if (n2) {
// n1 is null or undefined
result = -1
} else {
result = 0
}
return result
}