Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def gather_signatures(context, itx, owners):
do_exit = False
print("\n\n*******************\n")
print("Gather Signatures for Transaction:\n%s " % json.dumps(itx.ToJson(), indent=4))
print("Please use a client to sign the following: %s " % itx.GetHashData())
owner_index = 0
while not context.Completed and not do_exit:
next_script = owners[owner_index]
next_addr = scripthash_to_address(next_script.Data)
try:
print("\n*******************\n")
owner_input = prompt('Public Key and Signature for %s> ' % next_addr)
items = owner_input.split(' ')
pubkey = ECDSA.decode_secp256r1(items[0]).G
sig = items[1]
contract = Contract.CreateSignatureContract(pubkey)
if contract.Address == next_addr:
context.Add(contract, 0, sig)
print("Adding signature %s " % sig)
owner_index += 1
else:
print("Public Key does not match address %s " % next_addr)
except EOFError:
# Control-D pressed: quit
do_exit = True
def execute(self, arguments):
if len(arguments) != 1:
print("Please specify the required parameter")
return False
try:
flag = bool(util.strtobool(arguments[0]))
except ValueError:
print("Invalid option")
return False
settings.COMPILER_NEP_8 = flag
if flag:
print("NEP-8 compiler instruction usage is ON")
else:
print("NEP-8 compiler instruction usage is OFF")
return True
"""
Show unspent coin objects in the wallet.
Args:
wallet (neo.Wallet): wallet to show unspent coins from.
asset_id (UInt256): a bytearray (len 32) representing an asset on the blockchain.
from_addr (UInt160): a bytearray (len 20) representing an address.
watch_only (bool): indicate if this shows coins that are in 'watch only' addresses.
do_count (bool): if True only show a count of unspent assets.
Returns:
list: a list of unspent ``neo.Wallet.Coin`` in the wallet
"""
if wallet is None:
print("Please open a wallet.")
return
watch_only_flag = 64 if watch_only else 0
if asset_id:
unspents = wallet.FindUnspentCoinsByAsset(asset_id, from_addr=from_addr, watch_only_val=watch_only_flag)
else:
unspents = wallet.FindUnspentCoins(from_addr=from_addr, watch_only_val=watch_only)
if do_count:
print('\n-----------------------------------------------')
print('Total Unspent: %s' % len(unspents))
return unspents
for unspent in unspents:
print('\n-----------------------------------------------')
print(json.dumps(unspent.ToJson(), indent=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):
name = prompt("[Contract Name] > ")
version = prompt("[Contract Version] > ")
author = prompt("[Contract Author] > ")
email = prompt("[Contract Email] > ")
description = prompt("[Contract Description] > ")
print("Creating smart contract....")
print(" Name: %s " % name)
print(" Version: %s" % version)
print(" Author: %s " % author)
print(" Email: %s " % email)
print(" Description: %s " % description)
print(" Needs Storage: %s " % function_code.HasStorage)
print(" Needs Dynamic Invoke: %s " % function_code.HasDynamicInvoke)
print(" Is Payable: %s " % function_code.IsPayable)
print(json.dumps(function_code.ToJson(), indent=4))
return generate_deploy_script(function_code.Script, name, version, author, email, description,
function_code.ContractProperties, function_code.ReturnTypeBigInteger,
function_code.ParameterList)
def start_output_config():
# temporarily mute stdout while we try to reconfigure our settings
# components like `network` set at DEBUG level will spam through the console
# making it impractical to configure output levels
log_manager.mute_stdio()
print("Select your desired configuration per component.")
print("(1) DEBUG (2) INFO (3) ERROR (enter) keep current")
print("")
configurations = []
level_conversion = {1: logging.DEBUG, 2: logging.INFO, 3: logging.ERROR}
# cycle through all known components
for component, logger in log_manager.loggers.items():
component_name = component.replace(log_manager.root, "")
current_level = logging.getLevelName(logger.handlers[0].level)
line = "[{}] current: {} new: ".format(component_name, current_level)
choice = None
try:
choice = int(prompt(line))
except ValueError:
pass
return
if wallet is None:
print("Please open a wallet.")
return
if int_args <= 0:
print('Enter a number greater than 0.')
return
address_list = []
for _ in range(int_args):
keys = wallet.CreateKey()
account = Account.get(PublicKeyHash=keys.PublicKeyHash.ToBytes())
address_list.append(account.contract_set[0].Address.ToString())
print("Created %s new addresses: " % int_args, address_list)
return wallet
def execute(self, arguments):
item = PromptUtils.get_arg(arguments)
if not item:
print(f"run `{self.command_desc().command} help` to see supported queries")
return
try:
return self.execute_sub_command(item, arguments[1:])
except KeyError:
print(f"{item} is an invalid parameter")
return
hash = UInt160.ParseString(item).ToBytes()
except Exception:
print("Could not find contract from args: %s" % arguments)
return
contract = Blockchain.Default().GetContract(hash)
if contract is not None:
contract.DetermineIsNEP5()
print(json.dumps(contract.ToJson(), indent=4))
return contract.ToJson()
else:
print("Contract %s not found" % item)
return
else:
print('Please specify the required parameter')
return
def execute(self, arguments):
wallet = PromptData.Wallet
if len(arguments) < 3:
print("Please specify the minimum required parameters")
return False
pubkey_in_wallet = arguments[0]
if not PromptUtils.is_valid_public_key(pubkey_in_wallet):
print("Invalid public key format")
return False
key_script_hash = Crypto.ToScriptHash(pubkey_in_wallet, unhex=True)
if not wallet.ContainsKeyHash(key_script_hash):
print("Supplied first public key does not exist in own wallet.")
return False
try:
min_signature_cnt = int(arguments[1])
except ValueError:
print(f"Invalid minimum signature count value: {arguments[1]}")
return False
if min_signature_cnt < 1:
print("Minimum signatures count cannot be lower than 1")
return False