Exemplo n.º 1
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.hash = PublicKey.unhexlify(
         "02c08786d63f78bd0a6777ffe9c978cf5899756cfc32bfad09a89e211aeb926242"
     ).hash()
     self.locked_script = P2shScript(
         P2pkhScript(
             PublicKey.unhexlify(
                 "02c08786d63f78bd0a6777ffe9c978cf5899756cfc32bf"
                 "ad09a89e211aeb926242")))
Exemplo n.º 2
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.inner_script = MultisigScript(
         2,
         PublicKey.unhexlify(
             "02c08786d63f78bd0a6777ffe9c978cf5899756cfc32bfad09a89e2"
             "11aeb926242"),
         PublicKey.unhexlify(
             "033e81519ecf373ea3a5c7e1c051b71a898fb3438c9550e274d980f"
             "147eb4d069d"),
         PublicKey.unhexlify(
             "036d568125a969dc78b963b494fa7ed5f20ee9c2f2fc2c57f86c5df"
             "63089f2ed3a"), 3)
Exemplo n.º 3
0
    def test(self):
        for data in priv_pub_hash_addr_p2pkh_segwit:
            priv = PrivateKey.from_wif(data['privkey'])
            pub = PublicKey.unhexlify(data['pubkey'])
            pubhash = bytearray(unhexlify(data['pubkeyhash']))
            address = Address.from_string(data['address'], check_network=False)
            p2pkhhex = data['scriptpubkey']
            segwit_addr = data['segwit']

            self.assertEqual(priv.pub(), pub)
            self.assertEqual(pub.hash(), pubhash)
            self.assertEqual(address.hash, pubhash)
            self.assertEqual(P2pkhScript(pub).hexlify(), p2pkhhex)
            self.assertEqual(P2pkhScript(address).hexlify(), p2pkhhex)
            self.assertEqual(P2pkhScript(pubhash).hexlify(), p2pkhhex)
            self.assertEqual(str(P2shScript(P2wpkhV0Script(pub)).address()),
                             segwit_addr)
            self.assertEqual(
                str(P2shScript(P2wpkhV0Script(pubhash)).address()),
                segwit_addr)
            self.assertEqual(
                P2shScript(P2wpkhV0Script(pub)).scripthash,
                Address.from_string(segwit_addr).hash)
            self.assertEqual(
                P2shScript(P2wpkhV0Script(pubhash)).scripthash,
                Address.from_string(segwit_addr).hash)
Exemplo n.º 4
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.redeem_script = P2pkhScript(
            PublicKey.unhexlify('0384478d41e71dc6c3f9edde0f928a47d1b724c'
                                '05984ebfb4e7d0422e80abe95ff'))
        self.as_data = StackData.from_bytes(self.redeem_script.p2sh_hash())
        self.address = self.redeem_script.to_address()
Exemplo n.º 5
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.pubk = PublicKey.unhexlify(
         '0384478d41e71dc6c3f9edde0f928a47d1b724c05984ebfb4e7d0422e80abe95ff'
     )
     self.pubkh = self.pubk.hash()
     self.address = Address.from_string(
         'mquvJWnJJwTDUcdneQkUbrfN2wm9uiXd1p')
Exemplo n.º 6
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.m = 2
     self.pubkeys = [
         PublicKey.unhexlify(
             "02c08786d63f78bd0a6777ffe9c978cf5899756cfc32bfad09a89e211aeb926242"
         ),
         PublicKey.unhexlify(
             "033e81519ecf373ea3a5c7e1c051b71a898fb3438c9550e274d980f147eb4d069d"
         ),
         PublicKey.unhexlify(
             "036d568125a969dc78b963b494fa7ed5f20ee9c2f2fc2c57f86c5df63089f2ed3a"
         )
     ]
     self.n = 3
     self.hex_template = '{:02x}{}{:02x}ae'.format(
         self.m + 80, ''.join('{:02x}{}'.format(len(pk), pk)
                              for pk in self.pubkeys), self.n + 80)
Exemplo n.º 7
0
 def test_script_pubkey_fail(self):
     # nonstandard types
     self.assertFalse(
         eval(scripts['if_else_timelock']['code']).is_standard())
     self.assertFalse(
         eval(scripts['relativetimelock']['code']).is_standard())
     # n > 3
     self.assertFalse(
         MultisigScript(
             2,
             PublicKey.unhexlify(
                 "02c08786d63f78bd0a6777ffe9c978cf5899756cfc32bfad09a89e211aeb926242"
             ),
             PublicKey.unhexlify(
                 "033e81519ecf373ea3a5c7e1c051b71a898fb3438c9550e274d980f147eb4d069d"
             ),
             PublicKey.unhexlify(
                 "036d568125a969dc78b963b494fa7ed5f20ee9c2f2fc2c57f86c5df63089f2ed3a"
             ),
             PublicKey.unhexlify(
                 "036d568125a969dc78b963b494fa7ed5f20ee9c2f2fc2c57f86c5df63089f2ed3a"
             ), 4).is_standard())
     # m > n
     self.assertFalse(
         MultisigScript(
             4,
             PublicKey.unhexlify(
                 "02c08786d63f78bd0a6777ffe9c978cf5899756cfc32bfad09a89e211aeb926242"
             ),
             PublicKey.unhexlify(
                 "033e81519ecf373ea3a5c7e1c051b71a898fb3438c9550e274d980f147eb4d069d"
             ),
             PublicKey.unhexlify(
                 "036d568125a969dc78b963b494fa7ed5f20ee9c2f2fc2c57f86c5df63089f2ed3a"
             ), 3).is_standard())
     # >80-byte data
     self.assertFalse(
         NulldataScript(
             StackData.unhexlify(
                 '444f4350524f4f463832bd18ceb0a7861f2a8198013047a3fb861261523c0fc4164abc044e517702444f4350524f4f463832bd18ce'
                 'b0a7861f2a8198013047a3fb861261523c0fc4164abc044e51770211')
         ).is_standard())
Exemplo n.º 8
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.pubk = PublicKey.unhexlify(
         '0384478d41e71dc6c3f9edde0f928a47d1b724c05984ebfb4e7d0422e80abe95ff'
     )
     self.pubkh = self.pubk.hash()
Exemplo n.º 9
0
 def test_success(self):
     script = P2pkScript(PublicKey.unhexlify(self.pubk))
     self.assertTrue(
         script.decompile() == '{} OP_CHECKSIG'.format(self.pubk))
     self.assertTrue(script.hexlify() == '21{}ac'.format(self.pubk))
Exemplo n.º 10
0
 def test_address_generation(self):
     pubk = PublicKey.unhexlify(self.uncompressed)
     self.assertTrue(str(pubk.to_address(True)) == self.address)
Exemplo n.º 11
0
 def test_uncompression(self):
     pubk = PublicKey.unhexlify(self.compressed)
     self.assertTrue(
         hexlify(pubk.uncompressed).decode() == self.uncompressed)