def execute(self, arguments): wallet = PromptData.Wallet if len(arguments) != 3: print("Please specify the required parameters") return False token_str = arguments[0] from_addr = arguments[1] to_addr = arguments[2] try: token = PromptUtils.get_token(wallet, token_str) except ValueError as e: print(str(e)) return False try: allowance = token_get_allowance(wallet, token_str, from_addr, to_addr) print( f"{token.symbol} allowance for {from_addr} from {to_addr} : {allowance} " ) return True except ValueError as e: print(str(e)) return False
def token_history(wallet, token_str): notification_db = NotificationDB.instance() try: token = PromptUtils.get_token(wallet, token_str) except ValueError: raise events = notification_db.get_by_contract(token.ScriptHash) return token, events
def execute(self, arguments): wallet = PromptData.Wallet if len(arguments) < 2: print("Please specify the required parameters") return False arguments, priority_fee = PromptUtils.get_fee(arguments) token_str = arguments[0] try: token = PromptUtils.get_token(wallet, token_str) except ValueError as e: print(str(e)) return False register_addr = arguments[1:] addr_list = [] for addr in register_addr: if isValidPublicAddress(addr): addr_list.append(addr) else: print(f"{addr} is not a valid address") return False p_fee = Fixed8.Zero() if priority_fee is not None: p_fee = priority_fee if p_fee is False: logger.debug("invalid fee") return False tx, fee, results = token.CrowdsaleRegister(wallet, addr_list) if tx and results: if results[0].GetBigInteger() > 0: print("\n-----------------------------------------------------------") print("[%s] Will register addresses for crowdsale: %s " % (token.symbol, register_addr)) print("Invocation Fee: %s " % (fee.value / Fixed8.D)) print("-------------------------------------------------------------\n") comb_fee = p_fee + fee if comb_fee != fee: print(f"Priority Fee ({p_fee.value / Fixed8.D}) + Invocation Fee ({fee.value / Fixed8.D}) = {comb_fee.value / Fixed8.D}\n") print("Enter your password to send to the network") passwd = prompt("[Password]> ", is_password=True) if not wallet.ValidatePassword(passwd): print("incorrect password") return False return InvokeContract(wallet, tx, comb_fee) print("Could not register address(es)") return False
def execute(self, arguments): wallet = PromptData.Wallet if len(arguments) < 2: print("Please specify the required parameters") return False if len(arguments) > 6: # the 3rd and 4th argument are for attaching neo/gas, 5th for attaching a fee, 6th for attaching attributes print("Too many parameters supplied. Please check your command") return False arguments, priority_fee = PromptUtils.get_fee(arguments) arguments, invoke_attrs = PromptUtils.get_tx_attr_from_args(arguments) token_str = arguments[0] try: token = PromptUtils.get_token(wallet, token_str) except ValueError as e: print(str(e)) return False to_addr = arguments[1] if not isValidPublicAddress(to_addr): print(f"{to_addr} is not a valid address") return False remaining_args = arguments[2:] asset_attachments = [] for optional in remaining_args: _, neo_to_attach, gas_to_attach = PromptUtils.get_asset_attachments([optional]) if "attach-neo" in optional: if not neo_to_attach: print(f"Could not parse value from --attach-neo. Value must be an integer") return False else: asset_attachments.append(optional) if "attach-gas" in optional: if not gas_to_attach: print(f"Could not parse value from --attach-gas") return False else: asset_attachments.append(optional) fee = Fixed8.Zero() if priority_fee is not None: fee = priority_fee if fee is False: logger.debug("invalid fee") return False return token_mint(token, wallet, to_addr, asset_attachments=asset_attachments, fee=fee, invoke_attrs=invoke_attrs)
def _validate_nep5_args(wallet, token_str, from_addr, to_addr, amount): """ A helper function to validate common arguments used in NEP-5 functions Args: wallet (Wallet): a UserWallet instance token_str (str): symbol name or script_hash from_addr (str): a wallet address to_addr (str): a wallet address amount (float): the number of tokens to send Raises: ValueError: for invalid arguments Returns: token (NEP5Token): instance """ try: token = PromptUtils.get_token(wallet, token_str) except ValueError: raise if not isValidPublicAddress(from_addr): raise ValueError("send_from is not a valid address") if not isValidPublicAddress(to_addr): raise ValueError("send_to is not a valid address") try: # internally this function uses the `Decimal` class which will parse the float amount to its required format. # the name is a bit misleading /shrug amount = amount_from_string(token, amount) except Exception: raise ValueError(f"{amount} is not a valid amount") return token
def execute(self, arguments): wallet = PromptData.Wallet if len(arguments) < 2: print("Please specify the required parameters") return False token_str = arguments[0] try: token = PromptUtils.get_token(wallet, token_str) except ValueError as e: print(str(e)) return False register_addr = arguments[1:] addr_list = [] for addr in register_addr: if isValidPublicAddress(addr): addr_list.append(addr) else: print(f"{addr} is not a valid address") return False tx, fee, results = token.CrowdsaleRegister(wallet, addr_list) if tx and results: if results[0].GetBigInteger() > 0: print("\n-----------------------------------------------------------") print("[%s] Will register addresses for crowdsale: %s " % (token.symbol, register_addr)) print("Fee: %s " % (fee.value / Fixed8.D)) print("-------------------------------------------------------------\n") return InvokeContract(wallet, tx, fee) print("Could not register address(es)") return False
def execute(self, arguments): wallet = PromptData.Wallet if len(arguments) < 2: print("Please specify the required parameters") return False if len(arguments) > 5: # the 3rd and 4th argument are for attaching neo/gas, 5th for prompting for password print("Too many parameters supplied. Please check your command") return False token_str = arguments[0] try: token = PromptUtils.get_token(wallet, token_str) except ValueError as e: print(str(e)) return False to_addr = arguments[1] if not isValidPublicAddress(to_addr): print(f"{to_addr} is not a valid address") return False remaining_args = arguments[2:] asset_attachments = [] for optional in remaining_args: _, neo_to_attach, gas_to_attach = PromptUtils.get_asset_attachments([optional]) if "attach-neo" in optional: if not neo_to_attach: print(f"Could not parse value from --attach-neo. Value must be an integer") return False else: asset_attachments.append(optional) if "attach-gas" in optional: if not gas_to_attach: print(f"Could not parse value from --attach-gas") return False else: asset_attachments.append(optional) tx, fee, results = token.Mint(wallet, to_addr, asset_attachments) if tx and results: if results[0] is not None: print("\n-----------------------------------------------------------") print(f"[{token.symbol}] Will mint tokens to address: {to_addr}") print(f"Fee: {fee.value / Fixed8.D}") print("-------------------------------------------------------------\n") passwd = prompt("[Password]> ", is_password=True) if not wallet.ValidatePassword(passwd): print("incorrect password") return False return InvokeWithTokenVerificationScript(wallet, tx, token, fee) print("Failed to mint tokens") return False