コード例 #1
0
ファイル: wallet_cli.py プロジェクト: tsergien/fake_bitcoin
    def do_get10(self, args):
        print("\033[0;37;40m")
        children_amount = len(self.wallet["children"])
        init_chil = children_amount
        for i in range(20):
            childm, childc = wallet.get_key_chain(self.wallet["public_key"] +
                                                  self.chaincode +
                                                  str(children_amount + i))
            self.wallet["children"].append([childm, childc])
            children_amount = len(self.wallet["children"])

        print("Receiving: ")
        for k in range(10):
            c = self.wallet["children"][init_chil + k]
            addr = wallet.gen_address(wallet.get_pubkey_str(c[0]))
            self.addresses.append(addr)
            open("addresses.txt", "a+").write(addr + "\n")
            print(k, ". ", addr)
        print("Change addresses: ")
        for k in range(10, 20):
            c = self.wallet["children"][init_chil + k]
            addr = wallet.gen_address(wallet.get_pubkey_str(c[0]))
            self.addresses.append(addr)
            open("addresses.txt", "a+").write(addr + "\n")
            print(k - 10, ". ", addr)
コード例 #2
0
 def do_premine(self, args):
     print("\033[0;37;40m")
     "start auto mining process"
     print("Starting mining")
     addresses =[wallet.gen_address(wallet.wif_to_privkey(self.chain.miner_wif)),\
                 wallet.gen_address(wallet.wif_to_privkey(self.chain.miner_wif)), \
                 wallet.gen_address(wallet.wif_to_privkey(self.chain.miner_wif))]
     if args == "":
         N = 5
     else:
         N = int(args)
     i = 0
     while i < N:
         # sending random transactions between self addresses
         if i != 0:
             self.chain.utxo_pool.update_pool([])
             tx = form_tx.form_transaction(self.chain.address,
                                           addresses[i % 3], 70 + i * i,
                                           self.chain.utxo_pool,
                                           self.chain.miner_wif)
             self.chain.submit_tx(self.server_port + "/transaction/new",
                                  Serializer().serialize(tx))
         i += 1
         self.chain.mine()
     print("Stopping mining")
コード例 #3
0
def testing_forming():
    privkey = wallet.gen_privkey()
    wif = wallet.privkey_to_wif(privkey)

    sender = wallet.gen_address(wallet.get_pubkey_str(privkey))
    recipient = wallet.gen_address(wallet.get_pubkey_str(wallet.gen_privkey()))
    utxo_obj = Utxos()
    g_miner_reward = 50

    coinbase_tx = form_coinbase(recipient, wif, g_miner_reward)
    print(coinbase_tx.toJSON())
    serial_coinbase = Serializer().serialize(coinbase_tx)
    deserial_coinbase = Deserializer().deserialize(serial_coinbase)
コード例 #4
0
ファイル: wallet_cli.py プロジェクト: tsergien/fake_bitcoin
 def do_new_child(self, args):
     "Generates new child private key"
     print("\033[0;37;40m")
     ind = len(self.wallet["children"])
     childm, childc = wallet.get_key_chain(self.wallet["public_key"] +
                                           self.chaincode + str(ind))
     self.wallet["children"].append([childm, childc])
     addr = wallet.gen_address(wallet.get_pubkey_str(childm))
     self.addresses.append(addr)
     open("addresses.txt", "a+").write(addr + "\n")
     print("New child was generated: ")
     print("Child private key: ", childm)
     print("Addres:            ", addr)
コード例 #5
0
ファイル: wallet_cli.py プロジェクト: tsergien/fake_bitcoin
 def do_new_key(self, args):
     "Generates new pair of public and private keys"
     privkey = wallet.gen_privkey()
     wif = wallet.privkey_to_wif(privkey)
     vk = wallet.get_pubkey_str(privkey)
     pub_address = wallet.gen_address(vk)
     self.wallet["wif"] = wif
     self.addresses.append(pub_address)
     f = open("addresses.txt", "a+")
     f.write(pub_address + "\n")
     f.close()
     print("Private key : " + privkey)
     print("Address     : " + pub_address)
コード例 #6
0
def test():
    " SCRIPT  TEST "
    privkey = wallet.gen_privkey()
    wif = wallet.privkey_to_wif(privkey)
    pubkey = wallet.get_pubkey_str(privkey)
    address = wallet.gen_address(pubkey)

    scriptSig = get_scriptSig(wif, "1234567890abcdef1234567890")
    print("scriptSig: " + scriptSig)
    scriptPubKey = get_scriptPubKey(address)
    print("scriptPubKey: " + scriptPubKey)

    if exec_script(scriptSig, scriptPubKey, "1234567890abcdef1234567890"):
        print("script is correct")
コード例 #7
0
ファイル: wallet_cli.py プロジェクト: tsergien/fake_bitcoin
 def do_import(self, path):
     "Import WIF from file: import PATH"
     if not path:
         print("Please, enter path to file.")
         return
     try:
         self.wallet["wif"] = open(path, "r").read(51)
         privkey = wallet.wif_to_privkey(self.wallet["wif"])
         pubkey = wallet.get_pubkey_str(privkey)
         self.addresses.append(wallet.gen_address(pubkey))
         f = open("addresses.txt", "a+")
         f.write(self.addresses[-1] + "\n")
         f.close()
         print("Private key ( WIF ): " + self.wallet["wif"] +
               " was imported to wallet")
         print("Public address     : " + self.addresses[-1])
     except:
         print("File " + path +
               " doesn't exist or has invalid form ( WIF needed )")
コード例 #8
0
 def __init__(self):
     self.db = TinyDB('blks.json')
     self.utxo_pool = Utxos()
     self.utxo_pool.update_pool([])  ##############################
     self.bits = 0x33222222
     try:
         with open("miner_key", "r") as f:
             self.miner_wif = f.read(51)
         with open("miner_address.txt", "r") as f2:
             self.address = f2.read(34)
     except:
         with open("miner_key", "w") as f:
             privkey = wallet.gen_privkey()
             self.miner_wif = wallet.privkey_to_wif(privkey)
             f.write(self.miner_wif + "\n")
         with open("miner_address.txt", "w") as f2:
             self.address = wallet.gen_address(
                 wallet.get_pubkey_str(privkey))
             f2.write(self.address + "\n")