Skip to content
Snippets Groups Projects
Commit 6cc303d1 authored by Holger's avatar Holger
Browse files

Implementation of Witness_set_properties

All parameter are packed now in a correct way
Correct operationid for Witness_set_properties

objects.Amount
* naming of symbol and asset improved
parent e1cea48a
No related branches found
No related tags found
No related merge requests found
...@@ -29,7 +29,7 @@ default_prefix = "STM" ...@@ -29,7 +29,7 @@ default_prefix = "STM"
class Amount(object): class Amount(object):
def __init__(self, d): def __init__(self, d):
if isinstance(d, string_types): if isinstance(d, string_types):
self.amount, self.asset = d.strip().split(" ") self.amount, self.symbol = d.strip().split(" ")
self.precision = None self.precision = None
for c in known_chains: for c in known_chains:
if self.precision is not None: if self.precision is not None:
...@@ -37,15 +37,17 @@ class Amount(object): ...@@ -37,15 +37,17 @@ class Amount(object):
for asset in known_chains[c]["chain_assets"]: for asset in known_chains[c]["chain_assets"]:
if self.precision is not None: if self.precision is not None:
continue continue
if asset["symbol"] == self.asset: if asset["symbol"] == self.symbol:
self.precision = asset["precision"] self.precision = asset["precision"]
elif asset["asset"] == self.asset: self.asset = asset["asset"]
elif asset["asset"] == self.symbol:
self.precision = asset["precision"] self.precision = asset["precision"]
self.asset = asset["asset"]
if self.precision is None: if self.precision is None:
raise Exception("Asset unknown") raise Exception("Asset unknown")
self.amount = int(float(self.amount) * 10 ** self.precision) 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): elif isinstance(d, list):
self.amount = d[0] self.amount = d[0]
self.asset = d[2] self.asset = d[2]
...@@ -57,7 +59,8 @@ class Amount(object): ...@@ -57,7 +59,8 @@ class Amount(object):
for c in known_chains: for c in known_chains:
for asset in known_chains[c]["chain_assets"]: for asset in known_chains[c]["chain_assets"]:
if asset["asset"] == d["nai"]: if asset["asset"] == d["nai"]:
self.asset = asset["symbol"] self.asset = asset["asset"]
self.symbol = asset["symbol"]
if not self.asset: if not self.asset:
raise ValueError("Unknown NAI, cannot resolve symbol") raise ValueError("Unknown NAI, cannot resolve symbol")
self.amount = d["amount"] self.amount = d["amount"]
...@@ -65,8 +68,8 @@ class Amount(object): ...@@ -65,8 +68,8 @@ class Amount(object):
self.str_repr = json.dumps(d) self.str_repr = json.dumps(d)
else: else:
self.amount = d.amount self.amount = d.amount
self.asset = d.symbol self.symbol = d.symbol
# self.asset = d.asset["asset"] self.asset = d.asset["asset"]
self.precision = d.asset["precision"] self.precision = d.asset["precision"]
self.amount = int(float(self.amount) * 10 ** self.precision) self.amount = int(float(self.amount) * 10 ** self.precision)
self.str_repr = str(d) self.str_repr = str(d)
...@@ -75,11 +78,13 @@ class Amount(object): ...@@ -75,11 +78,13 @@ class Amount(object):
def __bytes__(self): def __bytes__(self):
# padding # 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) + return (struct.pack("<q", int(self.amount)) + struct.pack("<b", self.precision) +
py23_bytes(asset, "ascii")) py23_bytes(symbol, "ascii"))
def __str__(self): def __str__(self):
# return json.dumps({"amount": self.amount, "precision": self.precision, "nai": self.asset})
return self.str_repr return self.str_repr
......
...@@ -45,6 +45,7 @@ ops = [ ...@@ -45,6 +45,7 @@ ops = [
'set_reset_account', 'set_reset_account',
'claim_reward_balance', 'claim_reward_balance',
'delegate_vesting_shares', 'delegate_vesting_shares',
'witness_set_properties',
'account_create_with_delegation', 'account_create_with_delegation',
'fill_convert_request', 'fill_convert_request',
'author_reward', 'author_reward',
...@@ -61,7 +62,6 @@ ops = [ ...@@ -61,7 +62,6 @@ ops = [
'comment_payout_update', 'comment_payout_update',
'return_vesting_delegation', 'return_vesting_delegation',
'comment_benefactor_reward', 'comment_benefactor_reward',
'witness_set_properties'
] ]
operations = {o: ops.index(o) for o in ops} operations = {o: ops.index(o) for o in ops}
......
...@@ -6,6 +6,8 @@ from builtins import int, str ...@@ -6,6 +6,8 @@ from builtins import int, str
from beemgraphenebase.py23 import bytes_types, integer_types, string_types, text_type from beemgraphenebase.py23 import bytes_types, integer_types, string_types, text_type
from collections import OrderedDict from collections import OrderedDict
import json import json
from binascii import hexlify, unhexlify
import re
from beemgraphenebase.types import ( from beemgraphenebase.types import (
Uint8, Int16, Uint16, Uint32, Uint64, Uint8, Int16, Uint16, Uint32, Uint64,
Varint32, Int64, String, Bytes, Void, Varint32, Int64, String, Bytes, Void,
...@@ -285,14 +287,35 @@ class Witness_set_properties(GrapheneObject): ...@@ -285,14 +287,35 @@ class Witness_set_properties(GrapheneObject):
if "key" == k[0]: if "key" == k[0]:
block_signing_key = (PublicKey(k[1], prefix=prefix)) block_signing_key = (PublicKey(k[1], prefix=prefix))
props["key"] = repr(block_signing_key) 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"]: for k in kwargs["props"]:
if k[0] == "key": if k[0] in ["key", "new_signing_key"]:
continue 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 = [] props_list = []
for k in props: for k in props:
props_list.append(Array([String(k), String(props[k])])) if k == "key":
map_props = Array(props_list) 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([ super(Witness_set_properties, self).__init__(OrderedDict([
('owner', String(kwargs["owner"])), ('owner', String(kwargs["owner"])),
......
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