当前位置: 首页>>代码示例>>Python>>正文


Python core.x方法代码示例

本文整理汇总了Python中bitcoin.core.x方法的典型用法代码示例。如果您正苦于以下问题:Python core.x方法的具体用法?Python core.x怎么用?Python core.x使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在bitcoin.core的用法示例。


在下文中一共展示了core.x方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_from_invalid_pubkeys

# 需要导入模块: from bitcoin import core [as 别名]
# 或者: from bitcoin.core import x [as 别名]
def test_from_invalid_pubkeys(self):
        """Create P2PKHBitcoinAddress's from invalid pubkeys"""

        # first test with accept_invalid=True
        def T(invalid_pubkey, expected_str_addr):
            addr = P2PKHBitcoinAddress.from_pubkey(invalid_pubkey, accept_invalid=True)
            self.assertEqual(str(addr), expected_str_addr)

        T(x(''),
          '1HT7xU2Ngenf7D4yocz2SAcnNLW7rK8d4E')
        T(x('0378d430274f8c5ec1321338151e9f27f4c676a008bdf8638d07c0b6be9ab35c72'),
          '1L9V4NXbNtZsLjrD3nkU7gtEYLWRBWXLiZ')

        # With accept_invalid=False we should get CBitcoinAddressError's
        with self.assertRaises(CBitcoinAddressError):
            P2PKHBitcoinAddress.from_pubkey(x(''))
        with self.assertRaises(CBitcoinAddressError):
            P2PKHBitcoinAddress.from_pubkey(x('0378d430274f8c5ec1321338151e9f27f4c676a008bdf8638d07c0b6be9ab35c72'))
        with self.assertRaises(CBitcoinAddressError):
            P2PKHBitcoinAddress.from_pubkey(CPubKey(x('0378d430274f8c5ec1321338151e9f27f4c676a008bdf8638d07c0b6be9ab35c72'))) 
开发者ID:petertodd,项目名称:checklocktimeverify-demos,代码行数:22,代码来源:test_wallet.py

示例2: coerce_item

# 需要导入模块: from bitcoin import core [as 别名]
# 或者: from bitcoin.core import x [as 别名]
def coerce_item(cls, data):
        # Coerce binary string.
        def coerce_string(v):
            return Transaction.deserialize(v)

        # Coerce hex string.
        def coerce_hex_string(v):
            return Transaction.deserialize(x(v))

        # Coerce transaction instance.
        def coerce_tx(v):
            return Transaction.from_tx(v)

        for i in [coerce_string, coerce_hex_string, coerce_tx]:
            try:
                value = i(data)
            except Exception:
                continue
            else:
                if value:
                    return cls(value) 
开发者ID:mazaclub,项目名称:hashmal,代码行数:23,代码来源:item_types.py

示例3: test_pushdata

# 需要导入模块: from bitcoin import core [as 别名]
# 或者: from bitcoin.core import x [as 别名]
def test_pushdata(self):
        def T(data, expected):
            data = x(data)
            expected = x(expected)
            serialized_data = CScriptOp.encode_op_pushdata(data)
            self.assertEqual(serialized_data, expected)

        T('', '00')
        T('00', '0100')
        T('0011223344556677', '080011223344556677')
        T('ff'*0x4b, '4b' + 'ff'*0x4b)
        T('ff'*0x4c, '4c4c' + 'ff'*0x4c)
        T('ff'*0x4c, '4c4c' + 'ff'*0x4c)
        T('ff'*0xff, '4cff' + 'ff'*0xff)
        T('ff'*0x100, '4d0001' + 'ff'*0x100)
        T('ff'*0xffff, '4dffff' + 'ff'*0xffff)
        T('ff'*0x10000, '4e00000100' + 'ff'*0x10000) 
开发者ID:petertodd,项目名称:checklocktimeverify-demos,代码行数:19,代码来源:test_script.py

示例4: test_invalid_scripts

# 需要导入模块: from bitcoin import core [as 别名]
# 或者: from bitcoin.core import x [as 别名]
def test_invalid_scripts(self):
        def T(serialized):
            with self.assertRaises(CScriptInvalidError):
                list(CScript(x(serialized)))

        T('01')
        T('02')
        T('0201')
        T('4b')
        T('4b' + 'ff'*0x4a)
        T('4c')
        T('4cff' + 'ff'*0xfe)
        T('4d')
        T('4dff')
        T('4dffff' + 'ff'*0xfffe)
        T('4e')
        T('4effffff')
        T('4effffffff' + 'ff'*0xfffe) # not going to test with 4GiB-1... 
