def get_balances(self): available = { 'STEEM': Amount(self['balance']).amount, 'SBD': Amount(self['sbd_balance']).amount, 'VESTS': Amount(self['vesting_shares']).amount, } savings = { 'STEEM': Amount(self['savings_balance']).amount, 'SBD': Amount(self['savings_sbd_balance']).amount, } rewards = { 'STEEM': Amount(self['reward_steem_balance']).amount, 'SBD': Amount(self['reward_sbd_balance']).amount, 'VESTS': Amount(self['reward_vesting_balance']).amount, } totals = { 'STEEM': sum([available['STEEM'], savings['STEEM'], rewards['STEEM']]), 'SBD': sum([available['SBD'], savings['SBD'], rewards['SBD']]), 'VESTS': sum([available['VESTS'], rewards['VESTS']]), } total = walk_values(rpartial(round, 3), totals) return { 'available': available, 'savings': savings, 'rewards': rewards, 'total': total, }
def get_balances(self): available = { 'GOLOS': Amount(self['balance']).amount, 'GBG': Amount(self['sbd_balance']).amount, 'GESTS': Amount(self['vesting_shares']).amount, } savings = { 'GOLOS': Amount(self['savings_balance']).amount, 'GBG': Amount(self['savings_sbd_balance']).amount, } totals = { 'GOLOS': sum([available['GOLOS'], savings['GOLOS']]), 'GBG': sum([available['GBG'], savings['GBG']]), 'GESTS': sum([available['GESTS']]), } total = walk_values(rpartial(round, 3), totals) return { 'available': available, 'savings': savings, 'total': total, }
def get_balances(self): available = { 'BEARS': Amount(self['balance']).amount, 'BSD': Amount(self['bsd_balance']).amount, 'COINS': Amount(self['coining_shares']).amount, } savings = { 'BEARS': Amount(self['savings_balance']).amount, 'BSD': Amount(self['savings_bsd_balance']).amount, } rewards = { 'BEARS': Amount(self['reward_bears_balance']).amount, 'BSD': Amount(self['reward_bsd_balance']).amount, 'COINS': Amount(self['reward_coining_balance']).amount, } totals = { 'BEARS': sum([available['BEARS'], savings['BEARS'], rewards['BEARS']]), 'BSD': sum([available['BSD'], savings['BSD'], rewards['BSD']]), 'COINS': sum([available['COINS'], rewards['COINS']]), } total = walk_values(rpartial(round, 3), totals) return { 'available': available, 'savings': savings, 'rewards': rewards, 'total': total, }
def export(self): """ This method returns a dictionary that is type-safe to store as JSON or in a database. """ safe_dict = remove_from_dict(self, ['steemd', 'commit']) # Convert Amount class objects into pure dictionaries def decompose_amounts(item): if type(item) == Amount: return dict(item) return item return walk_values(decompose_amounts, safe_dict)
def typify(value: Union[dict, list, set, str]): """ Enhance block operation with native types. Typify takes a blockchain operation or dict/list/value, and then it parses and converts string types into native data types where appropriate. """ if type(value) == dict: return walk_values(typify, value) if type(value) in [list, set]: return list(map(typify, value)) if type(value) == str: if re.match('^\d+\.\d+ (GOLOS|GBG|GESTS)$', value): return keep_in_dict(dict(Amount(value)), ['amount', 'asset']) if re.match('^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}$', value): return parse_time(value) return value