示例#1
0
                "".join(['\x00' for i in range(leading_zeros)]), 'utf8'):
            return False
        return int(hash_g[leading_zeros]) < next_char_limit

    def find_nonce(self):
        for i in range(10000000):
            self.nonce = ''.join([
                chr(random.randint(0, 255)) for i in range(10 * leading_zeros)
            ])
            if self.good_nonce():
                return self.nonce
        return None


if __name__ == "__main__":
    pr1, pu1 = signature.generate_keys()
    pr2, pu2 = signature.generate_keys()
    pr3, pu3 = signature.generate_keys()

    Tx1 = Tx()
    Tx1.add_input(pu1, 1)
    Tx1.add_output(pu2, 1)
    Tx1.sign(pr1)

    if Tx1.is_valid():
        print("Success! Tx is valid")
    else:
        print("Error! Tx is invalid")

    savefile = open("save.dat", "wb")
    def find_nonce(self):
        for i in range(1000000):
            self.nonce = "".join([
                chr(random.randint(0, 255)) for i in range(10 * leading_zeros)
            ])

            if self.good_nonce():
                return self.nonce

        return None


if __name__ == '__main__':
    print("txBlock.py tests start here")

    private_key1, public_key1 = generate_keys()
    private_key2, public_key2 = generate_keys()
    private_key3, public_key3 = generate_keys()
    private_key4, public_key4 = generate_keys()

    Tx1 = Tx()
    Tx1.add_input(public_key1, 1)
    Tx1.add_output(public_key2, 1)
    Tx1.sign(private_key1)

    print('Tx{0} validation status before loading is: {1}'.format(
        1, Tx1.is_valid()))

    savefile = open("save.dat", "wb")
    pickle.dump(Tx1, savefile)
    savefile.close()
示例#3
0
    # Find nonce
    for i in range(10):
        print("Finding Nonce...")
        newBlock.find_nonce()
        if newBlock.good_nonce():
            break
    if not newBlock.good_nonce():
        print("Error. Couldn't find nonce")
        return False

    # Send new block to wallets
    for ip_addr in wallet_list:
        socketUtils.sendObj(ip_addr, newBlock, 5006)

    # Replace new block with previously longest block
    head_blocks.remove(newBlock.previousBlock)
    head_blocks.append(newBlock)

    print(head_blocks, "Everything done successfully in miner")
    # Open server connection
    # Rec'v 2 transactions
    # Collect them into block
    # Fine nonce
    # Send that block to wallet_list
    return False


my_private_key, my_public_key = signature.generate_keys()

minerServer('localhost', wallet_list, my_public_key)
 def __init__(self, name):
     self.name = name
     self.public_key, self.private_key = generate_keys()
示例#5
0
    # compute and add mining reward
    total_in, total_out = newBlock.count_totals()
    mine_reward = Tx()
    mine_reward.add_output(miner_public, 25.0 + total_in - total_out)
    newBlock.addTx(mine_reward)
    print("Reward obtained: ", mine_reward)

    # Find the nonce
    for i in range(10):
        print("Finding nonce")
        newBlock.find_nonce()
        if newBlock.good_nonce():
            print("Good nonce found")
            break
    if not newBlock.good_nonce():
        print("Error: couldn't find nonce")
        return False

    # Send the block to the wallets
    for ip_address in wallets:
        print("Send object: ", ip_address)
        socket_utils.sendObj('localhost', newBlock, 5006)
    head_blocks.remove(newBlock.previous_block)
    head_blocks.append(newBlock)
    return False


my_pr, my_pu = signature.generate_keys()
minerServer('localhost', wallets, my_pu)