예제 #1
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.2.17 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,
            payee_address=work["payee"].strip() if (work["payee"] != "") else None,
            masternode_payments=work["masternode_payments"],
            payee_amount=work["payee_amount"] if (work["payee_amount"] != "") else work["coinbasevalue"] / 5,
        )
    )
예제 #2
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,
    ))
예제 #3
0
 def test_address_to_pubkey_hash(self):
     assert data.address_to_pubkey_hash('7gnwGHt17heGpG9Crfeh4KGpYNFugPhJdh', networks.nets['dash']) == pack.IntType(160).unpack('9dc8b19033a16913b6e45437f76d0ab649e9e516'.decode('hex'))
예제 #4
0
 def test_address_to_pubkey_hash(self):
     assert data.address_to_pubkey_hash(
         '1KUCp7YP5FP8ViRxhfszSUJCTAajK6viGy',
         networks.nets['dash']) == pack.IntType(160).unpack(
             'ca975b00a8c203b8692f5a18d92dc5c2d2ebc57b'.decode('hex'))
예제 #5
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,
        ))
예제 #6
0
 def test_address_to_pubkey_hash(self):
     assert data.address_to_pubkey_hash('1KUCp7YP5FP8ViRxhfszSUJCTAajK6viGy', networks.nets['dash']) == pack.IntType(160).unpack('ca975b00a8c203b8692f5a18d92dc5c2d2ebc57b'.decode('hex'))
예제 #7
0
 def test_address_to_pubkey_hash(self):
     assert data.address_to_pubkey_hash('7gnwGHt17heGpG9Crfeh4KGpYNFugPhJdh', networks.nets['dash']) == pack.IntType(160).unpack('9dc8b19033a16913b6e45437f76d0ab649e9e516'.decode('hex'))