Esempio n. 1
0
    def set_market_fee(self, percentage_fee, max_market_fee, **kwargs):
        """
        Set trading percentage fee.

        :param float percentage_fee: Percentage of fee
        :param deex.amount.Amount max_market_fee: Max Fee
        """
        assert percentage_fee <= 100 and percentage_fee > 0
        flags = {"charge_market_fee": percentage_fee > 0}
        options = self["options"]
        test_permissions(options["issuer_permissions"], flags)
        flags_int = force_flag(options["flags"], flags)
        options.update(
            {
                "flags": flags_int,
                "market_fee_percent": percentage_fee * 100,
                "max_market_fee": int(max_market_fee),
            }
        )
        op = operations.Asset_update(
            **{
                "fee": {"amount": 0, "asset_id": "1.3.0"},
                "issuer": self["issuer"],
                "asset_to_update": self["id"],
                "new_options": options,
                "extensions": [],
            }
        )
        if kwargs.get("return_op") is True:
            return op
        return self.blockchain.finalizeOp(op, self["issuer"], "active")
Esempio n. 2
0
    def halt(self):
        """Halt this asset from being moved or traded."""
        from .account import Account

        nullaccount = Account(
            "null-account",  # We set the null-account
            blockchain_instance=self.blockchain,
        )
        flags = {"white_list": True, "transfer_restricted": True}
        options = self["options"]
        test_permissions(options["issuer_permissions"], flags)
        flags_int = force_flag(options["flags"], flags)
        options.update(
            {
                "flags": flags_int,
                "whitelist_authorities": [nullaccount["id"]],
                "blacklist_authorities": [],
                "whitelist_markets": [self["id"]],
                "blacklist_markets": [],
            }
        )
        op = operations.Asset_update(
            **{
                "fee": {"amount": 0, "asset_id": "1.3.0"},
                "issuer": self["issuer"],
                "asset_to_update": self["id"],
                "new_options": options,
                "extensions": [],
            }
        )
        return self.blockchain.finalizeOp(op, self["issuer"], "active")
Esempio n. 3
0
    def add_markets(self, type, authorities=None, force_enable=True):
        """
        Add markets to an assets white/black list.

        :param str type: ``blacklist`` or ``whitelist``
        :param list markets: List of markets (assets)
        :param bool force_enable: Force enable ``white_list`` flag
        """
        assert type in ["blacklist", "whitelist"]
        assert isinstance(authorities, (list, set))

        if authorities is None:
            authorities = []

        options = self["options"]
        if force_enable:
            test_permissions(options["issuer_permissions"], {"white_list": True})
            flags_int = force_flag(options["flags"], {"white_list": True})
            options.update({"flags": flags_int})
        else:
            assert test_permissions(
                options["flags"], ["white_list"]
            ), "whitelist feature not enabled"

        if type == "whitelist":
            options["whitelist_markets"].extend(
                [
                    Asset(a, blockchain_instance=self.blockchain)["id"]
                    for a in authorities
                ]
            )
        if type == "blacklist":
            options["blacklist_markets"].extend(
                [
                    Asset(a, blockchain_instance=self.blockchain)["id"]
                    for a in authorities
                ]
            )
        op = operations.Asset_update(
            **{
                "fee": {"amount": 0, "asset_id": "1.3.0"},
                "issuer": self["issuer"],
                "asset_to_update": self["id"],
                "new_options": options,
                "extensions": [],
            }
        )
        return self.blockchain.finalizeOp(op, self["issuer"], "active")
