Esempio n. 1
0
    def __init__(self):
        self.blocks = [
            0x00000000000132b9afeca5e9a2fdf4477338df6dcff1342300240bc70397c4bb
        ]
        self.headers = {
            0x132b9afeca5e9a2fdf4477338df6dcff1342300240bc70397c4bb: {
                'nonce':
                2093330011,
                'timestamp':
                1452288263,
                'merkle_root':
                0x43dda83285fae26de9a97331f617392261c77495debe97b7e18b1faf38d1ef8,
                'version':
                3,
                'previous_block':
                1048610514577342396345362905164852351970507722694242579238530L,
                'bits':
                dash_data.FloatingInteger(
                    bits=0x1b0d642e,
                    target=
                    0x44b9f20000000000000000000000000000000000000000000000L),
            }
        }

        self.conn = variable.Variable(self)
        self.new_headers = variable.Event()
        self.new_block = variable.Event()
        self.new_tx = variable.Event()
Esempio n. 2
0
 def test_header_hash(self):
     assert data.hash256(data.block_header_type.pack(dict(
         version=1,
         previous_block=0x000000000000038a2a86b72387f93c51298298a732079b3b686df3603d2f6282,
         merkle_root=0x37a43a3b812e4eb665975f46393b4360008824aab180f27d642de8c28073bc44,
         timestamp=1323752685,
         bits=data.FloatingInteger(437159528),
         nonce=3658685446,
     ))) == 0x000000000000003aaaf7638f9f9c0d0c60e8b0eb817dcdb55fd2b1964efc5175
Esempio n. 3
0
 def test_header_hash_dash(self):
     assert networks.nets['dash'].POW_FUNC(data.block_header_type.pack(dict(
         version=3,
         previous_block=0x0000000000058f1afc49ee27334f3198e72f5390f1dac1d549823ec70a6902aa,
         merkle_root=0x043dda83285fae26de9a97331f617392261c77495debe97b7e18b1faf38d1ef8,
         timestamp=1452288263,
         bits=data.FloatingInteger(0x1b0d642e),
         nonce=2093330011,
     ))) < 2**256//2**30
Esempio n. 4
0
 def test_header_hash_litecoin(self):
     assert networks.nets['litecoin'].POW_FUNC(
         data.block_header_type.pack(
             dict(
                 version=1,
                 previous_block=
                 0xd928d3066613d1c9dd424d5810cdd21bfeef3c698977e81ec1640e1084950073,
                 merkle_root=
                 0x03f4b646b58a66594a182b02e425e7b3a93c8a52b600aa468f1bc5549f395f16,
                 timestamp=1327807194,
                 bits=data.FloatingInteger(0x1d01b56f),
                 nonce=20736,
             ))) < 2**256 // 2**30
Esempio n. 5
0
 def __init__(self):
     self.blocks = [
         0x000000000000016c169477c25421250ec5d32cf9c6d38538b5de970a2355fd89
     ]
     self.headers = {
         0x16c169477c25421250ec5d32cf9c6d38538b5de970a2355fd89: {
             'nonce':
             1853158954,
             'timestamp':
             1351658517,
             'merkle_root':
             2282849479936278423916707524932131168473430114569971665822757638339486597658L,
             'version':
             1,
             'previous_block':
             1048610514577342396345362905164852351970507722694242579238530L,
             'bits':
             dash_data.FloatingInteger(
                 bits=0x1a0513c5,
                 target=
                 0x513c50000000000000000000000000000000000000000000000L),
         }
     }
