diff --git a/beembase/objects.py b/beembase/objects.py index 819edc6206642d48d537cfba1126190f8f133531..8de039097fccd09237edd7eb591981578c69be00 100644 --- a/beembase/objects.py +++ b/beembase/objects.py @@ -29,7 +29,7 @@ default_prefix = "STM" class Amount(object): def __init__(self, d): if isinstance(d, string_types): - self.amount, self.asset = d.strip().split(" ") + self.amount, self.symbol = d.strip().split(" ") self.precision = None for c in known_chains: if self.precision is not None: @@ -37,15 +37,17 @@ class Amount(object): for asset in known_chains[c]["chain_assets"]: if self.precision is not None: continue - if asset["symbol"] == self.asset: + if asset["symbol"] == self.symbol: self.precision = asset["precision"] - elif asset["asset"] == self.asset: + self.asset = asset["asset"] + elif asset["asset"] == self.symbol: self.precision = asset["precision"] + self.asset = asset["asset"] if self.precision is None: raise Exception("Asset unknown") self.amount = int(float(self.amount) * 10 ** self.precision) - self.str_repr = '{:.{}f} {}'.format((float(self.amount) / 10 ** self.precision), self.precision, self.asset) + self.str_repr = '{:.{}f} {}'.format((float(self.amount) / 10 ** self.precision), self.precision, self.symbol) elif isinstance(d, list): self.amount = d[0] self.asset = d[2] @@ -57,7 +59,8 @@ class Amount(object): for c in known_chains: for asset in known_chains[c]["chain_assets"]: if asset["asset"] == d["nai"]: - self.asset = asset["symbol"] + self.asset = asset["asset"] + self.symbol = asset["symbol"] if not self.asset: raise ValueError("Unknown NAI, cannot resolve symbol") self.amount = d["amount"] @@ -65,8 +68,8 @@ class Amount(object): self.str_repr = json.dumps(d) else: self.amount = d.amount - self.asset = d.symbol - # self.asset = d.asset["asset"] + self.symbol = d.symbol + self.asset = d.asset["asset"] self.precision = d.asset["precision"] self.amount = int(float(self.amount) * 10 ** self.precision) self.str_repr = str(d) @@ -75,11 +78,13 @@ class Amount(object): def __bytes__(self): # padding - asset = self.asset + "\x00" * (7 - len(self.asset)) + # asset = self.asset + "\x00" * (7 - len(self.asset)) + symbol = self.symbol + "\x00" * (7 - len(self.symbol)) return (struct.pack("<q", int(self.amount)) + struct.pack("<b", self.precision) + - py23_bytes(asset, "ascii")) + py23_bytes(symbol, "ascii")) def __str__(self): + # return json.dumps({"amount": self.amount, "precision": self.precision, "nai": self.asset}) return self.str_repr diff --git a/beembase/operationids.py b/beembase/operationids.py index c83f9654046ac99ca00971febe795cb26bcf30ba..92726da685ec16ee16a46499b3d9dd15d8100234 100644 --- a/beembase/operationids.py +++ b/beembase/operationids.py @@ -45,6 +45,7 @@ ops = [ 'set_reset_account', 'claim_reward_balance', 'delegate_vesting_shares', + 'witness_set_properties', 'account_create_with_delegation', 'fill_convert_request', 'author_reward', @@ -61,7 +62,6 @@ ops = [ 'comment_payout_update', 'return_vesting_delegation', 'comment_benefactor_reward', - 'witness_set_properties' ] operations = {o: ops.index(o) for o in ops} diff --git a/beembase/operations.py b/beembase/operations.py index 918f3f91e90c0483a8751010e72aaf99a9193b92..9ecf8c831957f3df27816d3c0d330358b46c09fc 100644 --- a/beembase/operations.py +++ b/beembase/operations.py @@ -6,6 +6,8 @@ from builtins import int, str from beemgraphenebase.py23 import bytes_types, integer_types, string_types, text_type from collections import OrderedDict import json +from binascii import hexlify, unhexlify +import re from beemgraphenebase.types import ( Uint8, Int16, Uint16, Uint32, Uint64, Varint32, Int64, String, Bytes, Void, @@ -285,14 +287,35 @@ class Witness_set_properties(GrapheneObject): if "key" == k[0]: block_signing_key = (PublicKey(k[1], prefix=prefix)) props["key"] = repr(block_signing_key) + elif "new_signing_key" == k[0]: + new_signing_key = (PublicKey(k[1], prefix=prefix)) + props["new_signing_key"] = repr(new_signing_key) for k in kwargs["props"]: - if k[0] == "key": + if k[0] in ["key", "new_signing_key"]: continue - props[k[0]] = (k[1]) + if isinstance(k[1], str): + is_hex = re.fullmatch(r'[0-9a-fA-F]+', k[1] or '') is not None + else: + is_hex = False + if isinstance(k[1], int) and k[0] in ["account_subsidy_budget", "account_subsidy_decay", "maximum_block_size", "sbd_interest_rate"]: + props[k[0]] = (hexlify(Uint32(k[1]).__bytes__())).decode() + elif not isinstance(k[1], str) and k[0] in ["account_creation_fee"]: + props[k[0]] = (hexlify(Amount(k[1]).__bytes__())).decode() + 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() + elif not isinstance(k[1], str) and k[0] in ["sbd_exchange_rate"]: + props[k[0]] = (hexlify(ExchangeRate(k[1]).__bytes__())).decode() + elif not is_hex and k[0] in ["url"]: + props[k[0]] = (hexlify(String(k[1]).__bytes__())).decode() + else: + props[k[0]] = (k[1]) props_list = [] for k in props: - props_list.append(Array([String(k), String(props[k])])) - map_props = Array(props_list) + if k == "key": + props_list.append(([String(k), String(props[k])])) + else: + props_list.append(([String(k), String(props[k])])) + map_props = Map(props_list) super(Witness_set_properties, self).__init__(OrderedDict([ ('owner', String(kwargs["owner"])),