Esempio n. 4
0
    def add_authorities(self, type, authorities=None):
        """
        Add authorities to an assets white/black list.

        :param str type: ``blacklist`` or ``whitelist``
        :param list authorities: List of authorities (Accounts)
        """
        assert type in ["blacklist", "whitelist"]
        assert isinstance(authorities, (list, set))
        from .account import Account

        if authorities is None:
            authorities = []

        flags = {"white_list": True}
        options = self["options"]
        test_permissions(options["issuer_permissions"], flags)
        flags_int = force_flag(options["flags"], flags)
        options.update({"flags": flags_int})

        if type == "whitelist":
            options["whitelist_authorities"].extend(
                [
                    Account(a, blockchain_instance=self.blockchain)["id"]
                    for a in authorities
                ]
            )
        if type == "blacklist":
            options["blacklist_authorities"].extend(
                [
                    Account(a, blockchain_instance=self.blockchain)["id"]
                    for a in authorities
                ]
            )
        op = operations.Asset_update(
            **{
                "fee": {"amount": 0, "asset_id": "1.3.0"},
                "issuer": self["issuer"],
                "asset_to_update": self["id"],
                "new_options": options,
                "extensions": [],
            }
        )
        return self.blockchain.finalizeOp(op, self["issuer"], "active")
Esempio n. 5
0
    def setoptions(self, flags, **kwargs):
        """
        Enable a certain flag.

        Flags:

         * charge_market_fee
         * white_list
         * override_authority
         * transfer_restricted
         * disable_force_settle
         * global_settle
         * disable_confidential
         * witness_fed_asset
         * committee_fed_asset

        :param dict flag: dictionary of flags and boolean
        """
        assert set(flags.keys()).issubset(asset_permissions.keys()), "unknown flag"

        options = self["options"]
        test_permissions(options["issuer_permissions"], flags)
        flags_int = force_flag(options["flags"], flags)
        options.update({"flags": flags_int})
        op = operations.Asset_update(
            **{
                "fee": {"amount": 0, "asset_id": "1.3.0"},
                "issuer": self["issuer"],
                "asset_to_update": self["id"],
                "new_options": options,
                "extensions": [],
            }
        )
        if kwargs.get("return_op") is True:
            return op
        return self.blockchain.finalizeOp(op, self["issuer"], "active")
Esempio n. 6
0
    def release(
        self,
        whitelist_authorities=None,
        blacklist_authorities=None,
        whitelist_markets=None,
        blacklist_markets=None,
    ):
        """
        Release this asset and allow unrestricted transfer, trading, etc.

        :param list whitelist_authorities: List of accounts that
            serve as whitelist authorities
        :param list blacklist_authorities: List of accounts that
            serve as blacklist authorities
        :param list whitelist_markets: List of assets to allow
            trading with
        :param list blacklist_markets: List of assets to prevent
            trading with
        """
        from .account import Account

        if whitelist_authorities is None:
            whitelist_authorities = []
        if blacklist_authorities is None:
            blacklist_authorities = []
        if whitelist_markets is None:
            whitelist_markets = []
        if blacklist_markets is None:
            blacklist_markets = []

        flags = {"white_list": False, "transfer_restricted": False}
        if whitelist_authorities or blacklist_authorities:
            flags["white_list"] = True
        options = self["options"]
        test_permissions(options["issuer_permissions"], flags)
        flags_int = force_flag(options["flags"], flags)
        options.update(
            {
                "flags": flags_int,
                "whitelist_authorities": [
                    Account(a, blockchain_instance=self.blockchain)["id"]
                    for a in whitelist_authorities
                ],
                "blacklist_authorities": [
                    Account(a, blockchain_instance=self.blockchain)["id"]
                    for a in blacklist_authorities
                ],
                "whitelist_markets": [Asset(a)["id"] for a in whitelist_markets],
                "blacklist_markets": [Asset(a)["id"] for a in blacklist_markets],
            }
        )
        op = operations.Asset_update(
            **{
                "fee": {"amount": 0, "asset_id": "1.3.0"},
                "issuer": self["issuer"],
                "asset_to_update": self["id"],
                "new_options": options,
                "extensions": [],
            }
        )
        return self.blockchain.finalizeOp(op, self["issuer"], "active")