Escrow Steem Python

Currently, I am playing around with steem-python.
I wanted to add some missing escrow functions.
And now I hit a wall.
Something is very wrong, I just don't know what.
Here are my thoughts:

Implementation

You just need to change 2 files:

  • steem/commit.py
  • steembase/operations.py

In steem/commit.py add following function:

def escrow_transfer(self,to,agent,fee_amount,fee_asset,escrow_id=None,sbd_amount=0,steem_amount=0,ratification_deadline=7 * 24 * 60 * 60,escrow_expiration=7 * 24 * 60 * 60,json_meta=None,account=None):

        if not account:
            account = configStorage.get("default_account")
        if not account:
            raise ValueError("You need to provide an account")
            
        assert fee_asset in ['STEEM', 'SBD']    


        op = operations.EscrowTransfer(
            **{"from": account,
               "to": to,
               "agent": agent,
               "escrow_id": escrow_id or random.getrandbits(32),
               "sbd_amount": '{:.{prec}f} {asset}'.format(
                   float(sbd_amount),
                   prec=3,
                   asset="SBD"
               ),
               "steem_amount": '{:.{prec}f} {asset}'.format(
                   float(steem_amount),
                   prec=3,
                   asset="STEEM"
               ),
               "fee": '{:.{prec}f} {asset}'.format(
                   float(fee_amount),
                   prec=3,
                   asset=fee_asset
               ),
               "ratification_deadline":transactions.fmt_time_from_now(ratification_deadline),
               "escrow_expiration":transactions.fmt_time_from_now(escrow_expiration),
               "json_meta":json_meta
               }
        )
        return self.finalizeOp(op, account, "active")

Also, you need to add from steembase import transactions because we are using from there fmt_time_from_now.

Next step, change steembase/operations.py:

class EscrowTransfer(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_meta" in kwargs and kwargs["json_meta"]:
                if isinstance(kwargs["json_meta"], dict):
                    meta = json.dumps(kwargs["json_meta"])
                else:
                    meta = kwargs["json_meta"]
                    
            super().__init__(OrderedDict([
                ('from', String(kwargs["from"])),
                ('to', String(kwargs["to"])),
                ('agent', String(kwargs["agent"])),
                ('escrow_id', Uint32(int(kwargs["escrow_id"]))),
                ('sbd_amount', Amount(kwargs["sbd_amount"])),
                ('steem_amount', Amount(kwargs["steem_amount"])),
                ('fee', Amount(kwargs["fee"])),
                ('ratification_deadline', PointInTime(kwargs["ratification_deadline"])),
                ('escrow_expiration', PointInTime(kwargs["escrow_expiration"])),
                ('json_meta', String(meta)),
            ]))

now we write a small test script:

from steem import Steem
from steem.commit import Commit
s = Steem()
c = Commit(steemd_instance=s,debug=True)
returncode = c.escrow_transfer(to='nanobot', agent='microbot', sbd_amount=0.01,fee_amount=0.001,fee_asset='SBD',ratification_deadline=100,escrow_expiration=100,account='isnochys')
print(returncode)

We enter our passphrase for the wallet, where all keys are store and get this error:

    raise RPCError(error_message)
steembase.exceptions.RPCError: 3010000 tx_missing_active_auth: missing required active authority
Missing Active Authority isnochys
    {"id":"isnochys","auth":{"weight_threshold":1,"account_auths":[],"key_auths":[["STM6fSSE2YjaKf8GSXcsrTmkLCykwnXFxJGnZkWv6w3UPy9yHF88G",1]]},"owner":{
weight_threshold":1,"account_auths":[],"key_auths":[["STM8YCB4RhAA66DupuwtBVQ53ZTYQNYshxHLBNjnUtn1Tw1oexAAg",1]]}}
    th_a  transaction.cpp:157 verify_authority

    {"ops":[["escrow_transfer",{"from":"isnochys","to":"nanobot","sbd_amount":"0.010 SBD","steem_amount":"0.000 STEEM","escrow_id":4189549674,"agent":"mirobot","fee":"0.001 SBD","json_meta":"","ratification_deadline":"2018-01-26T09:02:48","escrow_expiration":"2018-01-26T09:02:48"}]],"sigs":["STM6fUR5tcHYk
AFdPhJUDq2Ye28fBRCE9bhB9PuC7aYgE1PeWBRk"]}
    th_a  transaction.cpp:172 verify_authority

    {"*this":{"ref_block_num":44134,"ref_block_prefix":2718848,"expiration":"2018-01-26T09:02:08","operations":[["escrow_transfer",{"from":"isnochys","to
:"nanobot","sbd_amount":"0.010 SBD","steem_amount":"0.000 STEEM","escrow_id":4189549674,"agent":"microbot","fee":"0.001 SBD","json_meta":"","ratification
deadline":"2018-01-26T09:02:48","escrow_expiration":"2018-01-26T09:02:48"}]],"extensions":[],"signatures":["1f2f6dc8f1eda6269e3f2cabb5d6f00aa04085f0b5563
6757619181ad25e094ef657176c87b3cab39dd92f35b311746011cb84678b21185e85cae96781c16377a"]}}
    th_a  transaction.cpp:285 verify_authority

    {"call.method":"call","call.params":["database_api","verify_authority",[{"ref_block_num":44134,"ref_block_prefix":2718848,"expiration":"2018-01-26T09
02:08","operations":[["escrow_transfer",{"from":"isnochys","to":"nanobot","agent":"microbot","escrow_id":4189549674,"sbd_amount":"0.010 SBD","steem_amoun
":"0.000 STEEM","fee":"0.001 SBD","ratification_deadline":"2018-01-26T09:02:48","escrow_expiration":"2018-01-26T09:02:48","json_meta":""}]],"extensions":
],"signatures":["1f2f6dc8f1eda6269e3f2cabb5d6f00aa04085f0b5563b6757619181ad25e094ef657176c87b3cab39dd92f35b311746011cb84678b21185e85cae96781c16377a"]}]]}
    th_a  websocket_api.cpp:124 on_message

Missing Active Authority isnochys ..
Come on, thats me!
I do all the shenanigans with this account!
What step did I miss?
The active key should be the right one..

Oh, let's have a qiock look, how your outpot changes, when we set no_broadcast=True:

$ python test.py
Fri, 26 Jan 2018 10:19:15 +0000
Passphrase:
Not broadcasting anything!
{'ref_block_num': 44496, 'ref_block_prefix': 1419191626, 'expiration': '2018-01-26T09:20:15', 'operations': [['escrow_transfer', {'from': 'isnochys', 'to': 'nanobot', 'agent': 'microbot', 'escrow_id': 4291643727, 'sbd_amount': '0.010 SBD', 'steem_amount': '0.000 STEEM', 'fee': '0.001 SBD', 'ratification_deadline': '2018-01-26T09:20:55', 'escrow_expiration': '2018-01-26T09:20:55', 'json_meta': ''}]], 'extensions': [], 'signatures': ['20669ebcb1c8d467bfcf2c04f033959ccf6b46af8991f71315b0f28ca5d9f3f5c90b9a2e0a1446d9eee4423a907c4e0cc9d012ba257d35a67aaa1fc45c0913cf16']}

Hmm, the function is working, broadcasting is the issue here:(

H2
H3
H4
3 columns
2 columns
1 column
Join the conversation now