tigerbeetle 0.16.16__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,775 @@
1
+ ##########################################################
2
+ ## This file was auto-generated by tb_client_header.zig ##
3
+ ## Do not manually modify. ##
4
+ ##########################################################
5
+ from __future__ import annotations
6
+
7
+ import ctypes
8
+ import enum
9
+ from collections.abc import Callable # noqa: TCH003
10
+ from typing import Any
11
+
12
+ from .lib import c_uint128, dataclass, tbclient, validate_uint
13
+
14
+
15
+ class Operation(enum.IntEnum):
16
+ PULSE = 128
17
+ CREATE_ACCOUNTS = 129
18
+ CREATE_TRANSFERS = 130
19
+ LOOKUP_ACCOUNTS = 131
20
+ LOOKUP_TRANSFERS = 132
21
+ GET_ACCOUNT_TRANSFERS = 133
22
+ GET_ACCOUNT_BALANCES = 134
23
+ QUERY_ACCOUNTS = 135
24
+ QUERY_TRANSFERS = 136
25
+
26
+
27
+ class PacketStatus(enum.IntEnum):
28
+ OK = 0
29
+ TOO_MUCH_DATA = 1
30
+ CLIENT_EVICTED = 2
31
+ CLIENT_SHUTDOWN = 3
32
+ INVALID_OPERATION = 4
33
+ INVALID_DATA_SIZE = 5
34
+
35
+
36
+ Client = ctypes.c_void_p
37
+
38
+ class Status(enum.IntEnum):
39
+ SUCCESS = 0
40
+ UNEXPECTED = 1
41
+ OUT_OF_MEMORY = 2
42
+ ADDRESS_INVALID = 3
43
+ ADDRESS_LIMIT_EXCEEDED = 4
44
+ SYSTEM_RESOURCES = 5
45
+ NETWORK_SUBSYSTEM = 6
46
+
47
+
48
+ class AccountFlags(enum.IntFlag):
49
+ NONE = 0
50
+ LINKED = 1 << 0
51
+ DEBITS_MUST_NOT_EXCEED_CREDITS = 1 << 1
52
+ CREDITS_MUST_NOT_EXCEED_DEBITS = 1 << 2
53
+ HISTORY = 1 << 3
54
+ IMPORTED = 1 << 4
55
+ CLOSED = 1 << 5
56
+
57
+
58
+ class TransferFlags(enum.IntFlag):
59
+ NONE = 0
60
+ LINKED = 1 << 0
61
+ PENDING = 1 << 1
62
+ POST_PENDING_TRANSFER = 1 << 2
63
+ VOID_PENDING_TRANSFER = 1 << 3
64
+ BALANCING_DEBIT = 1 << 4
65
+ BALANCING_CREDIT = 1 << 5
66
+ CLOSING_DEBIT = 1 << 6
67
+ CLOSING_CREDIT = 1 << 7
68
+ IMPORTED = 1 << 8
69
+
70
+
71
+ class AccountFilterFlags(enum.IntFlag):
72
+ NONE = 0
73
+ DEBITS = 1 << 0
74
+ CREDITS = 1 << 1
75
+ REVERSED = 1 << 2
76
+
77
+
78
+ class QueryFilterFlags(enum.IntFlag):
79
+ NONE = 0
80
+ REVERSED = 1 << 0
81
+
82
+
83
+ class CreateAccountResult(enum.IntEnum):
84
+ OK = 0
85
+ LINKED_EVENT_FAILED = 1
86
+ LINKED_EVENT_CHAIN_OPEN = 2
87
+ IMPORTED_EVENT_EXPECTED = 22
88
+ IMPORTED_EVENT_NOT_EXPECTED = 23
89
+ TIMESTAMP_MUST_BE_ZERO = 3
90
+ IMPORTED_EVENT_TIMESTAMP_OUT_OF_RANGE = 24
91
+ IMPORTED_EVENT_TIMESTAMP_MUST_NOT_ADVANCE = 25
92
+ RESERVED_FIELD = 4
93
+ RESERVED_FLAG = 5
94
+ ID_MUST_NOT_BE_ZERO = 6
95
+ ID_MUST_NOT_BE_INT_MAX = 7
96
+ EXISTS_WITH_DIFFERENT_FLAGS = 15
97
+ EXISTS_WITH_DIFFERENT_USER_DATA_128 = 16
98
+ EXISTS_WITH_DIFFERENT_USER_DATA_64 = 17
99
+ EXISTS_WITH_DIFFERENT_USER_DATA_32 = 18
100
+ EXISTS_WITH_DIFFERENT_LEDGER = 19
101
+ EXISTS_WITH_DIFFERENT_CODE = 20
102
+ EXISTS = 21
103
+ FLAGS_ARE_MUTUALLY_EXCLUSIVE = 8
104
+ DEBITS_PENDING_MUST_BE_ZERO = 9
105
+ DEBITS_POSTED_MUST_BE_ZERO = 10
106
+ CREDITS_PENDING_MUST_BE_ZERO = 11
107
+ CREDITS_POSTED_MUST_BE_ZERO = 12
108
+ LEDGER_MUST_NOT_BE_ZERO = 13
109
+ CODE_MUST_NOT_BE_ZERO = 14
110
+ IMPORTED_EVENT_TIMESTAMP_MUST_NOT_REGRESS = 26
111
+
112
+
113
+ class CreateTransferResult(enum.IntEnum):
114
+ OK = 0
115
+ LINKED_EVENT_FAILED = 1
116
+ LINKED_EVENT_CHAIN_OPEN = 2
117
+ IMPORTED_EVENT_EXPECTED = 56
118
+ IMPORTED_EVENT_NOT_EXPECTED = 57
119
+ TIMESTAMP_MUST_BE_ZERO = 3
120
+ IMPORTED_EVENT_TIMESTAMP_OUT_OF_RANGE = 58
121
+ IMPORTED_EVENT_TIMESTAMP_MUST_NOT_ADVANCE = 59
122
+ RESERVED_FLAG = 4
123
+ ID_MUST_NOT_BE_ZERO = 5
124
+ ID_MUST_NOT_BE_INT_MAX = 6
125
+ EXISTS_WITH_DIFFERENT_FLAGS = 36
126
+ EXISTS_WITH_DIFFERENT_PENDING_ID = 40
127
+ EXISTS_WITH_DIFFERENT_TIMEOUT = 44
128
+ EXISTS_WITH_DIFFERENT_DEBIT_ACCOUNT_ID = 37
129
+ EXISTS_WITH_DIFFERENT_CREDIT_ACCOUNT_ID = 38
130
+ EXISTS_WITH_DIFFERENT_AMOUNT = 39
131
+ EXISTS_WITH_DIFFERENT_USER_DATA_128 = 41
132
+ EXISTS_WITH_DIFFERENT_USER_DATA_64 = 42
133
+ EXISTS_WITH_DIFFERENT_USER_DATA_32 = 43
134
+ EXISTS_WITH_DIFFERENT_LEDGER = 67
135
+ EXISTS_WITH_DIFFERENT_CODE = 45
136
+ EXISTS = 46
137
+ ID_ALREADY_FAILED = 68
138
+ FLAGS_ARE_MUTUALLY_EXCLUSIVE = 7
139
+ DEBIT_ACCOUNT_ID_MUST_NOT_BE_ZERO = 8
140
+ DEBIT_ACCOUNT_ID_MUST_NOT_BE_INT_MAX = 9
141
+ CREDIT_ACCOUNT_ID_MUST_NOT_BE_ZERO = 10
142
+ CREDIT_ACCOUNT_ID_MUST_NOT_BE_INT_MAX = 11
143
+ ACCOUNTS_MUST_BE_DIFFERENT = 12
144
+ PENDING_ID_MUST_BE_ZERO = 13
145
+ PENDING_ID_MUST_NOT_BE_ZERO = 14
146
+ PENDING_ID_MUST_NOT_BE_INT_MAX = 15
147
+ PENDING_ID_MUST_BE_DIFFERENT = 16
148
+ TIMEOUT_RESERVED_FOR_PENDING_TRANSFER = 17
149
+ CLOSING_TRANSFER_MUST_BE_PENDING = 64
150
+ AMOUNT_MUST_NOT_BE_ZERO = 18
151
+ LEDGER_MUST_NOT_BE_ZERO = 19
152
+ CODE_MUST_NOT_BE_ZERO = 20
153
+ DEBIT_ACCOUNT_NOT_FOUND = 21
154
+ CREDIT_ACCOUNT_NOT_FOUND = 22
155
+ ACCOUNTS_MUST_HAVE_THE_SAME_LEDGER = 23
156
+ TRANSFER_MUST_HAVE_THE_SAME_LEDGER_AS_ACCOUNTS = 24
157
+ PENDING_TRANSFER_NOT_FOUND = 25
158
+ PENDING_TRANSFER_NOT_PENDING = 26
159
+ PENDING_TRANSFER_HAS_DIFFERENT_DEBIT_ACCOUNT_ID = 27
160
+ PENDING_TRANSFER_HAS_DIFFERENT_CREDIT_ACCOUNT_ID = 28
161
+ PENDING_TRANSFER_HAS_DIFFERENT_LEDGER = 29
162
+ PENDING_TRANSFER_HAS_DIFFERENT_CODE = 30
163
+ EXCEEDS_PENDING_TRANSFER_AMOUNT = 31
164
+ PENDING_TRANSFER_HAS_DIFFERENT_AMOUNT = 32
165
+ PENDING_TRANSFER_ALREADY_POSTED = 33
166
+ PENDING_TRANSFER_ALREADY_VOIDED = 34
167
+ PENDING_TRANSFER_EXPIRED = 35
168
+ IMPORTED_EVENT_TIMESTAMP_MUST_NOT_REGRESS = 60
169
+ IMPORTED_EVENT_TIMESTAMP_MUST_POSTDATE_DEBIT_ACCOUNT = 61
170
+ IMPORTED_EVENT_TIMESTAMP_MUST_POSTDATE_CREDIT_ACCOUNT = 62
171
+ IMPORTED_EVENT_TIMEOUT_MUST_BE_ZERO = 63
172
+ DEBIT_ACCOUNT_ALREADY_CLOSED = 65
173
+ CREDIT_ACCOUNT_ALREADY_CLOSED = 66
174
+ OVERFLOWS_DEBITS_PENDING = 47
175
+ OVERFLOWS_CREDITS_PENDING = 48
176
+ OVERFLOWS_DEBITS_POSTED = 49
177
+ OVERFLOWS_CREDITS_POSTED = 50
178
+ OVERFLOWS_DEBITS = 51
179
+ OVERFLOWS_CREDITS = 52
180
+ OVERFLOWS_TIMEOUT = 53
181
+ EXCEEDS_CREDITS = 54
182
+ EXCEEDS_DEBITS = 55
183
+
184
+
185
+ @dataclass
186
+ class Account:
187
+ id: int = 0
188
+ debits_pending: int = 0
189
+ debits_posted: int = 0
190
+ credits_pending: int = 0
191
+ credits_posted: int = 0
192
+ user_data_128: int = 0
193
+ user_data_64: int = 0
194
+ user_data_32: int = 0
195
+ ledger: int = 0
196
+ code: int = 0
197
+ flags: AccountFlags = AccountFlags.NONE
198
+ timestamp: int = 0
199
+
200
+
201
+ @dataclass
202
+ class Transfer:
203
+ id: int = 0
204
+ debit_account_id: int = 0
205
+ credit_account_id: int = 0
206
+ amount: int = 0
207
+ pending_id: int = 0
208
+ user_data_128: int = 0
209
+ user_data_64: int = 0
210
+ user_data_32: int = 0
211
+ timeout: int = 0
212
+ ledger: int = 0
213
+ code: int = 0
214
+ flags: TransferFlags = TransferFlags.NONE
215
+ timestamp: int = 0
216
+
217
+
218
+ @dataclass
219
+ class CreateAccountsResult:
220
+ index: int = 0
221
+ result: CreateAccountResult = 0
222
+
223
+
224
+ @dataclass
225
+ class CreateTransfersResult:
226
+ index: int = 0
227
+ result: CreateTransferResult = 0
228
+
229
+
230
+ @dataclass
231
+ class AccountFilter:
232
+ account_id: int = 0
233
+ user_data_128: int = 0
234
+ user_data_64: int = 0
235
+ user_data_32: int = 0
236
+ code: int = 0
237
+ timestamp_min: int = 0
238
+ timestamp_max: int = 0
239
+ limit: int = 0
240
+ flags: AccountFilterFlags = AccountFilterFlags.NONE
241
+
242
+
243
+ @dataclass
244
+ class AccountBalance:
245
+ debits_pending: int = 0
246
+ debits_posted: int = 0
247
+ credits_pending: int = 0
248
+ credits_posted: int = 0
249
+ timestamp: int = 0
250
+
251
+
252
+ @dataclass
253
+ class QueryFilter:
254
+ user_data_128: int = 0
255
+ user_data_64: int = 0
256
+ user_data_32: int = 0
257
+ ledger: int = 0
258
+ code: int = 0
259
+ timestamp_min: int = 0
260
+ timestamp_max: int = 0
261
+ limit: int = 0
262
+ flags: QueryFilterFlags = QueryFilterFlags.NONE
263
+
264
+
265
+ class CPacket(ctypes.Structure):
266
+ @classmethod
267
+ def from_param(cls, obj):
268
+ validate_uint(bits=8, name="operation", number=obj.operation)
269
+ validate_uint(bits=32, name="data_size", number=obj.data_size)
270
+ validate_uint(bits=32, name="batch_size", number=obj.batch_size)
271
+ return cls(
272
+ next=obj.next,
273
+ user_data=obj.user_data,
274
+ operation=obj.operation,
275
+ status=obj.status,
276
+ data_size=obj.data_size,
277
+ data=obj.data,
278
+ batch_next=obj.batch_next,
279
+ batch_tail=obj.batch_tail,
280
+ batch_size=obj.batch_size,
281
+ batch_allowed=obj.batch_allowed,
282
+ )
283
+
284
+ CPacket._fields_ = [ # noqa: SLF001
285
+ ("next", ctypes.POINTER(CPacket)),
286
+ ("user_data", ctypes.c_void_p),
287
+ ("operation", ctypes.c_uint8),
288
+ ("status", ctypes.c_uint8),
289
+ ("data_size", ctypes.c_uint32),
290
+ ("data", ctypes.c_void_p),
291
+ ("batch_next", ctypes.POINTER(CPacket)),
292
+ ("batch_tail", ctypes.POINTER(CPacket)),
293
+ ("batch_size", ctypes.c_uint32),
294
+ ("batch_allowed", ctypes.c_bool),
295
+ ("reserved", ctypes.c_uint8 * 7),
296
+ ]
297
+
298
+
299
+ class CAccount(ctypes.Structure):
300
+ @classmethod
301
+ def from_param(cls, obj):
302
+ validate_uint(bits=128, name="id", number=obj.id)
303
+ validate_uint(bits=128, name="debits_pending", number=obj.debits_pending)
304
+ validate_uint(bits=128, name="debits_posted", number=obj.debits_posted)
305
+ validate_uint(bits=128, name="credits_pending", number=obj.credits_pending)
306
+ validate_uint(bits=128, name="credits_posted", number=obj.credits_posted)
307
+ validate_uint(bits=128, name="user_data_128", number=obj.user_data_128)
308
+ validate_uint(bits=64, name="user_data_64", number=obj.user_data_64)
309
+ validate_uint(bits=32, name="user_data_32", number=obj.user_data_32)
310
+ validate_uint(bits=32, name="ledger", number=obj.ledger)
311
+ validate_uint(bits=16, name="code", number=obj.code)
312
+ validate_uint(bits=64, name="timestamp", number=obj.timestamp)
313
+ return cls(
314
+ id=c_uint128.from_param(obj.id),
315
+ debits_pending=c_uint128.from_param(obj.debits_pending),
316
+ debits_posted=c_uint128.from_param(obj.debits_posted),
317
+ credits_pending=c_uint128.from_param(obj.credits_pending),
318
+ credits_posted=c_uint128.from_param(obj.credits_posted),
319
+ user_data_128=c_uint128.from_param(obj.user_data_128),
320
+ user_data_64=obj.user_data_64,
321
+ user_data_32=obj.user_data_32,
322
+ ledger=obj.ledger,
323
+ code=obj.code,
324
+ flags=obj.flags,
325
+ timestamp=obj.timestamp,
326
+ )
327
+
328
+
329
+ def to_python(self):
330
+ return Account(
331
+ id=self.id.to_python(),
332
+ debits_pending=self.debits_pending.to_python(),
333
+ debits_posted=self.debits_posted.to_python(),
334
+ credits_pending=self.credits_pending.to_python(),
335
+ credits_posted=self.credits_posted.to_python(),
336
+ user_data_128=self.user_data_128.to_python(),
337
+ user_data_64=self.user_data_64,
338
+ user_data_32=self.user_data_32,
339
+ ledger=self.ledger,
340
+ code=self.code,
341
+ flags=AccountFlags(self.flags),
342
+ timestamp=self.timestamp,
343
+ )
344
+
345
+ CAccount._fields_ = [ # noqa: SLF001
346
+ ("id", c_uint128),
347
+ ("debits_pending", c_uint128),
348
+ ("debits_posted", c_uint128),
349
+ ("credits_pending", c_uint128),
350
+ ("credits_posted", c_uint128),
351
+ ("user_data_128", c_uint128),
352
+ ("user_data_64", ctypes.c_uint64),
353
+ ("user_data_32", ctypes.c_uint32),
354
+ ("reserved", ctypes.c_uint32),
355
+ ("ledger", ctypes.c_uint32),
356
+ ("code", ctypes.c_uint16),
357
+ ("flags", ctypes.c_uint16),
358
+ ("timestamp", ctypes.c_uint64),
359
+ ]
360
+
361
+
362
+ class CTransfer(ctypes.Structure):
363
+ @classmethod
364
+ def from_param(cls, obj):
365
+ validate_uint(bits=128, name="id", number=obj.id)
366
+ validate_uint(bits=128, name="debit_account_id", number=obj.debit_account_id)
367
+ validate_uint(bits=128, name="credit_account_id", number=obj.credit_account_id)
368
+ validate_uint(bits=128, name="amount", number=obj.amount)
369
+ validate_uint(bits=128, name="pending_id", number=obj.pending_id)
370
+ validate_uint(bits=128, name="user_data_128", number=obj.user_data_128)
371
+ validate_uint(bits=64, name="user_data_64", number=obj.user_data_64)
372
+ validate_uint(bits=32, name="user_data_32", number=obj.user_data_32)
373
+ validate_uint(bits=32, name="timeout", number=obj.timeout)
374
+ validate_uint(bits=32, name="ledger", number=obj.ledger)
375
+ validate_uint(bits=16, name="code", number=obj.code)
376
+ validate_uint(bits=64, name="timestamp", number=obj.timestamp)
377
+ return cls(
378
+ id=c_uint128.from_param(obj.id),
379
+ debit_account_id=c_uint128.from_param(obj.debit_account_id),
380
+ credit_account_id=c_uint128.from_param(obj.credit_account_id),
381
+ amount=c_uint128.from_param(obj.amount),
382
+ pending_id=c_uint128.from_param(obj.pending_id),
383
+ user_data_128=c_uint128.from_param(obj.user_data_128),
384
+ user_data_64=obj.user_data_64,
385
+ user_data_32=obj.user_data_32,
386
+ timeout=obj.timeout,
387
+ ledger=obj.ledger,
388
+ code=obj.code,
389
+ flags=obj.flags,
390
+ timestamp=obj.timestamp,
391
+ )
392
+
393
+
394
+ def to_python(self):
395
+ return Transfer(
396
+ id=self.id.to_python(),
397
+ debit_account_id=self.debit_account_id.to_python(),
398
+ credit_account_id=self.credit_account_id.to_python(),
399
+ amount=self.amount.to_python(),
400
+ pending_id=self.pending_id.to_python(),
401
+ user_data_128=self.user_data_128.to_python(),
402
+ user_data_64=self.user_data_64,
403
+ user_data_32=self.user_data_32,
404
+ timeout=self.timeout,
405
+ ledger=self.ledger,
406
+ code=self.code,
407
+ flags=TransferFlags(self.flags),
408
+ timestamp=self.timestamp,
409
+ )
410
+
411
+ CTransfer._fields_ = [ # noqa: SLF001
412
+ ("id", c_uint128),
413
+ ("debit_account_id", c_uint128),
414
+ ("credit_account_id", c_uint128),
415
+ ("amount", c_uint128),
416
+ ("pending_id", c_uint128),
417
+ ("user_data_128", c_uint128),
418
+ ("user_data_64", ctypes.c_uint64),
419
+ ("user_data_32", ctypes.c_uint32),
420
+ ("timeout", ctypes.c_uint32),
421
+ ("ledger", ctypes.c_uint32),
422
+ ("code", ctypes.c_uint16),
423
+ ("flags", ctypes.c_uint16),
424
+ ("timestamp", ctypes.c_uint64),
425
+ ]
426
+
427
+
428
+ class CCreateAccountsResult(ctypes.Structure):
429
+ @classmethod
430
+ def from_param(cls, obj):
431
+ validate_uint(bits=32, name="index", number=obj.index)
432
+ return cls(
433
+ index=obj.index,
434
+ result=obj.result,
435
+ )
436
+
437
+
438
+ def to_python(self):
439
+ return CreateAccountsResult(
440
+ index=self.index,
441
+ result=CreateAccountResult(self.result),
442
+ )
443
+
444
+ CCreateAccountsResult._fields_ = [ # noqa: SLF001
445
+ ("index", ctypes.c_uint32),
446
+ ("result", ctypes.c_uint32),
447
+ ]
448
+
449
+
450
+ class CCreateTransfersResult(ctypes.Structure):
451
+ @classmethod
452
+ def from_param(cls, obj):
453
+ validate_uint(bits=32, name="index", number=obj.index)
454
+ return cls(
455
+ index=obj.index,
456
+ result=obj.result,
457
+ )
458
+
459
+
460
+ def to_python(self):
461
+ return CreateTransfersResult(
462
+ index=self.index,
463
+ result=CreateTransferResult(self.result),
464
+ )
465
+
466
+ CCreateTransfersResult._fields_ = [ # noqa: SLF001
467
+ ("index", ctypes.c_uint32),
468
+ ("result", ctypes.c_uint32),
469
+ ]
470
+
471
+
472
+ class CAccountFilter(ctypes.Structure):
473
+ @classmethod
474
+ def from_param(cls, obj):
475
+ validate_uint(bits=128, name="account_id", number=obj.account_id)
476
+ validate_uint(bits=128, name="user_data_128", number=obj.user_data_128)
477
+ validate_uint(bits=64, name="user_data_64", number=obj.user_data_64)
478
+ validate_uint(bits=32, name="user_data_32", number=obj.user_data_32)
479
+ validate_uint(bits=16, name="code", number=obj.code)
480
+ validate_uint(bits=64, name="timestamp_min", number=obj.timestamp_min)
481
+ validate_uint(bits=64, name="timestamp_max", number=obj.timestamp_max)
482
+ validate_uint(bits=32, name="limit", number=obj.limit)
483
+ return cls(
484
+ account_id=c_uint128.from_param(obj.account_id),
485
+ user_data_128=c_uint128.from_param(obj.user_data_128),
486
+ user_data_64=obj.user_data_64,
487
+ user_data_32=obj.user_data_32,
488
+ code=obj.code,
489
+ timestamp_min=obj.timestamp_min,
490
+ timestamp_max=obj.timestamp_max,
491
+ limit=obj.limit,
492
+ flags=obj.flags,
493
+ )
494
+
495
+
496
+ def to_python(self):
497
+ return AccountFilter(
498
+ account_id=self.account_id.to_python(),
499
+ user_data_128=self.user_data_128.to_python(),
500
+ user_data_64=self.user_data_64,
501
+ user_data_32=self.user_data_32,
502
+ code=self.code,
503
+ timestamp_min=self.timestamp_min,
504
+ timestamp_max=self.timestamp_max,
505
+ limit=self.limit,
506
+ flags=AccountFilterFlags(self.flags),
507
+ )
508
+
509
+ CAccountFilter._fields_ = [ # noqa: SLF001
510
+ ("account_id", c_uint128),
511
+ ("user_data_128", c_uint128),
512
+ ("user_data_64", ctypes.c_uint64),
513
+ ("user_data_32", ctypes.c_uint32),
514
+ ("code", ctypes.c_uint16),
515
+ ("reserved", ctypes.c_uint8 * 58),
516
+ ("timestamp_min", ctypes.c_uint64),
517
+ ("timestamp_max", ctypes.c_uint64),
518
+ ("limit", ctypes.c_uint32),
519
+ ("flags", ctypes.c_uint32),
520
+ ]
521
+
522
+
523
+ class CAccountBalance(ctypes.Structure):
524
+ @classmethod
525
+ def from_param(cls, obj):
526
+ validate_uint(bits=128, name="debits_pending", number=obj.debits_pending)
527
+ validate_uint(bits=128, name="debits_posted", number=obj.debits_posted)
528
+ validate_uint(bits=128, name="credits_pending", number=obj.credits_pending)
529
+ validate_uint(bits=128, name="credits_posted", number=obj.credits_posted)
530
+ validate_uint(bits=64, name="timestamp", number=obj.timestamp)
531
+ return cls(
532
+ debits_pending=c_uint128.from_param(obj.debits_pending),
533
+ debits_posted=c_uint128.from_param(obj.debits_posted),
534
+ credits_pending=c_uint128.from_param(obj.credits_pending),
535
+ credits_posted=c_uint128.from_param(obj.credits_posted),
536
+ timestamp=obj.timestamp,
537
+ )
538
+
539
+
540
+ def to_python(self):
541
+ return AccountBalance(
542
+ debits_pending=self.debits_pending.to_python(),
543
+ debits_posted=self.debits_posted.to_python(),
544
+ credits_pending=self.credits_pending.to_python(),
545
+ credits_posted=self.credits_posted.to_python(),
546
+ timestamp=self.timestamp,
547
+ )
548
+
549
+ CAccountBalance._fields_ = [ # noqa: SLF001
550
+ ("debits_pending", c_uint128),
551
+ ("debits_posted", c_uint128),
552
+ ("credits_pending", c_uint128),
553
+ ("credits_posted", c_uint128),
554
+ ("timestamp", ctypes.c_uint64),
555
+ ("reserved", ctypes.c_uint8 * 56),
556
+ ]
557
+
558
+
559
+ class CQueryFilter(ctypes.Structure):
560
+ @classmethod
561
+ def from_param(cls, obj):
562
+ validate_uint(bits=128, name="user_data_128", number=obj.user_data_128)
563
+ validate_uint(bits=64, name="user_data_64", number=obj.user_data_64)
564
+ validate_uint(bits=32, name="user_data_32", number=obj.user_data_32)
565
+ validate_uint(bits=32, name="ledger", number=obj.ledger)
566
+ validate_uint(bits=16, name="code", number=obj.code)
567
+ validate_uint(bits=64, name="timestamp_min", number=obj.timestamp_min)
568
+ validate_uint(bits=64, name="timestamp_max", number=obj.timestamp_max)
569
+ validate_uint(bits=32, name="limit", number=obj.limit)
570
+ return cls(
571
+ user_data_128=c_uint128.from_param(obj.user_data_128),
572
+ user_data_64=obj.user_data_64,
573
+ user_data_32=obj.user_data_32,
574
+ ledger=obj.ledger,
575
+ code=obj.code,
576
+ timestamp_min=obj.timestamp_min,
577
+ timestamp_max=obj.timestamp_max,
578
+ limit=obj.limit,
579
+ flags=obj.flags,
580
+ )
581
+
582
+
583
+ def to_python(self):
584
+ return QueryFilter(
585
+ user_data_128=self.user_data_128.to_python(),
586
+ user_data_64=self.user_data_64,
587
+ user_data_32=self.user_data_32,
588
+ ledger=self.ledger,
589
+ code=self.code,
590
+ timestamp_min=self.timestamp_min,
591
+ timestamp_max=self.timestamp_max,
592
+ limit=self.limit,
593
+ flags=QueryFilterFlags(self.flags),
594
+ )
595
+
596
+ CQueryFilter._fields_ = [ # noqa: SLF001
597
+ ("user_data_128", c_uint128),
598
+ ("user_data_64", ctypes.c_uint64),
599
+ ("user_data_32", ctypes.c_uint32),
600
+ ("ledger", ctypes.c_uint32),
601
+ ("code", ctypes.c_uint16),
602
+ ("reserved", ctypes.c_uint8 * 6),
603
+ ("timestamp_min", ctypes.c_uint64),
604
+ ("timestamp_max", ctypes.c_uint64),
605
+ ("limit", ctypes.c_uint32),
606
+ ("flags", ctypes.c_uint32),
607
+ ]
608
+
609
+
610
+ # Don't be tempted to use c_char_p for bytes_ptr - it's for null terminated strings only.
611
+ OnCompletion = ctypes.CFUNCTYPE(None, ctypes.c_void_p, Client, ctypes.POINTER(CPacket),
612
+ ctypes.c_uint64, ctypes.c_void_p, ctypes.c_uint32)
613
+
614
+ # Initialize a new TigerBeetle client which connects to the addresses provided and
615
+ # completes submitted packets by invoking the callback with the given context.
616
+ tb_client_init = tbclient.tb_client_init
617
+ tb_client_init.restype = Status
618
+ tb_client_init.argtypes = [ctypes.POINTER(Client), c_uint128, ctypes.c_char_p,
619
+ ctypes.c_uint32, ctypes.c_void_p, OnCompletion]
620
+
621
+ # Initialize a new TigerBeetle client which echos back any data submitted.
622
+ tb_client_init_echo = tbclient.tb_client_init_echo
623
+ tb_client_init_echo.restype = Status
624
+ tb_client_init.argtypes = [ctypes.POINTER(Client), c_uint128, ctypes.c_char_p,
625
+ ctypes.c_uint32, ctypes.c_void_p, OnCompletion]
626
+
627
+ # Closes the client, causing any previously submitted packets to be completed with
628
+ # `TB_PACKET_CLIENT_SHUTDOWN` before freeing any allocated client resources from init.
629
+ # It is undefined behavior to use any functions on the client once deinit is called.
630
+ tb_client_deinit = tbclient.tb_client_deinit
631
+ tb_client_deinit.restype = None
632
+ tb_client_deinit.argtypes = [Client]
633
+
634
+ # Submit a packet with its operation, data, and data_size fields set.
635
+ # Once completed, `on_completion` will be invoked with `on_completion_ctx` and the given
636
+ # packet on the `tb_client` thread (separate from caller's thread).
637
+ tb_client_submit = tbclient.tb_client_submit
638
+ tb_client_submit.restype = None
639
+ tb_client_submit.argtypes = [Client, ctypes.POINTER(CPacket)]
640
+ class AsyncStateMachineMixin:
641
+ _submit: Callable[[Operation, Any, Any, Any], Any]
642
+ async def create_accounts(self, accounts: list[Account]) -> list[CreateAccountsResult]:
643
+ return await self._submit(
644
+ Operation.CREATE_ACCOUNTS,
645
+ accounts,
646
+ CAccount,
647
+ CCreateAccountsResult,
648
+ )
649
+
650
+ async def create_transfers(self, transfers: list[Transfer]) -> list[CreateTransfersResult]:
651
+ return await self._submit(
652
+ Operation.CREATE_TRANSFERS,
653
+ transfers,
654
+ CTransfer,
655
+ CCreateTransfersResult,
656
+ )
657
+
658
+ async def lookup_accounts(self, accounts: list[int]) -> list[Account]:
659
+ return await self._submit(
660
+ Operation.LOOKUP_ACCOUNTS,
661
+ accounts,
662
+ c_uint128,
663
+ CAccount,
664
+ )
665
+
666
+ async def lookup_transfers(self, transfers: list[int]) -> list[Transfer]:
667
+ return await self._submit(
668
+ Operation.LOOKUP_TRANSFERS,
669
+ transfers,
670
+ c_uint128,
671
+ CTransfer,
672
+ )
673
+
674
+ async def get_account_transfers(self, filter: AccountFilter) -> list[Transfer]:
675
+ return await self._submit(
676
+ Operation.GET_ACCOUNT_TRANSFERS,
677
+ [filter],
678
+ CAccountFilter,
679
+ CTransfer,
680
+ )
681
+
682
+ async def get_account_balances(self, filter: AccountFilter) -> list[AccountBalance]:
683
+ return await self._submit(
684
+ Operation.GET_ACCOUNT_BALANCES,
685
+ [filter],
686
+ CAccountFilter,
687
+ CAccountBalance,
688
+ )
689
+
690
+ async def query_accounts(self, query_filter: QueryFilter) -> list[Account]:
691
+ return await self._submit(
692
+ Operation.QUERY_ACCOUNTS,
693
+ [query_filter],
694
+ CQueryFilter,
695
+ CAccount,
696
+ )
697
+
698
+ async def query_transfers(self, query_filter: QueryFilter) -> list[Transfer]:
699
+ return await self._submit(
700
+ Operation.QUERY_TRANSFERS,
701
+ [query_filter],
702
+ CQueryFilter,
703
+ CTransfer,
704
+ )
705
+
706
+
707
+
708
+ class StateMachineMixin:
709
+ _submit: Callable[[Operation, Any, Any, Any], Any]
710
+ def create_accounts(self, accounts: list[Account]) -> list[CreateAccountsResult]:
711
+ return self._submit(
712
+ Operation.CREATE_ACCOUNTS,
713
+ accounts,
714
+ CAccount,
715
+ CCreateAccountsResult,
716
+ )
717
+
718
+ def create_transfers(self, transfers: list[Transfer]) -> list[CreateTransfersResult]:
719
+ return self._submit(
720
+ Operation.CREATE_TRANSFERS,
721
+ transfers,
722
+ CTransfer,
723
+ CCreateTransfersResult,
724
+ )
725
+
726
+ def lookup_accounts(self, accounts: list[int]) -> list[Account]:
727
+ return self._submit(
728
+ Operation.LOOKUP_ACCOUNTS,
729
+ accounts,
730
+ c_uint128,
731
+ CAccount,
732
+ )
733
+
734
+ def lookup_transfers(self, transfers: list[int]) -> list[Transfer]:
735
+ return self._submit(
736
+ Operation.LOOKUP_TRANSFERS,
737
+ transfers,
738
+ c_uint128,
739
+ CTransfer,
740
+ )
741
+
742
+ def get_account_transfers(self, filter: AccountFilter) -> list[Transfer]:
743
+ return self._submit(
744
+ Operation.GET_ACCOUNT_TRANSFERS,
745
+ [filter],
746
+ CAccountFilter,
747
+ CTransfer,
748
+ )
749
+
750
+ def get_account_balances(self, filter: AccountFilter) -> list[AccountBalance]:
751
+ return self._submit(
752
+ Operation.GET_ACCOUNT_BALANCES,
753
+ [filter],
754
+ CAccountFilter,
755
+ CAccountBalance,
756
+ )
757
+
758
+ def query_accounts(self, query_filter: QueryFilter) -> list[Account]:
759
+ return self._submit(
760
+ Operation.QUERY_ACCOUNTS,
761
+ [query_filter],
762
+ CQueryFilter,
763
+ CAccount,
764
+ )
765
+
766
+ def query_transfers(self, query_filter: QueryFilter) -> list[Transfer]:
767
+ return self._submit(
768
+ Operation.QUERY_TRANSFERS,
769
+ [query_filter],
770
+ CQueryFilter,
771
+ CTransfer,
772
+ )
773
+
774
+
775
+