Beispiel #1
0
    def genContractWallet(self, nickname=None):
        path = os.path.join(self.topDir, 'wallets')
        if not os.path.isdir(path):
            os.mkdir(path)
        if nickname:
            for i, c in enumerate(self.contracts):
                if c["nickname"] == nickname:
                    print_msg("{} contract exists.".format(nickname))
                    return self.getContractWallet(i), c
        #print(type(self.contracts))
        #this next loop generates a wallet name that isn't in use yet.
        if self.contracts == []:
            walletFile = os.path.join(self.topDir, 'wallets',
                                      'contract0.wallet')
        else:
            walletNames = []
            for c in self.contracts:
                #print(c)
                walletNames.append(c['walletFile'])
            for i in range(len(walletNames) + 1):
                walletFile = os.path.join(self.topDir, 'wallets',
                                          'contract' + str(i) + '.wallet')
                if walletFile not in walletNames:
                    break
        storage = WalletStorage(walletFile)
        seed_type = 'standard'
        seed = Mnemonic('en').make_seed(seed_type)
        k = keystore.from_seed(seed, '', False)
        storage.put('keystore', k.dump())
        storage.put('wallet_type', 'standard')
        wallet = Wallet(storage)
        wallet.set_schnorr_enabled(False)
        wallet.update_password(None, '', True)
        wallet.synchronize()
        print_msg("Your wallet generation seed is:\n\"%s\"" % seed)
        print_msg(
            "Please keep it in a safe place; if you lose it, you will not be able to restore your wallet."
        )

        wallet.storage.write()
        print_msg("Wallet saved in '%s'" % wallet.storage.path)

        my_addr = wallet.get_unused_address()
        my_addr_index = wallet.receiving_addresses.index(my_addr)
        #my_addr_index is always going to be 0 if the wallet is unused, so maybe previous line unnecessary
        my_pubkey = wallet.derive_pubkeys(False, my_addr_index)
        my_x_pubkey = self.get_x_pubkey(my_addr_index, wallet)
        self.contracts.append({
            'walletFile': wallet.storage.path,
            "my_addr": my_addr.to_ui_string(),
            "my_pubkey": my_pubkey,
            "my_x_pubkey": my_x_pubkey,
            "nickname": nickname,
            "label": ""
        })
        #print(self.contracts)
        self.updateContracts()
        self.multiWallets.append(None)
        return wallet, self.contracts[-1]
Beispiel #2
0
    def test(self):
        stor = WalletStorage(
            '/home/ilia/.electron-cash/wallets/test/default_wallet')
        wal = Wallet(stor)
        wal.set_schnorr_enabled(False)
        stor2 = WalletStorage(
            '/home/ilia/.electron-cash/wallets/test/test_wallet')
        wal2 = Wallet(stor2)
        wal2.set_schnorr_enabled(False)
        c = commands.Commands(None, wal, None)
        c2 = commands.Commands(None, wal2, None)

        ao = "qq6cqr5sxgzrnrdfl62hrfy88pfhe89egqyld9nnj7"
        ai = "pqjdgep0cmscpvrk3n7euqqlqfmwk2770uagtjgcl5"

        outp = [{"type": 0, "address": ao, "value": 39500, "prevout_n": 0}]

        inp = [{
            "address":
            ai,
            "num_sig":
            2,
            "sequence":
            4294967294,
            "signatures": [None, None],
            "value":
            40000,
            "type":
            "p2sh",
            "redeemScript":
            "522103ad9164b6e6d94602f25823196f3a35d9b9afb7622223c7d5ee7bc8f17e7ca0bb2102a6ef7ee97b10e0d5866cf972c9fa8f0b0954d13d5a49423d3941fc0a71021eef52ae",
            "prevout_hash":
            "7451d7d947716f1fe3ed973c9a2cbebb5952c22fa0a4685b8331d2ffc37e23ce",
            "x_pubkeys": [
                "ff0488b21e000000000000000000833b2b39ca3b1aedcc76ebc2dd54f2201e3f8ceb7fa16fbe4341249e24c0a8af03b55587668eac88a678b564e7bf7368b6ae32d04fa1d7dc252a596a7925779a0200000100",
                "ff0488b21e000000000000000000fd897a1c33cf038d108419d73559aba5ba26a8c1b7952ae6ff65be21a78be1a102f4eb32dc585e2585967369b6618771c1dce8dc928d996042bef2c80782ac408300000000"
            ],
            "pubkeys": [
                "03ad9164b6e6d94602f25823196f3a35d9b9afb7622223c7d5ee7bc8f17e7ca0bb",
                "02a6ef7ee97b10e0d5866cf972c9fa8f0b0954d13d5a49423d3941fc0a71021eef"
            ],
            "prevout_n":
            0
        }]

        y = {"version": 1, "lockTime": 0, "outputs": outp, "inputs": inp}
        tx = c.serialize(y)
        #print(tx)
        w = c.deserialize(c.serialize(y))
        #print(w['inputs'][0]['address'])
        #print(c.deserialize(tx))
        tx2 = c.signtransaction(tx)
        #print(c.deserialize(tx2))
        tx3 = c2.signtransaction(tx2)
        print(c.deserialize(tx3))
        print(self.get_tx_size(tx3))
        print(self.get_tx_size(tx2))
        print(self.get_tx_size(tx))