def test_address_to_script(self): # bech32 native segwit # test vectors from BIP-0173 TODO self.assertEqual( address_to_script('MONA1Q4KPN6PSTHGD5UR894AUHJJ2G02WLGMP8KE08NE'), '0014ad833d060bba1b4e0ce5af797949487a9df46c27') self.assertEqual( address_to_script( 'mona1qp8f842ywwr9h5rdxyzggex7q3trvvvaarfssxccju52rj6htfzfsqr79j2' ), '002009d27aa88e70cb7a0da620908c9bc08ac6c633bd1a61036312e514396aeb4893' ) self.assertEqual(address_to_script('mona1sw50qpvnxy8'), '6002751e') self.assertEqual( address_to_script('mona1zw508d6qejxtdg4y5r3zarvaryvhm3vz7'), '5210751e76e8199196d454941c45d1b3a323') # base58 P2PKH self.assertEqual( address_to_script('MFMy9FwJsV6HiN5eZDqDETw4pw52q3UGrb'), '76a91451dadacc7021440cbe4ca148a5db563b329b4c0388ac') self.assertEqual( address_to_script('MVELZC3ks1Xk59kvKWuSN3mpByNwaxeaBJ'), '76a914e9fb298e72e29ebc2b89864a5e4ae10e0b84726088ac') # base58 P2SH self.assertEqual( address_to_script('PHjTKtgYLTJ9D2Bzw2f6xBB41KBm2HeGfg'), 'a9146449f568c9cd2378138f2636e1567112a184a9e887') self.assertEqual( address_to_script('3AqJ6Tn8qS8LKMDfi41AhuZiY6JbR6mt6E'), 'a9146449f568c9cd2378138f2636e1567112a184a9e887')
def parse_output(self, x) -> bytes: try: address = self.parse_address(x) return bfh(ravencoin.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.")
def test_address_to_script(self): # bech32 native segwit # test vectors from BIP-0173 self.assertEqual( address_to_script( 'tmona1qfj8lu0rafk2mpvk7jj62q8eerjpex3xlcadtupkrkhh5a73htmhs68e55m' ), '00204c8ffe3c7d4d95b0b2de94b4a01f391c839344dfc75abe06c3b5ef4efa375eef' ) self.assertEqual( address_to_script( 'tmona1q0p29rfu7ap3duzqj5t9e0jzgqzwdtd97pa5rhuz4r38t5a6dknyqxmyyaz' ), '0020785451a79ee862de0812a2cb97c848009cd5b4be0f683bf0551c4eba774db4c8' ) # base58 P2PKH self.assertEqual( address_to_script('mptvgSbAs4iwxQ7JQZdEN6Urpt3dtjbawd'), '76a91466e0ef980c8ff8129e8d0f716b2ce1df2f97bbbf88ac') self.assertEqual( address_to_script('mrodaP7iH3B9ZXSptfGQXLKE3hfdjMdf7y'), '76a9147bd0d45ec256701811ebb38cfd2ba3d17576bf3e88ac') # base58 P2SH self.assertEqual( address_to_script('pJwLxfRRUhAaYJsKzKCk9cATAn8Do2SS7L'), 'a91492e825fa92f4aa873c6caf4b20f6c7e949b456a987') self.assertEqual( address_to_script('pHNnBm6ECsh5QsUyXMzdoAXV8qV68wj2M4'), 'a91481c75a711f23443b44d70b10ddf856e39a6b254d87')
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 = ravencoin.script_to_address(ravencoin.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"))
def get_outputs(self, is_max): if self.payto_address: if is_max: amount = '!' else: amount = self.amount_edit.get_amount() _type, addr = self.payto_address script = ravencoin.address_to_script(addr) self.outputs = [TxOutput(_type, addr, amount, False, '', script)] return self.outputs[:]
def _change_outputs(self, tx, change_addrs, fee_estimator_numchange, dust_threshold): amounts = self._change_amounts(tx, len(change_addrs), fee_estimator_numchange) assert min(amounts) >= 0 assert len(change_addrs) >= len(amounts) assert all([isinstance(amt, int) for amt in amounts]) # If change is above dust threshold after accounting for the # size of the change output, add it to the transaction. amounts = [amount for amount in amounts if amount >= dust_threshold] change = [ TxOutput(TYPE_ADDRESS, addr, amount, False, '', ravencoin.address_to_script(addr)) for addr, amount in zip(change_addrs, amounts) ] return change
from electrum.transaction import Transaction from electrum import paymentrequest from electrum import paymentrequest_pb2 as pb2 from electrum.ravencoin 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)