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
nectar/rc.py ADDED
@@ -0,0 +1,333 @@
1
+ from typing import Any, Dict, Optional, Union
2
+
3
+ from nectar.constants import (
4
+ EXEC_FOLLOW_CUSTOM_OP_SCALE,
5
+ resource_execution_time,
6
+ state_object_size_info,
7
+ )
8
+ from nectarbase import operations
9
+ from nectarbase.objects import Operation
10
+ from nectarbase.signedtransactions import Signed_Transaction
11
+
12
+ from .instance import shared_blockchain_instance
13
+
14
+
15
+ class RC:
16
+ def __init__(self, blockchain_instance: Optional[Any] = None, **kwargs: Any) -> None:
17
+ """
18
+ Initialize the RC helper with a blockchain instance.
19
+
20
+ If `blockchain_instance` is provided it will be used for RC lookups and broadcasts;
21
+ otherwise the module-wide shared_blockchain_instance() is used. Extra keyword
22
+ arguments are accepted for compatibility but ignored.
23
+ """
24
+ self.blockchain = blockchain_instance or shared_blockchain_instance()
25
+
26
+ def get_tx_size(self, op: Union[Any, Operation, Dict[str, Any]]) -> int:
27
+ """
28
+ Estimate the serialized size (in bytes) of a signed transaction containing the given operation.
29
+
30
+ This constructs a dummy Signed_Transaction using fixed reference fields and a hard-coded private key, signs it on the "HIVE" chain, and returns the length of the resulting serialized transaction in bytes. The value is an estimate useful for RC sizing and does not represent a real broadcastable transaction.
31
+
32
+ Parameters:
33
+ op: Operation or dict-like operation payload to include in the transaction.
34
+
35
+ Returns:
36
+ int: Number of bytes in the serialized, signed transaction.
37
+ """
38
+ ops = [Operation(op)]
39
+ prefix = "HIVE"
40
+ wif = "5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3"
41
+ ref_block_num = 34294
42
+ ref_block_prefix = 3707022213
43
+ expiration = "2016-04-06T08:29:27"
44
+ tx = Signed_Transaction(
45
+ ref_block_num=ref_block_num,
46
+ ref_block_prefix=ref_block_prefix,
47
+ expiration=expiration,
48
+ operations=ops,
49
+ )
50
+ tx = tx.sign([wif], chain=prefix)
51
+ tx_size = len(bytes(tx))
52
+ return tx_size
53
+
54
+ def get_resource_count(
55
+ self,
56
+ tx_size: int,
57
+ execution_time_count: int,
58
+ state_bytes_count: int = 0,
59
+ new_account_op_count: int = 0,
60
+ market_op_count: int = 0,
61
+ ) -> Dict[str, int]:
62
+ """
63
+ Build and return a resource_count mapping for RC cost calculation.
64
+
65
+ Parameters:
66
+ tx_size (int): Transaction size in bytes; used for history bytes and for market bytes when applicable.
67
+ execution_time_count (int): Execution time units for the operation.
68
+ state_bytes_count (int, optional): Additional state bytes contributed by the operation (default 0).
69
+ new_account_op_count (int, optional): Number of new-account operations included (default 0).
70
+ market_op_count (int, optional): If > 0, marks the transaction as a market operation and sets market bytes to tx_size (default 0).
71
+
72
+ Returns:
73
+ dict: A dictionary containing keys used by the RC pricing engine, including:
74
+ - resource_history_bytes
75
+ - resource_state_bytes
76
+ - resource_new_accounts
77
+ - resource_execution_time
78
+ - resource_market_bytes (only present if market_op_count > 0)
79
+ """
80
+ resource_count = {"resource_history_bytes": tx_size}
81
+ resource_count["resource_state_bytes"] = state_object_size_info[
82
+ "transaction_object_base_size"
83
+ ]
84
+ resource_count["resource_state_bytes"] += (
85
+ state_object_size_info["transaction_object_byte_size"] * tx_size
86
+ )
87
+ resource_count["resource_state_bytes"] += state_bytes_count
88
+ resource_count["resource_new_accounts"] = new_account_op_count
89
+ resource_count["resource_execution_time"] = execution_time_count
90
+ if market_op_count > 0:
91
+ resource_count["resource_market_bytes"] = tx_size
92
+ return resource_count
93
+
94
+ def comment_dict(self, comment_dict: Dict[str, Any]) -> Dict[str, int]:
95
+ """Calc RC costs for a comment dict object
96
+
97
+ Example for calculating RC costs
98
+
99
+ .. code-block:: python
100
+
101
+ from nectar.rc import RC
102
+ comment_dict = {
103
+ "permlink": "test", "author": "thecrazygm",
104
+ "body": "test", "parent_permlink": "",
105
+ "parent_author": "", "title": "test",
106
+ "json_metadata": {"foo": "bar"}
107
+ }
108
+
109
+ rc = RC()
110
+ print(rc.comment_dict(comment_dict))
111
+
112
+ """
113
+ op = operations.Comment(**comment_dict)
114
+ tx_size = self.get_tx_size(op)
115
+ permlink_length = len(comment_dict["permlink"])
116
+ parent_permlink_length = len(comment_dict["parent_permlink"])
117
+ return self.comment(
118
+ tx_size=tx_size,
119
+ permlink_length=permlink_length,
120
+ parent_permlink_length=parent_permlink_length,
121
+ )
122
+
123
+ def comment(
124
+ self, tx_size: int = 1000, permlink_length: int = 10, parent_permlink_length: int = 10
125
+ ) -> Dict[str, int]:
126
+ """Calc RC for a comment"""
127
+ state_bytes_count = state_object_size_info["comment_object_base_size"]
128
+ state_bytes_count += (
129
+ state_object_size_info["comment_object_permlink_char_size"] * permlink_length
130
+ )
131
+ state_bytes_count += (
132
+ state_object_size_info["comment_object_parent_permlink_char_size"]
133
+ * parent_permlink_length
134
+ )
135
+ execution_time_count = resource_execution_time["comment_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 vote_dict(self, vote_dict: Dict[str, Any]) -> Dict[str, int]:
140
+ """Calc RC costs for a vote
141
+
142
+ Example for calculating RC costs
143
+
144
+ .. code-block:: python
145
+
146
+ from nectar.rc import RC
147
+ vote_dict = {
148
+ "voter": "foobara", "author": "foobarc",
149
+ "permlink": "foobard", "weight": 1000
150
+ }
151
+
152
+ rc = RC()
153
+ print(rc.vote_dict(vote_dict))
154
+
155
+ """
156
+ op = operations.Vote(**vote_dict)
157
+ tx_size = self.get_tx_size(op)
158
+ return self.vote(tx_size=tx_size)
159
+
160
+ def vote(self, tx_size: int = 210) -> Dict[str, int]:
161
+ """Calc RC for a vote"""
162
+ state_bytes_count = state_object_size_info["comment_vote_object_base_size"]
163
+ execution_time_count = resource_execution_time["vote_operation_exec_time"]
164
+ resource_count = self.get_resource_count(tx_size, execution_time_count, state_bytes_count)
165
+ return self.blockchain.get_rc_cost(resource_count)
166
+
167
+ def transfer_dict(self, transfer_dict: Dict[str, Any]) -> Dict[str, int]:
168
+ """
169
+ Calculate Resource Credit (RC) cost for a transfer operation represented as a dict.
170
+
171
+ The input dict must contain the fields required by a Transfer operation (for example: "from", "to", "amount", "memo"). This function builds a Transfer operation, estimates the signed transaction size, marks the operation as a market operation (market_op_count=1), and returns the RC cost computed by the blockchain instance.
172
+
173
+ Parameters:
174
+ transfer_dict (dict): Fields for a Transfer operation compatible with operations.Transfer.
175
+
176
+ Returns:
177
+ dict: RC cost structure as returned by the blockchain's get_rc_cost.
178
+ """
179
+ market_op_count = 1
180
+ op = operations.Transfer(**transfer_dict)
181
+ tx_size = self.get_tx_size(op)
182
+ return self.transfer(tx_size=tx_size, market_op_count=market_op_count)
183
+
184
+ def transfer(self, tx_size: int = 290, market_op_count: int = 1) -> Dict[str, int]:
185
+ """Calc RC of a transfer"""
186
+ execution_time_count = resource_execution_time["transfer_operation_exec_time"]
187
+ resource_count = self.get_resource_count(
188
+ tx_size, execution_time_count, market_op_count=market_op_count
189
+ )
190
+ return self.blockchain.get_rc_cost(resource_count)
191
+
192
+ def custom_json_dict(self, custom_json_dict: Dict[str, Any]) -> Dict[str, int]:
193
+ """Calc RC costs for a custom_json
194
+
195
+ Example for calculating RC costs
196
+
197
+ .. code-block:: python
198
+
199
+ from nectar.rc import RC
200
+ from collections import OrderedDict
201
+ custom_json_dict = {
202
+ "json": [
203
+ "reblog", OrderedDict([("account", "xeroc"), ("author", "chainsquad"),
204
+ ("permlink", "streemian-com-to-open-its-doors-and-offer-a-20-discount")
205
+ ])
206
+ ],
207
+ "required_auths": [],
208
+ "required_posting_auths": ["xeroc"],
209
+ "id": "follow"
210
+ }
211
+
212
+ rc = RC()
213
+ print(rc.custom_json_dict(custom_json_dict))
214
+
215
+ """
216
+ op = operations.Custom_json(**custom_json_dict)
217
+ tx_size = self.get_tx_size(op)
218
+ follow_id = custom_json_dict["id"] == "follow"
219
+ return self.custom_json(tx_size=tx_size, follow_id=follow_id)
220
+
221
+ def custom_json(self, tx_size: int = 444, follow_id: bool = False) -> Dict[str, int]:
222
+ execution_time_count = resource_execution_time["custom_json_operation_exec_time"]
223
+ if follow_id:
224
+ execution_time_count *= EXEC_FOLLOW_CUSTOM_OP_SCALE
225
+ resource_count = self.get_resource_count(tx_size, execution_time_count)
226
+ return self.blockchain.get_rc_cost(resource_count)
227
+
228
+ def account_update_dict(self, account_update_dict: Dict[str, Any]) -> Dict[str, int]:
229
+ """Calc RC costs for account update"""
230
+ op = operations.Account_update(**account_update_dict)
231
+ tx_size = self.get_tx_size(op)
232
+ execution_time_count = resource_execution_time["account_update_operation_exec_time"]
233
+ resource_count = self.get_resource_count(tx_size, execution_time_count)
234
+ return self.blockchain.get_rc_cost(resource_count)
235
+
236
+ def claim_account(self, tx_size: int = 300) -> Dict[str, int]:
237
+ """Claim account"""
238
+ execution_time_count = resource_execution_time["claim_account_operation_exec_time"]
239
+ resource_count = self.get_resource_count(
240
+ tx_size, execution_time_count, new_account_op_count=1
241
+ )
242
+ return self.blockchain.get_rc_cost(resource_count)
243
+
244
+ def get_authority_byte_count(self, auth: Dict[str, Any]) -> int:
245
+ return (
246
+ state_object_size_info["authority_base_size"]
247
+ + state_object_size_info["authority_account_member_size"] * len(auth["account_auths"])
248
+ + state_object_size_info["authority_key_member_size"] * len(auth["key_auths"])
249
+ )
250
+
251
+ def account_create_dict(self, account_create_dict: Dict[str, Any]) -> Dict[str, int]:
252
+ """Calc RC costs for account create"""
253
+ op = operations.Account_create(**account_create_dict)
254
+ state_bytes_count = state_object_size_info["account_object_base_size"]
255
+ state_bytes_count += state_object_size_info["account_authority_object_base_size"]
256
+ state_bytes_count += self.get_authority_byte_count(account_create_dict["owner"])
257
+ state_bytes_count += self.get_authority_byte_count(account_create_dict["active"])
258
+ state_bytes_count += self.get_authority_byte_count(account_create_dict["posting"])
259
+ tx_size = self.get_tx_size(op)
260
+ execution_time_count = resource_execution_time["account_update_operation_exec_time"]
261
+ resource_count = self.get_resource_count(tx_size, execution_time_count, state_bytes_count)
262
+ return self.blockchain.get_rc_cost(resource_count)
263
+
264
+ def create_claimed_account_dict(
265
+ self, create_claimed_account_dict: Dict[str, Any]
266
+ ) -> Dict[str, int]:
267
+ """Calc RC costs for claimed account create"""
268
+ op = operations.Create_claimed_account(**create_claimed_account_dict)
269
+ state_bytes_count = state_object_size_info["account_object_base_size"]
270
+ state_bytes_count += state_object_size_info["account_authority_object_base_size"]
271
+ state_bytes_count += self.get_authority_byte_count(create_claimed_account_dict["owner"])
272
+ state_bytes_count += self.get_authority_byte_count(create_claimed_account_dict["active"])
273
+ state_bytes_count += self.get_authority_byte_count(create_claimed_account_dict["posting"])
274
+ tx_size = self.get_tx_size(op)
275
+ execution_time_count = resource_execution_time["account_update_operation_exec_time"]
276
+ resource_count = self.get_resource_count(tx_size, execution_time_count, state_bytes_count)
277
+ return self.blockchain.get_rc_cost(resource_count)
278
+
279
+ def set_slot_delegator(
280
+ self, from_pool: str, to_account: str, to_slot: int, signer: str
281
+ ) -> Dict[str, Any]:
282
+ """Set a slot to receive RC from a pool
283
+
284
+ :param str from_pool: Pool to set the slot to
285
+ :param str to_account: Account on which we want to update the slot
286
+ :param int to_slot: slot we want to set
287
+ :param str signer: Account who broadcast this
288
+ """
289
+ json_body = [
290
+ "set_slot_delegator",
291
+ {
292
+ "from_pool": from_pool,
293
+ "to_account": to_account,
294
+ "to_slot": to_slot,
295
+ "signer": signer,
296
+ },
297
+ ]
298
+ return self.blockchain.custom_json("rc", json_body, required_auths=[signer])
299
+
300
+ def delegate_from_pool(self, from_pool: str, to_account: str, max_rc: int) -> Dict[str, Any]:
301
+ """Set a slot to receive RC from a pool
302
+
303
+ :param str from_pool: Pool to set the slot to
304
+ :param str to_account: Account on which we want to update the slot
305
+ :param int max_rc: max rc to delegate
306
+ """
307
+ json_body = [
308
+ "delegate_drc_from_pool",
309
+ {
310
+ "from_pool": from_pool,
311
+ "to_account": to_account,
312
+ "asset_symbol": {"nai": "@@000000037", "decimals": 6},
313
+ "drc_max_mana": max_rc,
314
+ },
315
+ ]
316
+ return self.blockchain.custom_json("rc", json_body, required_auths=[from_pool])
317
+
318
+ def delegate_to_pool(self, username: str, to_pool: str, rc: int) -> Dict[str, Any]:
319
+ """Set a slot to receive RC from a pool
320
+
321
+ :param str username: user delegating rc to the pool
322
+ :param str to_pool: Pool to delegate to
323
+ :param int rc: rc to delegate
324
+ """
325
+ json_body = [
326
+ "delegate_to_pool",
327
+ {
328
+ "from_account": username,
329
+ "to_pool": to_pool,
330
+ "amount": {"symbol": "VESTS", "amount": rc, "precision": 6, "nai": "@@000000037"},
331
+ },
332
+ ]
333
+ return self.blockchain.custom_json("rc", json_body, required_auths=[username])