Exemple #1
0
    def __init__(self, *args, amount=None, asset=None, muse_instance=None):
        self["asset"] = {}

        self.muse = muse_instance or shared_muse_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"], muse_instance=self.muse)

        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"], muse_instance=self.muse)
            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"], muse_instance=self.muse)
            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], muse_instance=self.muse)
            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"])
Exemple #2
0
 def __init__(
     self,
     member,
     muse_instance=None,
 ):
     self.member = member
     self.muse = muse_instance or shared_muse_instance()
     self.refresh()
Exemple #3
0
    def __init__(self, sport_id, muse_instance=None):
        self.muse = muse_instance or shared_muse_instance()
        self.eventgroups = self.muse.rpc.list_event_groups(sport_id)

        super(EventGroups, self).__init__([
            EventGroup(x, lazy=True, muse_instance=muse_instance)
            for x in self.eventgroups
        ])
Exemple #4
0
    def __init__(self, muse_instance=None):
        self.muse = muse_instance or shared_muse_instance()
        self.schedule = self.muse.rpc.get_object("2.12.0").get(
            "current_shuffled_witnesses", [])

        super(Witnesses, self).__init__([
            Witness(x, lazy=True, muse_instance=self.muse)
            for x in self.schedule
        ])
Exemple #5
0
    def __init__(self, muse_instance=None, mode="irreversible"):
        self.muse = muse_instance or shared_muse_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'!")
Exemple #6
0
    def __init__(self, data, muse_instance=None):
        self.muse = muse_instance or shared_muse_instance()

        if isinstance(data, dict):
            super(AccountUpdate, self).__init__(data)
        else:
            account = Account(data, muse_instance=self.muse)
            update = self.muse.rpc.get_objects(
                ["2.6.%s" % (account["id"].split(".")[2])])[0]
            super(AccountUpdate, self).__init__(update)
Exemple #7
0
    def __init__(
        self,
        block,
        muse_instance=None,
    ):
        self.muse = muse_instance or shared_muse_instance()
        self.block = block

        if isinstance(block, Block):
            super(Block, self).__init__(block)
        else:
            self.refresh()
Exemple #8
0
    def __init__(self, account, full=False, muse_instance=None):
        self.full = full
        self.muse = muse_instance or shared_muse_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()
Exemple #9
0
    def __init__(
        self,
        identifier,
        lazy=False,
        muse_instance=None,
    ):
        self.muse = muse_instance or shared_muse_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)
Exemple #10
0
    def __init__(
        self,
        accounts=[],
        objects=[],
        on_tx=None,
        on_object=None,
        on_block=None,
        on_account=None,
        muse_instance=None,
    ):
        # Events
        super(Notify, self).__init__()
        self.events = Events()

        # muse instance
        self.muse = muse_instance or shared_muse_instance()

        # Accounts
        account_ids = []
        for account_name in accounts:
            account = Account(account_name, muse_instance=self.muse)
            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 = MuseWebsocket(
            urls=self.muse.rpc.urls,
            user=self.muse.rpc.user,
            password=self.muse.rpc.password,
            accounts=account_ids,
            objects=objects,
            on_tx=on_tx,
            on_object=on_object,
            on_block=on_block,
            on_account=self.process_account,
        )
Exemple #11
0
    def __init__(
        self,
        witness,
        lazy=False,
        muse_instance=None,
    ):
        self.muse = muse_instance or shared_muse_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()
Exemple #12
0
    def __init__(self, asset, lazy=False, full=False, muse_instance=None):
        self.cached = False
        self.full = full
        self.asset = None

        self.muse = muse_instance or shared_muse_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")
Exemple #13
0
    def __init__(self, from_account, to_account, muse_instance=None):

        self.muse = muse_instance or shared_muse_instance()

        self.to_account = Account(to_account, muse_instance=self.muse)
        self.from_account = Account(from_account, muse_instance=self.muse)
 def __init__(self, tx={}, muse_instance=None):
     self.muse = muse_instance or shared_muse_instance()
     self.clear()
     if not isinstance(tx, dict):
         raise ValueError("Invalid TransactionBuilder Format")
     super(TransactionBuilder, self).__init__(tx)