hive-nectar 0.0.11__py3-none-any.whl → 0.1.0__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.
- {hive_nectar-0.0.11.dist-info → hive_nectar-0.1.0.dist-info}/METADATA +10 -11
- hive_nectar-0.1.0.dist-info/RECORD +88 -0
- nectar/__init__.py +1 -4
- nectar/account.py +791 -685
- nectar/amount.py +82 -21
- nectar/asset.py +1 -2
- nectar/block.py +34 -22
- nectar/blockchain.py +111 -143
- nectar/blockchaininstance.py +396 -247
- nectar/blockchainobject.py +33 -5
- nectar/cli.py +1058 -1349
- nectar/comment.py +313 -181
- nectar/community.py +39 -43
- nectar/constants.py +1 -14
- nectar/discussions.py +793 -139
- nectar/hive.py +137 -77
- nectar/hivesigner.py +106 -68
- nectar/imageuploader.py +33 -23
- nectar/instance.py +31 -79
- nectar/market.py +128 -264
- nectar/memo.py +40 -13
- nectar/message.py +23 -10
- nectar/nodelist.py +115 -81
- nectar/price.py +80 -61
- nectar/profile.py +6 -3
- nectar/rc.py +45 -25
- nectar/snapshot.py +285 -163
- nectar/storage.py +16 -5
- nectar/transactionbuilder.py +132 -41
- nectar/utils.py +37 -17
- nectar/version.py +1 -1
- nectar/vote.py +171 -30
- nectar/wallet.py +26 -19
- nectar/witness.py +153 -54
- nectarapi/graphenerpc.py +147 -133
- nectarapi/noderpc.py +12 -6
- nectarapi/rpcutils.py +12 -6
- nectarapi/version.py +1 -1
- nectarbase/ledgertransactions.py +24 -1
- nectarbase/objects.py +17 -6
- nectarbase/operations.py +160 -90
- nectarbase/signedtransactions.py +38 -2
- nectarbase/version.py +1 -1
- nectargraphenebase/account.py +295 -17
- nectargraphenebase/chains.py +0 -135
- nectargraphenebase/ecdsasig.py +152 -176
- nectargraphenebase/types.py +18 -4
- nectargraphenebase/unsignedtransactions.py +1 -1
- nectargraphenebase/version.py +1 -1
- hive_nectar-0.0.11.dist-info/RECORD +0 -91
- nectar/blurt.py +0 -562
- nectar/conveyor.py +0 -308
- nectar/steem.py +0 -581
- {hive_nectar-0.0.11.dist-info → hive_nectar-0.1.0.dist-info}/WHEEL +0 -0
- {hive_nectar-0.0.11.dist-info → hive_nectar-0.1.0.dist-info}/entry_points.txt +0 -0
- {hive_nectar-0.0.11.dist-info → hive_nectar-0.1.0.dist-info}/licenses/LICENSE.txt +0 -0
nectar/steem.py
DELETED
|
@@ -1,581 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
import logging
|
|
3
|
-
import math
|
|
4
|
-
from datetime import date, datetime, timezone
|
|
5
|
-
|
|
6
|
-
from nectar.blockchaininstance import BlockChainInstance
|
|
7
|
-
from nectar.constants import STEEM_100_PERCENT, STEEM_VOTE_REGENERATION_SECONDS
|
|
8
|
-
from nectargraphenebase.chains import known_chains
|
|
9
|
-
|
|
10
|
-
from .amount import Amount
|
|
11
|
-
from .utils import formatToTimeStamp
|
|
12
|
-
|
|
13
|
-
log = logging.getLogger(__name__)
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
class Steem(BlockChainInstance):
|
|
17
|
-
"""Connect to the Steem network.
|
|
18
|
-
|
|
19
|
-
:param str node: Node to connect to *(optional)*
|
|
20
|
-
:param str rpcuser: RPC user *(optional)*
|
|
21
|
-
:param str rpcpassword: RPC password *(optional)*
|
|
22
|
-
:param bool nobroadcast: Do **not** broadcast a transaction!
|
|
23
|
-
*(optional)*
|
|
24
|
-
:param bool unsigned: Do **not** sign a transaction! *(optional)*
|
|
25
|
-
:param bool debug: Enable Debugging *(optional)*
|
|
26
|
-
:param keys: Predefine the wif keys to shortcut the
|
|
27
|
-
wallet database *(optional)*
|
|
28
|
-
:type keys: array, dict, string
|
|
29
|
-
:param wif: Predefine the wif keys to shortcut the
|
|
30
|
-
wallet database *(optional)*
|
|
31
|
-
:type wif: array, dict, string
|
|
32
|
-
:param bool offline: Boolean to prevent connecting to network (defaults
|
|
33
|
-
to ``False``) *(optional)*
|
|
34
|
-
:param int expiration: Delay in seconds until transactions are supposed
|
|
35
|
-
to expire *(optional)* (default is 30)
|
|
36
|
-
:param str blocking: Wait for broadcasted transactions to be included
|
|
37
|
-
in a block and return full transaction (can be "head" or
|
|
38
|
-
"irreversible")
|
|
39
|
-
:param bool bundle: Do not broadcast transactions right away, but allow
|
|
40
|
-
to bundle operations. It is not possible to send out more than one
|
|
41
|
-
vote operation and more than one comment operation in a single broadcast *(optional)*
|
|
42
|
-
:param bool appbase: Use the new appbase rpc protocol on nodes with version
|
|
43
|
-
0.19.4 or higher. The settings has no effect on nodes with version of 0.19.3 or lower.
|
|
44
|
-
:param int num_retries: Set the maximum number of reconnects to the nodes before
|
|
45
|
-
NumRetriesReached is raised. Disabled for -1. (default is -1)
|
|
46
|
-
:param int num_retries_call: Repeat num_retries_call times a rpc call on node error (default is 5)
|
|
47
|
-
:param int timeout: Timeout setting for https nodes (default is 60)
|
|
48
|
-
:param bool use_sc2: When True, a steemconnect object is created. Can be used for
|
|
49
|
-
broadcast posting op or creating hot_links (default is False)
|
|
50
|
-
:param SteemConnect steemconnect: A SteemConnect object can be set manually, set use_sc2 to True
|
|
51
|
-
:param dict custom_chains: custom chain which should be added to the known chains
|
|
52
|
-
|
|
53
|
-
Three wallet operation modes are possible:
|
|
54
|
-
|
|
55
|
-
* **Wallet Database**: Here, the steemlibs load the keys from the
|
|
56
|
-
locally stored wallet SQLite database (see ``storage.py``).
|
|
57
|
-
To use this mode, simply call ``Steem()`` without the
|
|
58
|
-
``keys`` parameter
|
|
59
|
-
* **Providing Keys**: Here, you can provide the keys for
|
|
60
|
-
your accounts manually. All you need to do is add the wif
|
|
61
|
-
keys for the accounts you want to use as a simple array
|
|
62
|
-
using the ``keys`` parameter to ``Steem()``.
|
|
63
|
-
* **Force keys**: This more is for advanced users and
|
|
64
|
-
requires that you know what you are doing. Here, the
|
|
65
|
-
``keys`` parameter is a dictionary that overwrite the
|
|
66
|
-
``active``, ``owner``, ``posting`` or ``memo`` keys for
|
|
67
|
-
any account. This mode is only used for *foreign*
|
|
68
|
-
signatures!
|
|
69
|
-
|
|
70
|
-
If no node is provided, it will connect to default nodes of
|
|
71
|
-
http://geo.steem.pl. Default settings can be changed with:
|
|
72
|
-
|
|
73
|
-
.. code-block:: python
|
|
74
|
-
|
|
75
|
-
steem = Steem(<host>)
|
|
76
|
-
|
|
77
|
-
where ``<host>`` starts with ``https://``, ``ws://`` or ``wss://``.
|
|
78
|
-
|
|
79
|
-
The purpose of this class it to simplify interaction with
|
|
80
|
-
Steem.
|
|
81
|
-
|
|
82
|
-
The idea is to have a class that allows to do this:
|
|
83
|
-
|
|
84
|
-
.. code-block:: python
|
|
85
|
-
|
|
86
|
-
>>> from nectar import Steem
|
|
87
|
-
>>> steem = Steem()
|
|
88
|
-
>>> print(steem.get_blockchain_version()) # doctest: +SKIP
|
|
89
|
-
|
|
90
|
-
This class also deals with edits, votes and reading content.
|
|
91
|
-
|
|
92
|
-
Example for adding a custom chain:
|
|
93
|
-
|
|
94
|
-
.. code-block:: python
|
|
95
|
-
|
|
96
|
-
from nectar import Steem
|
|
97
|
-
stm = Steem(node=["https://mytstnet.com"], custom_chains={"MYTESTNET":
|
|
98
|
-
{'chain_assets': [{'asset': 'SBD', 'id': 0, 'precision': 3, 'symbol': 'SBD'},
|
|
99
|
-
{'asset': 'STEEM', 'id': 1, 'precision': 3, 'symbol': 'STEEM'},
|
|
100
|
-
{'asset': 'VESTS', 'id': 2, 'precision': 6, 'symbol': 'VESTS'}],
|
|
101
|
-
'chain_id': '79276aea5d4877d9a25892eaa01b0adf019d3e5cb12a97478df3298ccdd01674',
|
|
102
|
-
'min_version': '0.0.0',
|
|
103
|
-
'prefix': 'MTN'}
|
|
104
|
-
}
|
|
105
|
-
)
|
|
106
|
-
|
|
107
|
-
"""
|
|
108
|
-
|
|
109
|
-
def get_network(self, use_stored_data=True, config=None):
|
|
110
|
-
"""Identify the network
|
|
111
|
-
|
|
112
|
-
:param bool use_stored_data: if True, stored data will be returned. If stored data are
|
|
113
|
-
empty or old, refresh_data() is used.
|
|
114
|
-
|
|
115
|
-
:returns: Network parameters
|
|
116
|
-
:rtype: dictionary
|
|
117
|
-
"""
|
|
118
|
-
if use_stored_data:
|
|
119
|
-
self.refresh_data("config")
|
|
120
|
-
return self.data["network"]
|
|
121
|
-
|
|
122
|
-
if self.rpc is None:
|
|
123
|
-
return known_chains["STEEM"]
|
|
124
|
-
try:
|
|
125
|
-
return self.rpc.get_network(props=config)
|
|
126
|
-
except Exception:
|
|
127
|
-
return known_chains["STEEM"]
|
|
128
|
-
|
|
129
|
-
def rshares_to_token_backed_dollar(
|
|
130
|
-
self, rshares, not_broadcasted_vote=False, use_stored_data=True
|
|
131
|
-
):
|
|
132
|
-
return self.rshares_to_sbd(
|
|
133
|
-
rshares, not_broadcasted_vote=not_broadcasted_vote, use_stored_data=use_stored_data
|
|
134
|
-
)
|
|
135
|
-
|
|
136
|
-
def rshares_to_sbd(self, rshares, not_broadcasted_vote=False, use_stored_data=True):
|
|
137
|
-
"""Calculates the current SBD value of a vote"""
|
|
138
|
-
payout = float(rshares) * self.get_sbd_per_rshares(
|
|
139
|
-
use_stored_data=use_stored_data,
|
|
140
|
-
not_broadcasted_vote_rshares=rshares if not_broadcasted_vote else 0,
|
|
141
|
-
)
|
|
142
|
-
return payout
|
|
143
|
-
|
|
144
|
-
def get_sbd_per_rshares(self, not_broadcasted_vote_rshares=0, use_stored_data=True):
|
|
145
|
-
"""Returns the current rshares to SBD ratio"""
|
|
146
|
-
reward_fund = self.get_reward_funds(use_stored_data=use_stored_data)
|
|
147
|
-
reward_balance = float(Amount(reward_fund["reward_balance"], blockchain_instance=self))
|
|
148
|
-
recent_claims = float(reward_fund["recent_claims"]) + not_broadcasted_vote_rshares
|
|
149
|
-
if recent_claims == 0:
|
|
150
|
-
return 0
|
|
151
|
-
fund_per_share = reward_balance / (recent_claims)
|
|
152
|
-
median_price = self.get_median_price(use_stored_data=use_stored_data)
|
|
153
|
-
if median_price is None:
|
|
154
|
-
return 0
|
|
155
|
-
SBD_price = float(median_price * (Amount(1, self.steem_symbol, blockchain_instance=self)))
|
|
156
|
-
return fund_per_share * SBD_price
|
|
157
|
-
|
|
158
|
-
def get_steem_per_mvest(self, time_stamp=None, use_stored_data=True):
|
|
159
|
-
"""Returns the MVEST to STEEM ratio
|
|
160
|
-
|
|
161
|
-
:param int time_stamp: (optional) if set, return an estimated
|
|
162
|
-
STEEM per MVEST ratio for the given time stamp. If unset the
|
|
163
|
-
current ratio is returned (default). (can also be a datetime object)
|
|
164
|
-
"""
|
|
165
|
-
if self.offline and time_stamp is None:
|
|
166
|
-
time_stamp = datetime.now(timezone.utc)
|
|
167
|
-
|
|
168
|
-
if time_stamp is not None:
|
|
169
|
-
if isinstance(time_stamp, (datetime, date)):
|
|
170
|
-
time_stamp = formatToTimeStamp(time_stamp)
|
|
171
|
-
a = 2.1325476281078992e-05
|
|
172
|
-
b = -31099.685481490847
|
|
173
|
-
a2 = 2.9019227739473682e-07
|
|
174
|
-
b2 = 48.41432402074669
|
|
175
|
-
|
|
176
|
-
if time_stamp < (b2 - b) / (a - a2):
|
|
177
|
-
return a * time_stamp + b
|
|
178
|
-
else:
|
|
179
|
-
return a2 * time_stamp + b2
|
|
180
|
-
global_properties = self.get_dynamic_global_properties(use_stored_data=use_stored_data)
|
|
181
|
-
|
|
182
|
-
if "total_vesting_fund_steem" in global_properties:
|
|
183
|
-
return float(
|
|
184
|
-
Amount(global_properties["total_vesting_fund_steem"], blockchain_instance=self)
|
|
185
|
-
) / (
|
|
186
|
-
float(Amount(global_properties["total_vesting_shares"], blockchain_instance=self))
|
|
187
|
-
/ 1e6
|
|
188
|
-
)
|
|
189
|
-
else:
|
|
190
|
-
for key in global_properties:
|
|
191
|
-
if "total_vesting_fund_" in key:
|
|
192
|
-
return float(Amount(global_properties[key], blockchain_instance=self)) / (
|
|
193
|
-
float(
|
|
194
|
-
Amount(
|
|
195
|
-
global_properties["total_vesting_shares"], blockchain_instance=self
|
|
196
|
-
)
|
|
197
|
-
)
|
|
198
|
-
/ 1e6
|
|
199
|
-
)
|
|
200
|
-
|
|
201
|
-
def vests_to_sp(self, vests, timestamp=None, use_stored_data=True):
|
|
202
|
-
"""Converts vests to SP
|
|
203
|
-
|
|
204
|
-
:param amount.Amount vests/float vests: Vests to convert
|
|
205
|
-
:param int timestamp: (Optional) Can be used to calculate
|
|
206
|
-
the conversion rate from the past
|
|
207
|
-
|
|
208
|
-
"""
|
|
209
|
-
if isinstance(vests, Amount):
|
|
210
|
-
vests = float(vests)
|
|
211
|
-
return (
|
|
212
|
-
float(vests)
|
|
213
|
-
/ 1e6
|
|
214
|
-
* self.get_steem_per_mvest(timestamp, use_stored_data=use_stored_data)
|
|
215
|
-
)
|
|
216
|
-
|
|
217
|
-
def sp_to_vests(self, sp, timestamp=None, use_stored_data=True):
|
|
218
|
-
"""Converts SP to vests
|
|
219
|
-
|
|
220
|
-
:param float sp: Steem power to convert
|
|
221
|
-
:param datetime timestamp: (Optional) Can be used to calculate
|
|
222
|
-
the conversion rate from the past
|
|
223
|
-
"""
|
|
224
|
-
return sp * 1e6 / self.get_steem_per_mvest(timestamp, use_stored_data=use_stored_data)
|
|
225
|
-
|
|
226
|
-
def vests_to_token_power(self, vests, timestamp=None, use_stored_data=True):
|
|
227
|
-
return self.vests_to_sp(vests, timestamp=timestamp, use_stored_data=use_stored_data)
|
|
228
|
-
|
|
229
|
-
def token_power_to_vests(self, token_power, timestamp=None, use_stored_data=True):
|
|
230
|
-
return self.sp_to_vests(token_power, timestamp=timestamp, use_stored_data=use_stored_data)
|
|
231
|
-
|
|
232
|
-
def get_token_per_mvest(self, time_stamp=None, use_stored_data=True):
|
|
233
|
-
return self.get_steem_per_mvest(time_stamp=time_stamp, use_stored_data=use_stored_data)
|
|
234
|
-
|
|
235
|
-
def token_power_to_token_backed_dollar(
|
|
236
|
-
self,
|
|
237
|
-
token_power,
|
|
238
|
-
post_rshares=0,
|
|
239
|
-
voting_power=STEEM_100_PERCENT,
|
|
240
|
-
vote_pct=STEEM_100_PERCENT,
|
|
241
|
-
not_broadcasted_vote=True,
|
|
242
|
-
use_stored_data=True,
|
|
243
|
-
):
|
|
244
|
-
return self.sp_to_sbd(
|
|
245
|
-
token_power,
|
|
246
|
-
post_rshares=post_rshares,
|
|
247
|
-
voting_power=voting_power,
|
|
248
|
-
vote_pct=vote_pct,
|
|
249
|
-
not_broadcasted_vote=not_broadcasted_vote,
|
|
250
|
-
use_stored_data=use_stored_data,
|
|
251
|
-
)
|
|
252
|
-
|
|
253
|
-
def sp_to_sbd(
|
|
254
|
-
self,
|
|
255
|
-
sp,
|
|
256
|
-
post_rshares=0,
|
|
257
|
-
voting_power=STEEM_100_PERCENT,
|
|
258
|
-
vote_pct=STEEM_100_PERCENT,
|
|
259
|
-
not_broadcasted_vote=True,
|
|
260
|
-
use_stored_data=True,
|
|
261
|
-
):
|
|
262
|
-
"""Obtain the resulting SBD vote value from Steem power
|
|
263
|
-
|
|
264
|
-
:param number steem_power: Steem Power
|
|
265
|
-
:param int post_rshares: rshares of post which is voted
|
|
266
|
-
:param int voting_power: voting power (100% = 10000)
|
|
267
|
-
:param int vote_pct: voting percentage (100% = 10000)
|
|
268
|
-
:param bool not_broadcasted_vote: not_broadcasted or already broadcasted vote (True = not_broadcasted vote).
|
|
269
|
-
|
|
270
|
-
Only impactful for very big votes. Slight modification to the value calculation, as the not_broadcasted
|
|
271
|
-
vote rshares decreases the reward pool.
|
|
272
|
-
"""
|
|
273
|
-
vesting_shares = int(self.sp_to_vests(sp, use_stored_data=use_stored_data))
|
|
274
|
-
return self.vests_to_sbd(
|
|
275
|
-
vesting_shares,
|
|
276
|
-
post_rshares=post_rshares,
|
|
277
|
-
voting_power=voting_power,
|
|
278
|
-
vote_pct=vote_pct,
|
|
279
|
-
not_broadcasted_vote=not_broadcasted_vote,
|
|
280
|
-
use_stored_data=use_stored_data,
|
|
281
|
-
)
|
|
282
|
-
|
|
283
|
-
def vests_to_sbd(
|
|
284
|
-
self,
|
|
285
|
-
vests,
|
|
286
|
-
post_rshares=0,
|
|
287
|
-
voting_power=STEEM_100_PERCENT,
|
|
288
|
-
vote_pct=STEEM_100_PERCENT,
|
|
289
|
-
not_broadcasted_vote=True,
|
|
290
|
-
use_stored_data=True,
|
|
291
|
-
):
|
|
292
|
-
"""Obtain the resulting SBD vote value from vests
|
|
293
|
-
|
|
294
|
-
:param number vests: vesting shares
|
|
295
|
-
:param int post_rshares: rshares of post which is voted
|
|
296
|
-
:param int voting_power: voting power (100% = 10000)
|
|
297
|
-
:param int vote_pct: voting percentage (100% = 10000)
|
|
298
|
-
:param bool not_broadcasted_vote: not_broadcasted or already broadcasted vote (True = not_broadcasted vote).
|
|
299
|
-
|
|
300
|
-
Only impactful for very big votes. Slight modification to the value calculation, as the not_broadcasted
|
|
301
|
-
vote rshares decreases the reward pool.
|
|
302
|
-
"""
|
|
303
|
-
vote_rshares = self.vests_to_rshares(
|
|
304
|
-
vests, post_rshares=post_rshares, voting_power=voting_power, vote_pct=vote_pct
|
|
305
|
-
)
|
|
306
|
-
return self.rshares_to_sbd(
|
|
307
|
-
vote_rshares, not_broadcasted_vote=not_broadcasted_vote, use_stored_data=use_stored_data
|
|
308
|
-
)
|
|
309
|
-
|
|
310
|
-
def _max_vote_denom(self, use_stored_data=True):
|
|
311
|
-
# get props
|
|
312
|
-
global_properties = self.get_dynamic_global_properties(use_stored_data=use_stored_data)
|
|
313
|
-
vote_power_reserve_rate = global_properties["vote_power_reserve_rate"]
|
|
314
|
-
max_vote_denom = vote_power_reserve_rate * STEEM_VOTE_REGENERATION_SECONDS
|
|
315
|
-
return max_vote_denom
|
|
316
|
-
|
|
317
|
-
def _calc_resulting_vote(
|
|
318
|
-
self, voting_power=STEEM_100_PERCENT, vote_pct=STEEM_100_PERCENT, use_stored_data=True
|
|
319
|
-
):
|
|
320
|
-
# determine voting power used
|
|
321
|
-
used_power = int((voting_power * abs(vote_pct)) / STEEM_100_PERCENT * (60 * 60 * 24))
|
|
322
|
-
max_vote_denom = self._max_vote_denom(use_stored_data=use_stored_data)
|
|
323
|
-
used_power = int((used_power + max_vote_denom - 1) / max_vote_denom)
|
|
324
|
-
return used_power
|
|
325
|
-
|
|
326
|
-
def sp_to_rshares(
|
|
327
|
-
self,
|
|
328
|
-
steem_power,
|
|
329
|
-
post_rshares=0,
|
|
330
|
-
voting_power=STEEM_100_PERCENT,
|
|
331
|
-
vote_pct=STEEM_100_PERCENT,
|
|
332
|
-
use_stored_data=True,
|
|
333
|
-
):
|
|
334
|
-
"""Obtain the r-shares from Steem power
|
|
335
|
-
|
|
336
|
-
:param number steem_power: Steem Power
|
|
337
|
-
:param int post_rshares: rshares of post which is voted
|
|
338
|
-
:param int voting_power: voting power (100% = 10000)
|
|
339
|
-
:param int vote_pct: voting percentage (100% = 10000)
|
|
340
|
-
|
|
341
|
-
"""
|
|
342
|
-
# calculate our account voting shares (from vests)
|
|
343
|
-
vesting_shares = int(self.sp_to_vests(steem_power, use_stored_data=use_stored_data))
|
|
344
|
-
return self.vests_to_rshares(
|
|
345
|
-
vesting_shares,
|
|
346
|
-
post_rshares=post_rshares,
|
|
347
|
-
voting_power=voting_power,
|
|
348
|
-
vote_pct=vote_pct,
|
|
349
|
-
use_stored_data=use_stored_data,
|
|
350
|
-
)
|
|
351
|
-
|
|
352
|
-
def vests_to_rshares(
|
|
353
|
-
self,
|
|
354
|
-
vests,
|
|
355
|
-
post_rshares=0,
|
|
356
|
-
voting_power=STEEM_100_PERCENT,
|
|
357
|
-
vote_pct=STEEM_100_PERCENT,
|
|
358
|
-
subtract_dust_threshold=True,
|
|
359
|
-
use_stored_data=True,
|
|
360
|
-
):
|
|
361
|
-
"""Obtain the r-shares from vests
|
|
362
|
-
|
|
363
|
-
:param number vests: vesting shares
|
|
364
|
-
:param int post_rshares: rshares of post which is voted
|
|
365
|
-
:param int voting_power: voting power (100% = 10000)
|
|
366
|
-
:param int vote_pct: voting percentage (100% = 10000)
|
|
367
|
-
|
|
368
|
-
"""
|
|
369
|
-
used_power = self._calc_resulting_vote(
|
|
370
|
-
voting_power=voting_power, vote_pct=vote_pct, use_stored_data=use_stored_data
|
|
371
|
-
)
|
|
372
|
-
# calculate vote rshares
|
|
373
|
-
rshares = int(math.copysign(vests * 1e6 * used_power / STEEM_100_PERCENT, vote_pct))
|
|
374
|
-
if subtract_dust_threshold:
|
|
375
|
-
if abs(rshares) <= self.get_dust_threshold(use_stored_data=use_stored_data):
|
|
376
|
-
return 0
|
|
377
|
-
rshares -= math.copysign(
|
|
378
|
-
self.get_dust_threshold(use_stored_data=use_stored_data), vote_pct
|
|
379
|
-
)
|
|
380
|
-
rshares = self._calc_vote_claim(rshares, post_rshares)
|
|
381
|
-
return rshares
|
|
382
|
-
|
|
383
|
-
def sbd_to_rshares(self, sbd, not_broadcasted_vote=False, use_stored_data=True):
|
|
384
|
-
"""Obtain the r-shares from SBD
|
|
385
|
-
|
|
386
|
-
:param sbd: SBD
|
|
387
|
-
:type sbd: str, int, amount.Amount
|
|
388
|
-
:param bool not_broadcasted_vote: not_broadcasted or already broadcasted vote (True = not_broadcasted vote).
|
|
389
|
-
Only impactful for very high amounts of SBD. Slight modification to the value calculation, as the not_broadcasted
|
|
390
|
-
vote rshares decreases the reward pool.
|
|
391
|
-
|
|
392
|
-
"""
|
|
393
|
-
if isinstance(sbd, Amount):
|
|
394
|
-
sbd = Amount(sbd, blockchain_instance=self)
|
|
395
|
-
elif isinstance(sbd, str):
|
|
396
|
-
sbd = Amount(sbd, blockchain_instance=self)
|
|
397
|
-
else:
|
|
398
|
-
sbd = Amount(sbd, self.sbd_symbol, blockchain_instance=self)
|
|
399
|
-
if sbd["symbol"] != self.sbd_symbol:
|
|
400
|
-
raise AssertionError("Should input SBD, not any other asset!")
|
|
401
|
-
|
|
402
|
-
# If the vote was already broadcasted we can assume the blockchain values to be true
|
|
403
|
-
if not not_broadcasted_vote:
|
|
404
|
-
return int(float(sbd) / self.get_sbd_per_rshares(use_stored_data=use_stored_data))
|
|
405
|
-
|
|
406
|
-
# If the vote wasn't broadcasted (yet), we have to calculate the rshares while considering
|
|
407
|
-
# the change our vote is causing to the recent_claims. This is more important for really
|
|
408
|
-
# big votes which have a significant impact on the recent_claims.
|
|
409
|
-
reward_fund = self.get_reward_funds(use_stored_data=use_stored_data)
|
|
410
|
-
median_price = self.get_median_price(use_stored_data=use_stored_data)
|
|
411
|
-
recent_claims = int(reward_fund["recent_claims"])
|
|
412
|
-
reward_balance = Amount(reward_fund["reward_balance"], blockchain_instance=self)
|
|
413
|
-
reward_pool_sbd = median_price * reward_balance
|
|
414
|
-
if sbd > reward_pool_sbd:
|
|
415
|
-
raise ValueError("Provided more SBD than available in the reward pool.")
|
|
416
|
-
|
|
417
|
-
# This is the formula we can use to determine the "true" rshares.
|
|
418
|
-
# We get this formula by some math magic using the previous used formulas
|
|
419
|
-
# FundsPerShare = (balance / (claims + newShares)) * Price
|
|
420
|
-
# newShares = amount / FundsPerShare
|
|
421
|
-
# We can now resolve both formulas for FundsPerShare and set the formulas to be equal
|
|
422
|
-
# (balance / (claims + newShares)) * price = amount / newShares
|
|
423
|
-
# Now we resolve for newShares resulting in:
|
|
424
|
-
# newShares = claims * amount / (balance * price - amount)
|
|
425
|
-
rshares = (
|
|
426
|
-
recent_claims
|
|
427
|
-
* float(sbd)
|
|
428
|
-
/ ((float(reward_balance) * float(median_price)) - float(sbd))
|
|
429
|
-
)
|
|
430
|
-
return int(rshares)
|
|
431
|
-
|
|
432
|
-
def rshares_to_vote_pct(
|
|
433
|
-
self,
|
|
434
|
-
rshares,
|
|
435
|
-
post_rshares=0,
|
|
436
|
-
steem_power=None,
|
|
437
|
-
vests=None,
|
|
438
|
-
voting_power=STEEM_100_PERCENT,
|
|
439
|
-
use_stored_data=True,
|
|
440
|
-
):
|
|
441
|
-
"""Obtain the voting percentage for a desired rshares value
|
|
442
|
-
for a given Steem Power or vesting shares and voting_power
|
|
443
|
-
Give either steem_power or vests, not both.
|
|
444
|
-
When the output is greater than 10000 or less than -10000,
|
|
445
|
-
the given absolute rshares are too high
|
|
446
|
-
|
|
447
|
-
Returns the required voting percentage (100% = 10000)
|
|
448
|
-
|
|
449
|
-
:param number rshares: desired rshares value
|
|
450
|
-
:param number steem_power: Steem Power
|
|
451
|
-
:param number vests: vesting shares
|
|
452
|
-
:param int voting_power: voting power (100% = 10000)
|
|
453
|
-
|
|
454
|
-
"""
|
|
455
|
-
if steem_power is None and vests is None:
|
|
456
|
-
raise ValueError("Either steem_power or vests has to be set!")
|
|
457
|
-
if steem_power is not None and vests is not None:
|
|
458
|
-
raise ValueError("Either steem_power or vests has to be set. Not both!")
|
|
459
|
-
if steem_power is not None:
|
|
460
|
-
vests = int(self.sp_to_vests(steem_power, use_stored_data=use_stored_data) * 1e6)
|
|
461
|
-
|
|
462
|
-
if self.hardfork >= 20:
|
|
463
|
-
rshares += math.copysign(
|
|
464
|
-
self.get_dust_threshold(use_stored_data=use_stored_data), rshares
|
|
465
|
-
)
|
|
466
|
-
|
|
467
|
-
if post_rshares >= 0 and rshares > 0:
|
|
468
|
-
rshares = math.copysign(
|
|
469
|
-
self._calc_revert_vote_claim(abs(rshares), post_rshares), rshares
|
|
470
|
-
)
|
|
471
|
-
elif post_rshares < 0 and rshares < 0:
|
|
472
|
-
rshares = math.copysign(
|
|
473
|
-
self._calc_revert_vote_claim(abs(rshares), abs(post_rshares)), rshares
|
|
474
|
-
)
|
|
475
|
-
elif post_rshares < 0 and rshares > 0:
|
|
476
|
-
rshares = math.copysign(self._calc_revert_vote_claim(abs(rshares), 0), rshares)
|
|
477
|
-
elif post_rshares > 0 and rshares < 0:
|
|
478
|
-
rshares = math.copysign(
|
|
479
|
-
self._calc_revert_vote_claim(abs(rshares), post_rshares), rshares
|
|
480
|
-
)
|
|
481
|
-
|
|
482
|
-
max_vote_denom = self._max_vote_denom(use_stored_data=use_stored_data)
|
|
483
|
-
|
|
484
|
-
used_power = int(math.ceil(abs(rshares) * STEEM_100_PERCENT / vests))
|
|
485
|
-
used_power = used_power * max_vote_denom
|
|
486
|
-
|
|
487
|
-
vote_pct = used_power * STEEM_100_PERCENT / (60 * 60 * 24) / voting_power
|
|
488
|
-
return int(math.copysign(vote_pct, rshares))
|
|
489
|
-
|
|
490
|
-
def sbd_to_vote_pct(
|
|
491
|
-
self,
|
|
492
|
-
sbd,
|
|
493
|
-
post_rshares=0,
|
|
494
|
-
steem_power=None,
|
|
495
|
-
vests=None,
|
|
496
|
-
voting_power=STEEM_100_PERCENT,
|
|
497
|
-
not_broadcasted_vote=True,
|
|
498
|
-
use_stored_data=True,
|
|
499
|
-
):
|
|
500
|
-
"""Obtain the voting percentage for a desired SBD value
|
|
501
|
-
for a given Steem Power or vesting shares and voting power
|
|
502
|
-
Give either Steem Power or vests, not both.
|
|
503
|
-
When the output is greater than 10000 or smaller than -10000,
|
|
504
|
-
the SBD value is too high.
|
|
505
|
-
|
|
506
|
-
Returns the required voting percentage (100% = 10000)
|
|
507
|
-
|
|
508
|
-
:param sbd: desired SBD value
|
|
509
|
-
:type sbd: str, int, amount.Amount
|
|
510
|
-
:param number steem_power: Steem Power
|
|
511
|
-
:param number vests: vesting shares
|
|
512
|
-
:param bool not_broadcasted_vote: not_broadcasted or already broadcasted vote (True = not_broadcasted vote).
|
|
513
|
-
Only impactful for very high amounts of SBD. Slight modification to the value calculation, as the not_broadcasted
|
|
514
|
-
vote rshares decreases the reward pool.
|
|
515
|
-
|
|
516
|
-
"""
|
|
517
|
-
if isinstance(sbd, Amount):
|
|
518
|
-
sbd = Amount(sbd, blockchain_instance=self)
|
|
519
|
-
elif isinstance(sbd, str):
|
|
520
|
-
sbd = Amount(sbd, blockchain_instance=self)
|
|
521
|
-
else:
|
|
522
|
-
sbd = Amount(sbd, self.sbd_symbol, blockchain_instance=self)
|
|
523
|
-
if sbd["symbol"] != self.sbd_symbol:
|
|
524
|
-
raise AssertionError()
|
|
525
|
-
rshares = self.sbd_to_rshares(
|
|
526
|
-
sbd, not_broadcasted_vote=not_broadcasted_vote, use_stored_data=use_stored_data
|
|
527
|
-
)
|
|
528
|
-
return self.rshares_to_vote_pct(
|
|
529
|
-
rshares,
|
|
530
|
-
post_rshares=post_rshares,
|
|
531
|
-
steem_power=steem_power,
|
|
532
|
-
vests=vests,
|
|
533
|
-
voting_power=voting_power,
|
|
534
|
-
use_stored_data=use_stored_data,
|
|
535
|
-
)
|
|
536
|
-
|
|
537
|
-
@property
|
|
538
|
-
def chain_params(self):
|
|
539
|
-
if self.offline or self.rpc is None:
|
|
540
|
-
return known_chains["STEEM"]
|
|
541
|
-
else:
|
|
542
|
-
return self.get_network()
|
|
543
|
-
|
|
544
|
-
@property
|
|
545
|
-
def hardfork(self):
|
|
546
|
-
if self.offline or self.rpc is None:
|
|
547
|
-
versions = known_chains["STEEM"]["min_version"]
|
|
548
|
-
else:
|
|
549
|
-
hf_prop = self.get_hardfork_properties()
|
|
550
|
-
if "current_hardfork_version" in hf_prop:
|
|
551
|
-
versions = hf_prop["current_hardfork_version"]
|
|
552
|
-
else:
|
|
553
|
-
versions = self.get_blockchain_version()
|
|
554
|
-
return int(versions.split(".")[1])
|
|
555
|
-
|
|
556
|
-
@property
|
|
557
|
-
def is_steem(self):
|
|
558
|
-
config = self.get_config()
|
|
559
|
-
if config is None:
|
|
560
|
-
return True
|
|
561
|
-
return "STEEM_CHAIN_ID" in self.get_config()
|
|
562
|
-
|
|
563
|
-
@property
|
|
564
|
-
def sbd_symbol(self):
|
|
565
|
-
"""get the current chains symbol for SBD (e.g. "TBD" on testnet)"""
|
|
566
|
-
# some networks (e.g. whaleshares) do not have SBD
|
|
567
|
-
try:
|
|
568
|
-
symbol = self._get_asset_symbol(0)
|
|
569
|
-
except KeyError:
|
|
570
|
-
symbol = self._get_asset_symbol(1)
|
|
571
|
-
return symbol
|
|
572
|
-
|
|
573
|
-
@property
|
|
574
|
-
def steem_symbol(self):
|
|
575
|
-
"""get the current chains symbol for STEEM (e.g. "TESTS" on testnet)"""
|
|
576
|
-
return self._get_asset_symbol(1)
|
|
577
|
-
|
|
578
|
-
@property
|
|
579
|
-
def vests_symbol(self):
|
|
580
|
-
"""get the current chains symbol for VESTS"""
|
|
581
|
-
return self._get_asset_symbol(2)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|