Esempio n. 1
0
    def test_address_to_script(self):
        # base58 P2PKH
        self.assertEqual(address_to_script('yah2ARXMnY5A9VaR5Cd43fjiQnsu2vZ5a8'), '76a9149da64e300c5e4eb4aaffc9c2fd465348d5618ad488ac')
        self.assertEqual(address_to_script('yPeP8a774GuYaZyqJPxC7K24hcbcsqz1Au'), '76a914247d2d5b6334bdfa2038e85b20fc15264f8e5d2788ac')

        # base58 P2SH
        self.assertEqual(address_to_script('8pWgedHiF9DQswwXdR59ATSQe9pxyBZqbv'), 'a9146eae23d8c4a941316017946fc761a7a6c85561fb87')
        self.assertEqual(address_to_script('91EoMZCG6Yfs9NGZLYQcrJcUa55TLnvVxz'), 'a914e4567743d378957cd2ee7072da74b1203c1a7a0b87')
Esempio n. 2
0
    def test_address_to_script(self):
        # base58 P2PKH
        self.assertEqual(address_to_script('XeNTG4aihv1ru8xmaoiQnToSi8hLiTTNbh'), '76a91428662c67561b95c79d2257d2a93d9d151c977e9188ac')
        self.assertEqual(address_to_script('XkvgWFLxVmDaVkUF8bFE2QXP4f5C2KKWEg'), '76a914704f4b81cadb7bf7e68c08cd3657220f680f863c88ac')

        # base58 P2SH
        self.assertEqual(address_to_script('7WHUEVtMDLeereT5r4ZoNKjr3MXr4gqfon'), 'a9142a84cf00d47f699ee7bbc1dea5ec1bdecb4ac15487')
        self.assertEqual(address_to_script('7phNpVKta6kkbP24HfvvQVeHEmgBQYiJCB'), 'a914f47c8954e421031ad04ecd8e7752c9479206b9d387')
Esempio n. 3
0
 async def do_scan(self, wallet, cnt):
     w = wallet
     try:
         async with self.wallet_scans_lock:
             ws = self.wallet_scans.get(w)
             if not ws or ws.running:
                 return
             ws.running = True
             scans = list(ws.scans.values())
         n = Network.get_instance()
         loop = n.asyncio_loop
         done_cnt = 0
         to_scan_cnt = 0
         for s in scans:
             if not s.active:
                 continue
             to_scan_cnt += len(s.uncompleted)
         if to_scan_cnt:
             self.logger.info(f'total count to rescan: {to_scan_cnt}')
         else:
             for s in scans:
                 if not s.active:
                     continue
                 async with self.wallet_scans_lock:
                     await loop.run_in_executor(None, s.derive_addrs, cnt)
                 to_scan_cnt += cnt
             self.logger.info(f'total count to scan: {to_scan_cnt}')
         if not to_scan_cnt:
             return
         async with TaskGroup() as group:
             for s in scans:
                 for i, addr in s.addrs.items():
                     if i in s.balances:
                         continue
                     script = bitcoin.address_to_script(addr)
                     scripthash = bitcoin.script_to_scripthash(script)
                     coro = n.get_balance_for_scripthash(scripthash)
                     s.tasks[i] = await group.spawn(coro)
             while True:
                 task = await group.next_done()
                 if task is None:
                     break
                 done_cnt += 1
                 await self.on_progress(w, 100 * done_cnt / to_scan_cnt)
         for s in scans:
             for i, task in s.tasks.items():
                 try:
                     balance = task.result()
                     s.balances[i] = balance_total(**balance)
                     if i in s.errors:
                         s.errors.pop(i)
                 except BaseException as e:
                     self.logger.info(f'Exception on get_balance {repr(e)}')
                     s.errors[i] = e
             s.tasks.clear()
         await self.on_completed(w)
     except Exception as e:
         self.logger.info(f'Exception during wallet_scan: {repr(e)}')
         await self.on_error(w, e)
Esempio n. 4
0
 def parse_output(self, x) -> bytes:
     try:
         address = self.parse_address(x)
         return bfh(bitcoin.address_to_script(address))
     except Exception:
         pass
     try:
         script = self.parse_script(x)
         return bfh(script)
     except Exception:
         pass
     raise Exception("Invalid address or script.")
Esempio n. 5
0
 def pin_changed(s):
     if len(s) < len(self.idxs):
         i = self.idxs[len(s)]
         addr = self.txdata['address']
         if not constants.net.TESTNET:
             text = addr[:i] + '<u><b>' + addr[i:i+1] + '</u></b>' + addr[i+1:]
         else:
             # pin needs to be created from mainnet address
             addr_mainnet = bitcoin.script_to_address(bitcoin.address_to_script(addr), net=constants.BitcoinMainnet)
             addr_mainnet = addr_mainnet[:i] + '<u><b>' + addr_mainnet[i:i+1] + '</u></b>' + addr_mainnet[i+1:]
             text = str(addr) + '\n' + str(addr_mainnet)
         self.addrtext.setHtml(str(text))
     else:
         self.addrtext.setHtml(_("Press Enter"))
Esempio n. 6
0
from electrum_firo import paymentrequest
from electrum_firo import paymentrequest_pb2 as pb2
from electrum_firo.bitcoin import address_to_script

chain_file = 'mychain.pem'
cert_file = 'mycert.pem'
amount = 1000000
address = "18U5kpCAU4s8weFF8Ps5n8HAfpdUjDVF64"
memo = "blah"
out_file = "payreq"


with open(chain_file, 'r') as f:
    chain = tlslite.X509CertChain()
    chain.parsePemList(f.read())

certificates = pb2.X509Certificates()
certificates.certificate.extend(map(lambda x: str(x.bytes), chain.x509List))

with open(cert_file, 'r') as f:
    rsakey = tlslite.utils.python_rsakey.Python_RSAKey.parsePEM(f.read())

script = address_to_script(address)

pr_string = paymentrequest.make_payment_request(amount, script, memo, rsakey)

with open(out_file,'wb') as f:
    f.write(pr_string)

print("Payment request was written to file '%s'"%out_file)