Skip to content

Commit

Permalink
account:
Browse files Browse the repository at this point in the history
 * reputation added
* history improved and fixed
block:
* ops and ops_statistics added
blockchain:
* function-names improved
* ops_statistics added
blockchainobject
*json export added
Comment class added
Discussion class added
steem:
* follow and account by key api added and fixed
storage:
* more nodes added
utils
* Helpfunctions added
 vote
* blockchainobject
* refresh fixed
wallet
* purgeWallet added
Witness
* printAsTable function added
* WitnessesVotedByAccount added
* WitnessesRankedByVote added
* WitnessesByIds added
* LookupWitnesses added
Steemnoderpc
* register_apis fixed
test_wallet
* unit tests added
test_utils
* unittests added
  • Loading branch information
holgern committed Feb 21, 2018
1 parent 761a3a6 commit 47cf2b4
Show file tree
Hide file tree
Showing 36 changed files with 874 additions and 116 deletions.
9 changes: 9 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ Documentation is available at http://steempy.readthedocs.io/en/latest/

Changelog
=========

0.19.3
------
* Add Comment/Post
* Add Witness
* Several bugfixes
* Added all transactions that are supported from steem-python
* New library name planned: beem

0.19.2
------
* Notify and websocket fixed
Expand Down
17 changes: 17 additions & 0 deletions docs/comment.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Comment
~~~~~~~

Read data about a Comment/Post

.. code-block:: python
from steempy.comment import Comment
Witness("gtg")
.. autoclass:: steempy.comment.Comment
:members:

.. autoclass:: steempy.comment.Comments
:members:


9 changes: 4 additions & 5 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@
Welcome to steempy's documentation!
===============================================

Steem is a **blockchain-based autonomous company** (i.e. a DAC) that
offers decentralized exchanging as well as sophisticated financial
instruments as *products*.
Steem is a blockchain-based rewards platform for publishers to monetize
content and grow community.

It is based on *Graphene* (tm), a blockchain technology stack (i.e.
software) that allows for fast transactions and ascalable blockchain
solution. In case of Steem, it comes with decentralized trading of
assets as well as customized on-chain smart contracts.
solution. In case of Steem, it comes with decentralized publishing of
content.

About this Library
------------------
Expand Down
15 changes: 15 additions & 0 deletions docs/vote.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Vote
~~~~

Read data about a vote

.. code-block:: python
from steempy.vote import Vote
Witness("gtg")
.. autoclass:: steempy.vote.Vote
:members:



13 changes: 13 additions & 0 deletions docs/witness.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,16 @@ Read data about a witness

.. autoclass:: steempy.witness.Witnesses
:members:

.. autoclass:: steempy.witness.WitnessesVotedByAccount
:members:

.. autoclass:: steempy.witness.WitnessesRankedByVote
:members:

.. autoclass:: steempy.witness.WitnessesByIds
:members:

.. autoclass:: steempy.witness.LookupWitnesses
:members:

2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
ascii = codecs.lookup('ascii')
codecs.register(lambda name, enc=ascii: {True: enc}.get(name == 'mbcs'))

VERSION = '0.19.2'
VERSION = '0.19.3'


def write_version_py(filename):
Expand Down
4 changes: 3 additions & 1 deletion steempy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@
"utils",
"wallet",
"vote",
"message"
"message",
"comment",
"discussions"
]
56 changes: 39 additions & 17 deletions steempy/account.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from steempy.instance import shared_steem_instance
from .exceptions import AccountDoesNotExistsException
from .blockchainobject import BlockchainObject
from .utils import formatTimeString
from datetime import datetime
import json
import math


class Account(BlockchainObject):
Expand Down Expand Up @@ -40,7 +43,7 @@ def __init__(
self,
account,
id_item="name",
full=False,
full=True,
lazy=False,
steem_instance=None
):
Expand Down Expand Up @@ -68,7 +71,7 @@ def refresh(self):
account = account[0]
if not account:
raise AccountDoesNotExistsException(self.identifier)
# self.identifier = account["id"]
self.identifier = account["name"]

super(Account, self).__init__(account, id_item="name")

Expand All @@ -87,6 +90,22 @@ def profile(self):
"""
return json.loads(self["json_metadata"])["profile"]

@property
def rep(self):
return self.reputation()

def reputation(self, precision=2):
rep = int(self['reputation'])
if rep == 0:
return 25
score = (math.log10(abs(rep)) - 9) * 9 + 25
if rep < 0:
score = 50 - score
if precision is not None:
return round(score, precision)
else:
return score

@property
def available_balances(self):
""" List balances of an account. This call returns instances of
Expand Down Expand Up @@ -173,24 +192,20 @@ def ensure_full(self):
self.refresh()

def history(
self, first=None,
limit=100,
self, limit=100,
only_ops=[], exclude_ops=[]
):
""" Returns a generator for individual account transactions. The
latest operation will be first. This call can be used in a
``for`` loop.
:param int first: sequence number of the first
transaction to return (*optional*)
:param int limit: limit number of transactions to
:param int/datetime limit: limit number of transactions to
return (*optional*)
:param array only_ops: Limit generator by these
operations (*optional*)
:param array exclude_ops: Exclude thse operations from
generator (*optional*)
"""
from steempybase.operations import getOperationNameForId
_limit = 100
cnt = 0