开发者ID:petertodd,项目名称:checklocktimeverify-demos,代码行数:20,代码来源:test_script.py

示例5: test_equality

# 需要导入模块: from bitcoin import core [as 别名]
# 或者: from bitcoin.core import x [as 别名]
def test_equality(self):
        # Equality is on the serialized script, not the logical meaning.
        # This is important for P2SH.
        def T(serialized1, serialized2, are_equal):
            script1 = CScript(x(serialized1))
            script2 = CScript(x(serialized2))
            if are_equal:
                self.assertEqual(script1, script2)
            else:
                self.assertNotEqual(script1, script2)

        T('', '', True)
        T('', '00', False)
        T('00', '00', True)
        T('00', '01', False)
        T('01ff', '01ff', True)
        T('fc01ff', '01ff', False)

        # testing equality on an invalid script is legal, and evaluates based
        # on the serialization
        T('4e', '4e', True)
        T('4e', '4e00', False) 
开发者ID:petertodd,项目名称:checklocktimeverify-demos,代码行数:24,代码来源:test_script.py

示例6: test_is_push_only_on_invalid_pushdata

# 需要导入模块: from bitcoin import core [as 别名]
# 或者: from bitcoin.core import x [as 别名]
def test_is_push_only_on_invalid_pushdata(self):
        def T(hex_script):
            invalid_script = CScript(x(hex_script))
            self.assertFalse(invalid_script.is_push_only())

        T('01')
        T('02ff')
        T('4b')
        T('4c01')
        T('4c02ff')
        T('4d')
        T('4d0100')
        T('4d0200ff')
        T('4e')
        T('4e01000000')
        T('4e02000000ff') 
开发者ID:petertodd,项目名称:checklocktimeverify-demos,代码行数:18,代码来源:test_script.py

示例7: test_has_canonical_pushes_with_invalid_truncated_script

# 需要导入模块: from bitcoin import core [as 别名]
# 或者: from bitcoin.core import x [as 别名]
def test_has_canonical_pushes_with_invalid_truncated_script(self):
        def T(hex_script):
            script = CScript(x(hex_script))
            self.assertEqual(script.has_canonical_pushes(), False)

        T('01')
        T('02ff')
        T('4b')
        T('4c01')
        T('4c02ff')
        T('4d')
        T('4d0100')
        T('4d0200ff')
        T('4e')
        T('4e01000000')
        T('4e02000000ff') 
开发者ID:petertodd,项目名称:checklocktimeverify-demos,代码行数:18,代码来源:test_script.py

示例8: test_to_p2sh_scriptPubKey

# 需要导入模块: from bitcoin import core [as 别名]
# 或者: from bitcoin.core import x [as 别名]
def test_to_p2sh_scriptPubKey(self):
        def T(redeemScript, expected_hex_bytes):
            redeemScript = CScript(redeemScript)
            actual_script = redeemScript.to_p2sh_scriptPubKey()
            self.assertEqual(b2x(actual_script), expected_hex_bytes)

        T([],
          'a914b472a266d0bd89c13706a4132ccfb16f7c3b9fcb87')

        T([1,x('029b6d2c97b8b7c718c325d7be3ac30f7c9d67651bce0c929f55ee77ce58efcf84'),1,OP_CHECKMULTISIG],
          'a91419a7d869032368fd1f1e26e5e73a4ad0e474960e87')

        T([b'\xff'*517],
          'a9140da7fa40ebf248dfbca363c79921bdd665fed5ba87')

        with self.assertRaises(ValueError):
            CScript([b'a' * 518]).to_p2sh_scriptPubKey() 
开发者ID:petertodd,项目名称:checklocktimeverify-demos,代码行数:19,代码来源:test_script.py

示例9: test

# 需要导入模块: from bitcoin import core [as 别名]
# 或者: from bitcoin.core import x [as 别名]
def test(self):
        def T(expected, seed, data):
            self.assertEqual(MurmurHash3(seed, x(data)), expected)

        T(0x00000000, 0x00000000, "")
        T(0x6a396f08, 0xFBA4C795, "")
        T(0x81f16f39, 0xffffffff, "")

        T(0x514e28b7, 0x00000000, "00")
        T(0xea3f0b17, 0xFBA4C795, "00")
        T(0xfd6cf10d, 0x00000000, "ff")

        T(0x16c6b7ab, 0x00000000, "0011")
        T(0x8eb51c3d, 0x00000000, "001122")
        T(0xb4471bf8, 0x00000000, "00112233")
        T(0xe2301fa8, 0x00000000, "0011223344")
        T(0xfc2e4a15, 0x00000000, "001122334455")
        T(0xb074502c, 0x00000000, "00112233445566")
        T(0x8034d2a0, 0x00000000, "0011223344556677")
        T(0xb4698def, 0x00000000, "001122334455667788") 
