Skip to content

Commit

Permalink
Improved chain detection
Browse files Browse the repository at this point in the history
* Improve chain detection (Steem chain detection fixed and preparing for Hive HF24)
* Add authored_by and description fields in YAMLM header
* Improve doc
* beempy post image upload includes the markdown file path now
  • Loading branch information
holgern committed May 20, 2020
1 parent 7d028a4 commit 3d632e1
Show file tree
Hide file tree
Showing 12 changed files with 112 additions and 88 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
Changelog
=========
0.23.9
------
* Improve chain detection (Steem chain detection fixed and preparing for Hive HF24)
* Add authored_by and description fields in YAMLM header
* Improve doc
* beempy post image upload includes the markdown file path now

0.23.8
------
* Missing dongle.close() added (thanks to @netuoso)

0.23.7
------
* Fix update_account_jsonmetadata and add posting_json_metadata property to Account
Expand Down
17 changes: 14 additions & 3 deletions beem/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2169,6 +2169,10 @@ def download(permlink, account, save, export):
yaml_prefix += 'title: "%s"\n' % comment["title"]
yaml_prefix += 'permlink: %s\n' % comment["permlink"]
yaml_prefix += 'author: %s\n' % comment["author"]
if "author" in comment.json_metadata:
yaml_prefix += 'authored by: %s\n' % comment.json_metadata["author"]
if "description" in comment.json_metadata:
yaml_prefix += 'description: "%s"\n' % comment.json_metadata["description"]
yaml_prefix += 'last_update: %s\n' % comment.json()["last_update"]
yaml_prefix += 'max_accepted_payout: %s\n' % str(comment["max_accepted_payout"])
yaml_prefix += 'percent_steem_dollars: %s\n' % str(comment["percent_steem_dollars"])
Expand Down Expand Up @@ -2299,7 +2303,11 @@ def post(markdown_file, account, title, permlink, tags, reply_identifier, commun
beneficiaries = derive_beneficiaries(parameter["beneficiaries"])
for b in beneficiaries:
Account(b["account"], blockchain_instance=stm)

json_metadata = {}
if "authored_by" in parameter:
json_metadata["authored_by"] = parameter["authored_by"]
if "description" in parameter:
json_metadata["description"] = parameter["description"]
if permlink is not None:
try:
comment = Comment(construct_authorperm(author, permlink), blockchain_instance=stm)
Expand All @@ -2316,10 +2324,13 @@ def post(markdown_file, account, title, permlink, tags, reply_identifier, commun
continue
if stm.unsigned:
continue
basepath = os.path.dirname(markdown_file)
if os.path.exists(image):
tx = iu.upload(image, author, image_name)
body = body.replace(image, tx["url"])

elif os.path.exists(os.path.join(basepath, image)):
tx = iu.upload(image, author, image_name)
body = body.replace(image, tx["url"])

if comment is None and permlink is None and reply_identifier is None:
permlink = derive_permlink(title, with_suffix=False)
Expand All @@ -2333,7 +2344,7 @@ def post(markdown_file, account, title, permlink, tags, reply_identifier, commun
if reply_identifier is None and (len(tags) == 0 or tags is None):
raise ValueError("Tags must not be empty!")
tx = stm.post(title, body, author=author, permlink=permlink, reply_identifier=reply_identifier, community=community,
tags=tags, comment_options=comment_options, beneficiaries=beneficiaries, parse_body=parse_body,
tags=tags, json_metadata=json_metadata, comment_options=comment_options, beneficiaries=beneficiaries, parse_body=parse_body,
app='beempy/%s' % (__version__))
else:
import diff_match_patch as dmp_module
Expand Down
2 changes: 1 addition & 1 deletion beem/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"""THIS FILE IS GENERATED FROM beem SETUP.PY."""
version = '0.23.7'
version = '0.23.9'
6 changes: 4 additions & 2 deletions beemapi/graphenerpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,12 @@ def get_network(self, props=None):

if chain_id is None:
raise("Connecting to unknown network!")
if is_hive:
return self.known_chains["HIVE"]
highest_version_chain = None
for k, v in list(self.known_chains.items()):
if is_hive and k not in ["HIVE", "HIVE2"]:
continue
if is_steem and k not in ["STEEMZERO", "STEEM", "STEEMAPPBASE"]:
continue
if v["chain_id"] == chain_id and self.version_string_to_int(v["min_version"]) <= self.version_string_to_int(network_version):
if highest_version_chain is None:
highest_version_chain = v
Expand Down
2 changes: 1 addition & 1 deletion beemapi/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"""THIS FILE IS GENERATED FROM beem SETUP.PY."""
version = '0.23.7'
version = '0.23.9'
2 changes: 1 addition & 1 deletion beembase/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"""THIS FILE IS GENERATED FROM beem SETUP.PY."""
version = '0.23.7'
version = '0.23.9'
2 changes: 1 addition & 1 deletion beemgraphenebase/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"""THIS FILE IS GENERATED FROM beem SETUP.PY."""
version = '0.23.7'
version = '0.23.9'
28 changes: 14 additions & 14 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ About this Library
------------------

The purpose of *beem* is to simplify development of products and
services that use the Steem blockchain. It comes with
services that use the Hive blockchain. It comes with

* its own (bip32-encrypted) wallet
* RPC interface for the Blockchain backend
Expand All @@ -63,10 +63,10 @@ Quickstart

.. code-block:: python
from beem import Steem
steem = Steem()
steem.wallet.unlock("wallet-passphrase")
account = Account("test", steem_instance=steem)
from beem import Hive
hive = Hive()
hive.wallet.unlock("wallet-passphrase")
account = Account("test", blockchain_instance=hive)
account.transfer("<to>", "<amount>", "<asset>", "<memo>")
.. code-block:: python
Expand All @@ -91,21 +91,21 @@ Quickstart
.. code-block:: python
from beem.steem import Steem
stm = Steem()
stm.wallet.wipe(True)
stm.wallet.create("wallet-passphrase")
stm.wallet.unlock("wallet-passphrase")
stm.wallet.addPrivateKey("512345678")
stm.wallet.lock()
from beem.hive import Hive
hive = Hive()
hive.wallet.wipe(True)
hive.wallet.create("wallet-passphrase")
hive.wallet.unlock("wallet-passphrase")
hive.wallet.addPrivateKey("512345678")
hive.wallet.lock()
.. code-block:: python
from beem.market import Market
market = Market("SBD:STEEM")
market = Market("HBD:HIVE")
print(market.ticker())
market.steem.wallet.unlock("wallet-passphrase")
print(market.sell(300, 100) # sell 100 STEEM for 300 STEEM/SBD
print(market.sell(300, 100) # sell 100 HIVE for 300 HIVE/HBD
General
Expand Down
2 changes: 1 addition & 1 deletion docs/installation.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Installation
============
The minimal working python version is 2.7.x. or 3.4.x
The minimal working python version is 3.5.x

beem can be installed parallel to python-steem.

Expand Down
110 changes: 55 additions & 55 deletions docs/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Nodes for using beem with the Hive blockchain can be set by the command line too
beempy updatenodes --hive
Nodes for the Steem blockchain are set with
Nodes for the Hive blockchain are set with

.. code-block:: bash
Expand All @@ -21,12 +21,12 @@ Hive nodes can be set in a python script with

.. code-block:: python
from beem import Steem
from beem import Hive
from beem.nodelist import NodeList
nodelist = NodeList()
nodelist.update_nodes()
nodes = nodelist.get_nodes(hive=True)
hive = Steem(node=nodes)
nodes = nodelist.get_hive_nodes()
hive = Hive(node=nodes)
print(hive.is_hive)
Steem nodes can be set in a python script with
Expand All @@ -37,40 +37,40 @@ Steem nodes can be set in a python script with
from beem.nodelist import NodeList
nodelist = NodeList()
nodelist.update_nodes()
nodes = nodelist.get_nodes(hive=False)
nodes = nodelist.get_steem_nodes()
hive = Steem(node=nodes)
print(hive.is_hive)
Steem
-----
The steem object is the connection to the Steem/Hive blockchain.
Hive
----
The hive object is the connection to the Hive blockchain.
By creating this object different options can be set.

.. note:: All init methods of beem classes can be given
the ``steem_instance=`` parameter to assure that
the ``blockchain_instance=`` parameter to assure that
all objects use the same steem object. When the
``steem_instance=`` parameter is not used, the
steem object is taken from get_shared_steem_instance().
``blockchain_instance=`` parameter is not used, the
steem object is taken from get_shared_blockchain_instance().

:func:`beem.instance.shared_steem_instance` returns a global instance of steem.
It can be set by :func:`beem.instance.set_shared_steem_instance` otherwise it is created
:func:`beem.instance.shared_blockchain_instance` returns a global instance of steem.
It can be set by :func:`beem.instance.set_shared_blockchain_instance` otherwise it is created
on the first call.

.. code-block:: python
from beem import Steem
from beem import Hive
from beem.account import Account
stm = Steem()
account = Account("test", steem_instance=stm)
hive = Hive()
account = Account("test", blockchain_instance=hive)
.. code-block:: python
from beem import Steem
from beem import Hive
from beem.account import Account
from beem.instance import set_shared_steem_instance
stm = Steem()
set_shared_steem_instance(stm)
from beem.instance import set_shared_blockchain_instance
hive = Hive()
set_shared_blockchain_instance(hive)
account = Account("test")
Wallet and Keys
Expand All @@ -93,44 +93,44 @@ stored encrypted in a sql-database (wallet).

Creating a wallet
~~~~~~~~~~~~~~~~~
``steem.wallet.wipe(True)`` is only necessary when there was already an wallet created.
``hive.wallet.wipe(True)`` is only necessary when there was already an wallet created.

.. code-block:: python
from beem import Steem
steem = Steem()
steem.wallet.wipe(True)
steem.wallet.unlock("wallet-passphrase")
from beem import Hive
hive = Hive()
hive.wallet.wipe(True)
hive.wallet.unlock("wallet-passphrase")
Adding keys to the wallet
~~~~~~~~~~~~~~~~~~~~~~~~~
.. code-block:: python
from beem import Steem
steem = Steem()
steem.wallet.unlock("wallet-passphrase")
steem.wallet.addPrivateKey("xxxxxxx")
steem.wallet.addPrivateKey("xxxxxxx")
hive = Hive()
hive.wallet.unlock("wallet-passphrase")
hive.wallet.addPrivateKey("xxxxxxx")
hive.wallet.addPrivateKey("xxxxxxx")
Using the keys in the wallet
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. code-block:: python
from beem import Steem
steem = Steem()
steem.wallet.unlock("wallet-passphrase")
account = Account("test", steem_instance=steem)
from beem import Hive
hive = Hive()
hive.wallet.unlock("wallet-passphrase")
account = Account("test", blockchain_instance=hive)
account.transfer("<to>", "<amount>", "<asset>", "<memo>")
Private keys can also set temporary
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. code-block:: python
from beem import Steem
steem = Steem(keys=["xxxxxxxxx"])
account = Account("test", steem_instance=steem)
from beem import Hive
hive = Hive(keys=["xxxxxxxxx"])
account = Account("test", blockchain_instance=hive)
account.transfer("<to>", "<amount>", "<asset>", "<memo>")
Receiving information about blocks, accounts, votes, comments, market and witness
Expand Down Expand Up @@ -190,7 +190,7 @@ Access the market
.. code-block:: python
from beem.market import Market
market = Market("SBD:STEEM")
market = Market("HBD:HIVE")
print(market.ticker())
Access a witness
Expand All @@ -208,40 +208,40 @@ Sending a Transfer

.. code-block:: python
from beem import Steem
steem = Steem()
steem.wallet.unlock("wallet-passphrase")
account = Account("test", steem_instance=steem)
from beem import Hive
hive = Hive()
hive.wallet.unlock("wallet-passphrase")
account = Account("test", blockchain_instance=hive)
account.transfer("null", 1, "SBD", "test")
Upvote a post

.. code-block:: python
from beem.comment import Comment
from beem import Steem
steem = Steem()
steem.wallet.unlock("wallet-passphrase")
comment = Comment("@gtg/ffdhu-gtg-witness-log", steem_instance=steem)
from beem import Hive
hive = Hive()
hive.wallet.unlock("wallet-passphrase")
comment = Comment("@gtg/ffdhu-gtg-witness-log", blockchain_instance=hive)
comment.upvote(weight=10, voter="test")
Publish a post to the blockchain

.. code-block:: python
from beem import Steem
steem = Steem()
steem.wallet.unlock("wallet-passphrase")
steem.post("title", "body", author="test", tags=["a", "b", "c", "d", "e"], self_vote=True)
from beem import Hive
hive = Hive()
hive.wallet.unlock("wallet-passphrase")
hive.post("title", "body", author="test", tags=["a", "b", "c", "d", "e"], self_vote=True)
Sell STEEM on the market
Sell HIVE on the market

.. code-block:: python
from beem.market import Market
from beem import Steem
steem.wallet.unlock("wallet-passphrase")
market = Market("SBD:STEEM", steem_instance=steem)
from beem import Hive
hive.wallet.unlock("wallet-passphrase")
market = Market("HBD:HIVE", blockchain_instance=hive)
print(market.ticker())
market.steem.wallet.unlock("wallet-passphrase")
print(market.sell(300, 100)) # sell 100 STEEM for 300 STEEM/SBD
market.hive.wallet.unlock("wallet-passphrase")
print(market.sell(300, 100)) # sell 100 HIVE for 300 HIVE/HBD
Loading

0 comments on commit 3d632e1

Please sign in to comment.