From f6ec4a57e1c943a06f040ee2055b1050a302b1e1 Mon Sep 17 00:00:00 2001
From: Holger Nahrstaedt <holgernahrstaedt@gmx.de>
Date: Mon, 29 Jun 2020 14:49:34 +0200
Subject: [PATCH] Add rshares_to_token_backed_dollar

---
 CHANGELOG.rst              |  4 ++-
 beem/account.py            |  6 +---
 beem/blockchaininstance.py |  5 +++
 beem/cli.py                | 24 +++++++--------
 beem/hive.py               |  2 ++
 beem/steem.py              |  3 ++
 tests/beem/test_cli.py     | 62 +++++++++++++++++++-------------------
 7 files changed, 57 insertions(+), 49 deletions(-)

diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index da078da1..ef9f1199 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -9,11 +9,13 @@ Changelog
 * Add BLURT chain
 * Remove not used STEEM chains (STEEMZERO and STEEMAPPBASE)
 * add Blurt class
-* get_token_per_mvest, token_power_to_vests and vests_to_token_power have been added for chain independent usage
+* rshares_to_token_backed_dollar, get_token_per_mvest, token_power_to_vests and vests_to_token_power have been added for chain independent usage
 * New beempy command followlist, which can be used on HIVE to receive info about follow lists
 * Fix beempy info on Hive
 * Use Hive() on beempy when setting default_chain to "hive"
 * Simplify chain identification
+* Fix more Token symbols in beempy
+* Fix unittest
 
 0.24.3
 ------
diff --git a/beem/account.py b/beem/account.py
index 5235f0f0..6a901ba3 100644
--- a/beem/account.py
+++ b/beem/account.py
@@ -576,11 +576,7 @@ class Account(BlockchainObject):
             tp = self.get_token_power()
         else:
             tp = token_power
-        from beem import Steem
-        if isinstance(self.blockchain, Steem):
-            voteValue = self.blockchain.sp_to_sbd(tp, post_rshares=post_rshares, voting_power=voting_power * 100, vote_pct=voting_weight * 100, not_broadcasted_vote=not_broadcasted_vote)
-        else:
-            voteValue = self.blockchain.hp_to_hbd(tp, post_rshares=post_rshares, voting_power=voting_power * 100, vote_pct=voting_weight * 100, not_broadcasted_vote=not_broadcasted_vote)
+        voteValue = self.blockchain.rshares_to_token_backed_dollar(tp, post_rshares=post_rshares, voting_power=voting_power * 100, vote_pct=voting_weight * 100, not_broadcasted_vote=not_broadcasted_vote)
         return voteValue
 
     def get_voting_value_SBD(self, post_rshares=0, voting_weight=100, voting_power=None, steem_power=None, not_broadcasted_vote=True):
diff --git a/beem/blockchaininstance.py b/beem/blockchaininstance.py
index 4722cc63..95c4f819 100644
--- a/beem/blockchaininstance.py
+++ b/beem/blockchaininstance.py
@@ -684,6 +684,11 @@ class BlockChainInstance(object):
         """
         raise Exception("not implemented")
 
+    def rshares_to_token_backed_dollar(self, rshares, not_broadcasted_vote=False, use_stored_data=True):
+        """ Calculates the current HBD value of a vote
+        """
+        raise Exception("not implemented")
+
     def get_chain_properties(self, use_stored_data=True):
         """ Return witness elected chain properties
 
