def set_market_fee(self, percentage_fee, max_market_fee): """ Set trading percentage fee :param float percentage_fee: Percentage of fee :param bitshares.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": [] }) return self.bitshares.finalizeOp(op, self["issuer"], "active")
def add_authorities(self, type, authorities=[]): """ 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)) options = self["options"] if type == "whitelist": options["whitelist_authorities"].extend( [Account(a)["id"] for a in authorities]) if type == "blacklist": options["blacklist_authorities"].extend( [Account(a)["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.bitshares.finalizeOp(op, self["issuer"], "active")
def remove_markets(self, type, authorities=[]): """ Remove markets from an assets white/black list :param str type: ``blacklist`` or ``whitelist`` :param list markets: List of markets (assets) """ assert type in ["blacklist", "whitelist"] assert isinstance(authorities, (list, set)) options = self["options"] if type == "whitelist": for a in authorities: options["whitelist_markets"].remove(Asset(a)["id"]) if type == "blacklist": for a in authorities: options["blacklist_markets"].remove(Asset(a)["id"]) 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.bitshares.finalizeOp(op, self["issuer"], "active")
def test_asset_update(self): self.op = operations.Asset_update( **{ "fee": {"amount": 0, "asset_id": "1.3.0"}, "issuer": "1.2.0", "asset_to_update": "1.3.0", "new_options": { "max_supply": "1000000000000000", "market_fee_percent": 0, "max_market_fee": "1000000000000000", "issuer_permissions": 79, "flags": 0, "core_exchange_rate": { "base": {"amount": 0, "asset_id": "1.3.0"}, "quote": {"amount": 0, "asset_id": "1.3.0"}, }, "whitelist_authorities": [], "blacklist_authorities": [], "whitelist_markets": [], "blacklist_markets": [], "description": "", "extensions": [], }, "extensions": [], } ) self.cm = ( "f68585abf4dce7c80457010b000000000000000000000000008" "0c6a47e8d030000000080c6a47e8d03004f0000000000000000" "000000000000000000000000000000000000000000011f51477" "1af6ac47a12a387979b6452afcd3f50514277efd7938f5227a7" "fe7287db529d251e2b7c31d4a2d8ed59035b78b64f95e6011d9" "58ab9504008a56c83cbb6" ) self.doit()
def halt(self): """ Halt this asset from being moved or traded """ nullaccount = Account("null-account") # We set the null-account 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.bitshares.finalizeOp(op, self["issuer"], "active")
def remove_authorities(self, type, authorities=None): """ Remove authorities from 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 = [] options = self["options"] if type == "whitelist": for a in authorities: options["whitelist_authorities"].remove( Account(a, blockchain_instance=self.blockchain)["id"] ) if type == "blacklist": for a in authorities: options["blacklist_authorities"].remove( Account(a, blockchain_instance=self.blockchain)["id"] ) 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")
def test_asset_update(self): self.op = operations.Asset_update(**{ "fee": {"amount": 0, "asset_id": "1.3.0"}, "issuer": "1.2.0", "asset_to_update": "1.3.0", "new_options": { "max_supply": "1000000000000000", "market_fee_percent": 0, "max_market_fee": "1000000000000000", "issuer_permissions": 79, "flags": 0, "core_exchange_rate": { "base": {"amount": 0, "asset_id": "1.3.0"}, "quote": {"amount": 0, "asset_id": "1.3.0"} }, "whitelist_authorities": ["1.2.12", "1.2.13"], "blacklist_authorities": ["1.2.10", "1.2.11"], "whitelist_markets": ["1.3.10", "1.3.11"], "blacklist_markets": ["1.3.12", "1.3.13"], "description": "Foobar", "extensions": [] }, "extensions": [] }) self.cm = ("f68585abf4dce7c80457010b00000000000000000000000000" "80c6a47e8d030000000080c6a47e8d03004f00000000000000" "0000000000000000000000000000020c0d020a0b020a0b020c" "0d06466f6f626172000000011f5bd6a206d210d1d78eb423e0" "c2362013aa80830a8e61e5df2570eac05f1c57a4165c99099f" "c2e97ecbf2b46014c96a6f99cff8d20f55a6042929136055e5" "ad10") self.doit()
def setoptions(self, flags): """ 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": [] }) return self.bitshares.finalizeOp(op, self["issuer"], "active")
def test_asset_update_issuer_fail(self): with self.assertRaises(ValueError): self.op = operations.Asset_update( **{ "fee": {"amount": 0, "asset_id": "1.3.0"}, "issuer": "1.2.0", "asset_to_update": "1.3.0", "new_issuer": "1.2.1", "extensions": [], } )
def release( self, whitelist_authorities=[], blacklist_authorities=[], whitelist_markets=[], blacklist_markets=[], ): """ 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 flags = {"white_list": False, "transfer_restricted": False} 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")
def test_asset_update(self): op = operations.Asset_update( **{ "fee": { "amount": 0, "asset_id": "1.3.0" }, "issuer": "1.2.0", "asset_to_update": "1.3.0", "new_options": { "max_supply": "1000000000000000", "market_fee_percent": 0, "max_market_fee": "1000000000000000", "issuer_permissions": 79, "flags": 0, "core_exchange_rate": { "base": { "amount": 0, "asset_id": "1.3.0" }, "quote": { "amount": 0, "asset_id": "1.3.0" } }, "whitelist_authorities": ["1.2.12", "1.2.13"], "blacklist_authorities": ["1.2.10", "1.2.11"], "whitelist_markets": ["1.3.10", "1.3.11"], "blacklist_markets": ["1.3.12", "1.3.13"], "description": "Foobar", "extensions": [] }, "extensions": [] }) ops = [Operation(op)] tx = Signed_Transaction(ref_block_num=ref_block_num, ref_block_prefix=ref_block_prefix, expiration=expiration, operations=ops) tx = tx.sign([wif], chain=prefix) tx.verify([PrivateKey(wif).pubkey], "BTS") txWire = hexlify(bytes(tx)).decode("ascii") compare = ("f68585abf4dce7c80457010b00000000000000000000000000" "80c6a47e8d030000000080c6a47e8d03004f00000000000000" "0000000000000000000000000000020c0d020a0b020a0b020c" "0d06466f6f626172000000011f5bd6a206d210d1d78eb423e0" "c2362013aa80830a8e61e5df2570eac05f1c57a4165c99099f" "c2e97ecbf2b46014c96a6f99cff8d20f55a6042929136055e5" "ad10") self.assertEqual(compare[:-130], txWire[:-130])
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")
def update_assetSupply(inst, symbol, max_supply): asset = cybex.Asset(symbol) options = asset['options'] account = cybex.Account(inst.const['master_account']) options.update({ "max_supply": max_supply }) op = operations.Asset_update(**{ "fee": {"amount": 0, "asset_id": "1.3.0"}, "issuer": account["id"], "asset_to_update": asset["id"], "new_options": options, "extensions": [], "prefix": inst.prefix }) return inst.finalizeOp(op, account["name"], "active")
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")