开发者ID:petertodd,项目名称:checklocktimeverify-demos,代码行数:22,代码来源:test_bloom.py

示例10: test_create_insert_serialize

# 需要导入模块: from bitcoin import core [as 别名]
# 或者: from bitcoin.core import x [as 别名]
def test_create_insert_serialize(self):
        filter = CBloomFilter(3, 0.01, 0, CBloomFilter.UPDATE_ALL)

        def T(elem):
            """Filter contains elem"""
            elem = x(elem)
            filter.insert(elem)
            self.assertTrue(filter.contains(elem))

        def F(elem):
            """Filter does not contain elem"""
            elem = x(elem)
            self.assertFalse(filter.contains(elem))

        T('99108ad8ed9bb6274d3980bab5a85c048f0950c8')
        F('19108ad8ed9bb6274d3980bab5a85c048f0950c8')
        T('b5a2c786d9ef4658287ced5914b37a1b4aa32eee')
        T('b9300670b4c5366e95b2699e8b18bc75e5f729c5')

        self.assertEqual(filter.serialize(), x('03614e9b050000000000000001')) 
开发者ID:petertodd,项目名称:checklocktimeverify-demos,代码行数:22,代码来源:test_bloom.py

示例11: test

# 需要导入模块: from bitcoin import core [as 别名]
# 或者: from bitcoin.core import x [as 别名]
def test(self):
        def T(hex_pubkey, is_valid, is_fullyvalid, is_compressed):
            key = CPubKey(x(hex_pubkey))
            self.assertEqual(key.is_valid, is_valid)
            self.assertEqual(key.is_fullyvalid, is_fullyvalid)
            self.assertEqual(key.is_compressed, is_compressed)

        T('', False, False, False)
        T('00', True, True, False) # why is this valid?
        T('01', True, False, False)
        T('02', True, False, False)

        T('0378d430274f8c5ec1321338151e9f27f4c676a008bdf8638d07c0b6be9ab35c71',
          True, True, True)
        T('0478d430274f8c5ec1321338151e9f27f4c676a008bdf8638d07c0b6be9ab35c71',
          True, False, True)

        T('0378d430274f8c5ec1321338151e9f27f4c676a008bdf8638d07c0b6be9ab35c71',
          True, True, True)

        T('0478d430274f8c5ec1321338151e9f27f4c676a008bdf8638d07c0b6be9ab35c71a1518063243acd4dfe96b66e3f2ec8013c8e072cd09b3834a19f81f659cc3455',
          True, True, False) 
开发者ID:petertodd,项目名称:checklocktimeverify-demos,代码行数:24,代码来源:test_key.py

示例12: test_create_from_string

# 需要导入模块: from bitcoin import core [as 别名]
# 或者: from bitcoin.core import x [as 别名]
def test_create_from_string(self):
        """Create CBitcoinAddress's from strings"""

        def T(str_addr, expected_bytes, expected_nVersion, expected_class):
            addr = CBitcoinAddress(str_addr)
            self.assertEqual(addr.to_bytes(), expected_bytes)
            self.assertEqual(addr.nVersion, expected_nVersion)
            self.assertEqual(addr.__class__, expected_class)

        T('1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa',
          x('62e907b15cbf27d5425399ebf6f0fb50ebb88f18'), 0,
          P2PKHBitcoinAddress)

        T('37k7toV1Nv4DfmQbmZ8KuZDQCYK9x5KpzP',
          x('4266fc6f2c2861d7fe229b279a79803afca7ba34'), 5,
          P2SHBitcoinAddress) 
开发者ID:petertodd,项目名称:checklocktimeverify-demos,代码行数:18,代码来源:test_wallet.py

示例13: test_from_non_canonical_scriptPubKey

