return True

    # Generating different nonces until they are valid with required amount of leading zeros
    def search_nonce(self):
        for _ in range(100000):
            self.nonce = "".join(
                [chr(random.randint(0, 255)) for i in range(10 * nonce_zeros)])
            if self.valid_nonce():
                print(f"The Valid Nonce is: {self.nonce}")
                return self.nonce
        return None


if __name__ == "__main__":
    # Generating private and public keys
    pr1, pu1 = generate_keys()
    pr2, pu2 = generate_keys()
    pr3, pu3 = generate_keys()
    pr4, pu4 = generate_keys()
    pr5, pu5 = generate_keys()
    pr6, pu6 = generate_keys()

    # Adding the First Transaction
    print("TRANSACTION 1 Created")
    Tx1 = transactions()
    Tx1.add_input(pu1, 1)
    Tx1.add_output(pu2, 1)
    Tx1.sign(pr1)

    # Checking if the Transaction is valid or not
    if Tx1.is_valid():
示例#2
0
        return True

    def __gather(self):
        data = []
        data.append(self.inputs)
        data.append(self.outputs)
        data.append(self.escrow)
        return data

    def __repr__(self):
        return "Returing Transactions"


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

    print("=========================================")
    print("Possible Cases of Successful Transactions")
    print("=========================================")

    print("---------Transaction 1---------")
    print("Sender = A")
    print("Receiver = B")
    print("Sending = A1")
    print("Receiving = B1")
    transactions1 = transactions()
    transactions1.add_input(pu1, 1)
    this_block = last_block
    bal = 0.0
    while this_block != None:
        for tx in this_block.data:
            for addr, amt in tx.inputs:
                if addr == pu_key:
                    bal = bal - amt
            for addr, amt in tx.outputs:
                if addr == pu_key:
                    bal = bal + amt
        this_block = this_block.previousBlock
    return bal


if __name__ == "__main__":
    pr1, pu1 = generate_keys()
    pr2, pu2 = generate_keys()
    pr3, pu3 = 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")

    savefile = open("tx.dat", "wb")
    pickle.dump(Tx1, savefile)
    savefile.close()
示例#4
0
    # Find nonce
        print ("Finding Nonce...")
        newBlock.find_nonce(10000)
        if newBlock.good_nonce():
            print ("Good nonce found")
            # Send new block
            for ip_addr,port in wallet_list:
                print ("Sending to " + ip_addr + ":" + str(port))
                Socketutil.sendObj(ip_addr,newBlock,5006)
            head_blocks.remove(newBlock.previousBlock)
            head_blocks.append(newBlock)
            break
        return True 

if __name__ == '__main__': 
    my_pr, my_pu = generate_keys()
    t1 = threading.Thread(target = minerServer, args = (('localhost',5005),))
    t2 = threading.Thread(target = nonceFinder, args = (wallets,my_pu))
    server = Socketutil.newServerConnection('localhost', 5006)
    t1.start()
    t2.start()
    
    pr1,pu1 = generate_keys()
    pr2,pu2 = generate_keys()
    pr3,pu3 = generate_keys()

    Tx1 = Transactions.Tx()
    Tx2 = Transactions.Tx()
    
    Tx1.add_input(pu1, 4.0)
    Tx1.add_input(pu2, 1.0)
示例#5
0
        return int(currentHash[leadingZeros]) < nextCharLimit

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

        return None


if __name__ == '__main__':
    priv1, publ1 = generate_keys()
    priv2, publ2 = generate_keys()
    priv3, publ3 = generate_keys()
    priv4, publ4 = generate_keys()

    Tx1 = Tx()
    Tx1.add_input(publ1, 1)
    Tx1.add_output(publ2, 1)
    Tx1.sign(priv1)

    if Tx1.is_valid():
        print("Succesful transaction")
    else:
        print("Error: Invalid Transaction")

    savefile = open("tx.dat", "wb")