/
server_api.ts
358 lines (347 loc) · 12.1 KB
/
server_api.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
import { Asset } from "stellar-base";
import { Omit } from "utility-types";
import { Horizon } from "./horizon_api";
// more types
import { AccountRecordSigners as AccountRecordSignersType } from "./types/account";
import { AssetRecord as AssetRecordType } from "./types/assets";
import * as Effects from "./types/effects";
import { OfferRecord as OfferRecordType } from "./types/offer";
import { Trade } from "./types/trade";
/* tslint:disable-next-line: no-namespace */
export namespace ServerApi {
export type OfferRecord = OfferRecordType;
export type AccountRecordSigners = AccountRecordSignersType;
export type AssetRecord = AssetRecordType;
export interface CollectionPage<
T extends Horizon.BaseResponse = Horizon.BaseResponse
> {
records: T[];
next: () => Promise<CollectionPage<T>>;
prev: () => Promise<CollectionPage<T>>;
}
export interface CallFunctionTemplateOptions {
cursor?: string | number;
limit?: number;
order?: "asc" | "desc";
}
export type CallFunction<
T extends Horizon.BaseResponse = Horizon.BaseResponse
> = () => Promise<T>;
export type CallCollectionFunction<
T extends Horizon.BaseResponse = Horizon.BaseResponse
> = (options?: CallFunctionTemplateOptions) => Promise<CollectionPage<T>>;
type BaseEffectRecordFromTypes =
| Effects.AccountCreated
| Effects.AccountCredited
| Effects.AccountDebited
| Effects.AccountThresholdsUpdated
| Effects.AccountHomeDomainUpdated
| Effects.AccountFlagsUpdated
| Effects.DataCreated
| Effects.DataRemoved
| Effects.DataUpdated
| Effects.SequenceBumped
| Effects.SignerCreated
| Effects.SignerRemoved
| Effects.SignerUpdated
| Effects.TrustlineCreated
| Effects.TrustlineRemoved
| Effects.TrustlineUpdated
| Effects.TrustlineAuthorized
| Effects.TrustlineDeauthorized
| Effects.TrustlineAuthorizedToMaintainLiabilities
| Effects.ClaimableBalanceCreated
| Effects.ClaimableBalanceClaimed
| Effects.ClaimableBalanceClaimantCreated
| Effects.AccountSponsorshipCreated
| Effects.AccountSponsorshipRemoved
| Effects.AccountSponsorshipUpdated
| Effects.TrustlineSponsorshipCreated
| Effects.TrustlineSponsorshipUpdated
| Effects.TrustlineSponsorshipRemoved
| Effects.DateSponsorshipCreated
| Effects.DateSponsorshipUpdated
| Effects.DateSponsorshipRemoved
| Effects.ClaimableBalanceSponsorshipCreated
| Effects.ClaimableBalanceSponsorshipRemoved
| Effects.ClaimableBalanceSponsorshipUpdated
| Effects.SignerSponsorshipCreated
| Effects.SignerSponsorshipUpdated
| Effects.SignerSponsorshipRemoved
| Trade;
export type EffectRecord = BaseEffectRecordFromTypes & EffectRecordMethods;
export interface ClaimableBalanceRecord extends Horizon.BaseResponse {
id: string;
paging_token: string;
asset: string;
amount: string;
sponsor?: string;
last_modified_ledger: number;
claimants: Horizon.Claimant[];
}
export interface AccountRecord extends Horizon.BaseResponse {
id: string;
paging_token: string;
account_id: string;
sequence: string;
subentry_count: number;
home_domain?: string;
inflation_destination?: string;
last_modified_ledger: number;
thresholds: Horizon.AccountThresholds;
flags: Horizon.Flags;
balances: Horizon.BalanceLine[];
signers: AccountRecordSigners[];
data: (options: { value: string }) => Promise<{ value: string }>;
data_attr: {
[key: string]: string;
};
sponsor?: string;
num_sponsoring: number;
num_sponsored: number;
effects: CallCollectionFunction<EffectRecord>;
offers: CallCollectionFunction<OfferRecord>;
operations: CallCollectionFunction<OperationRecord>;
payments: CallCollectionFunction<PaymentOperationRecord>;
trades: CallCollectionFunction<TradeRecord>;
}
interface EffectRecordMethods {
operation?: CallFunction<OperationRecord>;
precedes?: CallFunction<EffectRecord>;
succeeds?: CallFunction<EffectRecord>;
}
export interface LedgerRecord extends Horizon.BaseResponse {
id: string;
paging_token: string;
hash: string;
prev_hash: string;
sequence: number;
transaction_count: number;
operation_count: number;
tx_set_operation_count: number | null;
closed_at: string;
total_coins: string;
fee_pool: string;
base_fee: number;
base_reserve: string;
max_tx_set_size: number;
protocol_version: number;
header_xdr: string;
base_fee_in_stroops: number;
base_reserve_in_stroops: number;
effects: CallCollectionFunction<EffectRecord>;
operations: CallCollectionFunction<OperationRecord>;
self: CallFunction<LedgerRecord>;
transactions: CallCollectionFunction<TransactionRecord>;
}
import OperationResponseType = Horizon.OperationResponseType;
import OperationResponseTypeI = Horizon.OperationResponseTypeI;
export interface BaseOperationRecord<
T extends OperationResponseType = OperationResponseType,
TI extends OperationResponseTypeI = OperationResponseTypeI
> extends Horizon.BaseOperationResponse<T, TI> {
self: CallFunction<OperationRecord>;
succeeds: CallFunction<OperationRecord>;
precedes: CallFunction<OperationRecord>;
effects: CallCollectionFunction<EffectRecord>;
transaction: CallFunction<TransactionRecord>;
}
export interface CreateAccountOperationRecord
extends BaseOperationRecord<
OperationResponseType.createAccount,
OperationResponseTypeI.createAccount
>,
Horizon.CreateAccountOperationResponse {}
export interface PaymentOperationRecord
extends BaseOperationRecord<
OperationResponseType.payment,
OperationResponseTypeI.payment
>,
Horizon.PaymentOperationResponse {
sender: CallFunction<AccountRecord>;
receiver: CallFunction<AccountRecord>;
}
export interface PathPaymentOperationRecord
extends BaseOperationRecord<
OperationResponseType.pathPayment,
OperationResponseTypeI.pathPayment
>,
Horizon.PathPaymentOperationResponse {}
export interface PathPaymentStrictSendOperationRecord
extends BaseOperationRecord<
OperationResponseType.pathPaymentStrictSend,
OperationResponseTypeI.pathPaymentStrictSend
>,
Horizon.PathPaymentStrictSendOperationResponse {}
export interface ManageOfferOperationRecord
extends BaseOperationRecord<
OperationResponseType.manageOffer,
OperationResponseTypeI.manageOffer
>,
Horizon.ManageOfferOperationResponse {}
export interface PassiveOfferOperationRecord
extends BaseOperationRecord<
OperationResponseType.createPassiveOffer,
OperationResponseTypeI.createPassiveOffer
>,
Horizon.PassiveOfferOperationResponse {}
export interface SetOptionsOperationRecord
extends BaseOperationRecord<
OperationResponseType.setOptions,
OperationResponseTypeI.setOptions
>,
Horizon.SetOptionsOperationResponse {}
export interface ChangeTrustOperationRecord
extends BaseOperationRecord<
OperationResponseType.changeTrust,
OperationResponseTypeI.changeTrust
>,
Horizon.ChangeTrustOperationResponse {}
export interface AllowTrustOperationRecord
extends BaseOperationRecord<
OperationResponseType.allowTrust,
OperationResponseTypeI.allowTrust
>,
Horizon.AllowTrustOperationResponse {}
export interface AccountMergeOperationRecord
extends BaseOperationRecord<
OperationResponseType.accountMerge,
OperationResponseTypeI.accountMerge
>,
Horizon.AccountMergeOperationResponse {}
export interface InflationOperationRecord
extends BaseOperationRecord<
OperationResponseType.inflation,
OperationResponseTypeI.inflation
>,
Horizon.InflationOperationResponse {}
export interface ManageDataOperationRecord
extends BaseOperationRecord<
OperationResponseType.manageData,
OperationResponseTypeI.manageData
>,
Horizon.ManageDataOperationResponse {}
export interface BumpSequenceOperationRecord
extends BaseOperationRecord<
OperationResponseType.bumpSequence,
OperationResponseTypeI.bumpSequence
>,
Horizon.BumpSequenceOperationResponse {}
export interface CreateClaimableBalanceOperationRecord
extends BaseOperationRecord<
OperationResponseType.createClaimableBalance,
OperationResponseTypeI.createClaimableBalance
>,
Horizon.CreateClaimableBalanceOperationResponse {}
export interface ClaimClaimableBalanceOperationRecord
extends BaseOperationRecord<
OperationResponseType.claimClaimableBalance,
OperationResponseTypeI.claimClaimableBalance
>,
Horizon.ClaimClaimableBalanceOperationResponse {}
export interface BeginSponsoringFutureReservesOperationRecord
extends BaseOperationRecord<
OperationResponseType.beginSponsoringFutureReserves,
OperationResponseTypeI.beginSponsoringFutureReserves
>,
Horizon.BeginSponsoringFutureReservesOperationResponse {}
export interface EndSponsoringFutureReservesOperationRecord
extends BaseOperationRecord<
OperationResponseType.endSponsoringFutureReserves,
OperationResponseTypeI.endSponsoringFutureReserves
>,
Horizon.EndSponsoringFutureReservesOperationResponse {}
export interface RevokeSponsorshipOperationRecord
extends BaseOperationRecord<
OperationResponseType.revokeSponsorship,
OperationResponseTypeI.revokeSponsorship
>,
Horizon.RevokeSponsorshipOperationResponse {}
export type OperationRecord =
| CreateAccountOperationRecord
| PaymentOperationRecord
| PathPaymentOperationRecord
| ManageOfferOperationRecord
| PassiveOfferOperationRecord
| SetOptionsOperationRecord
| ChangeTrustOperationRecord
| AllowTrustOperationRecord
| AccountMergeOperationRecord
| InflationOperationRecord
| ManageDataOperationRecord
| BumpSequenceOperationRecord
| PathPaymentStrictSendOperationRecord
| CreateClaimableBalanceOperationRecord
| ClaimClaimableBalanceOperationRecord
| BeginSponsoringFutureReservesOperationRecord
| EndSponsoringFutureReservesOperationRecord
| RevokeSponsorshipOperationRecord;
export interface TradeRecord extends Horizon.BaseResponse {
id: string;
paging_token: string;
ledger_close_time: string;
offer_id: string;
base_offer_id: string;
base_account: string;
base_amount: string;
base_asset_type: string;
base_asset_code?: string;
base_asset_issuer?: string;
counter_offer_id: string;
counter_account: string;
counter_amount: string;
counter_asset_type: string;
counter_asset_code?: string;
counter_asset_issuer?: string;
base_is_seller: boolean;
base: CallFunction<AccountRecord>;
counter: CallFunction<AccountRecord>;
operation: CallFunction<OperationRecord>;
}
export interface TransactionRecord
extends Omit<Horizon.TransactionResponse, "ledger"> {
ledger_attr: Horizon.TransactionResponse["ledger"];
account: CallFunction<AccountRecord>;
effects: CallCollectionFunction<EffectRecord>;
ledger: CallFunction<LedgerRecord>;
operations: CallCollectionFunction<OperationRecord>;
precedes: CallFunction<TransactionRecord>;
self: CallFunction<TransactionRecord>;
succeeds: CallFunction<TransactionRecord>;
}
export interface OrderbookRecord extends Horizon.BaseResponse {
bids: Array<{
price_r: {
d: number;
n: number;
};
price: string;
amount: string;
}>;
asks: Array<{
price_r: {
d: number;
n: number;
};
price: string;
amount: string;
}>;
base: Asset;
counter: Asset;
}
export interface PaymentPathRecord extends Horizon.BaseResponse {
path: Array<{
asset_code: string;
asset_issuer: string;
asset_type: string;
}>;
source_amount: string;
source_asset_type: string;
source_asset_code: string;
source_asset_issuer: string;
destination_amount: string;
destination_asset_type: string;
destination_asset_code: string;
destination_asset_issuer: string;
}
}