def refresh(self): """ Refresh the data from the API server """ asset = self.bitshares.rpc.get_asset(self.asset) if not asset: raise AssetDoesNotExistsException super(Asset, self).__init__(asset) if self.full: if self.is_bitasset: self["bitasset_data"] = self.bitshares.rpc.get_object( asset["bitasset_data_id"]) self["dynamic_asset_data"] = self.bitshares.rpc.get_object( asset["dynamic_asset_data_id"]) # Permissions and flags self["permissions"] = todict( asset["options"].get("issuer_permissions")) self["flags"] = todict(asset["options"].get("flags")) try: self["description"] = json.loads(asset["options"]["description"]) except: self["description"] = asset["options"]["description"] self.cached = True self._cache(asset)
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) # Permissions and flags self["permissions"] = todict(self["options"].get("issuer_permissions")) self["flags"] = todict(self["options"].get("flags")) try: self["description"] = json.loads(self["options"]["description"]) except Exception: self["description"] = self["options"]["description"]
def refresh(self): """ Refresh the data from the API server """ asset = self.blockchain.rpc.get_asset(self.identifier) if not asset: raise AssetDoesNotExistsException(self.identifier) super(Asset, self).__init__(asset, blockchain_instance=self.blockchain) if self.full: if "bitasset_data_id" in asset: self["bitasset_data"] = self.blockchain.rpc.get_object( asset["bitasset_data_id"]) self["dynamic_asset_data"] = self.blockchain.rpc.get_object( asset["dynamic_asset_data_id"]) # Permissions and flags self["permissions"] = todict( asset["options"].get("issuer_permissions")) self["flags"] = todict(asset["options"].get("flags")) try: self["description"] = json.loads(asset["options"]["description"]) except: self["description"] = asset["options"]["description"]
def prev_options(self): pm = False if "is_prediction_market" in self.asset: pm = self.asset["is_prediction_market"] return { "symbol": self.asset["symbol"], "issuer": self.asset["issuer"], "precision": self.asset["precision"], "max_supply": int(self.asset["options"]["max_supply"]), "core_exchange_rate": self.asset["options"]["core_exchange_rate"], "new_issuer": self.asset["issuer"], "permissions": todict(self.asset["options"]["issuer_permissions"]), "flags": self.asset["flags"], "description": self.asset["description"], "is_prediction_market": pm, "market_fee_percent": self.asset["options"]["market_fee_percent"], }
def test_create_asset(self): symbol = "FOOBAR" precision = 7 max_supply = 100000 description = "Test asset" is_bitasset = True market_fee_percent = 0.1 max_market_fee = 10 blacklist_authorities = ["init1"] blacklist_authorities_ids = [ Account(a)["id"] for a in blacklist_authorities ] blacklist_markets = ["BTS"] blacklist_markets_ids = ["1.3.0"] permissions = { "charge_market_fee": True, "white_list": True, "override_authority": True, "transfer_restricted": True, "disable_force_settle": True, "global_settle": True, "disable_confidential": True, "witness_fed_asset": True, "committee_fed_asset": True, } flags = { "charge_market_fee": False, "white_list": False, "override_authority": False, "transfer_restricted": False, "disable_force_settle": False, "global_settle": False, "disable_confidential": False, "witness_fed_asset": False, "committee_fed_asset": False, } tx = bitshares.create_asset( symbol, precision, max_supply, market_fee_percent=market_fee_percent, max_market_fee=max_market_fee, description=description, is_bitasset=is_bitasset, blacklist_authorities=blacklist_authorities, blacklist_markets=blacklist_markets, permissions=permissions, flags=flags, ) self.assertEqual(getOperationNameForId(tx["operations"][0][0]), "asset_create") op = tx["operations"][0][1] self.assertEqual(op["issuer"], "1.2.100") self.assertEqual(op["symbol"], symbol) self.assertEqual(op["precision"], precision) self.assertEqual(op["common_options"]["max_supply"], int(max_supply * 10**precision)) self.assertEqual(op["common_options"]["market_fee_percent"], int(market_fee_percent * 100)) self.assertEqual( op["common_options"]["max_market_fee"], int(max_market_fee * 10**precision), ) self.assertEqual(op["common_options"]["description"], description) self.assertEqual(op["common_options"]["blacklist_authorities"], blacklist_authorities_ids) self.assertEqual(op["common_options"]["blacklist_markets"], blacklist_markets_ids) self.assertEqual(todict(op["common_options"]["issuer_permissions"]), permissions) self.assertEqual(todict(op["common_options"]["flags"]), flags)
def setupAsset(self, asset): self.ui.symbolEdit.setText(asset["symbol"]) self.ui.precisionEdit.setText(str(asset["precision"])) self.ui.totalEdit.setText( str(asset["options"]["max_supply"] / pow(10, asset["precision"]))) set_combo(self.ui.transferAsset, asset["symbol"]) set_combo(self.ui.untransferAsset, asset["symbol"]) self.ui.symbolEdit.setEnabled(False) self.ui.precisionEdit.setEnabled(False) self.ui.totalEdit.setEnabled(False) self.ui.permList.setEnabled(False) self.ui.descriptionPlain.setPlainText(asset["options"]["description"]) self.ui.marketFee.setValue(int(asset["options"]["market_fee_percent"])) cer = asset["options"]["core_exchange_rate"] print(asset["symbol"], cer) rate = (int(cer["base"]["amount"]) / pow(10, 5)) / ( int(cer["quote"]["amount"]) / pow(10, asset["precision"])) self.ui.coreExchangeRate.setMaximum(1000000000000) # ? self.ui.coreExchangeRate.setDecimals(5) # BTS 5 - TODO: unhardcode? self.ui.coreExchangeRate.setValue(float(rate)) perm_dict = todict(asset["options"]["issuer_permissions"]) flag_dict = todict(asset["options"]["flags"]) i = 0 for k, v in perm_dict.items(): self.ui.permList.item(i).setCheckState( QtCore.Qt.Checked if v else QtCore.Qt.Unchecked) i += 1 i = 0 for k, v in flag_dict.items(): self.ui.flagList.item(i).setCheckState( QtCore.Qt.Checked if v else QtCore.Qt.Unchecked) i += 1 issuer = asset["issuer"] if not self.iso.offline: asset.refresh() try: issuer = self.iso.getAccount(issuer) issuer = issuer["name"] except: pass # Issue self.ui.transferAmount.setDecimals(asset["precision"]) self.ui.transferAmount.setMaximum( int(asset["options"]["max_supply"]) / pow(10, asset["precision"])) # self.ui.transferFromAccount.setEnabled(True) set_combo(self.ui.transferFromAccount, issuer) # self.ui.transferFromAccount.setEnabled(False) # Reserve self.ui.untransferAmount.setDecimals(asset["precision"]) self.ui.untransferAmount.setMaximum( int(asset["options"]["max_supply"]) / pow(10, asset["precision"])) # self.ui.untransferFromAccount.setEnabled(True) # set_combo(self.ui.untransferFromAccount, issuer) # self.ui.untransferFromAccount.setEnabled(False) set_combo(self.ui.accountBox, issuer) self.ui.accountBox.setEnabled(False) # BitAsset self.ui.isBitasset.setEnabled(False) if asset.is_bitasset: #["bitasset"]: #asset.full = True #asset.refresh() bitasset = asset["bitasset_data"] options = bitasset["options"] from pprint import pprint pprint(options) self.ui.isBitasset.setCheckState(1) self.ui.feedLifetime.setValue(options["feed_lifetime_sec"]) self.ui.forceSettlementDelay.setValue( options["force_settlement_delay_sec"]) self.ui.forceSettlementOffset.setValue( options["force_settlement_offset_percent"]) self.ui.maxForceSettlement.setValue( options["maximum_force_settlement_volume"]) self.ui.minimumFeeds.setValue(options["minimum_feeds"]) self.ui.backingAsset.setText(options["short_backing_asset"]) if "is_prediction_market" in asset and asset[ "is_prediction_market"]: self.ui.isPredictionMarket.setCheckState(1) if "is_prediction_market" in asset["options"] and asset["options"][ "is_prediction_market"]: self.ui.isPredictionMarket.setCheckState(1) else: self.ui.isBitasset.setCheckState(0) self.ui.isPredictionMarket.setVisible(False) self.ui.frameBitasset.setVisible(False)