From 67b91364ac04036d66066c7e591c837fad9fc4f7 Mon Sep 17 00:00:00 2001
From: Holger Nahrstaedt <holger@nahrstaedt.de>
Date: Tue, 1 May 2018 07:57:10 +0200
Subject: [PATCH] Layout of the doc improved and new content added

Layout of the doc improved in blockchain, discussions, steem, transactionbuilder, websocket
New content added to quickstart and tutorial
---
 beem/blockchain.py         |  8 +++-
 beem/discussions.py        |  1 +
 beem/steem.py              | 18 ++++----
 beem/transactionbuilder.py | 26 ++++++------
 beemapi/websocket.py       |  9 ----
 docs/quickstart.rst        | 33 ++++++++++++++-
 docs/tutorials.rst         | 85 ++++++++++++++++++++++++++++++++++++++
 7 files changed, 144 insertions(+), 36 deletions(-)

diff --git a/beem/blockchain.py b/beem/blockchain.py
index 9dc74b7b..23dac556 100644
--- a/beem/blockchain.py
+++ b/beem/blockchain.py
@@ -40,18 +40,21 @@ class Blockchain(object):
 
         This class let's you deal with blockchain related data and methods.
         Read blockchain related data:
+
         .. testsetup::
 
             from beem.blockchain import Blockchain
             chain = Blockchain()
 
         Read current block and blockchain info
+
         .. testcode::
 
-            print(chain.get_current_block())  # doctest: +SKIP
-            print(chain.steem.info())  # doctest: +SKIP
+            print(chain.get_current_block())
+            print(chain.steem.info())
 
         Monitor for new blocks. When ``stop`` is not set, monitoring will never stop.
+
         .. testcode::
 
             blocks = []
@@ -65,6 +68,7 @@ class Blockchain(object):
             100
 
         or each operation individually:
+
         .. testcode::
 
             ops = []
diff --git a/beem/discussions.py b/beem/discussions.py
index 7aded8d2..ec4e0a2a 100644
--- a/beem/discussions.py
+++ b/beem/discussions.py
@@ -26,6 +26,7 @@ class Query(dict):
         :param str parent_permlink:
 
         .. testcode::
+
             from beem.discussions import Query
             query = Query(limit=10, tag="steemit")
 
diff --git a/beem/steem.py b/beem/steem.py
index 310511ec..07ab5e13 100644
--- a/beem/steem.py
+++ b/beem/steem.py
@@ -649,18 +649,16 @@ class Steem(object):
                 TransactionBuilder (see :func:`steem.new_tx()`) to specify
                 where to put a specific operation.
 
-            ... note:: ``append_to`` is exposed to every method used in the
+            .. note:: ``append_to`` is exposed to every method used in the
                 Steem class
 
-            ... note::
+            .. note::   If ``ops`` is a list of operation, they all need to be
+                        signable by the same key! Thus, you cannot combine ops
+                        that require active permission with ops that require
+                        posting permission. Neither can you use different
+                        accounts for different operations!
 
