def __init__(self, sort="rank", observer=None, last=None, limit=100, lazy=False, full=True, blockchain_instance=None, **kwargs): if blockchain_instance is None: if kwargs.get("steem_instance"): blockchain_instance = kwargs["steem_instance"] elif kwargs.get("hive_instance"): blockchain_instance = kwargs["hive_instance"] self.blockchain = blockchain_instance or shared_blockchain_instance() if not self.blockchain.is_connected(): return communities = [] community_cnt = 0 batch_limit = 100 if batch_limit > limit: batch_limit = limit while community_cnt < limit: self.blockchain.rpc.set_next_node_on_empty_reply(False) communities += self.blockchain.rpc.list_communities({'sort': sort, 'observer': observer, "last": last, "limit": batch_limit}, api="bridge") community_cnt += batch_limit last = communities[-1]["name"] super(Communities, self).__init__( [ Community(x, lazy=lazy, full=full, blockchain_instance=self.blockchain) for x in communities ] )
def __init__(self, blockchain_instance=None, *args, **kwargs): if blockchain_instance is None: if kwargs.get("steem_instance"): blockchain_instance = kwargs["steem_instance"] elif kwargs.get("hive_instance"): blockchain_instance = kwargs["hive_instance"] self.blockchain = blockchain_instance or shared_blockchain_instance() # Compatibility after name change from wif->keys if "wif" in kwargs and "keys" not in kwargs: kwargs["keys"] = kwargs["wif"] if "keys" in kwargs and len(kwargs["keys"]) > 0: from beemstorage import InRamPlainKeyStore self.store = InRamPlainKeyStore() self.setKeys(kwargs["keys"]) else: """ If no keys are provided manually we load the SQLite keyStorage """ from beemstorage import SqliteEncryptedKeyStore self.store = kwargs.get( "key_store", SqliteEncryptedKeyStore(config=self.blockchain.config, **kwargs), )
def __init__( self, owner, full=False, lazy=False, blockchain_instance=None, **kwargs ): self.full = full self.lazy = lazy if blockchain_instance is None: if kwargs.get("steem_instance"): blockchain_instance = kwargs["steem_instance"] elif kwargs.get("hive_instance"): blockchain_instance = kwargs["hive_instance"] self.blockchain = blockchain_instance or shared_blockchain_instance() if isinstance(owner, dict): owner = self._parse_json_data(owner) super(Witness, self).__init__( owner, lazy=lazy, full=full, id_item="owner", blockchain_instance=blockchain_instance )
def __init__(self, blockchain_instance=None, *args, **kwargs): if blockchain_instance is None: if kwargs.get("steem_instance"): blockchain_instance = kwargs["steem_instance"] elif kwargs.get("hive_instance"): blockchain_instance = kwargs["hive_instance"] self.blockchain = blockchain_instance or shared_blockchain_instance() self.access_token = None config = self.blockchain.config self.get_refresh_token = kwargs.get("get_refresh_token", False) self.hot_sign_redirect_uri = kwargs.get("hot_sign_redirect_uri", config["hot_sign_redirect_uri"]) if self.hot_sign_redirect_uri == "": self.hot_sign_redirect_uri = None self.client_id = kwargs.get("client_id", config["hs_client_id"]) self.scope = kwargs.get("scope", "login") self.hs_oauth_base_url = kwargs.get("hs_oauth_base_url", config["hs_oauth_base_url"]) self.hs_api_url = kwargs.get("hs_api_url", config["hs_api_url"]) if "token" in kwargs and len(kwargs["token"]) > 0: from beemstorage import InRamPlainTokenStore self.store = InRamPlainTokenStore() token = kwargs["token"] self.set_access_token(token) name = self.me()["user"] self.setToken({name: token}) else: """ If no keys are provided manually we load the SQLite keyStorage """ from beemstorage import SqliteEncryptedTokenStore self.store = kwargs.get( "token_store", SqliteEncryptedTokenStore(config=config, **kwargs), )
def __init__( self, from_account=None, to_account=None, blockchain_instance=None, **kwargs ): if blockchain_instance is None: if kwargs.get("steem_instance"): blockchain_instance = kwargs["steem_instance"] elif kwargs.get("hive_instance"): blockchain_instance = kwargs["hive_instance"] self.blockchain = blockchain_instance or shared_blockchain_instance() if to_account and len(to_account) < 51: self.to_account = Account(to_account, blockchain_instance=self.blockchain) elif to_account and len(to_account) >= 51: self.to_account = PublicKey(to_account) else: self.to_account = None if from_account and len(from_account) < 51: self.from_account = Account(from_account, blockchain_instance=self.blockchain) elif from_account and len(from_account) >= 51: self.from_account = PrivateKey(from_account) else: self.from_account = None
def __init__( self, tx={}, use_condenser_api=True, blockchain_instance=None, **kwargs ): if blockchain_instance is None: if kwargs.get("steem_instance"): blockchain_instance = kwargs["steem_instance"] elif kwargs.get("hive_instance"): blockchain_instance = kwargs["hive_instance"] self.blockchain = blockchain_instance or shared_blockchain_instance() self.clear() if tx and isinstance(tx, dict): super(TransactionBuilder, self).__init__(tx) # Load operations self.ops = tx["operations"] self._require_reconstruction = False else: self._require_reconstruction = True self._use_ledger = self.blockchain.use_ledger self.path = self.blockchain.path self._use_condenser_api = use_condenser_api self.set_expiration(kwargs.get("expiration", self.blockchain.expiration))
def __init__(self, name_list, batch_limit=100, lazy=False, full=True, blockchain_instance=None, **kwargs): if blockchain_instance is None: if kwargs.get("steem_instance"): blockchain_instance = kwargs["steem_instance"] elif kwargs.get("hive_instance"): blockchain_instance = kwargs["hive_instance"] self.blockchain = blockchain_instance or shared_blockchain_instance() if not self.blockchain.is_connected(): return witnesses = [] name_cnt = 0 if self.blockchain.rpc.get_use_appbase(): while name_cnt < len(name_list): self.blockchain.rpc.set_next_node_on_empty_reply(False) witnesses += self.blockchain.rpc.find_witnesses({'owners': name_list[name_cnt:batch_limit + name_cnt]}, api="database")["witnesses"] name_cnt += batch_limit else: for witness in name_list: witnesses.append(self.blockchain.rpc.get_witness_by_account(witness)) self.identifier = "" super(GetWitnesses, self).__init__( [ Witness(x, lazy=lazy, full=full, blockchain_instance=self.blockchain) for x in witnesses ] )
def __init__(self, account, lazy=False, full=True, blockchain_instance=None, **kwargs): if blockchain_instance is None: if kwargs.get("steem_instance"): blockchain_instance = kwargs["steem_instance"] elif kwargs.get("hive_instance"): blockchain_instance = kwargs["hive_instance"] self.blockchain = blockchain_instance or shared_blockchain_instance() self.account = Account(account, full=True, blockchain_instance=self.blockchain) account_name = self.account["name"] self.identifier = account_name self.blockchain.rpc.set_next_node_on_empty_reply(False) if self.blockchain.rpc.get_use_appbase(): if "witnesses_voted_for" not in self.account: return limit = self.account["witnesses_voted_for"] witnessess_dict = self.blockchain.rpc.list_witness_votes({'start': [account_name], 'limit': limit, 'order': 'by_account_witness'}, api="database")['votes'] witnessess = [] for w in witnessess_dict: witnessess.append(w["witness"]) else: if "witness_votes" not in self.account: return witnessess = self.account["witness_votes"] super(WitnessesVotedByAccount, self).__init__( [ Witness(x, lazy=lazy, full=full, blockchain_instance=self.blockchain) for x in witnessess ] )
def __init__(self, starting_block_num, count=1000, lazy=False, full=True, blockchain_instance=None, **kwargs): if blockchain_instance is None: if kwargs.get("steem_instance"): blockchain_instance = kwargs["steem_instance"] elif kwargs.get("hive_instance"): blockchain_instance = kwargs["hive_instance"] self.blockchain = blockchain_instance or shared_blockchain_instance() if not self.blockchain.is_connected(): return blocks = [] self.blockchain.rpc.set_next_node_on_empty_reply(False) blocks = self.blockchain.rpc.get_block_range( { 'starting_block_num': starting_block_num, "count": count }, api="block")['blocks'] super(Blocks, self).__init__([ Block(x, lazy=lazy, full=full, blockchain_instance=self.blockchain) for x in blocks ])
def __init__(self, blockchain_instance=None, *args, **kwargs): if blockchain_instance is None: if kwargs.get("steem_instance"): blockchain_instance = kwargs["steem_instance"] elif kwargs.get("hive_instance"): blockchain_instance = kwargs["hive_instance"] self.blockchain = blockchain_instance or shared_blockchain_instance() # Compatibility after name change from wif->keys if "wif" in kwargs and "keys" not in kwargs: kwargs["keys"] = kwargs["wif"] master_password_set = False if "keys" in kwargs and len(kwargs["keys"]) > 0: self.setKeys(kwargs["keys"]) else: """ If no keys are provided manually we load the SQLite keyStorage """ from .storage import MasterPassword self.MasterPassword = MasterPassword master_password_set = True self.keyStorage = get_default_key_storage() if "token" in kwargs: self.setToken(kwargs["token"]) else: """ If no keys are provided manually we load the SQLite keyStorage """ if not master_password_set: from .storage import MasterPassword self.MasterPassword = MasterPassword self.tokenStorage = get_default_token_storage()
def __init__( self, # accounts=[], on_block=None, only_block_id=False, blockchain_instance=None, keep_alive=25, **kwargs): # Events Events.__init__(self) self.events = Events() # Steem instance if blockchain_instance is None: if kwargs.get("steem_instance"): blockchain_instance = kwargs["steem_instance"] elif kwargs.get("hive_instance"): blockchain_instance = kwargs["hive_instance"] self.blockchain = blockchain_instance or shared_blockchain_instance() # Callbacks if on_block: self.on_block += on_block # Open the websocket self.websocket = NodeWebsocket(urls=self.blockchain.rpc.nodes, user=self.blockchain.rpc.user, password=self.blockchain.rpc.password, only_block_id=only_block_id, on_block=self.process_block, keep_alive=keep_alive)
def __init__(self, from_account="", limit=100, lazy=False, full=False, blockchain_instance=None, **kwargs): if blockchain_instance is None: if kwargs.get("steem_instance"): blockchain_instance = kwargs["steem_instance"] elif kwargs.get("hive_instance"): blockchain_instance = kwargs["hive_instance"] self.blockchain = blockchain_instance or shared_blockchain_instance() self.identifier = from_account self.blockchain.rpc.set_next_node_on_empty_reply(False) if self.blockchain.rpc.get_use_appbase(): witnessess = self.blockchain.rpc.list_witnesses( { 'start': from_account, 'limit': limit, 'order': 'by_name' }, api="database")['witnesses'] else: witnessess = self.blockchain.rpc.lookup_witness_accounts( from_account, limit) if len(witnessess) == 0: return super(ListWitnesses, self).__init__([ Witness(x, lazy=lazy, full=full, blockchain_instance=self.blockchain) for x in witnessess ])
def __init__(self, community, observer="", full=True, lazy=False, blockchain_instance=None, **kwargs): """Initialize an community :param str community: Name of the community :param Hive/Steem blockchain_instance: Hive/Steem instance :param bool lazy: Use lazy loading :param bool full: Obtain all community data including orders, positions, etc. """ self.full = full self.lazy = lazy self.observer = observer if blockchain_instance is None: if kwargs.get("steem_instance"): blockchain_instance = kwargs["steem_instance"] elif kwargs.get("hive_instance"): blockchain_instance = kwargs["hive_instance"] self.blockchain = blockchain_instance or shared_blockchain_instance() if isinstance(community, dict): community = self._parse_json_data(community) super(Community, self).__init__(community, lazy=lazy, full=full, id_item="name", blockchain_instance=blockchain_instance)
def __init__(self, api=None, blockchain_instance=None, steem_instance=None): if api is None: self.api = Api() else: self.api = api self.blockchain = blockchain_instance or steem_instance or shared_blockchain_instance() self.nfts = Nfts(api=self.api) self.ssc_id = "ssc-mainnet-hive"
def __init__(self, message, blockchain_instance=None, **kwargs): if blockchain_instance is None: if kwargs.get("steem_instance"): blockchain_instance = kwargs["steem_instance"] elif kwargs.get("hive_instance"): blockchain_instance = kwargs["hive_instance"] self.blockchain = blockchain_instance or shared_blockchain_instance() self.message = message
def __init__(self, lazy=False, full=True, blockchain_instance=None, **kwargs): if blockchain_instance is None: if kwargs.get("steem_instance"): blockchain_instance = kwargs["steem_instance"] elif kwargs.get("hive_instance"): blockchain_instance = kwargs["hive_instance"] self.blockchain = blockchain_instance or shared_blockchain_instance() self.lazy = lazy self.full = full self.refresh()
def __init__(self, message, blockchain_instance=None, *args, **kwargs): if blockchain_instance is None: if kwargs.get("steem_instance"): blockchain_instance = kwargs["steem_instance"] elif kwargs.get("hive_instance"): blockchain_instance = kwargs["hive_instance"] self.blockchain = blockchain_instance or shared_blockchain_instance() self.message = message.replace("\r\n", "\n") self.signed_by_account = None self.signed_by_name = None self.meta = None self.plain_message = None
def __init__(self, from_account="", limit=100, lazy=False, full=False, blockchain_instance=None, **kwargs): if blockchain_instance is None: if kwargs.get("steem_instance"): blockchain_instance = kwargs["steem_instance"] elif kwargs.get("hive_instance"): blockchain_instance = kwargs["hive_instance"] self.blockchain = blockchain_instance or shared_blockchain_instance() witnessList = [] last_limit = limit self.identifier = "" use_condenser = True self.blockchain.rpc.set_next_node_on_empty_reply(False) if self.blockchain.rpc.get_use_appbase() and not use_condenser: query_limit = 1000 else: query_limit = 100 if self.blockchain.rpc.get_use_appbase() and not use_condenser and from_account == "": last_account = None elif self.blockchain.rpc.get_use_appbase() and not use_condenser: last_account = Witness(from_account, blockchain_instance=self.blockchain)["votes"] else: last_account = from_account if limit > query_limit: while last_limit > query_limit: tmpList = WitnessesRankedByVote(last_account, query_limit) if (last_limit < limit): witnessList.extend(tmpList[1:]) last_limit -= query_limit - 1 else: witnessList.extend(tmpList) last_limit -= query_limit if self.blockchain.rpc.get_use_appbase(): last_account = witnessList[-1]["votes"] else: last_account = witnessList[-1]["owner"] if (last_limit < limit): last_limit += 1 if self.blockchain.rpc.get_use_appbase() and not use_condenser: witnessess = self.blockchain.rpc.list_witnesses({'start': [last_account], 'limit': last_limit, 'order': 'by_vote_name'}, api="database")['witnesses'] elif self.blockchain.rpc.get_use_appbase() and use_condenser: witnessess = self.blockchain.rpc.get_witnesses_by_vote(last_account, last_limit, api="condenser") else: witnessess = self.blockchain.rpc.get_witnesses_by_vote(last_account, last_limit) # self.witness_count = len(self.voted_witnessess) if (last_limit < limit): witnessess = witnessess[1:] if len(witnessess) > 0: for x in witnessess: witnessList.append(Witness(x, lazy=lazy, full=full, blockchain_instance=self.blockchain)) if len(witnessList) == 0: return super(WitnessesRankedByVote, self).__init__(witnessList)
def __init__(self, symbol, api=None, blockchain_instance=None): if api is None: self.api = Api() else: self.api = api self.blockchain = blockchain_instance or shared_blockchain_instance() self.ssc_id = "ssc-mainnet-hive" if isinstance(symbol, dict): self.symbol = symbol["symbol"] super(Nft, self).__init__(symbol) else: self.symbol = symbol.upper() self.refresh()
def __init__(self, account, account_history=[], blockchain_instance=None, **kwargs): if blockchain_instance is None: if kwargs.get("steem_instance"): blockchain_instance = kwargs["steem_instance"] elif kwargs.get("hive_instance"): blockchain_instance = kwargs["hive_instance"] self.blockchain = blockchain_instance or shared_blockchain_instance() self.account = Account(account, blockchain_instance=self.blockchain) self.reset() super(AccountSnapshot, self).__init__(account_history)
def __init__(self, account, api=None, blockchain_instance=None, steem_instance=None): if api is None: self.api = Api() else: self.api = api self.ssc_id = "ssc-mainnet-hive" self.blockchain = blockchain_instance or steem_instance or shared_blockchain_instance( ) check_account = Account(account, blockchain_instance=self.blockchain) self.account = check_account["name"] self.refresh()
def __init__(self, base=None, quote=None, blockchain_instance=None, **kwargs): """ Init Market :param beem.steem.Steem blockchain_instance: Steem instance :param beem.asset.Asset base: Base asset :param beem.asset.Asset quote: Quote asset """ if blockchain_instance is None: if kwargs.get("steem_instance"): blockchain_instance = kwargs["steem_instance"] elif kwargs.get("hive_instance"): blockchain_instance = kwargs["hive_instance"] self.blockchain = blockchain_instance or shared_blockchain_instance() if quote is None and isinstance(base, str): quote_symbol, base_symbol = assets_from_string(base) quote = Asset(quote_symbol, blockchain_instance=self.blockchain) base = Asset(base_symbol, blockchain_instance=self.blockchain) super(Market, self).__init__({ "base": base, "quote": quote }, blockchain_instance=self.blockchain) elif base and quote: quote = Asset(quote, blockchain_instance=self.blockchain) base = Asset(base, blockchain_instance=self.blockchain) super(Market, self).__init__({ "base": base, "quote": quote }, blockchain_instance=self.blockchain) elif base is None and quote is None: quote = Asset(self.blockchain.backed_token_symbol, blockchain_instance=self.blockchain) base = Asset(self.blockchain.token_symbol, blockchain_instance=self.blockchain) super(Market, self).__init__({ "base": base, "quote": quote }, blockchain_instance=self.blockchain) else: raise ValueError("Unknown Market config")
def __init__(self, blockchain_instance=None, *args, **kwargs): if blockchain_instance is None: if kwargs.get("steem_instance"): blockchain_instance = kwargs["steem_instance"] elif kwargs.get("hive_instance"): blockchain_instance = kwargs["hive_instance"] self.blockchain = blockchain_instance or shared_blockchain_instance() self.access_token = None config = self.blockchain.config self.get_refresh_token = kwargs.get("get_refresh_token", False) self.hot_sign_redirect_uri = kwargs.get("hot_sign_redirect_uri", config["hot_sign_redirect_uri"]) if self.hot_sign_redirect_uri == "": self.hot_sign_redirect_uri = None self.client_id = kwargs.get("client_id", config["hs_client_id"]) self.scope = kwargs.get("scope", "login") self.hs_oauth_base_url = kwargs.get("hs_oauth_base_url", config["hs_oauth_base_url"]) self.hs_api_url = kwargs.get("hs_api_url", config["hs_api_url"])
def __init__(self, from_account=None, to_account=None, blockchain_instance=None, **kwargs): if blockchain_instance is None: if kwargs.get("steem_instance"): blockchain_instance = kwargs["steem_instance"] elif kwargs.get("hive_instance"): blockchain_instance = kwargs["hive_instance"] self.blockchain = blockchain_instance or shared_blockchain_instance() if to_account: self.to_account = Account(to_account, blockchain_instance=self.blockchain) if from_account: self.from_account = Account(from_account, blockchain_instance=self.blockchain)
def __init__(self, base, quote=None, blockchain_instance=None, **kwargs): self.blockchain = blockchain_instance or shared_blockchain_instance() if (isinstance(base, dict) and "sell_price" in base): super(Order, self).__init__(base["sell_price"]) self["id"] = base.get("id") elif (isinstance(base, dict) and "min_to_receive" in base and "amount_to_sell" in base): super(Order, self).__init__( Amount(base["min_to_receive"], blockchain_instance=self.blockchain), Amount(base["amount_to_sell"], blockchain_instance=self.blockchain), ) self["id"] = base.get("id") elif isinstance(base, Amount) and isinstance(quote, Amount): super(Order, self).__init__(None, base=base, quote=quote) else: raise ValueError("Unknown format to load Order")
def __init__(self, order, blockchain_instance=None, **kwargs): self.blockchain = blockchain_instance or shared_blockchain_instance() if isinstance( order, dict) and "current_pays" in order and "open_pays" in order: # filled orders from account history if "op" in order: order = order["op"] super(FilledOrder, self).__init__(Amount(order["open_pays"], blockchain_instance=self.blockchain), Amount(order["current_pays"], blockchain_instance=self.blockchain), blockchain_instance=self.blockchain) if "date" in order: self["date"] = formatTimeString(order["date"]) else: raise ValueError("Couldn't parse 'Price'.")
import io from beem.blockchain import Blockchain from beem.instance import shared_blockchain_instance from beem.utils import parse_time import logging log = logging.getLogger(__name__) logging.basicConfig(level=logging.INFO) class DemoBot(object): def vote(self, vote_event): w = vote_event["weight"] if w > 0: print("Vote by", vote_event["voter"], "for", vote_event["author"]) else: if w < 0: print("Downvote by", vote_event["voter"], "for", vote_event["author"]) else: print("(Down)vote by", vote_event["voter"], "for", vote_event["author"], "CANCELED") if __name__ == "__main__": tb = DemoBot() blockchain = Blockchain() print("Starting on %s network" % shared_blockchain_instance().get_blockchain_name()) for vote in blockchain.stream(opNames=["vote"]): tb.vote(vote)
from beem import Steem from beem import Hive from beem.instance import shared_blockchain_instance from beem.market import Market from django import template register = template.Library() shared_blockchain_instance() m = Market() @register.simple_tag def usd_price(): value = m.hive_usd_implied() value = float('{0:.2f}'.format(value)) return value
def __init__( self, data, klass=None, space_id=1, object_id=None, lazy=False, use_cache=True, id_item=None, blockchain_instance=None, *args, **kwargs ): if blockchain_instance is None: if kwargs.get("steem_instance"): blockchain_instance = kwargs["steem_instance"] elif kwargs.get("hive_instance"): blockchain_instance = kwargs["hive_instance"] self.blockchain = blockchain_instance or shared_blockchain_instance() self.cached = False self.identifier = None # We don't read lists, sets, or tuples if isinstance(data, (list, set, tuple)): raise ValueError( "Cannot interpret lists! Please load elements individually!") if id_item and isinstance(id_item, string_types): self.id_item = id_item else: self.id_item = "id" if klass and isinstance(data, klass): self.identifier = data.get(self.id_item) super(BlockchainObject, self).__init__(data) elif isinstance(data, dict): self.identifier = data.get(self.id_item) super(BlockchainObject, self).__init__(data) elif isinstance(data, integer_types): # This is only for block number basically self.identifier = data if not lazy and not self.cached: self.refresh() # make sure to store the blocknumber for caching self[self.id_item] = (data) # Set identifier again as it is overwritten in super() in refresh() self.identifier = data elif isinstance(data, string_types): self.identifier = data if not lazy and not self.cached: self.refresh() self[self.id_item] = str(data) self.identifier = data else: self.identifier = data if self.test_valid_objectid(self.identifier): # Here we assume we deal with an id self.testid(self.identifier) if self.iscached(data): super(BlockchainObject, self).__init__(self.getcache(data)) elif not lazy and not self.cached: self.refresh() if use_cache and not lazy: self.cache() self.cached = True
def __init__(self, amount, asset=None, fixed_point_arithmetic=False, new_appbase_format=True, blockchain_instance=None, **kwargs): self["asset"] = {} self.new_appbase_format = new_appbase_format self.fixed_point_arithmetic = fixed_point_arithmetic if blockchain_instance is None: if kwargs.get("steem_instance"): blockchain_instance = kwargs["steem_instance"] elif kwargs.get("hive_instance"): blockchain_instance = kwargs["hive_instance"] self.blockchain = blockchain_instance or shared_blockchain_instance() if amount and asset is None and isinstance(amount, Amount): # Copy Asset object self["amount"] = amount["amount"] self["symbol"] = amount["symbol"] self["asset"] = amount["asset"] elif amount and asset is None and isinstance(amount, list) and len(amount) == 3: # Copy Asset object self["amount"] = Decimal(amount[0]) / Decimal(10 ** amount[1]) self["asset"] = Asset(amount[2], blockchain_instance=self.blockchain) self["symbol"] = self["asset"]["symbol"] elif amount and asset is None and isinstance(amount, dict) and "amount" in amount and "nai" in amount and "precision" in amount: # Copy Asset object self.new_appbase_format = True self["amount"] = Decimal(amount["amount"]) / Decimal(10 ** amount["precision"]) self["asset"] = Asset(amount["nai"], blockchain_instance=self.blockchain) self["symbol"] = self["asset"]["symbol"] elif amount is not None and asset is None and isinstance(amount, string_types): self["amount"], self["symbol"] = amount.split(" ") self["asset"] = Asset(self["symbol"], blockchain_instance=self.blockchain) elif (amount and asset is None and isinstance(amount, dict) and "amount" in amount and "asset_id" in amount): self["asset"] = Asset(amount["asset_id"], blockchain_instance=self.blockchain) self["symbol"] = self["asset"]["symbol"] self["amount"] = Decimal(amount["amount"]) / Decimal(10 ** self["asset"]["precision"]) elif (amount and asset is None and isinstance(amount, dict) and "amount" in amount and "asset" in amount): self["asset"] = Asset(amount["asset"], blockchain_instance=self.blockchain) self["symbol"] = self["asset"]["symbol"] self["amount"] = Decimal(amount["amount"]) / Decimal(10 ** self["asset"]["precision"]) elif isinstance(amount, (float)) and asset and isinstance(asset, Asset): self["amount"] = str(amount) self["asset"] = asset self["symbol"] = self["asset"]["symbol"] elif isinstance(amount, (integer_types, Decimal)) and asset and isinstance(asset, Asset): self["amount"] = amount self["asset"] = asset self["symbol"] = self["asset"]["symbol"] elif isinstance(amount, (float)) and asset and isinstance(asset, dict): self["amount"] = str(amount) self["asset"] = asset self["symbol"] = self["asset"]["symbol"] elif isinstance(amount, (integer_types, Decimal)) and asset and isinstance(asset, dict): self["amount"] = amount self["asset"] = asset self["symbol"] = self["asset"]["symbol"] elif isinstance(amount, (float)) and asset and isinstance(asset, string_types): self["amount"] = str(amount) self["asset"] = Asset(asset, blockchain_instance=self.blockchain) self["symbol"] = asset elif isinstance(amount, (integer_types, Decimal)) and asset and isinstance(asset, string_types): self["amount"] = amount self["asset"] = Asset(asset, blockchain_instance=self.blockchain) self["symbol"] = asset elif amount and asset and isinstance(asset, Asset): self["amount"] = amount self["symbol"] = asset["symbol"] self["asset"] = asset elif amount and asset and isinstance(asset, string_types): self["amount"] = amount self["asset"] = Asset(asset, blockchain_instance=self.blockchain) self["symbol"] = self["asset"]["symbol"] else: raise ValueError if self.fixed_point_arithmetic: self["amount"] = quantize(self["amount"], self["asset"]["precision"]) else: self["amount"] = Decimal(self["amount"])