def __init__( self, member, karma_instance=None, ): self.member = member self.karma = karma_instance or shared_karma_instance() self.refresh()
def __init__(self, sport_id, karma_instance=None): self.karma = karma_instance or shared_karma_instance() self.eventgroups = self.karma.rpc.list_event_groups(sport_id) super(EventGroups, self).__init__([ EventGroup(x, lazy=True, karma_instance=karma_instance) for x in self.eventgroups ])
def __init__(self, karma_instance=None, mode="irreversible"): self.karma = karma_instance or shared_karma_instance() if mode == "irreversible": self.mode = 'last_irreversible_block_num' elif mode == "head": self.mode = "head_block_number" else: raise ValueError("invalid value for 'mode'!")
def __init__(self, karma_instance=None): self.karma = karma_instance or shared_karma_instance() self.schedule = self.karma.rpc.get_object("2.12.0").get("current_shuffled_witnesses", []) super(Witnesses, self).__init__( [ Witness(x, lazy=True, karma_instance=self.karma) for x in self.schedule ] )
def __init__( self, block, karma_instance=None, ): self.karma = karma_instance or shared_karma_instance() self.block = block if isinstance(block, Block): super(Block, self).__init__(block) else: self.refresh()
def __init__( self, data, karma_instance=None ): self.karma = karma_instance or shared_karma_instance() if isinstance(data, dict): super(AccountUpdate, self).__init__(data) else: account = Account(data, karma_instance=self.karma) update = self.karma.rpc.get_objects([ "2.6.%s" % (account["id"].split(".")[2]) ])[0] super(AccountUpdate, self).__init__(update)
def __init__( self, identifier, lazy=False, karma_instance=None, ): self.karma = karma_instance or shared_karma_instance() self.cached = False if isinstance(identifier, str): self.identifier = identifier if not lazy: self.refresh() elif isinstance(identifier, dict): self.cached = False self.identifier = identifier.get("id") super(Event, self).__init__(identifier)
def __init__( self, accounts=[], objects=[], on_tx=None, on_object=None, on_block=None, on_account=None, karma_instance=None, ): # Events super(Notify, self).__init__() self.events = Events() # karma instance self.karma = karma_instance or shared_karma_instance() # Accounts account_ids = [] for account_name in accounts: account = Account(account_name, karma_instance=self.karma) account_ids.append(account["id"]) # Callbacks if on_tx: self.on_tx += on_tx if on_object: self.on_object += on_object if on_block: self.on_block += on_block if on_account: self.on_account += on_account # Open the websocket self.websocket = KarmaWebsocket( urls=self.karma.rpc.urls, user=self.karma.rpc.user, password=self.karma.rpc.password, accounts=account_ids, objects=objects, on_tx=on_tx, on_object=on_object, on_block=on_block, on_account=self.process_account, )
def __init__( self, account, full=False, karma_instance=None ): self.full = full self.karma = karma_instance or shared_karma_instance() if isinstance(account, Account): super(Account, self).__init__(account) self.name = account["name"] elif isinstance(account, str): self.name = account.strip().lower() else: raise ValueError("Account() expects an account name, id or an instance of Account") self.refresh()
def __init__( self, witness, lazy=False, karma_instance=None, ): self.karma = karma_instance or shared_karma_instance() self.cached = False if isinstance(witness, Witness): self.witness = witness["name"] super(Witness, self).__init__(witness) self.cached = True self._cache(witness) else: self.witness = witness if witness in Witness.witness_cache: super(Witness, self).__init__(Witness.witness_cache[witness]) self.cached = True elif not lazy and not self.cached: self.refresh()
def __init__(self, asset, lazy=False, full=False, karma_instance=None): self.cached = False self.full = full self.asset = None self.karma = karma_instance or shared_karma_instance() if isinstance(asset, Asset): self.asset = asset.get("symbol") super(Asset, self).__init__(asset) self.cached = True self._cache(asset) elif isinstance(asset, str): self.asset = asset if self.asset in Asset.assets_cache: super(Asset, self).__init__(Asset.assets_cache[self.asset]) self.cached = True elif not lazy and not self.cached: self.refresh() self.cached = True else: raise ValueError( "Asset() expects a symbol, id or an instance of Asset")
def __init__(self, from_account, to_account, karma_instance=None): self.karma = karma_instance or shared_karma_instance() self.to_account = Account(to_account, karma_instance=self.karma) self.from_account = Account(from_account, karma_instance=self.karma)
def __init__(self, *args, amount=None, asset=None, karma_instance=None): self["asset"] = {} self.karma = karma_instance or shared_karma_instance() if len(args) == 1 and isinstance(args[0], Amount): # Copy Asset object self["amount"] = args[0]["amount"] self["symbol"] = args[0]["symbol"] self["asset"] = args[0]["asset"] elif len(args) == 1 and isinstance(args[0], str): self["amount"], self["symbol"] = args[0].split(" ") self["asset"] = Asset(self["symbol"], karma_instance=self.karma) elif (len(args) == 1 and isinstance(args[0], dict) and "amount" in args[0] and "asset_id" in args[0]): self["asset"] = Asset(args[0]["asset_id"], karma_instance=self.karma) self["symbol"] = self["asset"]["symbol"] self["amount"] = int(args[0]["amount"]) / 10 ** self["asset"]["precision"] elif (len(args) == 1 and isinstance(args[0], dict) and "amount" in args[0] and "asset" in args[0]): self["asset"] = Asset(args[0]["asset"], karma_instance=self.karma) self["symbol"] = self["asset"]["symbol"] self["amount"] = int(args[0]["amount"]) / 10 ** self["asset"]["precision"] elif len(args) == 2 and isinstance(args[1], Asset): self["amount"] = args[0] self["symbol"] = args[1]["symbol"] self["asset"] = args[1] elif len(args) == 2 and isinstance(args[1], str): self["amount"] = args[0] self["asset"] = Asset(args[1], karma_instance=self.karma) self["symbol"] = self["asset"]["symbol"] elif amount and asset and isinstance(asset, Asset): self["amount"] = amount self["asset"] = asset self["symbol"] = self["asset"]["symbol"] elif amount and asset and isinstance(asset, dict): self["amount"] = amount self["asset"] = asset self["symbol"] = self["asset"]["symbol"] elif amount and asset and isinstance(asset, str): self["amount"] = amount self["asset"] = Asset(asset) self["symbol"] = asset else: raise ValueError # make sure amount is a float self["amount"] = float(self["amount"])
def __init__(self, tx={}, karma_instance=None): self.karma = karma_instance or shared_karma_instance() self.clear() if not isinstance(tx, dict): raise ValueError("Invalid TransactionBuilder Format") super(TransactionBuilder, self).__init__(tx)