diff --git a/beemapi/graphenerpc.py b/beemapi/graphenerpc.py index 16586ac019531ca58333d82cf9783951806700a0..d4a2c8eeac0da78fb1bb05e2c2be5ce9c96a7739 100644 --- a/beemapi/graphenerpc.py +++ b/beemapi/graphenerpc.py @@ -459,6 +459,8 @@ class GrapheneRPC(object): api_name = get_api_name(self.is_appbase_ready(), *args, **kwargs) if self.is_appbase_ready() and self.use_condenser: api_name = "condenser_api" + if (api_name == None): + api_name = 'database_api' # let's be able to define the num_retries per query stored_num_retries_call = self.nodes.num_retries_call diff --git a/beembase/objects.py b/beembase/objects.py index a4c3703d14f472d643c15a78da4651c7790d03ed..8fa88c36fe4607aab66e25aa68a0881082dba71a 100644 --- a/beembase/objects.py +++ b/beembase/objects.py @@ -314,3 +314,100 @@ 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 b7e68474533805e0e794638de4780a6773fb1d1f..69c9b2e7cfb3a6cf31dd75dec457c23c96484425 100644 --- a/beembase/operationids.py +++ b/beembase/operationids.py @@ -73,8 +73,8 @@ ops_wls = [ 'withdraw_vesting', 'account_create', 'account_update', - 'account_forsale', - 'account_buying', + 'account_action', + 'social_action', 'witness_update', 'account_witness_vote', 'account_witness_proxy', @@ -85,6 +85,8 @@ ops_wls = [ 'set_withdraw_vesting_route', 'custom_binary', 'claim_reward_balance', + 'friend_action', + 'pod_action', 'author_reward', 'curation_reward', 'comment_reward', @@ -92,6 +94,8 @@ ops_wls = [ 'hardfork', 'comment_payout_update', 'comment_benefactor_reward', + 'devfund', + 'pod_virtual' ] operations_wls = {o: ops_wls.index(o) for o in ops_wls} diff --git a/beembase/operations.py b/beembase/operations.py index 7965f0b6d34bc73f0a4ce559d4d21bfe8dd84a2d..ca3d1fd4c33fc4a7c3b120f7b5a5b3957d3f8f32 100644 --- a/beembase/operations.py +++ b/beembase/operations.py @@ -829,3 +829,38 @@ 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 == 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 new file mode 100644 index 0000000000000000000000000000000000000000..ec73c1a3af1dce09b2cbe33df4ecfb23c78eca40 --- /dev/null +++ b/examples/wls_post.py @@ -0,0 +1,70 @@ +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) +