示例#1
0
    def execute(self, arguments):
        wallet = PromptData.Wallet

        if len(arguments) < 4:
            print("Please specify the required parameters")
            return False

        arguments, priority_fee = PromptUtils.get_fee(arguments)

        token_str = arguments[0]
        from_addr = arguments[1]
        to_addr = arguments[2]

        try:
            amount = float(arguments[3])
        except ValueError:
            print(f"{arguments[3]} is not a valid amount")
            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

        try:
            token = _validate_nep5_args(wallet, token_str, from_addr, to_addr, amount)
        except ValueError as e:
            print(str(e))
            return False

        decimal_amount = amount_from_string(token, amount)

        tx, fee, results = token.Approve(wallet, from_addr, to_addr, decimal_amount)

        if tx and results:
            if results[0].GetBigInteger() == 1:
                print("\n-----------------------------------------------------------")
                print(f"Approve allowance of {amount} {token.symbol} from {from_addr} to {to_addr}")
                print(f"Invocation fee: {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("Failed to approve tokens. Make sure you are entitled for approving.")
        return False
示例#2
0
    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
示例#3
0
    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)        
示例#4
0
    def execute(self, arguments):
        wallet = PromptData.Wallet

        if len(arguments) < 4:
            print("Please specify the required parameters")
            return False

        if len(arguments) > 6:
            # the 5th and 6th arguments are optional
            print("Too many parameters supplied. Please check your command")
            return False

        arguments, priority_fee = PromptUtils.get_fee(arguments)
        arguments, user_tx_attributes = PromptUtils.get_tx_attr_from_args(
            arguments)

        token = arguments[0]
        from_addr = arguments[1]
        to_addr = arguments[2]
        try:
            amount = float(arguments[3])
        except ValueError:
            print(f"{arguments[3]} is not a valid amount")
            return False

        fee = Fixed8.Zero()
        if priority_fee is not None:
            fee = priority_fee
            if fee is False:
                logger.debug("invalid fee")
                return False

        try:
            success = token_send(wallet,
                                 token,
                                 from_addr,
                                 to_addr,
                                 amount,
                                 fee=fee,
                                 user_tx_attributes=user_tx_attributes)
        except ValueError as e:
            # occurs if arguments are invalid
            print(str(e))
            success = False

        return success
示例#5
0
    def execute(self, arguments):
        wallet = PromptData.Wallet
        if not wallet:
            print("Please open a wallet")
            return False

        if len(arguments) < 5:
            print("Please specify the required parameters")
            return False

        args, from_addr = PromptUtils.get_from_addr(arguments)
        arguments, priority_fee = PromptUtils.get_fee(arguments)

        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

        path = args[0]

        try:
            needs_storage = bool(util.strtobool(args[1]))
            needs_dynamic_invoke = bool(util.strtobool(args[2]))
            is_payable = bool(util.strtobool(args[3]))

        except ValueError:
            print("Invalid boolean option")
            return False

        params = args[4]
        return_type = args[5]

        try:
            function_code = LoadContract(path, needs_storage,
                                         needs_dynamic_invoke, is_payable,
                                         params, return_type)
        except (ValueError, Exception) as e:
            print(str(e))
            return False

        contract_script = GatherContractDetails(function_code)
        if not contract_script:
            print("Failed to generate deploy script")
            return False

        tx, fee, results, num_ops, engine_success = test_invoke(
            contract_script, wallet, [], from_addr=from_addr)
        if tx and results:
            print(
                "\n-------------------------------------------------------------------------------------------------------------------------------------"
            )
            print("Test deploy invoke successful")
            print(f"Total operations executed: {num_ops}")
            print("Results:")
            print([item.GetInterface() for item in results])
            print(f"Deploy Invoke TX GAS cost: {tx.Gas.value / Fixed8.D}")
            print(f"Deploy Invoke TX Fee: {fee.value / Fixed8.D}")
            print(
                "-------------------------------------------------------------------------------------------------------------------------------------\n"
            )
            comb_fee = p_fee + fee
            if comb_fee != fee:
                print(
                    f"Priority Fee ({p_fee.value / Fixed8.D}) + Deploy Invoke TX Fee ({fee.value / Fixed8.D}) = {comb_fee.value / Fixed8.D}\n"
                )
            print("Enter your password to continue and deploy this contract")

            passwd = prompt("[password]> ", is_password=True)
            if not wallet.ValidatePassword(passwd):
                print("Incorrect password")
                return False

            return InvokeContract(wallet, tx, comb_fee, from_addr=from_addr)
        else:
            print("Test invoke failed")
            print(f"TX is {tx}, results are {results}")
            return False
