Esempio n. 1
0
def clean_and_collect_all(taddress=TEST_TADDR, fee=DEFAULT_FEE):
    zd = ZDaemon()

    print "Checking balance..."
    tx_unspents = zd.getUnspentTxs()
    if not len(tx_unspents):
        print "No spendable txs available - visit a faucet or mine!"
        exit()

    print "Generating temporary zaddress for tx..."
    # rewrite this
    zaddr = zd.z_getnewaddress()

    print "Generated zaddress: " + zaddr

    print "Gathering and transmitting unspent txs..."
    print "Please wait..."
    # rewrite this
    shielded_txs = zd.sweepAllUnspentTxs(zaddress)

    print "Sending unspent txs to shieleded address..."
    print "This may take a few minutes..."

    # rewrite this
    while zd.receiveTx(zsecret, encnote1).get('exists') is not True:
        print zd.receiveTx(zsecret, encnote1)
        time.sleep(5)

    print "Sent! Check " + taddress + " shortly."
Esempio n. 2
0
 def handle(self, *args, **kwargs):
     wait = kwargs['wait']
     timer = 0
     zd = ZDaemon()
     self.stdout.write('Checking for zcashd at {}'.format(zd.network))
     while timer < wait:
         time.sleep(1)
         timer += 1
         try:
             zd.getNetworkHeight()
             height = zd.getNetworkHeight()
             assert type(height) is int
             return
         except (requests.exceptions.ConnectionError, AssertionError):
             pass
         self.stdout.write('Waiting {:d}s, elapsed {:d}s'.format(
             wait, timer))
     self.stderr.write(
         'Unable to connect to zcash at: {} within {:d}s'.format(
             zd.network, wait))
     sys.exit(1)
Esempio n. 3
0
    def handle(self, *args, **options):
        zd = ZDaemon()
        # balance = zd.getsbalance()
        t_balance = zd.z_gettotalbalance()['transparent']
        z_balance = zd.z_gettotalbalance()['private']
        height = zd.getNetworkHeight()
        difficulty = zd.getNetworkDifficulty()

        hc = HealthCheck()
        hc.t_balance = t_balance
        hc.z_balance = z_balance
        hc.height = height
        hc.difficulty = difficulty
        hc.save()