diff --git a/beem/cli.py b/beem/cli.py
index 819298d5..c264f88f 100644
--- a/beem/cli.py
+++ b/beem/cli.py
@@ -3788,7 +3788,7 @@ def curation(authorperm, account, limit, min_vote, max_vote, min_performance, ma
         for vote in comment.get_votes():
             vote_time = vote["time"]
             
-            vote_SBD = stm.rshares_to_sbd(int(vote["rshares"]))
+            vote_SBD = stm.rshares_to_token_backed_dollar(int(vote["rshares"]))
             curation_SBD = curation_rewards_SBD["active_votes"][vote["voter"]]
             curation_SP = curation_rewards_SP["active_votes"][vote["voter"]]
             if vote_SBD > 0:
@@ -3938,17 +3938,17 @@ def rewards(accounts, only_sum, post, comment, curation, length, author, permlin
         m = Market(blockchain_instance=stm)
         latest = m.ticker()["latest"]
         if author and permlink:
-            t = PrettyTable(["Author", "Permlink", "Payout", stm.backed_token_symbol, "SP + STEEM", "Liquid USD", "Invested USD"])
+            t = PrettyTable(["Author", "Permlink", "Payout", stm.backed_token_symbol, "%sP + %s" % (stm.token_symbol[0], stm.token_symbol), "Liquid USD", "Invested USD"])
         elif author and title:
-                t = PrettyTable(["Author", "Title", "Payout", stm.backed_token_symbol, "SP + STEEM", "Liquid USD", "Invested USD"])
+                t = PrettyTable(["Author", "Title", "Payout", stm.backed_token_symbol, "%sP + %s" % (stm.token_symbol[0], stm.token_symbol), "Liquid USD", "Invested USD"])
         elif author:
-            t = PrettyTable(["Author", "Payout", stm.backed_token_symbol, "SP + STEEM", "Liquid USD", "Invested USD"])
+            t = PrettyTable(["Author", "Payout", stm.backed_token_symbol, "%sP + %s" % (stm.token_symbol[0], stm.token_symbol), "Liquid USD", "Invested USD"])
         elif not author and permlink:
-            t = PrettyTable(["Permlink", "Payout", stm.backed_token_symbol, "SP + STEEM", "Liquid USD", "Invested USD"])
+            t = PrettyTable(["Permlink", "Payout", stm.backed_token_symbol, "%sP + %s" % (stm.token_symbol[0], stm.token_symbol), "Liquid USD", "Invested USD"])
         elif not author and title:
-            t = PrettyTable(["Title", "Payout", stm.backed_token_symbol, "SP + STEEM", "Liquid USD", "Invested USD"])
+            t = PrettyTable(["Title", "Payout", stm.backed_token_symbol, "%sP + %s" % (stm.token_symbol[0], stm.token_symbol), "Liquid USD", "Invested USD"])
         else:
-            t = PrettyTable(["Received", stm.backed_token_symbol, "SP + STEEM", "Liquid USD", "Invested USD"])
+            t = PrettyTable(["Received", stm.backed_token_symbol, "%sP + %s" % (stm.token_symbol[0], stm.token_symbol), "Liquid USD", "Invested USD"])
         t.align = "l"
         rows = []
         start_op = account.estimate_virtual_op_num(limit_time)
@@ -3976,7 +3976,7 @@ def rewards(accounts, only_sum, post, comment, curation, length, author, permlin
                     payout_STEEM = Amount(v["steem_payout"], blockchain_instance=stm)
                     sum_reward[0] += float(payout_SBD)
                     sum_reward[1] += float(payout_STEEM)
-                    payout_SP = stm.vests_to_sp(Amount(v["vesting_payout"], blockchain_instance=stm))
+                    payout_SP = stm.vests_to_token_power(Amount(v["vesting_payout"], blockchain_instance=stm))
                     sum_reward[2] += float(payout_SP)
                     liquid_USD = float(payout_SBD) / float(latest) * float(median_price) + float(payout_STEEM) * float(median_price)
                     sum_reward[3] += liquid_USD
@@ -3999,7 +3999,7 @@ def rewards(accounts, only_sum, post, comment, curation, length, author, permlin
                                  (invested_USD)])
                 elif v["type"] == "curation_reward":
                     reward = Amount(v["reward"], blockchain_instance=stm)
-                    payout_SP = stm.vests_to_sp(reward)
+                    payout_SP = stm.vests_to_token_power(reward)
                     liquid_USD = 0
                     invested_USD = float(payout_SP) * float(median_price)
                     sum_reward[2] += float(payout_SP)
@@ -4061,14 +4061,14 @@ def rewards(accounts, only_sum, post, comment, curation, length, author, permlin
                        "-",
                        "-",
                        "%.2f %s" % (sum_reward[0], stm.backed_token_symbol),
-                       "%.2f SP" % (sum_reward[1] + sum_reward[2]),
+                       "%.2f %sP" % (sum_reward[1] + sum_reward[2], stm.token_symbol[0]),
                        "%.2f $" % (sum_reward[3]),
                        "%.2f $" % (sum_reward[4])])
         elif not author and not (permlink or title):
             t.add_row(["", "", "", "", ""])
             t.add_row(["Sum",
                        "%.2f %s" % (sum_reward[0], stm.backed_token_symbol),
-                       "%.2f SP" % (sum_reward[1] + sum_reward[2]),
+                       "%.2f %sP" % (sum_reward[1] + sum_reward[2], stm.token_symbol[0]),
                        "%.2f $" % (sum_reward[2]),
                        "%.2f $" % (sum_reward[3])])
         else:
@@ -4076,7 +4076,7 @@ def rewards(accounts, only_sum, post, comment, curation, length, author, permlin
             t.add_row(["Sum",
                        "-",
                        "%.2f %s" % (sum_reward[0], stm.backed_token_symbol),
-                       "%.2f SP" % (sum_reward[1] + sum_reward[2]),
+                       "%.2f %sP" % (sum_reward[1] + sum_reward[2], stm.token_symbol[0]),
                        "%.2f $" % (sum_reward[3]),
                        "%.2f $" % (sum_reward[4])])
         message = "\nShowing "
diff --git a/beem/hive.py b/beem/hive.py
index fcd37cd7..8e5b574a 100644
--- a/beem/hive.py
+++ b/beem/hive.py
@@ -137,6 +137,8 @@ class Hive(BlockChainInstance):
         except:
             return known_chains["HIVE"]
 
+    def rshares_to_token_backed_dollar(self, rshares, not_broadcasted_vote=False, use_stored_data=True):
+        return self.rshares_to_hbd(rshares, not_broadcasted_vote=not_broadcasted_vote, use_stored_data=use_stored_data)
 
     def rshares_to_hbd(self, rshares, not_broadcasted_vote=False, use_stored_data=True):
         """ Calculates the current HBD value of a vote
diff --git a/beem/steem.py b/beem/steem.py
index 00e6af91..02d1a7b7 100644
--- a/beem/steem.py
+++ b/beem/steem.py
@@ -135,6 +135,9 @@ class Steem(BlockChainInstance):
         except:
             return known_chains["STEEM"]
 
+    def rshares_to_token_backed_dollar(self, rshares, not_broadcasted_vote=False, use_stored_data=True):
+        return self.rshares_to_sbd(rshares, not_broadcasted_vote=not_broadcasted_vote, use_stored_data=use_stored_data)        
+
     def rshares_to_sbd(self, rshares, not_broadcasted_vote=False, use_stored_data=True):
         """ Calculates the current SBD value of a vote
         """
diff --git a/tests/beem/test_cli.py b/tests/beem/test_cli.py
index 788c34e5..2e515471 100644
--- a/tests/beem/test_cli.py
+++ b/tests/beem/test_cli.py
@@ -70,7 +70,7 @@ class Testcases(unittest.TestCase):
 
     def test_interest(self):
         runner = CliRunner()
-        result = runner.invoke(cli, ['-dt', 'interest', 'beembot', 'beempy'])
+        result = runner.invoke(cli, ['-dx', 'interest', 'beembot', 'beempy'])
         self.assertEqual(result.exit_code, 0)
 
     def test_config(self):
@@ -96,7 +96,7 @@ class Testcases(unittest.TestCase):
 
     def test_changerecovery(self):
         runner = CliRunner()
-        result = runner.invoke(cli, ['-dt', 'changerecovery', '-a', 'beembot', 'holger80'], input=wif + "\nexit\n")
+        result = runner.invoke(cli, ['-dx', 'changerecovery', '-a', 'beembot', 'holger80'], input=wif + "\nexit\n")
         self.assertEqual(result.exit_code, 0)
 
     def test_delkey(self):
@@ -162,54 +162,54 @@ class Testcases(unittest.TestCase):
 
     def test_upvote(self):
         runner = CliRunner()
-        result = runner.invoke(cli, ['-dt', 'upvote', '@steemit/firstpost'], input="test\n")
+        result = runner.invoke(cli, ['-dx', 'upvote', '@steemit/firstpost'], input="test\n")
         self.assertEqual(result.exit_code, 0)
-        result = runner.invoke(cli, ['-dt', 'upvote', '--weight', '100', '@steemit/firstpost'], input="test\n")
+        result = runner.invoke(cli, ['-dx', 'upvote', '--weight', '100', '@steemit/firstpost'], input="test\n")
         self.assertEqual(result.exit_code, 0)
 
     def test_downvote(self):
         runner = CliRunner()
-        result = runner.invoke(cli, ['-dt', 'downvote', '--weight', '100', '@steemit/firstpost'], input="test\n")
+        result = runner.invoke(cli, ['-dx', 'downvote', '--weight', '100', '@steemit/firstpost'], input="test\n")
         self.assertEqual(result.exit_code, 0)
 
     def test_download(self):
         runner = CliRunner()
-        result = runner.invoke(cli, ['-dt', 'download', '-a', 'steemit', 'firstpost'])
+        result = runner.invoke(cli, ['-dx', 'download', '-a', 'steemit', 'firstpost'])
         self.assertEqual(result.exit_code, 0)
-        result = runner.invoke(cli, ['-dt', 'download', '@steemit/firstpost'])
+        result = runner.invoke(cli, ['-dx', 'download', '@steemit/firstpost'])
         self.assertEqual(result.exit_code, 0)
 
     def test_transfer(self):
         stm = shared_steem_instance()
         runner = CliRunner()
-        result = runner.invoke(cli, ['-dt', 'transfer', 'beembot', '1', stm.backed_token_symbol, 'test'], input="test\n")
+        result = runner.invoke(cli, ['-dx', 'transfer', 'beembot', '1', stm.backed_token_symbol, 'test'], input="test\n")
         self.assertEqual(result.exit_code, 0)
 
     def test_powerdownroute(self):
         runner = CliRunner()
-        result = runner.invoke(cli, ['-dt', 'powerdownroute', 'beembot'], input="test\n")
+        result = runner.invoke(cli, ['-dx', 'powerdownroute', 'beembot'], input="test\n")
         self.assertEqual(result.exit_code, 0)
 
     def test_convert(self):
         runner = CliRunner()
-        result = runner.invoke(cli, ['-dt', 'convert', '1'], input="test\n")
+        result = runner.invoke(cli, ['-dx', 'convert', '1'], input="test\n")
         self.assertEqual(result.exit_code, 0)
 
     def test_powerup(self):
         runner = CliRunner()
-        result = runner.invoke(cli, ['-dt', 'powerup', '1'], input="test\n")
+        result = runner.invoke(cli, ['-dx', 'powerup', '1'], input="test\n")
         self.assertEqual(result.exit_code, 0)
 
     def test_powerdown(self):
         runner = CliRunner()
-        result = runner.invoke(cli, ['-dt', 'powerdown', '1e3'], input="test\n")
+        result = runner.invoke(cli, ['-dx', 'powerdown', '1e3'], input="test\n")
         self.assertEqual(result.exit_code, 0)
-        result = runner.invoke(cli, ['-dt', 'powerdown', '0'], input="test\n")
+        result = runner.invoke(cli, ['-dx', 'powerdown', '0'], input="test\n")
         self.assertEqual(result.exit_code, 0)
 
     def test_updatememokey(self):
         runner = CliRunner()
-        result = runner.invoke(cli, ['-dt', 'updatememokey'], input="test\ntest\ntest\n")
+        result = runner.invoke(cli, ['-dx', 'updatememokey'], input="test\ntest\ntest\n")
         self.assertEqual(result.exit_code, 0)
 
     def test_permissions(self):
@@ -244,9 +244,9 @@ class Testcases(unittest.TestCase):
 
     def test_allow_disallow(self):
         runner = CliRunner()
-        result = runner.invoke(cli, ['-dt', 'allow', '--account', 'beembot', '--permission', 'posting', 'beempy'], input="test\n")
+        result = runner.invoke(cli, ['-dx', 'allow', '--account', 'beembot', '--permission', 'posting', 'beempy'], input="test\n")
         self.assertEqual(result.exit_code, 0)
-        result = runner.invoke(cli, ['-dt', 'disallow', '--account', 'holger80', '--permission', 'posting', 'rewarding'], input="test\n")
+        result = runner.invoke(cli, ['-dx', 'disallow', '--account', 'holger80', '--permission', 'posting', 'rewarding'], input="test\n")
         self.assertEqual(result.exit_code, 0)
 
     def test_witnesses(self):
@@ -263,29 +263,29 @@ class Testcases(unittest.TestCase):
 
     def test_approvewitness(self):
         runner = CliRunner()
-        result = runner.invoke(cli, ['-dt', 'approvewitness', '-a', 'beempy', 'holger80'], input="test\n")
+        result = runner.invoke(cli, ['-dx', 'approvewitness', '-a', 'beempy', 'holger80'], input="test\n")
         self.assertEqual(result.exit_code, 0)
 
     def test_disapprovewitness(self):
         runner = CliRunner()
-        result = runner.invoke(cli, ['-dt', 'disapprovewitness',  '-a', 'beempy', 'holger80'], input="test\n")
+        result = runner.invoke(cli, ['-dx', 'disapprovewitness',  '-a', 'beempy', 'holger80'], input="test\n")
         self.assertEqual(result.exit_code, 0)
 
     def test_addproxy(self):
         runner = CliRunner()
-        result = runner.invoke(cli, ['-dt', 'setproxy', '-a', 'beempy', 'holger80'], input="test\n")
+        result = runner.invoke(cli, ['-dx', 'setproxy', '-a', 'beempy', 'holger80'], input="test\n")
         self.assertEqual(result.exit_code, 0)
 
     def test_delproxy(self):
         runner = CliRunner()
-        result = runner.invoke(cli, ['-dt', 'delproxy',  '-a', 'fullnodeupdate'], input="test\n")
+        result = runner.invoke(cli, ['-dx', 'delproxy',  '-a', 'fullnodeupdate'], input="test\n")
         self.assertEqual(result.exit_code, 0)
 
     def test_newaccount(self):
         runner = CliRunner()
-        result = runner.invoke(cli, ['-dt', 'newaccount', 'beem3'], input="test\ntest\ntest\n")
+        result = runner.invoke(cli, ['-dx', 'newaccount', 'beem3'], input="test\ntest\ntest\n")
         self.assertEqual(result.exit_code, 0)
-        result = runner.invoke(cli, ['-dt', 'newaccount', '--owner', 'STM7mLs2hns87f7kbf3o2HBqNoEaXiTeeU89eVF6iUCrMQJFzBsPo',
+        result = runner.invoke(cli, ['-dx', 'newaccount', '--owner', 'STM7mLs2hns87f7kbf3o2HBqNoEaXiTeeU89eVF6iUCrMQJFzBsPo',
                                      '--active', 'STM7rUmnpnCp9oZqMQeRKDB7GvXTM9KFvhzbA3AKcabgTBfQZgHZp',
                                      '--posting', 'STM6qGWHsCpmHbphnQbS2yfhvhJXDUVDwnsbnrMZkTqfnkNEZRoLP',
                                      '--memo', 'STM8Wvi74GYzBKgnUmiLvptzvxmPtXfjGPJL8QY3rebecXaxGGQyV', 'beem3'], input="test\ntest\n")
@@ -349,7 +349,7 @@ class Testcases(unittest.TestCase):
 
     def test_cancel(self):
         runner = CliRunner()
-        result = runner.invoke(cli, ['-dt', 'cancel', '5'], input="test\n")
+        result = runner.invoke(cli, ['-dx', 'cancel', '5'], input="test\n")
         self.assertEqual(result.exit_code, 0)
 
     def test_openorders(self):
@@ -378,25 +378,25 @@ class Testcases(unittest.TestCase):
 
     def test_witnesscreate(self):
         runner = CliRunner()
-        result = runner.invoke(cli, ['-dt', 'witnesscreate', 'beem', pub_key], input="test\n")
+        result = runner.invoke(cli, ['-dx', 'witnesscreate', 'beem', pub_key], input="test\n")
 
     def test_witnessupdate(self):
         runner = CliRunner()
-        runner.invoke(cli, ['-dt', 'witnessupdate', 'gtg', '--maximum_block_size', 65000, '--account_creation_fee', 0.1, '--sbd_interest_rate', 0, '--url', 'https://google.de', '--signing_key', wif])
+        runner.invoke(cli, ['-dx', 'witnessupdate', 'gtg', '--maximum_block_size', 65000, '--account_creation_fee', 0.1, '--sbd_interest_rate', 0, '--url', 'https://google.de', '--signing_key', wif])
 
     def test_profile(self):
         runner = CliRunner()
-        result = runner.invoke(cli, ['-dt', 'setprofile', 'url', 'https://google.de'], input="test\n")
+        result = runner.invoke(cli, ['-dx', 'setprofile', 'url', 'https://google.de'], input="test\n")
         self.assertEqual(result.exit_code, 0)
-        result = runner.invoke(cli, ['-dt', 'delprofile', 'url'], input="test\n")
+        result = runner.invoke(cli, ['-dx', 'delprofile', 'url'], input="test\n")
         self.assertEqual(result.exit_code, 0)
 
     def test_claimreward(self):
         runner = CliRunner()
-        result = runner.invoke(cli, ['-dt', 'claimreward'], input="test\n")
-        result = runner.invoke(cli, ['-dt', 'claimreward', '--claim_all_steem'], input="test\n")
-        result = runner.invoke(cli, ['-dt', 'claimreward', '--claim_all_sbd'], input="test\n")
-        result = runner.invoke(cli, ['-dt', 'claimreward', '--claim_all_vests'], input="test\n")
+        result = runner.invoke(cli, ['-dx', 'claimreward'], input="test\n")
+        result = runner.invoke(cli, ['-dx', 'claimreward', '--claim_all_steem'], input="test\n")
+        result = runner.invoke(cli, ['-dx', 'claimreward', '--claim_all_sbd'], input="test\n")
+        result = runner.invoke(cli, ['-dx', 'claimreward', '--claim_all_vests'], input="test\n")
         self.assertEqual(result.exit_code, 0)
 
     def test_power(self):
-- 
GitLab