def ImportMultiSigContractAddr(wallet, args):
    if len(args) < 4:
        print(
            "please specify multisig contract like such: 'import multisig_addr {pubkey in wallet} {minimum # of signatures required} {signing pubkey 1} {signing pubkey 2}...'"
        )
        return

    if wallet is None:
        print("please open a wallet")
        return

    pubkey = get_arg(args, 0)
    m = get_arg(args, 1)
    publicKeys = args[2:]

    if publicKeys[1]:
        pubkey_script_hash = Crypto.ToScriptHash(pubkey, unhex=True)

        verification_contract = Contract.CreateMultiSigContract(
            pubkey_script_hash, int(m), publicKeys)

        address = verification_contract.Address

        wallet.AddContract(verification_contract)

        print("Added multi-sig contract address %s to wallet" % address)
        return address

    return 'Hello'
Exemple #2
0
def ImportMultiSigContractAddr(wallet, args):
    if len(args) < 4:
        print(
            "please specify multisig contract like such: 'import multisig_addr {pubkey in wallet} {minimum # of signatures required} {signing pubkey 1} {signing pubkey 2}...'"
        )
        return

    if wallet is None:
        print("please open a wallet")
        return

    pubkey = get_arg(args, 0)
    m = get_arg(args, 1)
    publicKeys = args[2:]
    print(
        "1011010101 -https://github.com/SharedMocha/neo-python/edit/master/neo/Prompt/Commands/LoadSmartContract.py"
    )

    if publicKeys[1]:
        print(
            "2022222222 -https://github.com/SharedMocha/neo-python/edit/master/neo/Prompt/Commands/LoadSmartContract.py"
        )
        pubkey_script_hash = Crypto.ToScriptHash(pubkey, unhex=True)

        verification_contract = Contract.CreateMultiSigContract(
            pubkey_script_hash, int(m), publicKeys)

        address = verification_contract.Address

        wallet.AddContract(verification_contract)

        print("Added multi-sig contract address %s to wallet" % address)
        return address

    return 'Hello'
Exemple #3
0
    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

        # validate minimum required signing key count
        signing_keys = arguments[2:]
        len_signing_keys = len(signing_keys)
        if len_signing_keys < min_signature_cnt:
            # we need at least 2 public keys in total otherwise it's just a regular address.
            # 1 pub key is from an address in our own wallet, a secondary key can come from any place.
            print(
                f"Missing remaining signing keys. Minimum required: {min_signature_cnt} given: {len_signing_keys}"
            )
            return False

        # validate remaining pub keys
        for key in signing_keys:
            if not PromptUtils.is_valid_public_key(key):
                print(f"Invalid signing key {key}")
                return False

        signing_keys.append(pubkey_in_wallet)

        # validate that all signing keys are unique
        if len(signing_keys) > len(set(signing_keys)):
            print("Provided signing keys are not unique")
            return False

        verification_contract = Contract.CreateMultiSigContract(
            key_script_hash, min_signature_cnt, signing_keys)
        address = verification_contract.Address
        wallet.AddContract(verification_contract)
        print(f"Added multi-sig contract address {address} to wallet")
        return True
    def claim_initial_neo(self, target_address):
        wallets = []
        i = 0
        tx_json = None
        dbloops = []

        print("Signing new transaction with 3 of 4 node keys...")
        for pkey, wif in nodekeys.items():
            walletpath = "wallet{}.db3".format(i + 1)
            if os.path.exists(walletpath):
                os.remove(walletpath)
            wallet = UserWallet.Create(path=walletpath,
                                       password=to_aes_key(self.wallet_pwd))
            wallets.append(wallet)

            print("Importing node private key to to {}".format(walletpath))
            prikey = KeyPair.PrivateKeyFromWIF(wif)
            wallet.CreateKey(prikey)

            print("Importing multi-sig contract to {}".format(walletpath))
            keys = list(nodekeys.keys())
            pubkey_script_hash = Crypto.ToScriptHash(pkey, unhex=True)
            verification_contract = Contract.CreateMultiSigContract(
                pubkey_script_hash, 3, keys)
            wallet.AddContract(verification_contract)
            print("Added multi-sig contract address %s to wallet" %
                  verification_contract.Address)

            dbloop = task.LoopingCall(wallet.ProcessBlocks)
            dbloop.start(1)
            dbloops.append(dbloop)

            # print("Wallet %s " % json.dumps(wallet.ToJson(), indent=4))

            if i == 0:
                print(
                    "Creating spend transaction to {}".format(target_address))
                tx_json = self.send_neo(wallet, multisig_addr, target_address,
                                        '100000000')
                if tx_json is None:
                    break
            else:
                tx_json = self.sign_and_finish(wallet, tx_json)

            if tx_json == 'success':
                print(
                    "Finished, {} should now own all the NEO on the private network."
                    .format(target_address))
                break
            i += 1
Exemple #5
0
def make_multisig(target_pubkey, wallet):
    wallets = []
    i = 0
    tx_json = None
    dbloops = []
    pubkey = wallet.PubKeys()[0]['Public Key']
    multisig_args = [pubkey, 1, target_pubkey, pubkey]

    pubkey = multisig_args[0]
    m = multisig_args[1]
    publicKeys = multisig_args[2:]

    pubkey_script_hash = Crypto.ToScriptHash(pubkey, unhex=True)
    verification_contract = Contract.CreateMultiSigContract(
        pubkey_script_hash, int(m), publicKeys)
    address = verification_contract.Address
    wallet.AddContract(verification_contract)

    print("Added multi-sig contract address %s to wallet" % address)
    return address