Esempio n. 4
0
def index(request):
    # TODO: Going to show the page no matter what, so pull these variables out.
    if HealthCheck.objects.latest('timestamp'):
        hc = HealthCheck.objects.latest('timestamp')
        t_balance = hc.t_balance
        z_balance = hc.z_balance
        print "T balance", t_balance
        print " z balance", z_balance
        balance = {'transparent': t_balance, 'private': z_balance}
        difficulty = hc.difficulty
        height = hc.height
        payouts = Drip.objects.count()
    else:
        balance = '0'
        difficulty = '0'
        height = '0'

    zd = ZDaemon()
    version = zd.getVersion()

    #If it is a post, an address was submitted.
    if request.method == 'POST':
        # Check IP and payout address
        # This is the old workaround, added get_client_ip
        ip = request.META.get('REMOTE_ADDR')
        if ip == '127.0.0.1':
            ip = request.META.get('HTTP_X_REAL_IP')
        ip = get_client_ip(request)
        address = request.POST.get('address', '')
        print "IP: ", ip
        print "address: ", address
        try:
            last_payout = Drip.objects.filter(Q(ip=ip) | Q(
                address=address)).order_by('-timestamp')[0]
            now = datetime.utcnow().replace(
                tzinfo=timezone.get_current_timezone())
            timesince = (now - last_payout.timestamp).total_seconds()

            # TODO: keep track of sessions as well, track one per session?

            if timesince < (60 * 60 * 12):
                msg = "Sorry, you received a payout too recently.  Come back later."
                return render(
                    request, 'faucet/faucet.html', {
                        'version': version,
                        'balance': balance,
                        'difficulty': difficulty,
                        'height': height,
                        'payouts': payouts,
                        'flash': True,
                        'message': msg
                    })

        except (Drip.DoesNotExist, IndexError) as e:
            # Nothing in queryset, so we've never seen this ip and address before (individually)
            pass

        # zd = ZDaemon()
        try:
            # Did the tx work?
            if len(address) == len('tmKBPqa8qqKA7vrGq1AaXHSAr9vqa3GczzK'):
                tx = zd.sendtoaddress(address, 1.0)
                if len(tx) == len(
                        '2ac64e297e3910e7ffda7210e7aa2463fe2ec5f69dfe7fdf0b4b9be138a9bfb8'
                ):
                    #Save Drip.
                    drip = Drip(address=address, txid=tx, ip=ip)
                    drip.save()
                    msg = "Sent! txid: {0}. View your transaction on the testnet explorer.".format(
                        tx)
                    return render(
                        request, 'faucet/faucet.html', {
                            'version': version,
                            'balance': balance,
                            'difficulty': difficulty,
                            'height': height,
                            'payouts': payouts,
                            'flash': True,
                            'message': msg
                        })
            elif len(address) == len(
                    'ztbx5DLDxa5ZLFTchHhoPNkKs57QzSyib6UqXpEdy76T1aUdFxJt1w9318Z8DJ73XzbnWHKEZP9Yjg712N5kMmP4QzS9iC9'
            ):
                # sender = 'ztbx5DLDxa5ZLFTchHhoPNkKs57QzSyib6UqXpEdy76T1aUdFxJt1w9318Z8DJ73XzbnWHKEZP9Yjg712N5kMmP4QzS9iC9'
                zaddrs = zd.z_listaddresses()
                sender = zaddrs[0]
                msg = 'Thanks for using zfaucet!'
                opid = zd.z_sendmany(sender, address, 1.0, msg)
                print "OPID", opid
                if opid != None and 'opid' in opid:
                    resp = zd.z_getoperationstatus(opid)
                    print "Operation status response:", resp
                    print "operation status: ", resp[0]['status']
                    #why is it not working when it's executing?
                    if resp[0]['status'] == 'executing':
                        msg = "Sent! Get the status of your private payout with z_getoperationstatus '[\"{0}\"]'.".format(
                            opid)
                        return render(
                            request, 'faucet/faucet.html', {
                                'version': version,
                                'balance': balance,
                                'difficulty': difficulty,
                                'height': height,
                                'payouts': payouts,
                                'flash': True,
                                'message': msg
                            })
                    if resp[0]['status'] == 'failed':
                        msg = "Operation failed for {0}. Error message: {1}".format(
                            opid, resp[0]['error']['message'])
                        return render(
                            request, 'faucet/faucet.html', {
                                'version': version,
                                'balance': balance,
                                'difficulty': difficulty,
                                'height': height,
                                'payouts': payouts,
                                'flash': True,
                                'message': msg
                            })
        except:
            # TODO: Give better error if faucet is empty!
            print "IN ERROR"
            msg = "Issue sending transaction.  Is your address correct?"
            return render(
                request, 'faucet/faucet.html', {
                    'version': version,
                    'balance': balance,
                    'difficulty': difficulty,
                    'height': height,
                    'payouts': payouts,
                    'flash': True,
                    'message': msg
                })

    return render(
        request, 'faucet/faucet.html', {
            'version': version,
            'balance': balance,
            'difficulty': difficulty,
            'height': height,
            'payouts': payouts,
            'flash': False,
            'message': ""
        })
Esempio n. 5
0
def test_daemon():
    zd = ZDaemon()

    # Network tests
    print zd.getBlockHash(100)
    print zd.getBlockByHash(zd.getBlockHash(100))
    print zd.getBlockByHeight(100)
    print zd.getNetworkHeight()
    print zd.getNetworkDifficulty()
    print zd.getVersion()
    print zd.getConnectionCount()

    # Taddr Wallet tests
    print zd.getbalance()
    print zd.listunspent()
    print zd.getnewaddress()

    # Zaddr wallet tests
    print zd.z_getnewaddress()
    zaddrs = zd.z_listaddresses()
    print zaddrs
    zaddr_received = zd.z_listreceivedbyaddress(zaddr)
    print zaddr_received
Esempio n. 6
0
 def handle(self, *args, **options):
     zd = ZDaemon()
     zaddrs = zd.z_listaddresses()
     zd.sweep_coinbase(zaddrs[0])