-                If ``ops`` is a list of operation, they all need to be
-                signable by the same key! Thus, you cannot combine ops
-                that require active permission with ops that require
-                posting permission. Neither can you use different
-                accounts for different operations!
-
-            ... note:: This uses ``beem.txbuffer`` as instance of
+            .. note:: This uses ``beem.txbuffer`` as instance of
                 :class:`beem.transactionbuilder.TransactionBuilder`.
                 You may want to use your own txbuffer
         """
@@ -1044,7 +1042,7 @@ class Steem(object):
             :param dict props: Properties
             :param str account: (optional) witness account name
 
-             Properties:::
+            Properties:::
 
                 {
                     "account_creation_fee": x,
diff --git a/beem/transactionbuilder.py b/beem/transactionbuilder.py
index ad96f46f..a58f5d52 100644
--- a/beem/transactionbuilder.py
+++ b/beem/transactionbuilder.py
@@ -34,19 +34,19 @@ class TransactionBuilder(dict):
         :param str expiration: expiration date
         :param Steem steem_instance: If not set, shared_steem_instance() is used
 
-        .. code-block:: python
-
-           >>> from beem.transactionbuilder import TransactionBuilder
-           >>> from beembase.operations import Transfer
-           >>> from beem import Steem
-           >>> wif = "5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3"
-           >>> stm = Steem(nobroadcast=True, keys={'active': wif})
-           >>> tx = TransactionBuilder(steem_instance=stm)
-           >>> transfer = {"from": "test", "to": "test1", "amount": "1 STEEM", "memo": ""}
-           >>> tx.appendOps(Transfer(transfer))
-           >>> tx.appendSigner("test", "active") # or tx.appendWif(wif)
-           >>> signed_tx = tx.sign()
-           >>> broadcast_tx = tx.broadcast()
+        .. testcode::
+
+           from beem.transactionbuilder import TransactionBuilder
+           from beembase.operations import Transfer
+           from beem import Steem
+           wif = "5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3"
+           stm = Steem(nobroadcast=True, keys={'active': wif})
+           tx = TransactionBuilder(steem_instance=stm)
+           transfer = {"from": "test", "to": "test1", "amount": "1 STEEM", "memo": ""}
+           tx.appendOps(Transfer(transfer))
+           tx.appendSigner("test", "active") # or tx.appendWif(wif)
+           signed_tx = tx.sign()
+           broadcast_tx = tx.broadcast()
 
     """
     def __init__(
diff --git a/beemapi/websocket.py b/beemapi/websocket.py
index 19813bb9..ed1c0494 100644
--- a/beemapi/websocket.py
+++ b/beemapi/websocket.py
@@ -47,15 +47,6 @@ class SteemWebsocket(Events):
             ws.on_block += print
             ws.run_forever()
 
-        Notices:
-
-        * ``on_block``:
-
-            .. code-block:: js
-
-                '0062f19df70ecf3a478a84b4607d9ad8b3e3b607'
-
-
     """
     __events__ = [
         'on_block',
diff --git a/docs/quickstart.rst b/docs/quickstart.rst
index 3c529d4d..bb8e2cd5 100644
--- a/docs/quickstart.rst
+++ b/docs/quickstart.rst
@@ -91,7 +91,9 @@ Private keys can also set temporary
    account.transfer("<to>", "<amount>", "<asset>", "<memo>")
 
 Receiving information about blocks, accounts, votes, comments, market and witness
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+---------------------------------------------------------------------------------
+
+Recieve all Blocks from the Blockchain
 
 .. code-block:: python
 
@@ -100,11 +102,15 @@ Receiving information about blocks, accounts, votes, comments, market and witnes
    for op in Blockchain.ops():
        print(op)
 
+Access one Block
+
 .. code-block:: python
 
    from beem.block import Block
    print(Block(1))
 
+Access an account
+
 .. code-block:: python
 
    from beem.account import Account
@@ -113,24 +119,39 @@ Receiving information about blocks, accounts, votes, comments, market and witnes
    for h in account.history():
        print(h)
 
+A single vote
+
 .. code-block:: python
 
    from beem.vote import Vote
    vote = Vote(u"@gtg/ffdhu-gtg-witness-log|gandalf")
    print(vote.json())
 
+All votes from an account
+
+.. code-block:: python
+
+   from beem.vote import AccountVotes
+   allVotes = AccountVotes("gtg")
+
+Access a post
+
 .. code-block:: python
 
    from beem.comment import Comment
    comment = Comment("@gtg/ffdhu-gtg-witness-log")
    print(comment["active_votes"])
 
+Access the market
+
 .. code-block:: python
 
    from beem.market import Market
    market = Market("SBD:STEEM")
    print(market.ticker())
 
+Access a witness
+
 .. code-block:: python
 
    from beem.witness import Witness
@@ -138,7 +159,9 @@ Receiving information about blocks, accounts, votes, comments, market and witnes
    print(witness.is_active)
 
 Sending transaction to the blockchain
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+-------------------------------------
+
+Sending a Transfer
 
 .. code-block:: python
 
@@ -148,6 +171,8 @@ Sending transaction to the blockchain
    account = Account("test", steem_instance=steem)
    account.transfer("null", 1, "SBD", "test")
 
+Upvote a post
+
 .. code-block:: python
 
    from beem.comment import Comment
@@ -157,6 +182,8 @@ Sending transaction to the blockchain
    comment = Comment("@gtg/ffdhu-gtg-witness-log", steem_instance=steem)
    comment.upvote(weight=10, voter="test")
 
+Publish a post to the blockchain
+
 .. code-block:: python
 
    from beem import Steem
@@ -164,6 +191,8 @@ Sending transaction to the blockchain
    steem.wallet.unlock("wallet-passphrase")
    steem.post("title", "body", author="test", tags=["a", "b", "c", "d", "e"], self_vote=True)
 
+Sell STEEM on the market
+
 .. code-block:: python
 
    from beem.market import Market
diff --git a/docs/tutorials.rst b/docs/tutorials.rst
index 45ed1589..ac6ec1f9 100644
--- a/docs/tutorials.rst
+++ b/docs/tutorials.rst
@@ -10,6 +10,8 @@ transactions. This can be used to do a multi-send (one sender, multiple
 receivers), but it also allows to use any other kind of operation. The
 advantage here is that the user can be sure that the operations are
 executed in the same order as they are added to the transaction.
+A block can only include one vote operation and
+one comment operation from each sender.
 
 .. code-block:: python
 
@@ -129,3 +131,86 @@ Sell at a timely rate
         )
 
         sell()
+
+Batch api calls on AppBase
+--------------------------
+
+Batch api calls are possible with AppBase RPC nodes.
+If you call a Api-Call with add_to_queue=True it is not submitted but stored in rpc_queue.
+When a call with add_to_queue=False (default setting) is started,
+the complete queue is sended at once to the node. The result is a list with replies.
+
+.. code-block:: python
+
+    from beem import Steem
+    stm = Steem("https://api.steemit.com")
+    stm.rpc.get_config(add_to_queue=True)
+    stm.rpc.rpc_queue
+
+.. code-block:: python
+
+    [{'method': 'condenser_api.get_config', 'jsonrpc': '2.0', 'params': [], 'id': 6}]
+
+.. code-block:: python
+
+    result = stm.rpc.get_block({"block_num":1}, api="block", add_to_queue=False)
+    len(result)
+
+.. code-block:: python
+
+    2
+
+
+Account history
+---------------
+Lets calculate the curation reward from the last 7 days:
+
+.. code-block:: python
+
+    from datetime import datetime, timedelta
+    from beem.account import Account
+    from beem.amount import Amount
+    
+    acc = Account("gtg")
+    stop = datetime.utcnow() - timedelta(days=7)
+    reward_vests = Amount("0 VESTS")
+    for reward in acc.history_reverse(stop=stop, only_ops=["curation_reward"]):
+                reward_vests += Amount(reward['reward'])
+    curation_rewards_SP = acc.steem.vests_to_sp(reward_vests.amount)
+    print("Rewards are %.3f SP" % curation_rewards_SP)
+
+Transactionbuilder
+------------------
+Sign transactions with beem without using the wallet and build the transaction by hand.
+Example without using the wallet:
+
+.. code-block:: python
+
+    from beem import Steem
+    from beem.transactionbuilder import TransactionBuilder
+    stm = Steem()
+    tx = TransactionBuilder(steem_instance=stm)
+    tx.appendOps(Transfer(**{"from": 'user_a',
+                             "to": 'user_b',
+                             "amount": '1.000 SBD',
+                             "memo": 'test 2'}))
+    tx.appendWif('5.....') # `user_a`
+    tx.sign()
+    tx.broadcast()
+
+Example with using the wallet:
+
+.. code-block:: python
+
+    from beem.transactionbuilder import TransactionBuilder
+    from beem import Steem
+    stm = Steem()
+    stm.wallet.unlock("secret_password")
+    tx = TransactionBuilder(steem_instance=stm)
+    tx.appendOps(Transfer(**{"from": 'user_a',
+                             "to": 'user_b',
+                             "amount": '1.000 SBD',
+                             "memo": 'test 2'}))
+    tx.appendSigner('user_a', 'active')
+    tx.sign()
+    tx.broadcast()
-- 
GitLab