Esempio n. 6
0
def getwork(dashd, net, use_getblocktemplate=True):
    def go():
        if use_getblocktemplate:
            return dashd.rpc_getblocktemplate(dict(mode='template'))
        else:
            return dashd.rpc_getmemorypool()

    try:
        start = time.time()
        work = yield go()
        end = time.time()
    except jsonrpc.Error_for_code(-32601):  # Method not found
        use_getblocktemplate = not use_getblocktemplate
        try:
            start = time.time()
            work = yield go()
            end = time.time()
        except jsonrpc.Error_for_code(-32601):  # Method not found
            print >> sys.stderr, 'Error: dash version too old! Upgrade to v0.11.2.17 or newer!'
            raise deferral.RetrySilentlyException()

    if work['transactions']:
        packed_transactions = [
            (x['data'] if isinstance(x, dict) else x).decode('hex')
            for x in work['transactions']
        ]
    else:
        packed_transactions = []
    if 'height' not in work:
        work['height'] = (yield dashd.rpc_getblock(
            work['previousblockhash']))['height'] + 1
    elif p2pool.DEBUG:
        assert work['height'] == (yield dashd.rpc_getblock(
            work['previousblockhash']))['height'] + 1

    # Dash Payments
    packed_payments = []
    payment_amount = 0

    payment_objects = []
    if 'masternode' in work:
        if isinstance(work['masternode'], list):
            payment_objects += work['masternode']
        else:
            payment_objects += [work['masternode']]
    if 'superblock' in work:
        payment_objects += work['superblock']

    for obj in payment_objects:
        g = {}
        if 'payee' in obj:
            g['payee'] = str(obj['payee'])
            g['amount'] = obj['amount']
            if g['amount'] > 0:
                payment_amount += g['amount']
                packed_payments.append(g)

    coinbase_payload = None
    if 'coinbase_payload' in work and len(work['coinbase_payload']) != 0:
        coinbase_payload = work['coinbase_payload'].decode('hex')

    defer.returnValue(
        dict(
            version=work['version'],
            previous_block=int(work['previousblockhash'], 16),
            transactions=map(dash_data.tx_type.unpack, packed_transactions),
            transaction_hashes=map(dash_data.hash256, packed_transactions),
            transaction_fees=[
                x.get('fee', None) if isinstance(x, dict) else None
                for x in work['transactions']
            ],
            subsidy=work['coinbasevalue'],
            time=work['time'] if 'time' in work else work['curtime'],
            bits=dash_data.FloatingIntegerType().unpack(
                work['bits'].decode('hex')[::-1]) if isinstance(
                    work['bits'],
                    (str,
                     unicode)) else dash_data.FloatingInteger(work['bits']),
            coinbaseflags=work['coinbaseflags'].decode('hex')
            if 'coinbaseflags' in work else ''.join(
                x.decode('hex') for x in work['coinbaseaux'].itervalues())
            if 'coinbaseaux' in work else '',
            height=work['height'],
            last_update=time.time(),
            use_getblocktemplate=use_getblocktemplate,
            latency=end - start,
            payment_amount=payment_amount,
            packed_payments=packed_payments,
            coinbase_payload=coinbase_payload,
        ))
Esempio n. 7
0
def getwork(dashd, net, use_getblocktemplate=False):
    def go():
        if use_getblocktemplate:
            return dashd.rpc_getblocktemplate(dict(mode='template'))
        else:
            return dashd.rpc_getmemorypool()

    try:
        start = time.time()
        work = yield go()
        end = time.time()
    except jsonrpc.Error_for_code(-32601):  # Method not found
        use_getblocktemplate = not use_getblocktemplate
        try:
            start = time.time()
            work = yield go()
            end = time.time()
        except jsonrpc.Error_for_code(-32601):  # Method not found
            print >> sys.stderr, 'Error: Dash version too old! Upgrade to v0.11.0.11 or newer!'
            raise deferral.RetrySilentlyException()
    packed_transactions = [
        (x['data'] if isinstance(x, dict) else x).decode('hex')
        for x in work['transactions']
    ]
    packed_votes = [(x['data'] if isinstance(x, dict) else x).decode('hex')
                    for x in work['votes']]
    if 'height' not in work:
        work['height'] = (yield dashd.rpc_getblock(
            work['previousblockhash']))['height'] + 1
    elif p2pool.DEBUG:
        assert work['height'] == (yield dashd.rpc_getblock(
            work['previousblockhash']))['height'] + 1
    defer.returnValue(
        dict(
            version=work['version'],
            previous_block=int(work['previousblockhash'], 16),
            transactions=map(dash_data.tx_type.unpack, packed_transactions),
            transaction_hashes=map(dash_data.hash256, packed_transactions),
            transaction_fees=[
                x.get('fee', None) if isinstance(x, dict) else None
                for x in work['transactions']
            ],
            subsidy=work['coinbasevalue'],
            time=work['time'] if 'time' in work else work['curtime'],
            bits=dash_data.FloatingIntegerType().unpack(
                work['bits'].decode('hex')[::-1]) if isinstance(
                    work['bits'],
                    (str,
                     unicode)) else dash_data.FloatingInteger(work['bits']),
            coinbaseflags=work['coinbaseflags'].decode('hex')
            if 'coinbaseflags' in work else ''.join(
                x.decode('hex') for x in work['coinbaseaux'].itervalues())
            if 'coinbaseaux' in work else '',
            height=work['height'],
            last_update=time.time(),
            use_getblocktemplate=use_getblocktemplate,
            latency=end - start,
            votes=map(dash_data.vote_type.unpack, packed_votes),
            payee=dash_data.address_to_pubkey_hash(work['payee'], net.PARENT)
            if (work['payee'] != '') else None,
            masternode_payments=work['masternode_payments'],
            payee_amount=work['payee_amount'] if
            (work['payee_amount'] != '') else work['coinbasevalue'] / 5,
        ))