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/rc.py ADDED
@@ -0,0 +1,308 @@
1
+ # -*- coding: utf-8 -*-
2
+ from binascii import hexlify
3
+
4
+ from nectar.constants import (
5
+ EXEC_FOLLOW_CUSTOM_OP_SCALE,
6
+ resource_execution_time,
7
+ state_object_size_info,
8
+ )
9
+ from nectarbase import operations
10
+ from nectarbase.objects import Operation
11
+ from nectarbase.signedtransactions import Signed_Transaction
12
+ from nectargraphenebase.py23 import py23_bytes
13
+
14
+ from .instance import shared_blockchain_instance
15
+
16
+
17
+ class RC(object):
18
+ def __init__(self, blockchain_instance=None, **kwargs):
19
+ if blockchain_instance is None:
20
+ if kwargs.get("steem_instance"):
21
+ blockchain_instance = kwargs["steem_instance"]
22
+ elif kwargs.get("hive_instance"):
23
+ blockchain_instance = kwargs["hive_instance"]
24
+ self.blockchain = blockchain_instance or shared_blockchain_instance()
25
+
26
+ def get_tx_size(self, op):
27
+ """Returns the tx size of an operation"""
28
+ ops = [Operation(op)]
29
+ prefix = "STEEM"
30
+ wif = "5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3"
31
+ ref_block_num = 34294
32
+ ref_block_prefix = 3707022213
33
+ expiration = "2016-04-06T08:29:27"
34
+ tx = Signed_Transaction(
35
+ ref_block_num=ref_block_num,
36
+ ref_block_prefix=ref_block_prefix,
37
+ expiration=expiration,
38
+ operations=ops,
39
+ )
40
+ tx = tx.sign([wif], chain=prefix)
41
+ txWire = hexlify(py23_bytes(tx)).decode("ascii")
42
+ tx_size = len(txWire)
43
+ return tx_size
44
+
45
+ def get_resource_count(
46
+ self,
47
+ tx_size,
48
+ execution_time_count,
49
+ state_bytes_count=0,
50
+ new_account_op_count=0,
51
+ market_op_count=0,
52
+ ):
53
+ """Creates the resource_count dictionary based on tx_size, state_bytes_count, new_account_op_count and market_op_count"""
54
+ resource_count = {"resource_history_bytes": tx_size}
55
+ resource_count["resource_state_bytes"] = state_object_size_info[
56
+ "transaction_object_base_size"
57
+ ]
58
+ resource_count["resource_state_bytes"] += (
59
+ state_object_size_info["transaction_object_byte_size"] * tx_size
60
+ )
61
+ resource_count["resource_state_bytes"] += state_bytes_count
62
+ resource_count["resource_new_accounts"] = new_account_op_count
63
+ resource_count["resource_execution_time"] = execution_time_count
64
+ if market_op_count > 0:
65
+ resource_count["resource_market_bytes"] = tx_size
66
+ return resource_count
67
+
68
+ def comment_dict(self, comment_dict):
69
+ """Calc RC costs for a comment dict object
70
+
71
+ Example for calculating RC costs
72
+
73
+ .. code-block:: python
74
+
75
+ from nectar.rc import RC
76
+ comment_dict = {
77
+ "permlink": "test", "author": "thecrazygm",
78
+ "body": "test", "parent_permlink": "",
79
+ "parent_author": "", "title": "test",
80
+ "json_metadata": {"foo": "bar"}
81
+ }
82
+
83
+ rc = RC()
84
+ print(rc.comment_from_dict(comment_dict))
85
+
86
+ """
87
+ op = operations.Comment(**comment_dict)
88
+ tx_size = self.get_tx_size(op)
89
+ permlink_length = len(comment_dict["permlink"])
90
+ parent_permlink_length = len(comment_dict["parent_permlink"])
91
+ return self.comment(
92
+ tx_size=tx_size,
93
+ permlink_length=permlink_length,
94
+ parent_permlink_length=parent_permlink_length,
95
+ )
96
+
97
+ def comment(self, tx_size=1000, permlink_length=10, parent_permlink_length=10):
98
+ """Calc RC for a comment"""
99
+ state_bytes_count = state_object_size_info["comment_object_base_size"]
100
+ state_bytes_count += (
101
+ state_object_size_info["comment_object_permlink_char_size"] * permlink_length
102
+ )
103
+ state_bytes_count += (
104
+ state_object_size_info["comment_object_parent_permlink_char_size"]
105
+ * parent_permlink_length
106
+ )
107
+ execution_time_count = resource_execution_time["comment_operation_exec_time"]
108
+ resource_count = self.get_resource_count(tx_size, execution_time_count, state_bytes_count)
109
+ return self.blockchain.get_rc_cost(resource_count)
110
+
111
+ def vote_dict(self, vote_dict):
112
+ """Calc RC costs for a vote
113
+
114
+ Example for calculating RC costs
115
+
116
+ .. code-block:: python
117
+
118
+ from nectar.rc import RC
119
+ vote_dict = {
120
+ "voter": "foobara", "author": "foobarc",
121
+ "permlink": "foobard", "weight": 1000
122
+ }
123
+
124
+ rc = RC()
125
+ print(rc.comment(vote_dict))
126
+
127
+ """
128
+ op = operations.Vote(**vote_dict)
129
+ tx_size = self.get_tx_size(op)
130
+ return self.vote(tx_size=tx_size)
131
+
132
+ def vote(self, tx_size=210):
133
+ """Calc RC for a vote"""
134
+ state_bytes_count = state_object_size_info["comment_vote_object_base_size"]
135
+ execution_time_count = resource_execution_time["vote_operation_exec_time"]
136
+ resource_count = self.get_resource_count(tx_size, execution_time_count, state_bytes_count)
137
+ return self.blockchain.get_rc_cost(resource_count)
138
+
139
+ def transfer_dict(self, transfer_dict):
140
+ """Calc RC costs for a transfer dict object
141
+
142
+ Example for calculating RC costs
143
+
144
+ .. code-block:: python
145
+
146
+ from nectar.rc import RC
147
+ from nectar.amount import Amount
148
+ transfer_dict = {
149
+ "from": "foo", "to": "baar",
150
+ "amount": Amount("111.110 STEEM"),
151
+ "memo": "Fooo"
152
+ }
153
+
154
+ rc = RC()
155
+ print(rc.comment(transfer_dict))
156
+
157
+ """
158
+ market_op_count = 1
159
+ op = operations.Transfer(**transfer_dict)
160
+ tx_size = self.get_tx_size(op)
161
+ return self.transfer(tx_size=tx_size, market_op_count=market_op_count)
162
+
163
+ def transfer(self, tx_size=290, market_op_count=1):
164
+ """Calc RC of a transfer"""
165
+ execution_time_count = resource_execution_time["transfer_operation_exec_time"]
166
+ resource_count = self.get_resource_count(
167
+ tx_size, execution_time_count, market_op_count=market_op_count
168
+ )
169
+ return self.blockchain.get_rc_cost(resource_count)
170
+
171
+ def custom_json_dict(self, custom_json_dict):
172
+ """Calc RC costs for a custom_json
173
+
174
+ Example for calculating RC costs
175
+
176
+ .. code-block:: python
177
+
178
+ from nectar.rc import RC
179
+ from collections import OrderedDict
180
+ custom_json_dict = {
181
+ "json": [
182
+ "reblog", OrderedDict([("account", "xeroc"), ("author", "chainsquad"),
183
+ ("permlink", "streemian-com-to-open-its-doors-and-offer-a-20-discount")
184
+ ])
185
+ ],
186
+ "required_auths": [],
187
+ "required_posting_auths": ["xeroc"],
188
+ "id": "follow"
189
+ }
190
+
191
+ rc = RC()
192
+ print(rc.comment(custom_json_dict))
193
+
194
+ """
195
+ op = operations.Custom_json(**custom_json_dict)
196
+ tx_size = self.get_tx_size(op)
197
+ follow_id = custom_json_dict["id"] == "follow"
198
+ return self.custom_json(tx_size=tx_size, follow_id=follow_id)
199
+
200
+ def custom_json(self, tx_size=444, follow_id=False):
201
+ execution_time_count = resource_execution_time["custom_json_operation_exec_time"]
202
+ if follow_id:
203
+ execution_time_count *= EXEC_FOLLOW_CUSTOM_OP_SCALE
204
+ resource_count = self.get_resource_count(tx_size, execution_time_count)
205
+ return self.blockchain.get_rc_cost(resource_count)
206
+
207
+ def account_update_dict(self, account_update_dict):
208
+ """Calc RC costs for account update"""
209
+ op = operations.Account_update(**account_update_dict)
210
+ tx_size = self.get_tx_size(op)
211
+ execution_time_count = resource_execution_time["account_update_operation_exec_time"]
212
+ resource_count = self.get_resource_count(tx_size, execution_time_count)
213
+ return self.blockchain.get_rc_cost(resource_count)
214
+
215
+ def claim_account(self, tx_size=300):
216
+ """Claim account"""
217
+ execution_time_count = resource_execution_time["claim_account_operation_exec_time"]
218
+ resource_count = self.get_resource_count(
219
+ tx_size, execution_time_count, new_account_op_count=1
220
+ )
221
+ return self.blockchain.get_rc_cost(resource_count)
222
+
223
+ def get_authority_byte_count(self, auth):
224
+ return (
225
+ state_object_size_info["authority_base_size"]
226
+ + state_object_size_info["authority_account_member_size"] * len(auth["account_auths"])
227
+ + state_object_size_info["authority_key_member_size"] * len(auth["key_auths"])
228
+ )
229
+
230
+ def account_create_dict(self, account_create_dict):
231
+ """Calc RC costs for account create"""
232
+ op = operations.Account_create(**account_create_dict)
233
+ state_bytes_count = state_object_size_info["account_object_base_size"]
234
+ state_bytes_count += state_object_size_info["account_authority_object_base_size"]
235
+ state_bytes_count += self.get_authority_byte_count(account_create_dict["owner"])
236
+ state_bytes_count += self.get_authority_byte_count(account_create_dict["active"])
237
+ state_bytes_count += self.get_authority_byte_count(account_create_dict["posting"])
238
+ tx_size = self.get_tx_size(op)
239
+ execution_time_count = resource_execution_time["account_update_operation_exec_time"]
240
+ resource_count = self.get_resource_count(tx_size, execution_time_count, state_bytes_count)
241
+ return self.blockchain.get_rc_cost(resource_count)
242
+
243
+ def create_claimed_account_dict(self, create_claimed_account_dict):
244
+ """Calc RC costs for claimed account create"""
245
+ op = operations.Create_claimed_account(**create_claimed_account_dict)
246
+ state_bytes_count = state_object_size_info["account_object_base_size"]
247
+ state_bytes_count += state_object_size_info["account_authority_object_base_size"]
248
+ state_bytes_count += self.get_authority_byte_count(create_claimed_account_dict["owner"])
249
+ state_bytes_count += self.get_authority_byte_count(create_claimed_account_dict["active"])
250
+ state_bytes_count += self.get_authority_byte_count(create_claimed_account_dict["posting"])
251
+ tx_size = self.get_tx_size(op)
252
+ execution_time_count = resource_execution_time["account_update_operation_exec_time"]
253
+ resource_count = self.get_resource_count(tx_size, execution_time_count, state_bytes_count)
254
+ return self.blockchain.get_rc_cost(resource_count)
255
+
256
+ def set_slot_delegator(self, from_pool, to_account, to_slot, signer):
257
+ """Set a slot to receive RC from a pool
258
+
259
+ :param str from_pool: Pool to set the slot to
260
+ :param str to_account: Account on which we want to update the slot
261
+ :param int to_slot: slot we want to set
262
+ :param str signer: Account who broadcast this
263
+ """
264
+ json_body = [
265
+ "set_slot_delegator",
266
+ {
267
+ "from_pool": from_pool,
268
+ "to_account": to_account,
269
+ "to_slot": to_slot,
270
+ "signer": signer,
271
+ },
272
+ ]
273
+ return self.blockchain.custom_json("rc", json_body, required_auths=[signer])
274
+
275
+ def delegate_from_pool(self, from_pool, to_account, max_rc):
276
+ """Set a slot to receive RC from a pool
277
+
278
+ :param str from_pool: Pool to set the slot to
279
+ :param str to_account: Account on which we want to update the slot
280
+ :param int max_rc: max rc to delegate
281
+ """
282
+ json_body = [
283
+ "delegate_drc_from_pool",
284
+ {
285
+ "from_pool": from_pool,
286
+ "to_account": to_account,
287
+ "asset_symbol": {"nai": "@@000000037", "decimals": 6},
288
+ "drc_max_mana": max_rc,
289
+ },
290
+ ]
291
+ return self.blockchain.custom_json("rc", json_body, required_auths=[from_pool])
292
+
293
+ def delegate_to_pool(self, username, to_pool, rc):
294
+ """Set a slot to receive RC from a pool
295
+
296
+ :param str username: user delegating rc to the pool
297
+ :param str to_pool: Pool to delegate to
298
+ :param str rc: rc to delegate
299
+ """
300
+ json_body = [
301
+ "delegate_to_pool",
302
+ {
303
+ "from_account": username,
304
+ "to_pool": to_pool,
305
+ "amount": {"symbol": "VESTS", "amount": rc, "precision": 6, "nai": "@@000000037"},
306
+ },
307
+ ]
308
+ return self.blockchain.custom_json("rc", json_body, required_auths=[username])