示例#6
0
    def execute(self, arguments):
        wallet = PromptData.Wallet
        if not wallet:
            print("Please open a wallet")
            return False

        arguments, from_addr = PromptUtils.get_from_addr(arguments)
        arguments, priority_fee = PromptUtils.get_fee(arguments)
        arguments, invoke_attrs = PromptUtils.get_tx_attr_from_args(arguments)
        arguments, owners = PromptUtils.get_owners_from_params(arguments)

        if len(arguments) < 1:
            print("Please specify the required parameters")
            return False

        hash_string = arguments[0]
        try:
            script_hash = UInt160.ParseString(hash_string)
        except Exception:
            # because UInt160 throws a generic exception. Should be fixed in the future
            print("Invalid script hash")
            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, num_ops, engine_success = TestInvokeContract(
            wallet,
            arguments,
            from_addr=from_addr,
            invoke_attrs=invoke_attrs,
            owners=owners)
        if tx and results:

            parameterized_results = [
                ContractParameter.ToParameter(item).ToJson()
                for item in results
            ]

            print(
                "\n-------------------------------------------------------------------------------------------------------------------------------------"
            )
            print("Test invoke successful")
            print(f"Total operations: {num_ops}")
            print(f"Results {str(parameterized_results)}")
            print(f"Invoke TX GAS cost: {tx.Gas.value / Fixed8.D}")
            print(f"Invoke TX fee: {fee.value / Fixed8.D}")
            print(
                "-------------------------------------------------------------------------------------------------------------------------------------\n"
            )
            comb_fee = p_fee + fee
            if comb_fee != fee:
                print(
                    f"Priority Fee ({p_fee.value / Fixed8.D}) + Invoke TX Fee ({fee.value / Fixed8.D}) = {comb_fee.value / Fixed8.D}\n"
                )
            print("Enter your password to continue and deploy this contract")

            tx.Attributes = invoke_attrs

            passwd = prompt("[password]> ", is_password=True)
            if not wallet.ValidatePassword(passwd):
                return print("Incorrect password")

            return InvokeContract(wallet,
                                  tx,
                                  comb_fee,
                                  from_addr=from_addr,
                                  owners=owners)
        else:
            print("Error testing contract invoke")
            return False
示例#7
0
    def execute(self, arguments):
        wallet = PromptData.Wallet

        if len(arguments) < 4:
            print("Please specify the required parameters")
            return False

        arguments, priority_fee = PromptUtils.get_fee(arguments)

        token_str = arguments[0]
        from_addr = arguments[1]
        to_addr = arguments[2]

        try:
            amount = float(arguments[3])
        except ValueError:
            print(f"{arguments[3]} is not a valid amount")
            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

        try:
            token, tx, fee, results = test_token_send_from(
                wallet, token_str, from_addr, to_addr, amount)
        except ValueError as e:
            # invalid arguments or bad allowance
            print(str(e))
            return False
        except Exception as e:
            # we act as the final capturing place
            print("Something really unexpected happened")
            logger.error(traceback.format_exc())
            return False

        if tx is not None and results is not None:
            vm_result = results[0].GetBigInteger()
            if vm_result == 1:
                print(
                    "\n-----------------------------------------------------------"
                )
                print("Transfer of %s %s from %s to %s" % (string_from_amount(
                    token, amount), token.symbol, from_addr, to_addr))
                print("Transfer 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}) + Transfer Fee ({fee.value / Fixed8.D}) = {comb_fee.value / Fixed8.D}\n"
                    )
                print("Enter your password to send to the network")

                try:
                    passwd = prompt("[Password]> ", is_password=True)
                except KeyboardInterrupt:
                    print("Transaction cancelled")
                    return False
                if not wallet.ValidatePassword(passwd):
                    print("incorrect password")
                    return False

                return InvokeContract(wallet, tx, comb_fee)

            print(
                f"Could not transfer tokens. Virtual machine returned: {vm_result}"
            )
            return False

        print(
            f"Could not transfer tokens. An unknown error occurred resulting in no Transaction object or VM output."
        )
        return False