Esempio n. 1
0
    def post(self, request):
        print("enter wallet send")
        try:
            data = JSONParser().parse(request)
            wallet_id = data.get('wallet_id')
            address = data.get('address')
            amount = data.get('amount')
            print('wallet_id ' + str(wallet_id))
            print('address ' + str(address))
            '''
            print('wallet starts')
            srv = BitcoindClient()
            print(srv.getutxos('1CRkjhJgWC6tPNdfqnXRgYDPniSScHenuP'))
            print('bitcoin fee created')
            '''

            wallet = HDWallet(wallet_id, db_uri=db_uri)
            print(' wallet.username ',
                  wallet.key_for_path('m/44\'/0\'/1\'/0/0'))

            user = User.objects.filter(username=wallet.username)
            print('user', user)
            if user.count() > 0:
                user = user[0]
                print('wallets  ', wallet, ' user_id ', user.user_id)

                from_wallet_key = wallet.key(wallet.name)
                print('from wallet key', from_wallet_key.key_id)
                print('to wallet key as same ', wallet.key(address))

                # print('performing txn update  update db')
                # wallet.transactions_update(account_id=user.user_id,key_id=from_wallet.key_id)

                utx = wallet.utxos_update(account_id=user.user_id)
                wallet.info()
                wallet.get_key()
                print('key change', wallet.get_key_change())
                utxos = wallet.utxos(account_id=user.user_id)
                res = wallet.send_to(address, amount)
                print("Send transaction result:")
                if res.hash:
                    print("Successfully send, tx id:", res.hash)
                else:
                    print("TX not send, result:", res.errors)

                return JsonResponse(res.as_dict(), safe=False)

        except Exception as e:
            track = traceback.format_exc()
            logger.exception(track)
            raise e
Esempio n. 2
0
            (len(key_list), SIGS_N))
    wallet3o5 = HDWallet.create_multisig(WALLET_NAME,
                                         key_list,
                                         SIGS_REQUIRED,
                                         sort_keys=True,
                                         network=NETWORK)
    wallet3o5.new_key()

    print("\n\nA multisig wallet with 1 key has been created on this system")
else:
    wallet3o5 = HDWallet(WALLET_NAME)

print("\nUpdating UTXO's...")
wallet3o5.utxos_update()
wallet3o5.info()
utxos = wallet3o5.utxos()

# Creating transactions just like in a normal wallet, then send raw transaction to other cosigners. They
# can sign the transaction with there on key and pass it on to the next signer or broadcast it to the network.
# You can use sign_raw.py to import and sign a raw transaction.

# Example
# if utxos:
#     print("\nNew unspent outputs found!")
#     print("Now a new transaction will be created to sweep this wallet and send bitcoins to a testnet faucet")
#     send_to_address = 'mv4rnyY3Su5gjcDNzbMLKBQkBicCtHUtFB'
#     res = wallet3o5.sweep(send_to_address, min_confirms=0)
#     if 'transaction' in res:
#         print("Now send the raw transaction hex to one of the other cosigners to sign using sign_raw.py")
#         print("Raw transaction: " % res['transaction'].raw_hex())
#     else:
Esempio n. 3
0
        else:
            print("     '%s'," % key.wif_private())
    print("]")
    print(
        "wlt = HDWallet.create('%s', key_list, sigs_required=2, witness_type='%s', network='%s')"
        % (WALLET_NAME, WITNESS_TYPE, NETWORK))
    print("wlt.get_key()")
    print("wlt.info()")
else:
    from bitcoinlib.config.config import BITCOINLIB_VERSION, BCL_DATABASE_DIR
    online_wallet = HDWallet(WALLET_NAME,
                             db_uri=BCL_DATABASE_DIR +
                             '/bitcoinlib.tmp.sqlite')
    online_wallet.utxos_update()
    online_wallet.info()
    utxos = online_wallet.utxos()
    if utxos:
        print("\nNew unspent outputs found!")
        print(
            "Now a new transaction will be created to sweep this wallet and send bitcoins to a testnet faucet"
        )
        send_to_address = 'n2eMqTT929pb1RDNuqEnxdaLau1rxy3efi'
        t = online_wallet.sweep(send_to_address, min_confirms=0)
        print(t.raw_hex())
        print(
            "Now copy-and-paste the raw transaction hex to your Offline PC and sign it there with a second signature:"
        )
        print("\nfrom bitcoinlib.wallets import HDWallet")
        print("")
        print("wlt = HDWallet('%s')" % WALLET_NAME)
        print("utxos = ", end='')
