-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi-helpers.ts
124 lines (104 loc) · 2.27 KB
/
api-helpers.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
import { StacksMainnet, StacksTestnet } from 'micro-stacks/network';
// General
// TODO: there has to be a better way to do this
type ResponseType =
| string
| number
| boolean
| GetCityInfo
| ActivationDetails
| GetCoinbaseInfo
| CoinbaseThresholds
| CoinbaseAmounts
| CoinbaseDetails
| MiningStats
| Miner
| BlockWinner
| StackingStats
| Stacker;
export const createResponse = (data: ResponseType, status = 200): Response => {
return new Response(typeof data === 'string' ? data : JSON.stringify(data), { status: status });
};
// Stacks
export const NETWORK = (network: string) => {
switch (network) {
case 'mainnet':
return new StacksMainnet();
case 'testnet':
return new StacksTestnet();
default:
return new StacksTestnet();
}
};
export const DEPLOYER = (network: string) => {
switch (network) {
case 'mainnet':
return 'SP8A9HZ3PKST0S42VM9523Z9NV42SZ026V4K39WH';
case 'testnet':
return 'ST8A9HZ3PKST0S42VM9523Z9NV42SZ026VZRMY61';
default:
return 'ST8A9HZ3PKST0S42VM9523Z9NV42SZ026VZRMY61';
}
};
// CCD005 City Data
export interface GetCityInfo {
activated: boolean; // activatedAt in contract
details: ActivationDetails;
treasury: string;
}
export interface ActivationDetails {
succededAt: number;
delay: number;
activatedAt: number;
threshold: number;
}
export interface GetCoinbaseInfo {
thresholds: CoinbaseThresholds;
amounts: CoinbaseAmounts;
details: CoinbaseDetails;
}
export interface CoinbaseThresholds {
cbt1: number;
cbt2: number;
cbt3: number;
cbt4: number;
cbt5: number;
}
export interface CoinbaseAmounts {
cbaBonus: number;
cba1: number;
cba2: number;
cba3: number;
cba4: number;
cba5: number;
cbaDefault: number;
}
export interface CoinbaseDetails {
bonus: number;
epoch: number;
}
// CCD006 CityCoin Mining
export interface MiningStats {
miners: number;
amount: number;
claimed: boolean;
}
export interface Miner {
commit: number;
low: number;
high: number;
winner: boolean;
}
export interface BlockWinner {
winner: boolean;
claimed: boolean;
}
// CCD007 CityCoin Stacking
export interface StackingStats {
total: number;
reward: number | undefined;
}
export interface Stacker {
stacked: number;
claimable: number;
}