# 需要导入模块: from bitcoin import core [as 别名]
# 或者: from bitcoin.core import x [as 别名]
def test_from_non_canonical_scriptPubKey(self):
        def T(hex_scriptpubkey, expected_str_address):
            scriptPubKey = CScript(x(hex_scriptpubkey))
            addr = P2PKHBitcoinAddress.from_scriptPubKey(scriptPubKey)
            self.assertEqual(str(addr), expected_str_address)

            # now test that CBitcoinAddressError is raised with accept_non_canonical_pushdata=False
            with self.assertRaises(CBitcoinAddressError):
                P2PKHBitcoinAddress.from_scriptPubKey(scriptPubKey, accept_non_canonical_pushdata=False)

        T('76a94c14000000000000000000000000000000000000000088ac', '1111111111111111111114oLvT2')
        T('76a94d1400000000000000000000000000000000000000000088ac', '1111111111111111111114oLvT2'),
        T('76a94e14000000000000000000000000000000000000000000000088ac', '1111111111111111111114oLvT2')

        # make sure invalid scripts raise CBitcoinAddressError
        with self.assertRaises(CBitcoinAddressError):
            P2PKHBitcoinAddress.from_scriptPubKey(x('76a94c14')) 
开发者ID:petertodd,项目名称:checklocktimeverify-demos,代码行数:19,代码来源:test_wallet.py

示例14: test_from_bare_checksig_scriptPubKey

# 需要导入模块: from bitcoin import core [as 别名]
# 或者: from bitcoin.core import x [as 别名]
def test_from_bare_checksig_scriptPubKey(self):
        def T(hex_scriptpubkey, expected_str_address):
            scriptPubKey = CScript(x(hex_scriptpubkey))
            addr = P2PKHBitcoinAddress.from_scriptPubKey(scriptPubKey)
            self.assertEqual(str(addr), expected_str_address)

            # now test that CBitcoinAddressError is raised with accept_non_canonical_pushdata=False
            with self.assertRaises(CBitcoinAddressError):
                P2PKHBitcoinAddress.from_scriptPubKey(scriptPubKey, accept_bare_checksig=False)

        # compressed
        T('21000000000000000000000000000000000000000000000000000000000000000000ac', '14p5cGy5DZmtNMQwTQiytBvxMVuTmFMSyU')

        # uncompressed
        T('410000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ac', '1QLFaVVt99p1y18zWSZnespzhkFxjwBbdP')

        # non-canonical encoding
        T('4c21000000000000000000000000000000000000000000000000000000000000000000ac', '14p5cGy5DZmtNMQwTQiytBvxMVuTmFMSyU')

        # odd-lengths are *not* accepted
        with self.assertRaises(CBitcoinAddressError):
            P2PKHBitcoinAddress.from_scriptPubKey(x('2200000000000000000000000000000000000000000000000000000000000000000000ac')) 
开发者ID:petertodd,项目名称:checklocktimeverify-demos,代码行数:24,代码来源:test_wallet.py

示例15: test_from_valid_pubkey

# 需要导入模块: from bitcoin import core [as 别名]
# 或者: from bitcoin.core import x [as 别名]
def test_from_valid_pubkey(self):
        """Create P2PKHBitcoinAddress's from valid pubkeys"""

        def T(pubkey, expected_str_addr):
            addr = P2PKHBitcoinAddress.from_pubkey(pubkey)
            self.assertEqual(str(addr), expected_str_addr)

        T(x('0378d430274f8c5ec1321338151e9f27f4c676a008bdf8638d07c0b6be9ab35c71'),
          '1C7zdTfnkzmr13HfA2vNm5SJYRK6nEKyq8')
        T(x('0478d430274f8c5ec1321338151e9f27f4c676a008bdf8638d07c0b6be9ab35c71a1518063243acd4dfe96b66e3f2ec8013c8e072cd09b3834a19f81f659cc3455'),
          '1JwSSubhmg6iPtRjtyqhUYYH7bZg3Lfy1T')

        T(CPubKey(x('0378d430274f8c5ec1321338151e9f27f4c676a008bdf8638d07c0b6be9ab35c71')),
          '1C7zdTfnkzmr13HfA2vNm5SJYRK6nEKyq8')
        T(CPubKey(x('0478d430274f8c5ec1321338151e9f27f4c676a008bdf8638d07c0b6be9ab35c71a1518063243acd4dfe96b66e3f2ec8013c8e072cd09b3834a19f81f659cc3455')),
          '1JwSSubhmg6iPtRjtyqhUYYH7bZg3Lfy1T') 
开发者ID:petertodd,项目名称:checklocktimeverify-demos,代码行数:18,代码来源:test_wallet.py


注:本文中的bitcoin.core.x方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。