Expand All @@ -202,9 +217,7 @@ def history(
if not mostrecent:
return

if not first:
# first = int(mostrecent[0].get("id").split(".")[2]) + 1
first = 9999999999
first = int(mostrecent[0][0])

while True:
# RPC call
Expand All @@ -213,21 +226,30 @@ def history(
first,
_limit,
)
for i in txs:
for i in reversed(txs):
if exclude_ops and i[1]["op"][0] in exclude_ops:
continue
if not only_ops or i[1]["op"][0] in only_ops:
cnt += 1
yield i
if limit >= 0 and cnt >= limit:
return

if isinstance(limit, datetime):
timediff = limit - formatTimeString(i[1]["timestamp"])
if timediff.total_seconds() > 0:
return
yield i
else:
yield i
if limit >= 0 and cnt >= limit:
return
if not txs:
break
if len(txs) < _limit:
break
# first = int(txs[-1]["id"].split(".")[2])
first = txs[-1][1]["block"]
first = txs[0][0]
if first < 2:
break
if first < _limit:
_limit = first - 1

# def upgrade(self):
# return self.steem.upgrade_account(account=self)
Expand Down
23 changes: 23 additions & 0 deletions steempy/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,29 @@ def time(self):
"""
return parse_time(self['timestamp'])

def ops(self):
ops = []
for tx in self["transactions"]:
for op in tx["operations"]:
# Replace opid by op name
# op[0] = getOperationNameForId(op[0])
ops.append(op)
return ops

def ops_statistics(self, add_to_ops_stat=None):
if add_to_ops_stat is None:
import steempybase.operationids
ops_stat = steempybase.operationids.operations.copy()
for key in ops_stat:
ops_stat[key] = 0
else:
ops_stat = add_to_ops_stat.copy()

for tx in self["transactions"]:
for op in tx["operations"]:
ops_stat[op[0]] += 1
return ops_stat


class BlockHeader(BlockchainObject):
def refresh(self):
Expand Down
61 changes: 51 additions & 10 deletions steempy/blockchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,27 @@ def __init__(
else:
raise ValueError("invalid value for 'mode'!")

def info(self):
def get_dynamic_global_properties(self):
""" This call returns the *dynamic global properties*
"""
return self.steem.rpc.get_dynamic_global_properties()

def feed_history(self):
def get_feed_history(self):
""" Returns the feed_history
"""
return self.steem.rpc.get_feed_history()

def current_median_history_price(self):
def get_current_median_history_price(self):
""" Returns the current median price
"""
return self.steem.rpc.get_current_median_history_price()

def next_scheduled_hardfork(self):
def get_next_scheduled_hardfork(self):
""" Returns Hardfork and live_time of the hardfork
"""
return self.steem.rpc.get_next_scheduled_hardfork()

def hardfork_version(self):
def get_hardfork_version(self):
""" Current Hardfork Version as String
"""
return self.steem.rpc.get_hardfork_version()
Expand All @@ -63,12 +63,23 @@ def get_network(self):
return self.steem.rpc.get_network()

def get_chain_properties(self):
""" Return chain properties
""" Return witness elected chain properties
::
{'account_creation_fee': '30.000 STEEM',
'maximum_block_size': 65536,
'sbd_interest_rate': 250}
"""
return self.steem.rpc.get_chain_properties()

def config(self):
""" Returns config
def get_state(self, path="value"):
""" get_state
"""
return self.steem.rpc.get_state(path)

def get_config(self):
""" Returns internal chain configuration.
"""
return self.steem.rpc.get_config()

Expand All @@ -78,7 +89,7 @@ def get_current_block_num(self):
.. note:: The block number returned depends on the ``mode`` used
when instanciating from this class.
"""
return self.info().get(self.mode)
return self.get_dynamic_global_properties().get(self.mode)

def get_current_block(self):
""" This call returns the current block
Expand Down Expand Up @@ -123,7 +134,7 @@ def blocks(self, start=None, stop=None):
confirmed by 2/3 of all block producers and is thus irreversible)
"""
# Let's find out how often blocks are generated!
block_interval = self.config().get("STEEMIT_BLOCK_INTERVAL")
block_interval = self.get_config().get("STEEMIT_BLOCK_INTERVAL")

if not start:
start = self.get_current_block_num()
Expand Down Expand Up @@ -179,6 +190,36 @@ def ops(self, start=None, stop=None, **kwargs):
"timestamp": block["timestamp"]
}

def ops_statistics(self, start, stop=None, add_to_ops_stat=None, verbose=True):
""" Generates a statistics for all operations (including virtual operations) starting from
``start``.
:param int start: Starting block
:param int stop: Stop at this block, if set to None, the current_block_num is taken
:param dict add_to_ops_stat, if set, the result is added to add_to_ops_stat
:param bool verbose, if True, the current block number and timestamp is printed
This call returns a dict with all possible operations and their occurence.
"""
if add_to_ops_stat is None:
import steempybase.operationids
ops_stat = steempybase.operationids.operations.copy()
for key in ops_stat:
ops_stat[key] = 0
else:
ops_stat = add_to_ops_stat.copy()
current_block = self.get_current_block_num()
if start > current_block:
return
if stop is None:
stop = current_block
for block in self.blocks(start=start, stop=stop):
if verbose:
print(str(block["block_num"]) + " " + block["timestamp"])
for tx in block["transactions"]:
for op in tx["operations"]:
ops_stat[op[0]] += 1
return ops_stat

def stream(self, opNames=[], *args, **kwargs):
""" Yield specific operations (e.g. comments) only
Expand Down
Loading

0 comments on commit 47cf2b4

Please sign in to comment.