Esempio n. 7
0
def index(request):
    # TODO: Going to show the page no matter what, so pull these variables out.
    if HealthCheck.objects.latest('timestamp'):
        hc = HealthCheck.objects.latest('timestamp')
        t_balance = hc.t_balance
        z_balance = hc.z_balance
        print('T balance'.format(t_balance))
        print('z balance"'.format(z_balance))
        balance = {'transparent': t_balance, 'private': z_balance}
        difficulty = hc.difficulty
        height = hc.height
        payouts = Drip.objects.count()
    else:
        balance = '0'
        difficulty = '0'
        height = '0'

    zd = ZDaemon(network=ZCASH_NETWORK)
    version = zd.getVersion()

    #If it is a post, an address was submitted.
    if request.method == 'POST':
        # Check IP and payout address
        # This is the old workaround, added get_client_ip
        ip = request.META.get('REMOTE_ADDR')
        if ip == '127.0.0.1':
            ip = request.META.get('HTTP_X_REAL_IP')
        ip = get_client_ip(request)
        address = request.POST.get('address', '')
        print('client IP: {}'.format(ip))
        print('client address: {}'.format(address))
        try:
            last_payout = Drip.objects.filter(Q(ip=ip) | Q(
                address=address)).order_by('-timestamp')[0]
            now = datetime.utcnow().replace(
                tzinfo=django_tz.get_current_timezone())
            timesince = (now - last_payout.timestamp).total_seconds()

            # TODO: keep track of sessions as well, track one per session?

            if timesince < (60 * 60 * 12):
                msg = "Sorry, you received a payout too recently.  Come back later."
                return render(
                    request, 'faucet/faucet.html', {
                        'version': version,
                        'balance': balance,
                        'difficulty': difficulty,
                        'height': height,
                        'payouts': payouts,
                        'flash': True,
                        'message': msg
                    })

        except (Drip.DoesNotExist, IndexError) as e:
            # Nothing in queryset, so we've never seen this ip and address before (individually)
            pass

        # zd = ZDaemon()
        try:
            # Did the tx work?
            # Transparent address
            if len(address) == len('tmKBPqa8qqKA7vrGq1AaXHSAr9vqa3GczzK'):
                tx = zd.sendtoaddress(address, 1.0)
                if len(tx) == len(
                        '2ac64e297e3910e7ffda7210e7aa2463fe2ec5f69dfe7fdf0b4b9be138a9bfb8'
                ):
                    #Save Drip.
                    print(
                        'Saving Drip for {address} transaction {txid} from ip: {ip}'
                        .format(address=address, txid=tx, ip=ip))
                    drip = Drip(address=address, txid=tx, ip=ip)
                    drip.save()
                    msg = "Sent! txid: {0}. View your transaction on the testnet explorer.".format(
                        tx)
                    return render(
                        request, 'faucet/faucet.html', {
                            'version': version,
                            'balance': balance,
                            'difficulty': difficulty,
                            'height': height,
                            'payouts': payouts,
                            'flash': True,
                            'message': msg
                        })
            # Sapling address
            elif len(address) == len(
                    'ztestsapling1603ydy9hg79lv5sv9pm5hn95cngfv4qpd6y54a8wkyejn72jl30a4pfhw8u00p93mu4nj6qxsqg'
            ):
                print('Received a Sapling address')
                # sender = 'ztestsapling1603ydy9hg79lv5sv9pm5hn95cngfv4qpd6y54a8wkyejn72jl30a4pfhw8u00p93mu4nj6qxsqg'
                zaddrs = zd.z_listaddresses()
                sender = zaddrs[1]
                msg = 'Thanks for using zfaucet!'
                opid = zd.z_sendmany(sender, address, 1.0, msg)
                print('OPID: {}'.format(opid))
                if opid != None and 'opid' in opid:
                    resp = zd.z_getoperationstatus(opid)
                    print('Operation status response: {}'.format(resp))
                    print('operation status: {}'.format(resp[0]['status']))
                    #why is it not working when it's executing?
                    if resp[0]['status'] == 'executing':
                        msg = "Sent! You should receive your Sapling funds shortly."
                        return render(
                            request, 'faucet/faucet.html', {
                                'version': version,
                                'balance': balance,
                                'difficulty': difficulty,
                                'height': height,
                                'payouts': payouts,
                                'flash': True,
                                'message': msg
                            })
                    if resp[0]['status'] == 'failed':
                        msg = "Operation failed for {0}. Error message: {1}".format(
                            opid, resp[0]['error']['message'])
                        return render(
                            request, 'faucet/faucet.html', {
                                'version': version,
                                'balance': balance,
                                'difficulty': difficulty,
                                'height': height,
                                'payouts': payouts,
                                'flash': True,
                                'message': msg
                            })
            # Sprout
            elif len(address) == len(
                    'ztSwdDwPhpUZ447YU1BqjxrvutHfu2AyENwUohhTMhnWHreAEHTELhRLvqkARmCSudW1GAcrg58TVaqT7oTH1ohFA7k7V11'
            ):
                # sender = 'ztSwdDwPhpUZ447YU1BqjxrvutHfu2AyENwUohhTMhnWHreAEHTELhRLvqkARmCSudW1GAcrg58TVaqT7oTH1ohFA7k7V11'
                print('Received a Sprout address')
                zaddrs = zd.z_listaddresses()
                sender = zaddrs[0]
                msg = 'Thanks for using zfaucet!'
                opid = zd.z_sendmany(sender, address, 1.0, msg)
                print('OPID: {}'.format(opid))
                if opid != None and 'opid' in opid:
                    resp = zd.z_getoperationstatus(opid)
                    print('Operation status response: {}'.format(resp))
                    print('operation status: {}'.format(resp[0]['status']))
                    #why is it not working when it's executing?
                    if resp[0]['status'] == 'executing':
                        msg = "Sent! You should receive your Sprout funds shortly."
                        return render(
                            request, 'faucet/faucet.html', {
                                'version': version,
                                'balance': balance,
                                'difficulty': difficulty,
                                'height': height,
                                'payouts': payouts,
                                'flash': True,
                                'message': msg
                            })
                    if resp[0]['status'] == 'failed':
                        msg = "Operation failed for {0}. Error message: {1}".format(
                            opid, resp[0]['error']['message'])
                        return render(
                            request, 'faucet/faucet.html', {
                                'version': version,
                                'balance': balance,
                                'difficulty': difficulty,
                                'height': height,
                                'payouts': payouts,
                                'flash': True,
                                'message': msg
                            })
        except:
            # TODO: Give better error if faucet is empty!
            print('ERROR: unknow address format')
            msg = "Issue sending transaction.  Is your address correct?"
            return render(
                request, 'faucet/faucet.html', {
                    'version': version,
                    'balance': balance,
                    'difficulty': difficulty,
                    'height': height,
                    'payouts': payouts,
                    'flash': True,
                    'message': msg
                })

    return render(
        request, 'faucet/faucet.html', {
            'version': version,
            'balance': balance,
            'difficulty': difficulty,
            'height': height,
            'payouts': payouts,
            'flash': False,
            'message': ""
        })
