hive-nectar 0.2.9__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.
Files changed (87) hide show
  1. hive_nectar-0.2.9.dist-info/METADATA +194 -0
  2. hive_nectar-0.2.9.dist-info/RECORD +87 -0
  3. hive_nectar-0.2.9.dist-info/WHEEL +4 -0
  4. hive_nectar-0.2.9.dist-info/entry_points.txt +2 -0
  5. hive_nectar-0.2.9.dist-info/licenses/LICENSE.txt +23 -0
  6. nectar/__init__.py +37 -0
  7. nectar/account.py +5076 -0
  8. nectar/amount.py +553 -0
  9. nectar/asciichart.py +303 -0
  10. nectar/asset.py +122 -0
  11. nectar/block.py +574 -0
  12. nectar/blockchain.py +1242 -0
  13. nectar/blockchaininstance.py +2590 -0
  14. nectar/blockchainobject.py +263 -0
  15. nectar/cli.py +5937 -0
  16. nectar/comment.py +1552 -0
  17. nectar/community.py +854 -0
  18. nectar/constants.py +95 -0
  19. nectar/discussions.py +1437 -0
  20. nectar/exceptions.py +152 -0
  21. nectar/haf.py +381 -0
  22. nectar/hive.py +630 -0
  23. nectar/imageuploader.py +114 -0
  24. nectar/instance.py +113 -0
  25. nectar/market.py +876 -0
  26. nectar/memo.py +542 -0
  27. nectar/message.py +379 -0
  28. nectar/nodelist.py +309 -0
  29. nectar/price.py +603 -0
  30. nectar/profile.py +74 -0
  31. nectar/py.typed +0 -0
  32. nectar/rc.py +333 -0
  33. nectar/snapshot.py +1024 -0
  34. nectar/storage.py +62 -0
  35. nectar/transactionbuilder.py +659 -0
  36. nectar/utils.py +630 -0
  37. nectar/version.py +3 -0
  38. nectar/vote.py +722 -0
  39. nectar/wallet.py +472 -0
  40. nectar/witness.py +728 -0
  41. nectarapi/__init__.py +12 -0
  42. nectarapi/exceptions.py +126 -0
  43. nectarapi/graphenerpc.py +596 -0
  44. nectarapi/node.py +194 -0
  45. nectarapi/noderpc.py +79 -0
  46. nectarapi/openapi.py +107 -0
  47. nectarapi/py.typed +0 -0
  48. nectarapi/rpcutils.py +98 -0
  49. nectarapi/version.py +3 -0
  50. nectarbase/__init__.py +15 -0
  51. nectarbase/ledgertransactions.py +106 -0
  52. nectarbase/memo.py +242 -0
  53. nectarbase/objects.py +521 -0
  54. nectarbase/objecttypes.py +21 -0
  55. nectarbase/operationids.py +102 -0
  56. nectarbase/operations.py +1357 -0
  57. nectarbase/py.typed +0 -0
  58. nectarbase/signedtransactions.py +89 -0
  59. nectarbase/transactions.py +11 -0
  60. nectarbase/version.py +3 -0
  61. nectargraphenebase/__init__.py +27 -0
  62. nectargraphenebase/account.py +1121 -0
  63. nectargraphenebase/aes.py +49 -0
  64. nectargraphenebase/base58.py +197 -0
  65. nectargraphenebase/bip32.py +575 -0
  66. nectargraphenebase/bip38.py +110 -0
  67. nectargraphenebase/chains.py +15 -0
  68. nectargraphenebase/dictionary.py +2 -0
  69. nectargraphenebase/ecdsasig.py +309 -0
  70. nectargraphenebase/objects.py +130 -0
  71. nectargraphenebase/objecttypes.py +8 -0
  72. nectargraphenebase/operationids.py +5 -0
  73. nectargraphenebase/operations.py +25 -0
  74. nectargraphenebase/prefix.py +13 -0
  75. nectargraphenebase/py.typed +0 -0
  76. nectargraphenebase/signedtransactions.py +221 -0
  77. nectargraphenebase/types.py +557 -0
  78. nectargraphenebase/unsignedtransactions.py +288 -0
  79. nectargraphenebase/version.py +3 -0
  80. nectarstorage/__init__.py +57 -0
  81. nectarstorage/base.py +317 -0
  82. nectarstorage/exceptions.py +15 -0
  83. nectarstorage/interfaces.py +244 -0
  84. nectarstorage/masterpassword.py +237 -0
  85. nectarstorage/py.typed +0 -0
  86. nectarstorage/ram.py +27 -0
  87. nectarstorage/sqlite.py +343 -0
