Skip to content
Snippets Groups Projects
Commit 4d7fbc03 authored by crokkon's avatar crokkon
Browse files

beembase: adding chain prefix handling

parent e1859a0b
No related branches found
No related tags found
No related merge requests found
...@@ -27,7 +27,7 @@ default_prefix = "STM" ...@@ -27,7 +27,7 @@ default_prefix = "STM"
@python_2_unicode_compatible @python_2_unicode_compatible
class Amount(object): class Amount(object):
def __init__(self, d, prefix="STM"): def __init__(self, d, prefix=default_prefix):
if isinstance(d, string_types): if isinstance(d, string_types):
self.amount, self.symbol = d.strip().split(" ") self.amount, self.symbol = d.strip().split(" ")
self.precision = None self.precision = None
...@@ -164,8 +164,9 @@ class WitnessProps(GrapheneObject): ...@@ -164,8 +164,9 @@ class WitnessProps(GrapheneObject):
else: else:
if len(args) == 1 and len(kwargs) == 0: if len(args) == 1 and len(kwargs) == 0:
kwargs = args[0] kwargs = args[0]
prefix = kwargs.get("prefix", default_prefix)
super(WitnessProps, self).__init__(OrderedDict([ super(WitnessProps, self).__init__(OrderedDict([
('account_creation_fee', Amount(kwargs["account_creation_fee"])), ('account_creation_fee', Amount(kwargs["account_creation_fee"], prefix=prefix)),
('maximum_block_size', Uint32(kwargs["maximum_block_size"])), ('maximum_block_size', Uint32(kwargs["maximum_block_size"])),
('sbd_interest_rate', Uint16(kwargs["sbd_interest_rate"])), ('sbd_interest_rate', Uint16(kwargs["sbd_interest_rate"])),
])) ]))
...@@ -178,9 +179,10 @@ class Price(GrapheneObject): ...@@ -178,9 +179,10 @@ class Price(GrapheneObject):
else: else:
if len(args) == 1 and len(kwargs) == 0: if len(args) == 1 and len(kwargs) == 0:
kwargs = args[0] kwargs = args[0]
prefix = kwargs.get("prefix", default_prefix)
super(Price, self).__init__(OrderedDict([ super(Price, self).__init__(OrderedDict([
('base', Amount(kwargs["base"])), ('base', Amount(kwargs["base"], prefix=prefix)),
('quote', Amount(kwargs["quote"])) ('quote', Amount(kwargs["quote"], prefix=prefix))
])) ]))
...@@ -238,10 +240,11 @@ class ExchangeRate(GrapheneObject): ...@@ -238,10 +240,11 @@ class ExchangeRate(GrapheneObject):
if len(args) == 1 and len(kwargs) == 0: if len(args) == 1 and len(kwargs) == 0:
kwargs = args[0] kwargs = args[0]
prefix = kwargs.get("prefix", default_prefix)
super(ExchangeRate, self).__init__( super(ExchangeRate, self).__init__(
OrderedDict([ OrderedDict([
('base', Amount(kwargs["base"])), ('base', Amount(kwargs["base"], prefix=prefix)),
('quote', Amount(kwargs["quote"])), ('quote', Amount(kwargs["quote"], prefix=prefix)),
])) ]))
......
...@@ -64,7 +64,7 @@ class Transfer(GrapheneObject): ...@@ -64,7 +64,7 @@ class Transfer(GrapheneObject):
super(Transfer, self).__init__(OrderedDict([ super(Transfer, self).__init__(OrderedDict([
('from', String(kwargs["from"])), ('from', String(kwargs["from"])),
('to', String(kwargs["to"])), ('to', String(kwargs["to"])),
('amount', Amount(kwargs["amount"])), ('amount', Amount(kwargs["amount"], prefix=prefix)),
('memo', memo), ('memo', memo),
])) ]))
...@@ -89,10 +89,11 @@ class Transfer_to_vesting(GrapheneObject): ...@@ -89,10 +89,11 @@ class Transfer_to_vesting(GrapheneObject):
return return
if len(args) == 1 and len(kwargs) == 0: if len(args) == 1 and len(kwargs) == 0:
kwargs = args[0] kwargs = args[0]
prefix = kwargs.get("prefix", default_prefix)
super(Transfer_to_vesting, self).__init__(OrderedDict([ super(Transfer_to_vesting, self).__init__(OrderedDict([
('from', String(kwargs["from"])), ('from', String(kwargs["from"])),
('to', String(kwargs["to"])), ('to', String(kwargs["to"])),
('amount', Amount(kwargs["amount"])), ('amount', Amount(kwargs["amount"], prefix=prefix)),
])) ]))
...@@ -102,9 +103,10 @@ class Withdraw_vesting(GrapheneObject): ...@@ -102,9 +103,10 @@ class Withdraw_vesting(GrapheneObject):
return return
if len(args) == 1 and len(kwargs) == 0: if len(args) == 1 and len(kwargs) == 0:
kwargs = args[0] kwargs = args[0]
prefix = kwargs.get("prefix", default_prefix)
super(Withdraw_vesting, self).__init__(OrderedDict([ super(Withdraw_vesting, self).__init__(OrderedDict([
('account', String(kwargs["account"])), ('account', String(kwargs["account"])),
('vesting_shares', Amount(kwargs["vesting_shares"])), ('vesting_shares', Amount(kwargs["vesting_shares"], prefix=prefix)),
])) ]))
...@@ -190,7 +192,7 @@ class Account_create(GrapheneObject): ...@@ -190,7 +192,7 @@ class Account_create(GrapheneObject):
meta = kwargs["json_metadata"] meta = kwargs["json_metadata"]
super(Account_create, self).__init__(OrderedDict([ super(Account_create, self).__init__(OrderedDict([
('fee', Amount(kwargs["fee"])), ('fee', Amount(kwargs["fee"], prefix=prefix)),
('creator', String(kwargs["creator"])), ('creator', String(kwargs["creator"])),
('new_account_name', String(kwargs["new_account_name"])), ('new_account_name', String(kwargs["new_account_name"])),
('owner', Permission(kwargs["owner"], prefix=prefix)), ('owner', Permission(kwargs["owner"], prefix=prefix)),
...@@ -221,8 +223,8 @@ class Account_create_with_delegation(GrapheneObject): ...@@ -221,8 +223,8 @@ class Account_create_with_delegation(GrapheneObject):
meta = kwargs["json_metadata"] meta = kwargs["json_metadata"]
super(Account_create_with_delegation, self).__init__(OrderedDict([ super(Account_create_with_delegation, self).__init__(OrderedDict([
('fee', Amount(kwargs["fee"])), ('fee', Amount(kwargs["fee"], prefix=prefix)),
('delegation', Amount(kwargs["delegation"])), ('delegation', Amount(kwargs["delegation"], prefix=prefix)),
('creator', String(kwargs["creator"])), ('creator', String(kwargs["creator"])),
('new_account_name', String(kwargs["new_account_name"])), ('new_account_name', String(kwargs["new_account_name"])),
('owner', Permission(kwargs["owner"], prefix=prefix)), ('owner', Permission(kwargs["owner"], prefix=prefix)),
...@@ -302,10 +304,12 @@ class Witness_set_properties(GrapheneObject): ...@@ -302,10 +304,12 @@ class Witness_set_properties(GrapheneObject):
elif isinstance(k[1], int) and k[0] in ["sbd_interest_rate"]: elif isinstance(k[1], int) and k[0] in ["sbd_interest_rate"]:
props[k[0]] = (hexlify(Uint16(k[1]).__bytes__())).decode() props[k[0]] = (hexlify(Uint16(k[1]).__bytes__())).decode()
elif not isinstance(k[1], str) and k[0] in ["account_creation_fee"]: elif not isinstance(k[1], str) and k[0] in ["account_creation_fee"]:
props[k[0]] = (hexlify(Amount(k[1]).__bytes__())).decode() props[k[0]] = (hexlify(Amount(k[1], prefix=prefix).__bytes__())).decode()
elif not is_hex and isinstance(k[1], str) and k[0] in ["account_creation_fee"]: elif not is_hex and isinstance(k[1], str) and k[0] in ["account_creation_fee"]:
props[k[0]] = (hexlify(Amount(k[1]).__bytes__())).decode() props[k[0]] = (hexlify(Amount(k[1], prefix=prefix).__bytes__())).decode()
elif not isinstance(k[1], str) and k[0] in ["sbd_exchange_rate"]: elif not isinstance(k[1], str) and k[0] in ["sbd_exchange_rate"]:
if 'prefix' not in k[1]:
k[1]['prefix'] = prefix
props[k[0]] = (hexlify(ExchangeRate(k[1]).__bytes__())).decode() props[k[0]] = (hexlify(ExchangeRate(k[1]).__bytes__())).decode()
elif not is_hex and k[0] in ["url"]: elif not is_hex and k[0] in ["url"]:
props[k[0]] = (hexlify(String(k[1]).__bytes__())).decode() props[k[0]] = (hexlify(String(k[1]).__bytes__())).decode()
...@@ -341,13 +345,15 @@ class Witness_update(GrapheneObject): ...@@ -341,13 +345,15 @@ class Witness_update(GrapheneObject):
else: else:
block_signing_key = PublicKey( block_signing_key = PublicKey(
prefix + "1111111111111111111111111111111114T1Anm", prefix=prefix) prefix + "1111111111111111111111111111111114T1Anm", prefix=prefix)
if 'prefix' not in kwargs['props']:
kwargs['props']['prefix'] = prefix
super(Witness_update, self).__init__(OrderedDict([ super(Witness_update, self).__init__(OrderedDict([
('owner', String(kwargs["owner"])), ('owner', String(kwargs["owner"])),
('url', String(kwargs["url"])), ('url', String(kwargs["url"])),
('block_signing_key', block_signing_key), ('block_signing_key', block_signing_key),
('props', WitnessProps(kwargs["props"])), ('props', WitnessProps(kwargs["props"])),
('fee', Amount(kwargs["fee"])), ('fee', Amount(kwargs["fee"], prefix=prefix)),
])) ]))
...@@ -410,6 +416,7 @@ class Comment_options(GrapheneObject): ...@@ -410,6 +416,7 @@ class Comment_options(GrapheneObject):
return return
if len(args) == 1 and len(kwargs) == 0: if len(args) == 1 and len(kwargs) == 0:
kwargs = args[0] kwargs = args[0]
prefix = kwargs.get("prefix", default_prefix)
# handle beneficiaries # handle beneficiaries
if "beneficiaries" in kwargs and kwargs['beneficiaries']: if "beneficiaries" in kwargs and kwargs['beneficiaries']:
...@@ -424,7 +431,7 @@ class Comment_options(GrapheneObject): ...@@ -424,7 +431,7 @@ class Comment_options(GrapheneObject):
('author', String(kwargs["author"])), ('author', String(kwargs["author"])),
('permlink', String(kwargs["permlink"])), ('permlink', String(kwargs["permlink"])),
('max_accepted_payout', ('max_accepted_payout',
Amount(kwargs["max_accepted_payout"])), Amount(kwargs["max_accepted_payout"], prefix=prefix)),
('percent_steem_dollars', ('percent_steem_dollars',
Uint16(int(kwargs["percent_steem_dollars"]))), Uint16(int(kwargs["percent_steem_dollars"]))),
('allow_votes', Bool(bool(kwargs["allow_votes"]))), ('allow_votes', Bool(bool(kwargs["allow_votes"]))),
...@@ -453,6 +460,9 @@ class Feed_publish(GrapheneObject): ...@@ -453,6 +460,9 @@ class Feed_publish(GrapheneObject):
return return
if len(args) == 1 and len(kwargs) == 0: if len(args) == 1 and len(kwargs) == 0:
kwargs = args[0] kwargs = args[0]
prefix = kwargs.get("prefix", default_prefix)
if 'prefix' not in kwargs['exchange_rate']:
kwargs['exchange_rate']['prefix'] = prefix
super(Feed_publish, self).__init__( super(Feed_publish, self).__init__(
OrderedDict([ OrderedDict([
('publisher', String(kwargs["publisher"])), ('publisher', String(kwargs["publisher"])),
...@@ -466,11 +476,12 @@ class Convert(GrapheneObject): ...@@ -466,11 +476,12 @@ class Convert(GrapheneObject):
return return
if len(args) == 1 and len(kwargs) == 0: if len(args) == 1 and len(kwargs) == 0:
kwargs = args[0] kwargs = args[0]
prefix = kwargs.get("prefix", default_prefix)
super(Convert, self).__init__( super(Convert, self).__init__(
OrderedDict([ OrderedDict([
('owner', String(kwargs["owner"])), ('owner', String(kwargs["owner"])),
('requestid', Uint32(kwargs["requestid"])), ('requestid', Uint32(kwargs["requestid"])),
('amount', Amount(kwargs["amount"])), ('amount', Amount(kwargs["amount"], prefix=prefix)),
])) ]))
...@@ -508,10 +519,11 @@ class Claim_account(GrapheneObject): ...@@ -508,10 +519,11 @@ class Claim_account(GrapheneObject):
return return
if len(args) == 1 and len(kwargs) == 0: if len(args) == 1 and len(kwargs) == 0:
kwargs = args[0] kwargs = args[0]
prefix = kwargs.get("prefix", default_prefix)
super(Claim_account, self).__init__( super(Claim_account, self).__init__(
OrderedDict([ OrderedDict([
('creator', String(kwargs["creator"])), ('creator', String(kwargs["creator"])),
('fee', Amount(kwargs["fee"])), ('fee', Amount(kwargs["fee"], prefix=prefix)),
('extensions', Array([])), ('extensions', Array([])),
])) ]))
...@@ -553,11 +565,12 @@ class Delegate_vesting_shares(GrapheneObject): ...@@ -553,11 +565,12 @@ class Delegate_vesting_shares(GrapheneObject):
return return
if len(args) == 1 and len(kwargs) == 0: if len(args) == 1 and len(kwargs) == 0:
kwargs = args[0] kwargs = args[0]
prefix = kwargs.get("prefix", default_prefix)
super(Delegate_vesting_shares, self).__init__( super(Delegate_vesting_shares, self).__init__(
OrderedDict([ OrderedDict([
('delegator', String(kwargs["delegator"])), ('delegator', String(kwargs["delegator"])),
('delegatee', String(kwargs["delegatee"])), ('delegatee', String(kwargs["delegatee"])),
('vesting_shares', Amount(kwargs["vesting_shares"])), ('vesting_shares', Amount(kwargs["vesting_shares"], prefix=prefix)),
])) ]))
...@@ -567,12 +580,13 @@ class Limit_order_create(GrapheneObject): ...@@ -567,12 +580,13 @@ class Limit_order_create(GrapheneObject):
return return
if len(args) == 1 and len(kwargs) == 0: if len(args) == 1 and len(kwargs) == 0:
kwargs = args[0] kwargs = args[0]
prefix = kwargs.get("prefix", default_prefix)
super(Limit_order_create, self).__init__( super(Limit_order_create, self).__init__(
OrderedDict([ OrderedDict([
('owner', String(kwargs["owner"])), ('owner', String(kwargs["owner"])),
('orderid', Uint32(kwargs["orderid"])), ('orderid', Uint32(kwargs["orderid"])),
('amount_to_sell', Amount(kwargs["amount_to_sell"])), ('amount_to_sell', Amount(kwargs["amount_to_sell"], prefix=prefix)),
('min_to_receive', Amount(kwargs["min_to_receive"])), ('min_to_receive', Amount(kwargs["min_to_receive"], prefix=prefix)),
('fill_or_kill', Bool(kwargs["fill_or_kill"])), ('fill_or_kill', Bool(kwargs["fill_or_kill"])),
('expiration', PointInTime(kwargs["expiration"])), ('expiration', PointInTime(kwargs["expiration"])),
])) ]))
...@@ -584,11 +598,14 @@ class Limit_order_create2(GrapheneObject): ...@@ -584,11 +598,14 @@ class Limit_order_create2(GrapheneObject):
return return
if len(args) == 1 and len(kwargs) == 0: if len(args) == 1 and len(kwargs) == 0:
kwargs = args[0] kwargs = args[0]
prefix = kwargs.get("prefix", default_prefix)
if 'prefix' not in kwargs['exchange_rate']:
kwargs['exchange_rate']['prefix'] = prefix
super(Limit_order_create2, self).__init__( super(Limit_order_create2, self).__init__(
OrderedDict([ OrderedDict([
('owner', String(kwargs["owner"])), ('owner', String(kwargs["owner"])),
('orderid', Uint32(kwargs["orderid"])), ('orderid', Uint32(kwargs["orderid"])),
('amount_to_sell', Amount(kwargs["amount_to_sell"])), ('amount_to_sell', Amount(kwargs["amount_to_sell"], prefix=prefix)),
('fill_or_kill', Bool(kwargs["fill_or_kill"])), ('fill_or_kill', Bool(kwargs["fill_or_kill"])),
('exchange_rate', ExchangeRate(kwargs["exchange_rate"])), ('exchange_rate', ExchangeRate(kwargs["exchange_rate"])),
('expiration', PointInTime(kwargs["expiration"])), ('expiration', PointInTime(kwargs["expiration"])),
...@@ -615,6 +632,7 @@ class Transfer_from_savings(GrapheneObject): ...@@ -615,6 +632,7 @@ class Transfer_from_savings(GrapheneObject):
return return
if len(args) == 1 and len(kwargs) == 0: if len(args) == 1 and len(kwargs) == 0:
kwargs = args[0] kwargs = args[0]
prefix = kwargs.get("prefix", default_prefix)
if "memo" not in kwargs: if "memo" not in kwargs:
kwargs["memo"] = "" kwargs["memo"] = ""
...@@ -623,7 +641,7 @@ class Transfer_from_savings(GrapheneObject): ...@@ -623,7 +641,7 @@ class Transfer_from_savings(GrapheneObject):
('from', String(kwargs["from"])), ('from', String(kwargs["from"])),
('request_id', Uint32(kwargs["request_id"])), ('request_id', Uint32(kwargs["request_id"])),
('to', String(kwargs["to"])), ('to', String(kwargs["to"])),
('amount', Amount(kwargs["amount"])), ('amount', Amount(kwargs["amount"], prefix=prefix)),
('memo', String(kwargs["memo"])), ('memo', String(kwargs["memo"])),
])) ]))
...@@ -647,12 +665,13 @@ class Claim_reward_balance(GrapheneObject): ...@@ -647,12 +665,13 @@ class Claim_reward_balance(GrapheneObject):
return return
if len(args) == 1 and len(kwargs) == 0: if len(args) == 1 and len(kwargs) == 0:
kwargs = args[0] kwargs = args[0]
prefix = kwargs.get("prefix", default_prefix)
super(Claim_reward_balance, self).__init__( super(Claim_reward_balance, self).__init__(
OrderedDict([ OrderedDict([
('account', String(kwargs["account"])), ('account', String(kwargs["account"])),
('reward_steem', Amount(kwargs["reward_steem"])), ('reward_steem', Amount(kwargs["reward_steem"], prefix=prefix)),
('reward_sbd', Amount(kwargs["reward_sbd"])), ('reward_sbd', Amount(kwargs["reward_sbd"], prefix=prefix)),
('reward_vests', Amount(kwargs["reward_vests"])), ('reward_vests', Amount(kwargs["reward_vests"], prefix=prefix)),
])) ]))
...@@ -662,13 +681,14 @@ class Transfer_to_savings(GrapheneObject): ...@@ -662,13 +681,14 @@ class Transfer_to_savings(GrapheneObject):
return return
if len(args) == 1 and len(kwargs) == 0: if len(args) == 1 and len(kwargs) == 0:
kwargs = args[0] kwargs = args[0]
prefix = kwargs.get("prefix", default_prefix)
if "memo" not in kwargs: if "memo" not in kwargs:
kwargs["memo"] = "" kwargs["memo"] = ""
super(Transfer_to_savings, self).__init__( super(Transfer_to_savings, self).__init__(
OrderedDict([ OrderedDict([
('from', String(kwargs["from"])), ('from', String(kwargs["from"])),
('to', String(kwargs["to"])), ('to', String(kwargs["to"])),
('amount', Amount(kwargs["amount"])), ('amount', Amount(kwargs["amount"], prefix=prefix)),
('memo', String(kwargs["memo"])), ('memo', String(kwargs["memo"])),
])) ]))
...@@ -714,6 +734,7 @@ class Escrow_transfer(GrapheneObject): ...@@ -714,6 +734,7 @@ class Escrow_transfer(GrapheneObject):
return return
if len(args) == 1 and len(kwargs) == 0: if len(args) == 1 and len(kwargs) == 0:
kwargs = args[0] kwargs = args[0]
prefix = kwargs.get("prefix", default_prefix)
meta = "" meta = ""
if "json_meta" in kwargs and kwargs["json_meta"]: if "json_meta" in kwargs and kwargs["json_meta"]:
if (isinstance(kwargs["json_meta"], dict) or isinstance(kwargs["json_meta"], list)): if (isinstance(kwargs["json_meta"], dict) or isinstance(kwargs["json_meta"], list)):
...@@ -726,9 +747,9 @@ class Escrow_transfer(GrapheneObject): ...@@ -726,9 +747,9 @@ class Escrow_transfer(GrapheneObject):
('to', String(kwargs["to"])), ('to', String(kwargs["to"])),
('agent', String(kwargs["agent"])), ('agent', String(kwargs["agent"])),
('escrow_id', Uint32(kwargs["escrow_id"])), ('escrow_id', Uint32(kwargs["escrow_id"])),
('sbd_amount', Amount(kwargs["sbd_amount"])), ('sbd_amount', Amount(kwargs["sbd_amount"], prefix=prefix)),
('steem_amount', Amount(kwargs["steem_amount"])), ('steem_amount', Amount(kwargs["steem_amount"], prefix=prefix)),
('fee', Amount(kwargs["fee"])), ('fee', Amount(kwargs["fee"], prefix=prefix)),
('ratification_deadline', PointInTime(kwargs["ratification_deadline"])), ('ratification_deadline', PointInTime(kwargs["ratification_deadline"])),
('escrow_expiration', PointInTime(kwargs["escrow_expiration"])), ('escrow_expiration', PointInTime(kwargs["escrow_expiration"])),
('json_meta', String(meta)), ('json_meta', String(meta)),
...@@ -756,14 +777,15 @@ class Escrow_release(GrapheneObject): ...@@ -756,14 +777,15 @@ class Escrow_release(GrapheneObject):
return return
if len(args) == 1 and len(kwargs) == 0: if len(args) == 1 and len(kwargs) == 0:
kwargs = args[0] kwargs = args[0]
prefix = kwargs.get("prefix", default_prefix)
super(Escrow_release, self).__init__( super(Escrow_release, self).__init__(
OrderedDict([ OrderedDict([
('from', String(kwargs["from"])), ('from', String(kwargs["from"])),
('to', String(kwargs["to"])), ('to', String(kwargs["to"])),
('who', String(kwargs["who"])), ('who', String(kwargs["who"])),
('escrow_id', Uint32(kwargs["escrow_id"])), ('escrow_id', Uint32(kwargs["escrow_id"])),
('sbd_amount', Amount(kwargs["sbd_amount"])), ('sbd_amount', Amount(kwargs["sbd_amount"], prefix=prefix)),
('steem_amount', Amount(kwargs["steem_amount"])), ('steem_amount', Amount(kwargs["steem_amount"], prefix=prefix)),
])) ]))
......
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