Esempio n. 8
0
def find_z_legacy_address():
    zd = ZDaemon(network=ZCASH_NETWORK)
    for z_addr in zd.z_listaddresses():
        if z_addr.startswith('ztestsapling'):
            return z_addr
Esempio n. 9
0
def find_taddr_with_unspent():
    zd = ZDaemon(network=ZCASH_NETWORK)
    for utxo in zd.listunspent():
        if utxo['spendable'] == True and utxo['amount'] > 0.1:
            return utxo['address']
Esempio n. 10
0
from django.http import JsonResponse
from django.utils import timezone as django_tz
from  zfaucet.settings import DONATION_ORG

import re
from datetime import *

from pyZcash.rpc.ZDaemon import *

zd = ZDaemon(network=ZCASH_NETWORK)

def donations(request):
    data = {}
    data['org'] = DONATION_ORG
    data['t_address'] = find_taddr_with_unspent()
    data['z_address_legacy'] = find_z_legacy_address()
    data['z_address_sapling'] = find_z_sapling_address()
    return JsonResponse(data)

def find_taddr_with_unspent():
    zd = ZDaemon(network=ZCASH_NETWORK)
    for utxo in zd.listunspent():
        if utxo['spendable'] == True and utxo['amount'] > 0.1:
            return utxo['address']

def find_z_sapling_address():
    zd = ZDaemon(network=ZCASH_NETWORK)
    for z_addr in zd.z_listaddresses():
        if z_addr.startswith('zt') and not z_addr.startswith('ztestsapling'):
            return z_addr