def apply_for_sr(self, url, address=None): """Apply to become a super representative Args: url (str): official website address address (str): address """ # If the address of the sender is not specified, we prescribe the default if address is None: address = self.tron.default_address.hex if not self.tron.isAddress(address): raise TronError('Invalid address provided') if not is_valid_url(url): raise TronError('Invalid url provided') return self.tron.manager.request( '/wallet/createwitness', { 'owner_address': self.tron.address.to_hex(address), 'url': self.tron.toHex(text=url) })
def create_token(self, **kwargs): """Issue Token Issuing a token on the TRON Protocol can be done by anyone who has at least 1024 TRX in their account. When a token is issued it will be shown on the token overview page. Users can then participate within the issuing time and exchange their TRX for tokens.After issuing the token your account will receive the amount of tokens equal to the total supply. When other users exchange their TRX for tokens then the tokens will be withdrawn from your account and you will receive TRX equal to the specified exchange rate. Args: **kwargs: Fill in the required parameters Examples: >>> start_func = datetime.now() >>> start = int(start_func.timestamp() * 1000) >>> >>> end_func = datetime.now() + timedelta(days=2) >>> end = int(end_func.timestamp() * 1000) >>> >>> opt = { >>> 'name': 'Tron', >>> 'abbreviation': 'TRX', >>> 'description': 'Hello World', >>> 'url': 'https://github.com', >>> 'totalSupply': 25000000, >>> 'frozenAmount': 1, >>> 'frozenDuration': 2, >>> 'freeBandwidth': 10000, >>> 'freeBandwidthLimit': 10000, >>> 'saleStart': start, >>> 'saleEnd': end, >>> 'voteScore': 1 >>> } """ issuer_address = kwargs.setdefault('issuer_address', self.tron.default_address.hex) if not self.tron.isAddress(issuer_address): raise TronError('Invalid issuer address provided') total_supply = kwargs.setdefault('totalSupply', 0) trx_ratio = kwargs.setdefault('trxRatio', 1) token_ratio = kwargs.setdefault('tokenRatio', 1) sale_start = kwargs.setdefault('saleStart', START_DATE) free_bandwidth = kwargs.setdefault('freeBandwidth', 0) free_bandwidth_limit = kwargs.setdefault('freeBandwidthLimit', 0) frozen_amount = kwargs.setdefault('frozenAmount', 0) frozen_duration = kwargs.setdefault('frozenDuration', 0) vote_score = kwargs.setdefault('voteScore', 0) precision = kwargs.setdefault('precision', 0) if not is_string(kwargs.get('name')): raise ValueError('Invalid token name provided') if not is_string(kwargs.get('abbreviation')): raise ValueError('Invalid token abbreviation provided') if not is_integer(total_supply) or total_supply <= 0: raise ValueError('Invalid supply amount provided') if not is_integer(trx_ratio) or trx_ratio <= 0: raise ValueError('TRX ratio must be a positive integer') if not is_integer(token_ratio) or token_ratio <= 0: raise ValueError('Token ratio must be a positive integer') if not is_integer(vote_score) or vote_score <= 0: raise ValueError( 'voteScore must be a positive integer greater than 0') if not is_integer(precision) or precision <= 0 or precision > 6: raise ValueError( 'precision must be a positive integer > 0 and <= 6') if not is_integer(sale_start) or sale_start < START_DATE: raise ValueError('Invalid sale start timestamp provided') if not is_integer(kwargs.get('saleEnd')) or \ kwargs.get('saleEnd') <= sale_start: raise ValueError('Invalid sale end timestamp provided') if not is_string(kwargs.get('description')): raise ValueError('Invalid token description provided') if not is_valid_url(kwargs.get('url')): raise ValueError('Invalid token url provided') if not is_integer(free_bandwidth) or free_bandwidth < 0: raise ValueError('Invalid free bandwidth amount provided') if not is_integer(free_bandwidth_limit) or free_bandwidth_limit < 0 \ or (free_bandwidth and not free_bandwidth_limit): raise ValueError('Invalid free bandwidth limit provided') if not is_integer(frozen_amount) or frozen_amount < 0 \ or (not frozen_duration and frozen_amount): raise ValueError('Invalid frozen supply provided') if not is_integer(frozen_duration) or frozen_duration < 0 \ or (frozen_duration and not frozen_amount): raise ValueError('Invalid frozen duration provided') frozen_supply = { 'frozen_amount': int(frozen_amount), 'frozen_days': int(frozen_duration) } response = self.tron.manager.request( '/wallet/createassetissue', { 'owner_address': self.tron.address.to_hex(issuer_address), 'name': self.tron.toHex(text=kwargs.get('name')), 'abbr': self.tron.toHex(text=kwargs.get('abbreviation')), 'description': self.tron.toHex(text=kwargs.get('description')), 'url': self.tron.toHex(text=kwargs.get('url')), 'total_supply': int(total_supply), 'trx_num': int(trx_ratio), 'num': int(token_ratio), 'start_time': int(sale_start), 'end_time': int(kwargs.get('saleEnd')), 'free_asset_net_limit': int(free_bandwidth), 'public_free_asset_net_limit': int(free_bandwidth_limit), 'frozen_supply': frozen_supply, 'vote_score': vote_score, 'precision': precision }) return response