hive-nectar 0.0.2__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.

Potentially problematic release.


This version of hive-nectar might be problematic. Click here for more details.

Files changed (86) hide show
  1. hive_nectar-0.0.2.dist-info/METADATA +182 -0
  2. hive_nectar-0.0.2.dist-info/RECORD +86 -0
  3. hive_nectar-0.0.2.dist-info/WHEEL +4 -0
  4. hive_nectar-0.0.2.dist-info/entry_points.txt +2 -0
  5. hive_nectar-0.0.2.dist-info/licenses/LICENSE.txt +23 -0
  6. nectar/__init__.py +32 -0
  7. nectar/account.py +4371 -0
  8. nectar/amount.py +475 -0
  9. nectar/asciichart.py +270 -0
  10. nectar/asset.py +82 -0
  11. nectar/block.py +446 -0
  12. nectar/blockchain.py +1178 -0
  13. nectar/blockchaininstance.py +2284 -0
  14. nectar/blockchainobject.py +221 -0
  15. nectar/blurt.py +563 -0
  16. nectar/cli.py +6285 -0
  17. nectar/comment.py +1217 -0
  18. nectar/community.py +513 -0
  19. nectar/constants.py +111 -0
  20. nectar/conveyor.py +309 -0
  21. nectar/discussions.py +1709 -0
  22. nectar/exceptions.py +149 -0
  23. nectar/hive.py +546 -0
  24. nectar/hivesigner.py +420 -0
  25. nectar/imageuploader.py +72 -0
  26. nectar/instance.py +129 -0
  27. nectar/market.py +1013 -0
  28. nectar/memo.py +449 -0
  29. nectar/message.py +357 -0
  30. nectar/nodelist.py +444 -0
  31. nectar/price.py +557 -0
  32. nectar/profile.py +65 -0
  33. nectar/rc.py +308 -0
  34. nectar/snapshot.py +726 -0
  35. nectar/steem.py +582 -0
  36. nectar/storage.py +53 -0
  37. nectar/transactionbuilder.py +622 -0
  38. nectar/utils.py +545 -0
  39. nectar/version.py +2 -0
  40. nectar/vote.py +557 -0
  41. nectar/wallet.py +472 -0
  42. nectar/witness.py +617 -0
  43. nectarapi/__init__.py +11 -0
  44. nectarapi/exceptions.py +123 -0
  45. nectarapi/graphenerpc.py +589 -0
  46. nectarapi/node.py +178 -0
  47. nectarapi/noderpc.py +229 -0
  48. nectarapi/rpcutils.py +97 -0
  49. nectarapi/version.py +2 -0
  50. nectarbase/__init__.py +14 -0
  51. nectarbase/ledgertransactions.py +75 -0
  52. nectarbase/memo.py +243 -0
  53. nectarbase/objects.py +429 -0
  54. nectarbase/objecttypes.py +22 -0
  55. nectarbase/operationids.py +102 -0
  56. nectarbase/operations.py +1297 -0
  57. nectarbase/signedtransactions.py +48 -0
  58. nectarbase/transactions.py +11 -0
  59. nectarbase/version.py +2 -0
  60. nectargrapheneapi/__init__.py +6 -0
  61. nectargraphenebase/__init__.py +27 -0
  62. nectargraphenebase/account.py +846 -0
  63. nectargraphenebase/aes.py +52 -0
  64. nectargraphenebase/base58.py +192 -0
  65. nectargraphenebase/bip32.py +494 -0
  66. nectargraphenebase/bip38.py +134 -0
  67. nectargraphenebase/chains.py +149 -0
  68. nectargraphenebase/dictionary.py +3 -0
  69. nectargraphenebase/ecdsasig.py +326 -0
  70. nectargraphenebase/objects.py +123 -0
  71. nectargraphenebase/objecttypes.py +6 -0
  72. nectargraphenebase/operationids.py +3 -0
  73. nectargraphenebase/operations.py +23 -0
  74. nectargraphenebase/prefix.py +11 -0
  75. nectargraphenebase/py23.py +38 -0
  76. nectargraphenebase/signedtransactions.py +201 -0
  77. nectargraphenebase/types.py +419 -0
  78. nectargraphenebase/unsignedtransactions.py +283 -0
  79. nectargraphenebase/version.py +2 -0
  80. nectarstorage/__init__.py +38 -0
  81. nectarstorage/base.py +306 -0
  82. nectarstorage/exceptions.py +16 -0
  83. nectarstorage/interfaces.py +237 -0
  84. nectarstorage/masterpassword.py +239 -0
  85. nectarstorage/ram.py +30 -0
  86. nectarstorage/sqlite.py +334 -0