Esempio n. 4
0
try:
    w.import_key(key='T43gB4F6k1Ly3YWbMuddq13xLb56hevUDP3RthKArr7FPHjQiXpp', network='litecoin')
except WalletError as e:
    print("Import litecoin key in bitcoin wallet gives an EXPECTED error: %s" % e)

print("\n=== Normalize BIP32 key path ===")
key_path = "m/44h/1'/0p/2000/1"
print("Raw: %s, Normalized: %s" % (key_path, normalize_path(key_path)))

print("\n=== Send test bitcoins to an address ===")
wallet_import = HDWallet('TestNetWallet', db_uri=test_database)
for _ in range(10):
    wallet_import.new_key()
wallet_import.utxos_update(99)
wallet_import.info()
utxos = wallet_import.utxos(99)
try:
    res = wallet_import.send_to('mxdLD8SAGS9fe2EeCXALDHcdTTbppMHp8N', 1000, 99)
    print("Send transaction result:")
    if res.hash:
        print("Successfully send, tx id:", res.hash)
    else:
        print("TX not send, result:", res.errors)
except WalletError as e:
    print("TX not send, error: %s" % e.msg)
except Exception as e:
    print(e)

#
# Segwit wallets
#
Esempio n. 5
0
    print("")
    print("key_list = [")
    print("    '%s'," % key_list[0].account_multisig_key().wif_public())
    print("    '%s'," % key_list[1].wif())
    print("    HDKey('%s', key_type='single')" % key_list[2].wif_public())
    print("]")
    print(
        "wlt = HDWallet.create_multisig('%s', key_list, 2, sort_keys=True, network='%s')"
        % (WALLET_NAME, NETWORK))
    print("wlt.new_key()")
    print("wlt.info()")
else:
    thispc_wallet = HDWallet(WALLET_NAME)
    thispc_wallet.utxos_update()
    thispc_wallet.info()
    utxos = thispc_wallet.utxos()
    if utxos:
        print("\nNew unspent outputs found!")
        print(
            "Now a new transaction will be created to sweep this wallet and send bitcoins to a testnet faucet"
        )
        send_to_address = 'n2eMqTT929pb1RDNuqEnxdaLau1rxy3efi'
        res = thispc_wallet.sweep(send_to_address, min_confirms=0)

        assert 'transaction' in res
        print(
            "Now copy-and-paste the raw transaction hex to your Other PC and sign it there with a second signature:"
        )
        print("\nfrom bitcoinlib.wallets import HDWallet")
        print("")
        print("wlt = HDWallet('%s')" % WALLET_NAME)
Esempio n. 6
0
import bitcoinlib.transactions
import bitcoinlib.encoding
import hashlib
from bitcoinlib.mnemonic import Mnemonic
import codecs
import base58check

passphrase = "space cricket train sell disagree assume onion soap journey style camera false"
wallet_name = "trial"

#w = HDWallet.create(wallet_name, keys=passphrase, network='testnet', db_uri='./trial.db')
w = HDWallet(wallet_name, db_uri='./trial.db')
#w.utxos_update()
key = w.get_key()

address = key.address
print("address:", address)
# TODO: hash160 not working
# print("hash", bitcoinlib.encoding.hash160(address))
print(w.balance())

tx_hash = w.utxos()[-1]['tx_hash']

t = w.transaction(tx_hash)
script = t.outputs[0].lock_script
print(t.outputs[0].script_type)
# print(codecs.decode(t.outputs[0].lock_script, 'base58'))
print(script)

print(bitcoinlib.transactions.script_to_string(script))