@@ -0,0 +1,557 @@
1
+ import json
2
+ import struct
3
+ import time
4
+ from binascii import hexlify, unhexlify
5
+ from collections.abc import Sequence
6
+
7
+ # Move calendar import to avoid circular import issue in Python 3.13
8
+ from datetime import datetime
9
+ from typing import Any, List, Optional, Tuple, Union
10
+
11
+ # Import calendar only when needed to avoid circular imports
12
+ timeformat = "%Y-%m-%dT%H:%M:%S%Z"
13
+
14
+
15
+ def varint(n: int) -> bytes:
16
+ """Varint encoding."""
17
+ data = b""
18
+ while n >= 0x80:
19
+ data += bytes([(n & 0x7F) | 0x80])
20
+ n >>= 7
21
+ data += bytes([n])
22
+ return data
23
+
24
+
25
+ def varintdecode(data: Optional[Union[bytes, str]]) -> int:
26
+ """Varint decoding."""
27
+ if data is None:
28
+ raise ValueError("Cannot decode varint from None")
29
+ if isinstance(data, str):
30
+ data = data.encode("utf-8")
31
+ shift = 0
32
+ result = 0
33
+ for b in bytes(data):
34
+ result |= (b & 0x7F) << shift
35
+ if not (b & 0x80):
36
+ break
37
+ shift += 7
38
+ return result
39
+
40
+
41
+ def variable_buffer(s: bytes) -> bytes:
42
+ """Encodes variable length buffer."""
43
+ return varint(len(s)) + s
44
+
45
+
46
+ def JsonObj(data: Any) -> Any:
47
+ """Returns json object from data."""
48
+ return json.loads(str(data))
49
+
50
+
51
+ class Uint8:
52
+ """Uint8."""
53
+
54
+ def __init__(self, d: Any) -> None:
55
+ """init."""
56
+ self.data = int(d)
57
+
58
+ def __bytes__(self) -> bytes:
59
+ """Returns bytes."""
60
+ return struct.pack("<B", self.data)
61
+
62
+ def __str__(self) -> str:
63
+ """Returns str"""
64
+ return "%d" % self.data
65
+
66
+
67
+ class Int16:
68
+ """Int16."""
69
+
70
+ def __init__(self, d: Any) -> None:
71
+ """init."""
72
+ self.data = int(d)
73
+
74
+ def __bytes__(self) -> bytes:
75
+ """Returns bytes."""
76
+ return struct.pack("<h", self.data)
77
+
78
+ def __str__(self) -> str:
79
+ """Returns str"""
80
+ return "%d" % self.data
81
+
82
+
83
+ class Uint16:
84
+ """Uint16."""
85
+
86
+ def __init__(self, d: Any) -> None:
87
+ self.data = int(d)
88
+
89
+ def __bytes__(self) -> bytes:
90
+ """Returns bytes."""
91
+ return struct.pack("<H", self.data)
92
+
93
+ def __str__(self) -> str:
94
+ return "%d" % self.data
95
+
96
+
97
+ class Uint32:
98
+ """Uint32."""
99
+
100
+ def __init__(self, d: Any) -> None:
101
+ """
102
+ Initialize Uint32 object.
103
+
104
+ Args:
105
+ d (Any): The data to be stored in the Uint32 object.
106
+ """
107
+ self.data = int(d)
108
+
109
+ def __bytes__(self) -> bytes:
110
+ """
111
+ Returns the bytes representation of the Uint32 object.
112
+
113
+ Returns:
114
+ bytes: The bytes representation of the Uint32 object.
115
+ """
116
+ return struct.pack("<I", self.data)
117
+
118
+ def __str__(self) -> str:
119
+ """
120
+ Returns the string representation of the Uint32 object.
121
+
122
+ Returns:
123
+ str: The string representation of the Uint32 object.
124
+ """
125
+ return "%d" % self.data
126
+
127
+
128
+ class Uint64:
129
+ """Uint64."""
130
+
131
+ def __init__(self, d: Any) -> None:
132
+ """
133
+ Initialize Uint64 object.
134
+
135
+ Args:
136
+ d (Any): The data to be stored in the Uint64 object.
137
+ """
138
+ self.data = int(d)
139
+
140
+ def __bytes__(self) -> bytes:
141
+ """
142
+ Returns the bytes representation of the Uint64 object.
143
+
144
+ Returns:
145
+ bytes: The bytes representation of the Uint64 object.
146
+ """
147
+ return struct.pack("<Q", self.data)
148
+
149
+ def __str__(self) -> str:
150
+ """
151
+ Returns the string representation of the Uint64 object.
152
+
153
+ Returns:
154
+ str: The string representation of the Uint64 object.
155
+ """
156
+ return "%d" % self.data
157
+
158
+
159
+ class Varint32:
160
+ """Varint32."""
161
+
162
+ def __init__(self, d: Any) -> None:
163
+ """
164
+ Initialize Varint32 object.
165
+
166
+ Args:
167
+ d (Any): The data to be stored in the Varint32 object.
168
+ """
169
+ self.data = int(d)
170
+
171
+ def __bytes__(self) -> bytes:
172
+ """
173
+ Returns the bytes representation of the Varint32 object.
174
+
175
+ Returns:
176
+ bytes: The bytes representation of the Varint32 object.
177
+ """
178
+ return varint(self.data)
179
+
180
+ def __str__(self) -> str:
181
+ """
182
+ Returns the string representation of the Varint32 object.
183
+
184
+ Returns:
185
+ str: The string representation of the Varint32 object.
186
+ """
187
+ return "%d" % self.data
188
+
189
+
190
+ class Int64:
191
+ """Int64."""
192
+
193
+ def __init__(self, d: Any) -> None:
194
+ """
195
+ Initialize Int64 object.
196
+
197
+ Args:
198
+ d (Any): The data to be stored in the Int64 object.
199
+ """
200
+ self.data = int(d)
201
+
202
+ def __bytes__(self) -> bytes:
203
+ """
204
+ Returns the bytes representation of the Int64 object.
205
+
206
+ Returns:
207
+ bytes: The bytes representation of the Int64 object.
208
+ """
209
+ return struct.pack("<q", self.data)
210
+
211
+ def __str__(self) -> str:
212
+ """
213
+ Returns the string representation of the Int64 object.
214
+
215
+ Returns:
216
+ str: The string representation of the Int64 object.
217
+ """
218
+ return "%d" % self.data
219
+
220
+
221
+ class HexString:
222
+ """HexString."""
223
+
224
+ def __init__(self, d: Any) -> None:
225
+ """
226
+ Initialize HexString object.
227
+
228
+ Args:
229
+ d (Any): The data to be stored in the HexString object.
230
+ """
231
+ self.data = d
232
+
233
+ def __bytes__(self) -> bytes:
234
+ """
235
+ Returns the bytes representation of the HexString object.
236
+
237
+ Returns:
238
+ bytes: The bytes representation of the HexString object.
239
+ """
240
+ d = bytes(unhexlify(bytes(self.data, "ascii")))
241
+ return variable_buffer(d)
242
+
243
+ def __str__(self) -> str:
244
+ """
245
+ Returns the string representation of the HexString object.
246
+
247
+ Returns:
248
+ str: The string representation of the HexString object.
249
+ """
250
+ return str(self.data)
251
+
252
+
253
+ class String:
254
+ """String."""
255
+
256
+ def __init__(self, d: Any) -> None:
257
+ self.data = d
258
+
259
+ def __bytes__(self) -> bytes:
260
+ """Returns bytes representation."""
261
+ d = self.unicodify()
262
+ return varint(len(d)) + d
263
+
264
+ def __str__(self) -> str:
265
+ """Returns data as string."""
266
+ return "%s" % str(self.data)
267
+
268
+ def unicodify(self) -> bytes:
269
+ r = []
270
+ for s in self.data:
271
+ o = ord(s)
272
+ if (o <= 7) or (o == 11) or (o > 13 and o < 32):
273
+ r.append("u%04x" % o)
274
+ elif o == 8:
275
+ r.append("b")
276
+ elif o == 9:
277
+ r.append("\t")
278
+ elif o == 10:
279
+ r.append("\n")
280
+ elif o == 12:
281
+ r.append("f")
282
+ elif o == 13:
283
+ r.append("\r")
284
+ else:
285
+ r.append(s)
286
+ return bytes("".join(r), "utf-8")
287
+
288
+
289
+ class Bytes:
290
+ """Bytes."""
291
+
292
+ def __init__(self, d: Any) -> None:
293
+ self.data = d
294
+
295
+ def __bytes__(self) -> bytes:
296
+ """Returns data as bytes."""
297
+ d = unhexlify(bytes(self.data, "utf-8"))
298
+ return varint(len(d)) + d
299
+
300
+ def __str__(self) -> str:
301
+ """Returns data as string."""
302
+ return str(self.data)
303
+
304
+
305
+ class Hash(Bytes):
306
+ """Hash."""
307
+
308
+ def json(self) -> str:
309
+ return str(self.data)
310
+
311
+ def __bytes__(self) -> bytes:
312
+ return unhexlify(bytes(self.data, "utf-8"))
313
+
314
+
315
+ class Ripemd160(Hash):
316
+ """Ripemd160."""
317
+
318
+ def __init__(self, a: str) -> None:
319
+ assert len(a) == 40, "Require 40 char long hex"
320
+ super().__init__(a)
321
+
322
+
323
+ class Sha1(Hash):
324
+ """Sha1."""
325
+
326
+ def __init__(self, a: str) -> None:
327
+ assert len(a) == 40, "Require 40 char long hex"
328
+ super().__init__(a)
329
+
330
+
331
+ class Sha256(Hash):
332
+ """Sha256."""
333
+
334
+ def __init__(self, a: str) -> None:
335
+ assert len(a) == 64, "Require 64 char long hex"
336
+ super().__init__(a)
337
+
338
+
339
+ class Void:
340
+ """Void."""
341
+
342
+ def __init__(self) -> None:
343
+ pass
344
+
345
+ def __bytes__(self) -> bytes:
346
+ """Returns bytes representation."""
347
+ return b""
348
+
349
+ def __str__(self) -> str:
350
+ """Returns data as string."""
351
+ return ""
352
+
353
+
354
+ class Array:
355
+ """Array."""
356
+
357
+ def __init__(self, d: List[Any]) -> None:
358
+ self.data = d
359
+ self.length = Varint32(len(self.data))
360
+
361
+ def __bytes__(self) -> bytes:
362
+ """Returns bytes representation."""
363
+ return bytes(self.length) + b"".join([bytes(a) for a in self.data])
364
+
365
+ def __str__(self) -> str:
366
+ """Returns data as string."""
367
+ r = []
368
+ for a in self.data:
369
+ try:
370
+ if isinstance(a, String):
371
+ r.append(str(a))
372
+ else:
373
+ r.append(JsonObj(a))
374
+ except Exception:
375
+ r.append(str(a))
376
+ return json.dumps(r)
377
+
378
+
379
+ class PointInTime:
380
+ """PointInTime."""
381
+
382
+ def __init__(self, d: Union[str, datetime]) -> None:
383
+ self.data = d
384
+
385
+ def __bytes__(self) -> bytes:
386
+ """
387
+ Return a 4-byte little-endian Unix timestamp for the stored point-in-time.
388
+
389
+ If the instance holds a datetime, it is converted to a POSIX timestamp using UTC. If it holds a string, the string is parsed (with the module-level `timeformat` and "UTC" appended) and converted to a POSIX timestamp. The timestamp is encoded as a signed 32-bit little-endian integer when negative, otherwise as an unsigned 32-bit little-endian integer.
390
+ """
391
+ # Import lazily to avoid import-time cycles
392
+ from calendar import timegm
393
+
394
+ if isinstance(self.data, datetime):
395
+ # Use UTC, not local time
396
+ unixtime = timegm(self.data.utctimetuple())
397
+ else:
398
+ s = self.data
399
+ # Accept ISO8601 'Z' suffix
400
+ if isinstance(s, str) and s.endswith("Z"):
401
+ s = s[:-1]
402
+ unixtime = timegm(time.strptime((s + "UTC"), timeformat))
403
+ if unixtime < 0:
404
+ return struct.pack("<i", unixtime)
405
+ return struct.pack("<I", unixtime)
406
+
407
+ def __str__(self) -> str:
408
+ """Returns data as string."""
409
+ return str(self.data)
410
+
411
+
412
+ class Signature:
413
+ """Signature."""
414
+
415
+ def __init__(self, d: bytes) -> None:
416
+ self.data = d
417
+
418
+ def __bytes__(self) -> bytes:
419
+ """Returns bytes representation."""
420
+ return self.data
421
+
422
+ def __str__(self) -> str:
423
+ """Returns data as string."""
424
+ return json.dumps(hexlify(self.data).decode("ascii"))
425
+
426
+
427
+ class Bool(Uint8): # Bool = Uint8
428
+ """Bool."""
429
+
430
+ def __init__(self, d: Any) -> None:
431
+ super().__init__(d)
432
+
433
+ def __str__(self) -> str:
434
+ """Returns data as string."""
435
+ return json.dumps(True) if self.data else json.dumps(False)
436
+
437
+
438
+ class Set(Array): # Set = Array
439
+ """Set."""
440
+
441
+ def __init__(self, d: List[Any]) -> None:
442
+ super().__init__(d)
443
+
444
+
445
+ class Fixed_array:
446
+ """Fixed_array."""
447
+
448
+ def __init__(self, d: Any) -> None:
449
+ raise NotImplementedError
450
+
451
+ def __bytes__(self) -> bytes:
452
+ """Returns bytes representation."""
453
+ raise NotImplementedError
454
+
455
+ def __str__(self) -> str:
456
+ """Returns data as string."""
457
+ raise NotImplementedError
458
+
459
+
460
+ class Optional:
461
+ """Optional."""
462
+
463
+ def __init__(self, d: Any) -> None:
464
+ self.data = d
465
+
466
+ def __bytes__(self) -> bytes:
467
+ """Returns data as bytes."""
468
+ if not self.data:
469
+ return bytes(Bool(0))
470
+ else:
471
+ return bytes(Bool(1)) + bytes(self.data)
472
+
473
+ def __str__(self) -> str:
474
+ """Returns data as string."""
475
+ return str(self.data)
476
+
477
+ def isempty(self) -> bool:
478
+ """Returns True if data is empty, False otherwise."""
479
+ return not self.data
480
+
481
+
482
+ class Static_variant:
483
+ """Static_variant."""
484
+
485
+ def __init__(self, d: Any, type_id: int, legacy_style: bool = True) -> None:
486
+ self.data = d
487
+ self.type_id = type_id
488
+
489
+ # `legacy_style = True` it means, that static variant is treated like an array, otherwise like an object
490
+ self.legacy_style = legacy_style
491
+
492
+ def __bytes__(self) -> bytes:
493
+ """Returns bytes representation."""
494
+ return varint(self.type_id) + bytes(self.data)
495
+
496
+ def __str__(self) -> str:
497
+ """Returns data as string."""
498
+ if self.legacy_style:
499
+ return json.dumps([self.type_id, self.data.json()])
500
+ else:
501
+ return json.dumps({"type": self.type_id, "value": self.data.json()})
502
+
503
+
504
+ class Map:
505
+ """Map."""
506
+
507
+ def __init__(self, data: Sequence[Sequence[Any]]) -> None:
508
+ self.data: List[Tuple[Any, Any]] = [tuple(entry) for entry in data] # type: ignore[arg-type]
509
+
510
+ def __bytes__(self) -> bytes:
511
+ """Returns bytes representation."""
512
+ b = b""
513
+ b += varint(len(self.data))
514
+ for e in self.data:
515
+ b += bytes(e[0]) + bytes(e[1])
516
+ return b
517
+
518
+ def __str__(self) -> str:
519
+ """Returns data as string."""
520
+ r = []
521
+ for e in self.data:
522
+ r.append([str(e[0]), str(e[1])])
523
+ return json.dumps(r)
524
+
525
+
526
+ class Id:
527
+ """Id."""
528
+
529
+ def __init__(self, d: int) -> None:
530
+ self.data = Varint32(d)
531
+
532
+ def __bytes__(self) -> bytes:
533
+ """Returns bytes representation."""
534
+ return bytes(self.data)
535
+
536
+ def __str__(self) -> str:
537
+ """Returns data as string."""
538
+ return str(self.data)
539
+
540
+
541
+ class Enum8(Uint8):
542
+ """Enum8."""
543
+
544
+ # List needs to be provided by super class
545
+ options = []
546
+
547
+ def __init__(self, selection: Union[str, int]) -> None:
548
+ if selection not in self.options or (
549
+ isinstance(selection, int) and len(self.options) < selection
550
+ ):
551
+ raise ValueError("Options are {}. Given '{}'".format(str(self.options), selection))
552
+
553
+ super().__init__(self.options.index(selection))
554
+
555
+ def __str__(self) -> str:
556
+ """Returns data as string."""
557
+ return str(self.options[self.data])