From 798662e915a49972d4bce2a096c9fde8a77d56af Mon Sep 17 00:00:00 2001 From: Holger Nahrstaedt <holgernahrstaedt@gmx.de> Date: Wed, 8 Jul 2020 21:57:22 +0200 Subject: [PATCH] Remove whaleshares related code --- beem/account.py | 4 +- beembase/objects.py | 99 +--------------------------------------- beembase/operationids.py | 34 -------------- beembase/operations.py | 38 +-------------- examples/wls_post.py | 70 ---------------------------- 5 files changed, 5 insertions(+), 240 deletions(-) delete mode 100644 examples/wls_post.py diff --git a/beem/account.py b/beem/account.py index de867c31..4f420b96 100644 --- a/beem/account.py +++ b/beem/account.py @@ -1809,7 +1809,9 @@ class Account(BlockchainObject): else: try: op_count = 0 - op_count = self._get_account_history(start=-1, limit=1) + op_count = self._get_account_history(start=-1, limit=0) + if op_count is None or len(op_count) == 0: + op_count = self._get_account_history(start=-1, limit=1) if isinstance(op_count, list) and len(op_count) > 0 and len(op_count[0]) > 0: return op_count[0][0] else: diff --git a/beembase/objects.py b/beembase/objects.py index 9c3489d4..7e4cbd4a 100644 --- a/beembase/objects.py +++ b/beembase/objects.py @@ -20,7 +20,7 @@ from .objecttypes import object_type from beemgraphenebase.account import PublicKey from beemgraphenebase.objects import Operation as GPHOperation from beemgraphenebase.chains import known_chains -from .operationids import operations, operations_wls +from .operationids import operations import struct default_prefix = "STM" @@ -336,100 +336,3 @@ class CommentOptionExtensions(Static_variant): else: raise Exception("Unknown CommentOptionExtension") super(CommentOptionExtensions, self).__init__(data, type_id) - - -class SocialActionCommentCreate(GrapheneObject): - def __init__(self, *args, **kwargs): - if isArgsThisClass(self, args): - self.data = args[0].data - else: - if len(args) == 1 and len(kwargs) == 0: - kwargs = args[0] - - meta = "" - if "json_metadata" in kwargs and kwargs["json_metadata"]: - if (isinstance(kwargs["json_metadata"], dict) - or isinstance(kwargs["json_metadata"], list)): - meta = json.dumps(kwargs["json_metadata"]) - else: - meta = kwargs["json_metadata"] - - pod = String(kwargs["pod"]) if "pod" in kwargs else None - max_accepted_payout = Amount(kwargs["max_accepted_payout"]) if "max_accepted_payout" in kwargs else None - allow_replies = Bool(kwargs["allow_replies"]) if "allow_replies" in kwargs else None - allow_votes = Bool(kwargs["allow_votes"]) if "allow_votes" in kwargs else None - allow_curation_rewards = Bool(kwargs["allow_curation_rewards"]) if "allow_curation_rewards" in kwargs else None - allow_friends = Bool(kwargs["allow_friends"]) if "allow_friends" in kwargs else None - - super(SocialActionCommentCreate, self).__init__( - OrderedDict([ - ('permlink', String(kwargs["permlink"])), - ('parent_author', String(kwargs["parent_author"])), - ('parent_permlink', String(kwargs["parent_permlink"])), - ('pod', Optional(pod)), - ('max_accepted_payout', Optional(max_accepted_payout)), - ('allow_replies', Optional(allow_replies)), - ('allow_votes', Optional(allow_votes)), - ('allow_curation_rewards', Optional(allow_curation_rewards)), - ('allow_friends', Optional(allow_friends)), - ('title', String(kwargs["title"])), - ('body', String(kwargs["body"])), - ('json_metadata', String(meta)), - ])) - -class SocialActionCommentUpdate(GrapheneObject): - def __init__(self, *args, **kwargs): - if isArgsThisClass(self, args): - self.data = args[0].data - else: - if len(args) == 1 and len(kwargs) == 0: - kwargs = args[0] - - meta = Optional(None) - if "json_metadata" in kwargs and kwargs["json_metadata"]: - if (isinstance(kwargs["json_metadata"], dict) - or isinstance(kwargs["json_metadata"], list)): - meta = json.dumps(kwargs["json_metadata"]) - else: - if "json_metadata" in kwargs: - meta = kwargs["json_metadata"] - - title = kwargs["title"] if "title" in kwargs else None - body = kwargs["body"] if "body" in kwargs else None - - super(SocialActionCommentUpdate, self).__init__( - OrderedDict([ - ('permlink', String(kwargs["permlink"])), - ('title', Optional(String(kwargs["title"]))), - ('body', Optional(String(kwargs["body"]))), - ('json_metadata', meta), - ])) - -class SocialActionCommentDelete(GrapheneObject): - def __init__(self, *args, **kwargs): - if isArgsThisClass(self, args): - self.data = args[0].data - else: - if len(args) == 1 and len(kwargs) == 0: - kwargs = args[0] - - super(SocialActionCommentDelete, self).__init__( - OrderedDict([ - ('permlink', String(kwargs["permlink"])) - ])) - -class SocialActionVariant(Static_variant): - def __init__(self, o): - type_id, data = o - if type_id == 0: - data = SocialActionCommentCreate(data) - else: - if type_id == 1: - data = SocialActionCommentUpdate(data) - else: - if type_id == 2: - data = SocialActionCommentDelete(data) - else: - raise Exception("Unknown SocialAction") - Static_variant.__init__(self, data, type_id) - diff --git a/beembase/operationids.py b/beembase/operationids.py index 41c65b28..70be3c32 100644 --- a/beembase/operationids.py +++ b/beembase/operationids.py @@ -77,40 +77,6 @@ ops = [ ] operations = {o: ops.index(o) for o in ops} -ops_wls = [ - 'vote', - 'comment', - 'transfer', - 'transfer_to_vesting', - 'withdraw_vesting', - 'account_create', - 'account_update', - 'account_action', - 'social_action', - 'witness_update', - 'account_witness_vote', - 'account_witness_proxy', - 'custom', - 'delete_comment', - 'custom_json', - 'comment_options', - 'set_withdraw_vesting_route', - 'custom_binary', - 'claim_reward_balance', - 'friend_action', - 'pod_action', - 'author_reward', - 'curation_reward', - 'comment_reward', - 'shutdown_witness', - 'hardfork', - 'comment_payout_update', - 'comment_benefactor_reward', - 'devfund', - 'pod_virtual' -] -operations_wls = {o: ops_wls.index(o) for o in ops_wls} - def getOperationNameForId(i): """ Convert an operation id into the corresponding string diff --git a/beembase/operations.py b/beembase/operations.py index 9a83c865..ae505ef7 100644 --- a/beembase/operations.py +++ b/beembase/operations.py @@ -29,8 +29,7 @@ from .objects import ( ExchangeRate, Beneficiaries, Beneficiary, - CommentOptionExtensions, - SocialActionVariant + CommentOptionExtensions ) default_prefix = "STM" @@ -1030,38 +1029,3 @@ class Decline_voting_rights(GrapheneObject): ('account', String(kwargs["account"])), ('decline', Bool(kwargs["decline"])), ])) - - -class Social_action(GrapheneObject): - def __init__(self, *args, **kwargs): - if isArgsThisClass(self, args): - self.data = args[0].data - else: - if len(args) == 1 and len(kwargs) == 0: - kwargs = args[0] - - # handle action - action = kwargs.get('action') - if action is None: - action_obj = kwargs.get('social_action_comment_create') - action_id = 0 - if action_obj and type(action_obj) == dict: - action_id = 0 - else: - action_obj = kwargs.get('social_action_comment_update') - if action_obj and type(action_obj) == dict: - action_id = 1 - else: - action_obj = kwargs.get('social_action_comment_delete') - if action_obj and type(action_obj) == dict: - action_id = 2 - stat_var = [action_id, action_obj] - action = SocialActionVariant(stat_var) - else: - action = SocialActionVariant([action[0], action[1]]) - - super(Social_action, self).__init__( - OrderedDict([ - ('account', String(kwargs["account"])), - ('action', action), - ])) diff --git a/examples/wls_post.py b/examples/wls_post.py deleted file mode 100644 index ec73c1a3..00000000 --- a/examples/wls_post.py +++ /dev/null @@ -1,70 +0,0 @@ -from __future__ import absolute_import -from __future__ import division -from __future__ import print_function -from __future__ import unicode_literals -import sys -from datetime import datetime, timedelta -import time -import io -import logging - -from beem.blockchain import Blockchain -from beem.block import Block -from beem.account import Account -from beem.amount import Amount -from beemgraphenebase.account import PasswordKey, PrivateKey, PublicKey -from beem.steem import Steem -from beem.utils import parse_time, formatTimedelta -from beemapi.exceptions import NumRetriesReached -from beem.nodelist import NodeList -from beembase import operations -from beem.transactionbuilder import TransactionBuilder -log = logging.getLogger(__name__) -logging.basicConfig(level=logging.INFO) - -def test_post(wls): - op1 = operations.Social_action( - **{ - "account": "guest123", - "social_action_comment_create": { - "permlink": 'just-a-test-post', - "parent_author": "", - "parent_permlink": "test", - "title": "just a test post", - "body": "test post body", - "json_metadata": '{"app":"wls_python"}' - } - }) - - op2 = operations.Social_action( - **{ - "account": "guest123", - "social_action_comment_update": { - "permlink": 'just-a-test-post', - "title": "just a test post", - "body": "test post body", - } - }) - - op3 = operations.Vote( - **{ - 'voter': 'guest123', - 'author': 'wlsuser', - 'permlink': 'another-test-post', - 'weight': 10000, - }) - - privateWif = "5K..." - tx = TransactionBuilder(use_condenser_api=True, steem_instance=wls) - tx.appendOps(op1) - tx.appendWif(privateWif) - tx.sign() - tx.broadcast() - -if __name__ == "__main__": - # `blocking=True` forces use of broadcast_transaction_synchronous - wls = Steem(node=["https://pubrpc.whaleshares.io"], blocking=True) - print(wls.get_blockchain_version()) - print(wls.get_config()) - test_post(wls) - -- GitLab