Skip to content
Snippets Groups Projects
Unverified Commit 6971c20d authored by Holger Nahrstaedt's avatar Holger Nahrstaedt Committed by GitHub
Browse files

Merge pull request #192 from alexpmorris/wls-v25

fixes compatibility issues with WhaleShares HF2 / v2.5
parents 093c4409 9f0c2222
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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)
......@@ -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}
......
......@@ -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),
]))
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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment