Exemple #1
0
    def estimate_target():
        """
        We are actually interested in the average number of hashes required to
        mine a block. number of hashes required is inversely proportional
        to target. So we average over inverse-targets, and inverse the final
        answer. """
        def sumTargets(l):
            if len(l) < 1:
                return 0
            while len(l) > 1:
                l = [blockchain.hexSum(l[0], l[1])] + l[2:]
            return l[0]

        targets = blockchain.recent_blockthings('targets',
                                                custom.history_length)
        w = weights(len(targets))  # should be rat instead of float
        tw = sum(w)
        targets = map(blockchain.hexInvert, targets)

        def weighted_multiply(i):
            return targetTimesFloat(targets[i], w[i] /
                                    tw)  # this should use rat division instead

        weighted_targets = [weighted_multiply(i) for i in range(len(targets))]
        return blockchain.hexInvert(sumTargets(weighted_targets))
Exemple #2
0
 def genesis(pubkey, DB):
     target=blockchain.target(DB)
     out={'version':custom.version,
          'length':0,
          'time':time.time(),
          'target':target,
          'diffLength':blockchain.hexInvert(target),
          'txs':[make_mint(pubkey, DB)]}
     out=tools.unpackage(tools.package(out))
     return out
Exemple #3
0
def genesis(pubkey, DB):
    target_ = target.target()
    out = {'version': custom.version,
           'length': 0,
           'time': time.time(),
           'target': target_,
           'diffLength': blockchain.hexInvert(target_),
           'txs': [make_mint(pubkey, DB)]}
    out = tools.unpackage(tools.package(out))
    return out
 def genesis(pubkey, DB):
     target = blockchain.target(DB)
     out = {'version': custom.version,
            'length': 0,
            'time': time.time(),
            'target': target,
            'diffLength': blockchain.hexInvert(target),
            'txs': [make_mint(pubkey, DB)]}
     print('out: ' + str(out))
     out = tools.unpackage(tools.package(out))
     return out
Exemple #5
0
 def make_block(prev_block, txs, pubkey, DB):
     leng=int(prev_block['length'])+1
     target=blockchain.target(DB, leng)
     diffLength=blockchain.hexSum(prev_block['diffLength'], blockchain.hexInvert(target))
     out={'version':custom.version,
          'txs':txs+[make_mint(pubkey, DB)],
          'length':leng,
          'time':time.time(),
          'diffLength':diffLength,
          'target':target,
          'prevHash':tools.det_hash(prev_block)}
     out=tools.unpackage(tools.package(out))
     return out
 def make_block(prev_block, txs, pubkey, DB):
     leng = int(prev_block['length']) + 1
     target = blockchain.target(DB, leng)
     diffLength = blockchain.hexSum(prev_block['diffLength'],
                                    blockchain.hexInvert(target))
     out = {'version': custom.version,
            'txs': txs + [make_mint(pubkey, DB)],
            'length': leng,
            'time': time.time(),
            'diffLength': diffLength,
            'target': target,
            'prevHash': tools.det_hash(prev_block)}
     out = tools.unpackage(tools.package(out))
     return out
Exemple #7
0
 def estimate_target(DB):
     """
     We are actually interested in the average number of hashes required to
     mine a block. number of hashes required is inversely proportional
     to target. So we average over inverse-targets, and inverse the final
     answer. """
     def sumTargets(l):
         if len(l) < 1:
             return 0
         while len(l) > 1:
             l = [blockchain.hexSum(l[0], l[1])] + l[2:]
         return l[0]
     targets = blockchain.recent_blockthings('targets', DB, custom.history_length)
     w = weights(len(targets))
     tw = sum(w)
     targets = map(blockchain.hexInvert, targets)
     def weighted_multiply(i):
         return targetTimesFloat(targets[i], w[i]/tw)
     weighted_targets = [weighted_multiply(i) for i in range(len(targets))]
     return blockchain.hexInvert(sumTargets(weighted_targets))