nectar/amount.py ADDED
@@ -0,0 +1,475 @@
1
+ # -*- coding: utf-8 -*-
2
+ from decimal import ROUND_DOWN, Decimal
3
+
4
+ from nectar.asset import Asset
5
+ from nectar.instance import shared_blockchain_instance
6
+ from nectargraphenebase.py23 import integer_types, string_types
7
+
8
+
9
+ def check_asset(other, self, stm):
10
+ if isinstance(other, dict) and "asset" in other and isinstance(self, dict) and "asset" in self:
11
+ if not Asset(other["asset"], blockchain_instance=stm) == Asset(
12
+ self["asset"], blockchain_instance=stm
13
+ ):
14
+ raise AssertionError()
15
+ else:
16
+ if not other == self:
17
+ raise AssertionError()
18
+
19
+
20
+ def quantize(amount, precision):
21
+ # make sure amount is decimal and has the asset precision
22
+ amount = Decimal(amount)
23
+ places = Decimal(10) ** (-precision)
24
+ return amount.quantize(places, rounding=ROUND_DOWN)
25
+
26
+
27
+ class Amount(dict):
28
+ """This class deals with Amounts of any asset to simplify dealing with the tuple::
29
+
30
+ (amount, asset)
31
+
32
+ :param list args: Allows to deal with different representations of an amount
33
+ :param float amount: Let's create an instance with a specific amount
34
+ :param str asset: Let's you create an instance with a specific asset (symbol)
35
+ :param boolean fixed_point_arithmetic: when set to True, all operation are fixed
36
+ point operations and the amount is always be rounded down to the precision
37
+ :param Steem steem_instance: Steem instance
38
+ :returns: All data required to represent an Amount/Asset
39
+ :rtype: dict
40
+ :raises ValueError: if the data provided is not recognized
41
+
42
+ Way to obtain a proper instance:
43
+
44
+ * ``args`` can be a string, e.g.: "1 SBD"
45
+ * ``args`` can be a dictionary containing ``amount`` and ``asset_id``
46
+ * ``args`` can be a dictionary containing ``amount`` and ``asset``
47
+ * ``args`` can be a list of a ``float`` and ``str`` (symbol)
48
+ * ``args`` can be a list of a ``float`` and a :class:`nectar.asset.Asset`
49
+ * ``amount`` and ``asset`` are defined manually
50
+
51
+ An instance is a dictionary and comes with the following keys:
52
+
53
+ * ``amount`` (float)
54
+ * ``symbol`` (str)
55
+ * ``asset`` (instance of :class:`nectar.asset.Asset`)
56
+
57
+ Instances of this class can be used in regular mathematical expressions
58
+ (``+-*/%``) such as:
59
+
60
+ .. testcode::
61
+
62
+ from nectar.amount import Amount
63
+ from nectar.asset import Asset
64
+ a = Amount("1 STEEM")
65
+ b = Amount(1, "STEEM")
66
+ c = Amount("20", Asset("STEEM"))
67
+ a + b
68
+ a * 2
69
+ a += b
70
+ a /= 2.0
71
+
72
+ .. testoutput::
73
+
74
+ 2.000 STEEM
75
+ 2.000 STEEM
76
+
77
+ """
78
+
79
+ def __init__(
80
+ self,
81
+ amount,
82
+ asset=None,
83
+ fixed_point_arithmetic=False,
84
+ new_appbase_format=True,
85
+ blockchain_instance=None,
86
+ **kwargs,
87
+ ):
88
+ self["asset"] = {}
89
+ self.new_appbase_format = new_appbase_format
90
+ self.fixed_point_arithmetic = fixed_point_arithmetic
91
+
92
+ if blockchain_instance is None:
93
+ if kwargs.get("steem_instance"):
94
+ blockchain_instance = kwargs["steem_instance"]
95
+ elif kwargs.get("hive_instance"):
96
+ blockchain_instance = kwargs["hive_instance"]
97
+ self.blockchain = blockchain_instance or shared_blockchain_instance()
98
+
99
+ if amount and asset is None and isinstance(amount, Amount):
100
+ # Copy Asset object
101
+ self["amount"] = amount["amount"]
102
+ self["symbol"] = amount["symbol"]
103
+ self["asset"] = amount["asset"]
104
+
105
+ elif amount and asset is None and isinstance(amount, list) and len(amount) == 3:
106
+ # Copy Asset object
107
+ self["amount"] = Decimal(amount[0]) / Decimal(10 ** amount[1])
108
+ self["asset"] = Asset(amount[2], blockchain_instance=self.blockchain)
109
+ self["symbol"] = self["asset"]["symbol"]
110
+
111
+ elif (
112
+ amount
113
+ and asset is None
114
+ and isinstance(amount, dict)
115
+ and "amount" in amount
116
+ and "nai" in amount
117
+ and "precision" in amount
118
+ ):
119
+ # Copy Asset object
120
+ self.new_appbase_format = True
121
+ self["amount"] = Decimal(amount["amount"]) / Decimal(10 ** amount["precision"])
122
+ self["asset"] = Asset(amount["nai"], blockchain_instance=self.blockchain)
123
+ self["symbol"] = self["asset"]["symbol"]
124
+
125
+ elif amount is not None and asset is None and isinstance(amount, string_types):
126
+ self["amount"], self["symbol"] = amount.split(" ")
127
+ self["asset"] = Asset(self["symbol"], blockchain_instance=self.blockchain)
128
+
129
+ elif (
130
+ amount
131
+ and asset is None
132
+ and isinstance(amount, dict)
133
+ and "amount" in amount
134
+ and "asset_id" in amount
135
+ ):
136
+ self["asset"] = Asset(amount["asset_id"], blockchain_instance=self.blockchain)
137
+ self["symbol"] = self["asset"]["symbol"]
138
+ self["amount"] = Decimal(amount["amount"]) / Decimal(10 ** self["asset"]["precision"])
139
+
140
+ elif (
141
+ amount
142
+ and asset is None
143
+ and isinstance(amount, dict)
144
+ and "amount" in amount
145
+ and "asset" in amount
146
+ ):
147
+ self["asset"] = Asset(amount["asset"], blockchain_instance=self.blockchain)
148
+ self["symbol"] = self["asset"]["symbol"]
149
+ self["amount"] = Decimal(amount["amount"]) / Decimal(10 ** self["asset"]["precision"])
150
+
151
+ elif isinstance(amount, (float)) and asset and isinstance(asset, Asset):
152
+ self["amount"] = str(amount)
153
+ self["asset"] = asset
154
+ self["symbol"] = self["asset"]["symbol"]
155
+
156
+ elif isinstance(amount, (integer_types, Decimal)) and asset and isinstance(asset, Asset):
157
+ self["amount"] = amount
158
+ self["asset"] = asset
159
+ self["symbol"] = self["asset"]["symbol"]
160
+
161
+ elif isinstance(amount, (float)) and asset and isinstance(asset, dict):
162
+ self["amount"] = str(amount)
163
+ self["asset"] = asset
164
+ self["symbol"] = self["asset"]["symbol"]
165
+
166
+ elif isinstance(amount, (integer_types, Decimal)) and asset and isinstance(asset, dict):
167
+ self["amount"] = amount
168
+ self["asset"] = asset
169
+ self["symbol"] = self["asset"]["symbol"]
170
+
171
+ elif isinstance(amount, (float)) and asset and isinstance(asset, string_types):
172
+ self["amount"] = str(amount)
173
+ self["asset"] = Asset(asset, blockchain_instance=self.blockchain)
174
+ self["symbol"] = asset
175
+
176
+ elif (
177
+ isinstance(amount, (integer_types, Decimal))
178
+ and asset
179
+ and isinstance(asset, string_types)
180
+ ):
181
+ self["amount"] = amount
182
+ self["asset"] = Asset(asset, blockchain_instance=self.blockchain)
183
+ self["symbol"] = asset
184
+ elif amount and asset and isinstance(asset, Asset):
185
+ self["amount"] = amount
186
+ self["symbol"] = asset["symbol"]
187
+ self["asset"] = asset
188
+ elif amount and asset and isinstance(asset, string_types):
189
+ self["amount"] = amount
190
+ self["asset"] = Asset(asset, blockchain_instance=self.blockchain)
191
+ self["symbol"] = self["asset"]["symbol"]
192
+ else:
193
+ raise ValueError
194
+ if self.fixed_point_arithmetic:
195
+ self["amount"] = quantize(self["amount"], self["asset"]["precision"])
196
+ else:
197
+ self["amount"] = Decimal(self["amount"])
198
+
199
+ def copy(self):
200
+ """Copy the instance and make sure not to use a reference"""
201
+ return Amount(
202
+ amount=self["amount"],
203
+ asset=self["asset"].copy(),
204
+ new_appbase_format=self.new_appbase_format,
205
+ fixed_point_arithmetic=self.fixed_point_arithmetic,
206
+ blockchain_instance=self.blockchain,
207
+ )
208
+
209
+ @property
210
+ def amount(self):
211
+ """Returns the amount as float"""
212
+ return float(self["amount"])
213
+
214
+ @property
215
+ def amount_decimal(self):
216
+ """Returns the amount as decimal"""
217
+ return self["amount"]
218
+
219
+ @property
220
+ def symbol(self):
221
+ """Returns the symbol of the asset"""
222
+ return self["symbol"]
223
+
224
+ def tuple(self):
225
+ return float(self), self.symbol
226
+
227
+ @property
228
+ def asset(self):
229
+ """Returns the asset as instance of :class:`steem.asset.Asset`"""
230
+ if not self["asset"]:
231
+ self["asset"] = Asset(self["symbol"], blockchain_instance=self.blockchain)
232
+ return self["asset"]
233
+
234
+ def json(self):
235
+ if self.blockchain.is_connected() and self.blockchain.rpc.get_use_appbase():
236
+ if self.new_appbase_format:
237
+ return {
238
+ "amount": str(int(self)),
239
+ "nai": self["asset"]["asset"],
240
+ "precision": self["asset"]["precision"],
241
+ }
242
+ else:
243
+ return [str(int(self)), self["asset"]["precision"], self["asset"]["asset"]]
244
+ else:
245
+ return str(self)
246
+
247
+ def __str__(self):
248
+ amount = quantize(self["amount"], self["asset"]["precision"])
249
+ symbol = self["symbol"]
250
+ return "{:.{prec}f} {}".format(amount, symbol, prec=self["asset"]["precision"])
251
+
252
+ def __float__(self):
253
+ if self.fixed_point_arithmetic:
254
+ return float(quantize(self["amount"], self["asset"]["precision"]))
255
+ else:
256
+ return float(self["amount"])
257
+
258
+ def __int__(self):
259
+ amount = quantize(self["amount"], self["asset"]["precision"])
260
+ return int(amount * 10 ** self["asset"]["precision"])
261
+
262
+ def __add__(self, other):
263
+ a = self.copy()
264
+ if isinstance(other, Amount):
265
+ check_asset(other["asset"], self["asset"], self.blockchain)
266
+ a["amount"] += other["amount"]
267
+ else:
268
+ a["amount"] += Decimal(other)
269
+ if self.fixed_point_arithmetic:
270
+ a["amount"] = quantize(a["amount"], self["asset"]["precision"])
271
+ return a
272
+
273
+ def __sub__(self, other):
274
+ a = self.copy()
275
+ if isinstance(other, Amount):
276
+ check_asset(other["asset"], self["asset"], self.blockchain)
277
+ a["amount"] -= other["amount"]
278
+ else:
279
+ a["amount"] -= Decimal(other)
280
+ if self.fixed_point_arithmetic:
281
+ a["amount"] = quantize(a["amount"], self["asset"]["precision"])
282
+ return a
283
+
284
+ def __mul__(self, other):
285
+ from .price import Price
286
+
287
+ a = self.copy()
288
+ if isinstance(other, Amount):
289
+ check_asset(other["asset"], self["asset"], self.blockchain)
290
+ a["amount"] *= other["amount"]
291
+ elif isinstance(other, Price):
292
+ if not self["asset"] == other["quote"]["asset"]:
293
+ raise AssertionError()
294
+ a = self.copy() * other["price"]
295
+ a["asset"] = other["base"]["asset"].copy()
296
+ a["symbol"] = other["base"]["asset"]["symbol"]
297
+ else:
298
+ a["amount"] *= Decimal(other)
299
+ if self.fixed_point_arithmetic:
300
+ a["amount"] = quantize(a["amount"], self["asset"]["precision"])
301
+ return a
302
+
303
+ def __floordiv__(self, other):
304
+ a = self.copy()
305
+ if isinstance(other, Amount):
306
+ from .price import Price
307
+
308
+ check_asset(other["asset"], self["asset"], self.blockchain)
309
+ return Price(self, other, blockchain_instance=self.blockchain)
310
+ else:
311
+ a["amount"] //= Decimal(other)
312
+ if self.fixed_point_arithmetic:
313
+ a["amount"] = quantize(a["amount"], self["asset"]["precision"])
314
+ return a
315
+
316
+ def __div__(self, other):
317
+ from .price import Price
318
+
319
+ a = self.copy()
320
+ if isinstance(other, Amount):
321
+ check_asset(other["asset"], self["asset"], self.blockchain)
322
+ return Price(self, other, blockchain_instance=self.blockchain)
323
+ elif isinstance(other, Price):
324
+ if not self["asset"] == other["base"]["asset"]:
325
+ raise AssertionError()
326
+ a = self.copy()
327
+ a["amount"] = a["amount"] / other["price"]
328
+ a["asset"] = other["quote"]["asset"].copy()
329
+ a["symbol"] = other["quote"]["asset"]["symbol"]
330
+ else:
331
+ a["amount"] /= Decimal(other)
332
+ if self.fixed_point_arithmetic:
333
+ a["amount"] = quantize(a["amount"], self["asset"]["precision"])
334
+ return a
335
+
336
+ def __mod__(self, other):
337
+ a = self.copy()
338
+ if isinstance(other, Amount):
339
+ check_asset(other["asset"], self["asset"], self.blockchain)
340
+ a["amount"] %= other["amount"]
341
+ else:
342
+ a["amount"] %= Decimal(other)
343
+ if self.fixed_point_arithmetic:
344
+ a["amount"] = quantize(a["amount"], self["asset"]["precision"])
345
+ return a
346
+
347
+ def __pow__(self, other):
348
+ a = self.copy()
349
+ if isinstance(other, Amount):
350
+ check_asset(other["asset"], self["asset"], self.blockchain)
351
+ a["amount"] **= other["amount"]
352
+ else:
353
+ a["amount"] **= Decimal(other)
354
+ if self.fixed_point_arithmetic:
355
+ a["amount"] = quantize(a["amount"], self["asset"]["precision"])
356
+ return a
357
+
358
+ def __iadd__(self, other):
359
+ if isinstance(other, Amount):
360
+ check_asset(other["asset"], self["asset"], self.blockchain)
361
+ self["amount"] += other["amount"]
362
+ else:
363
+ self["amount"] += Decimal(other)
364
+ if self.fixed_point_arithmetic:
365
+ self["amount"] = quantize(self["amount"], self["asset"]["precision"])
366
+ return self
367
+
368
+ def __isub__(self, other):
369
+ if isinstance(other, Amount):
370
+ check_asset(other["asset"], self["asset"], self.blockchain)
371
+ self["amount"] -= other["amount"]
372
+ else:
373
+ self["amount"] -= Decimal(other)
374
+ if self.fixed_point_arithmetic:
375
+ self["amount"] = quantize(self["amount"], self["asset"]["precision"])
376
+ return self
377
+
378
+ def __imul__(self, other):
379
+ if isinstance(other, Amount):
380
+ check_asset(other["asset"], self["asset"], self.blockchain)
381
+ self["amount"] *= other["amount"]
382
+ else:
383
+ self["amount"] *= Decimal(other)
384
+
385
+ self["amount"] = quantize(self["amount"], self["asset"]["precision"])
386
+ return self
387
+
388
+ def __idiv__(self, other):
389
+ if isinstance(other, Amount):
390
+ check_asset(other["asset"], self["asset"], self.blockchain)
391
+ return self["amount"] / other["amount"]
392
+ else:
393
+ self["amount"] /= Decimal(other)
394
+ if self.fixed_point_arithmetic:
395
+ self["amount"] = quantize(self["amount"], self["asset"]["precision"])
396
+ return self
397
+
398
+ def __ifloordiv__(self, other):
399
+ if isinstance(other, Amount):
400
+ self["amount"] //= other["amount"]
401
+ else:
402
+ self["amount"] //= Decimal(other)
403
+ self["amount"] = quantize(self["amount"], self["asset"]["precision"])
404
+ return self
405
+
406
+ def __imod__(self, other):
407
+ if isinstance(other, Amount):
408
+ check_asset(other["asset"], self["asset"], self.blockchain)
409
+ self["amount"] %= other["amount"]
410
+ else:
411
+ self["amount"] %= Decimal(other)
412
+ if self.fixed_point_arithmetic:
413
+ self["amount"] = quantize(self["amount"], self["asset"]["precision"])
414
+ return self
415
+
416
+ def __ipow__(self, other):
417
+ if isinstance(other, Amount):
418
+ self["amount"] **= other
419
+ else:
420
+ self["amount"] **= Decimal(other)
421
+ if self.fixed_point_arithmetic:
422
+ self["amount"] = quantize(self["amount"], self["asset"]["precision"])
423
+ return self
424
+
425
+ def __lt__(self, other):
426
+ quant_amount = quantize(self["amount"], self["asset"]["precision"])
427
+ if isinstance(other, Amount):
428
+ check_asset(other["asset"], self["asset"], self.blockchain)
429
+ return quant_amount < quantize(other["amount"], self["asset"]["precision"])
430
+ else:
431
+ return quant_amount < quantize((other or 0), self["asset"]["precision"])
432
+
433
+ def __le__(self, other):
434
+ quant_amount = quantize(self["amount"], self["asset"]["precision"])
435
+ if isinstance(other, Amount):
436
+ check_asset(other["asset"], self["asset"], self.blockchain)
437
+ return quant_amount <= quantize(other["amount"], self["asset"]["precision"])
438
+ else:
439
+ return quant_amount <= quantize((other or 0), self["asset"]["precision"])
440
+
441
+ def __eq__(self, other):
442
+ quant_amount = quantize(self["amount"], self["asset"]["precision"])
443
+ if isinstance(other, Amount):
444
+ check_asset(other["asset"], self["asset"], self.blockchain)
445
+ return quant_amount == quantize(other["amount"], self["asset"]["precision"])
446
+ else:
447
+ return quant_amount == quantize((other or 0), self["asset"]["precision"])
448
+
449
+ def __ne__(self, other):
450
+ quant_amount = quantize(self["amount"], self["asset"]["precision"])
451
+ if isinstance(other, Amount):
452
+ check_asset(other["asset"], self["asset"], self.blockchain)
453
+ return self["amount"] != quantize(other["amount"], self["asset"]["precision"])
454
+ else:
455
+ return quant_amount != quantize((other or 0), self["asset"]["precision"])
456
+
457
+ def __ge__(self, other):
458
+ quant_amount = quantize(self["amount"], self["asset"]["precision"])
459
+ if isinstance(other, Amount):
460
+ check_asset(other["asset"], self["asset"], self.blockchain)
461
+ return self["amount"] >= quantize(other["amount"], self["asset"]["precision"])
462
+ else:
463
+ return quant_amount >= quantize((other or 0), self["asset"]["precision"])
464
+
465
+ def __gt__(self, other):
466
+ quant_amount = quantize(self["amount"], self["asset"]["precision"])
467
+ if isinstance(other, Amount):
468
+ check_asset(other["asset"], self["asset"], self.blockchain)
469
+ return quant_amount > quantize(other["amount"], self["asset"]["precision"])
470
+ else:
471
+ return quant_amount > quantize((other or 0), self["asset"]["precision"])
472
+
473
+ __repr__ = __str__
474
+ __truediv__ = __div__
475
+ __truemul__ = __mul__