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


Python hexbytes.h2b函数代码示例

本文整理汇总了Python中pycoin.encoding.hexbytes.h2b函数的典型用法代码示例。如果您正苦于以下问题:Python h2b函数的具体用法?Python h2b怎么用?Python h2b使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: check_bip143_tx

 def check_bip143_tx(
         self, tx_u_hex, tx_s_hex, txs_out_value_scripthex_pair, tx_in_count, tx_out_count, version, lock_time):
     tx_u = Tx.from_hex(tx_u_hex)
     tx_s = Tx.from_hex(tx_s_hex)
     txs_out = [
         TxOut(int(coin_value * 1e8), h2b(script_hex)) for coin_value, script_hex in txs_out_value_scripthex_pair
     ]
     for tx in (tx_u, tx_s):
         self.assertEqual(len(tx.txs_in), tx_in_count)
         self.assertEqual(len(tx.txs_out), tx_out_count)
         self.assertEqual(tx.version, version)
         self.assertEqual(tx.lock_time, lock_time)
         tx.set_unspents(txs_out)
     self.check_unsigned(tx_u)
     self.check_signed(tx_s)
     tx_hex = tx_u.as_hex()
     self.assertEqual(tx_hex, tx_u_hex)
     tx_hex = tx_s.as_hex()
     self.assertEqual(tx_hex, tx_s_hex)
     tx_u_prime = self.unsigned_copy(tx_s)
     tx_hex = tx_u_prime.as_hex()
     self.assertEqual(tx_hex, tx_u_hex)
     self.assertEqual(b2h_rev(double_sha256(h2b(tx_s_hex))), tx_s.w_id())
     self.assertEqual(b2h_rev(double_sha256(h2b(tx_u_hex))), tx_u.w_id())
     self.assertEqual(b2h_rev(double_sha256(h2b(tx_u_hex))), tx_u.id())
     return tx_u, tx_s
开发者ID:alanxu89,项目名称:pycoin,代码行数:26,代码来源:segwit_test.py

示例2: tx_from_json_dict

def tx_from_json_dict(r):
    version = r.get("version")
    lock_time = r.get("locktime")
    txs_in = []
    for vin in r.get("vin"):
        if "coinbase" in vin:
            previous_hash = b'\0' * 32
            script = h2b(vin.get("coinbase"))
            previous_index = 4294967295
        else:
            previous_hash = h2b_rev(vin.get("txid"))
            scriptSig = vin.get("scriptSig")
            if "hex" in scriptSig:
                script = h2b(scriptSig.get("hex"))
            else:
                script = BitcoinScriptTools.compile(scriptSig.get("asm"))
            previous_index = vin.get("vout")
        sequence = vin.get("sequence")
        txs_in.append(Tx.TxIn(previous_hash, previous_index, script, sequence))
    txs_out = []
    for vout in r.get("vout"):
        coin_value = btc_to_satoshi(decimal.Decimal(vout.get("value")))
        script = BitcoinScriptTools.compile(vout.get("scriptPubKey").get("asm"))
        txs_out.append(Tx.TxOut(coin_value, script))
    tx = Tx(version, txs_in, txs_out, lock_time)
    bh = r.get("blockhash")
    if bh:
        bh = h2b_rev(bh)
    tx.confirmation_block_hash = bh
    return tx
开发者ID:alanxu89,项目名称:pycoin,代码行数:30,代码来源:insight.py

示例3: parse_scripts

def parse_scripts(args, keychain):
    warnings = []

    for p2s in args.pay_to_script or []:
        try:
            keychain.add_p2s_script(h2b(p2s))
        except Exception:
            warnings.append("warning: error parsing pay-to-script value %s" % p2s)

    hex_re = re.compile(r"[0-9a-fA-F]+")
    for f in args.pay_to_script_file or []:
        count = 0
        for l in f:
            try:
                m = hex_re.search(l)
                if m:
                    p2s = m.group(0)
                    keychain.add_p2s_script(h2b(p2s))
                    count += 1
            except Exception:
                warnings.append("warning: error parsing pay-to-script file %s" % f.name)
        if count == 0:
            warnings.append("warning: no scripts found in %s" % f.name)
    keychain.commit()
    return warnings
开发者ID:richardkiss,项目名称:pycoin,代码行数:25,代码来源:tx.py

示例4: test_hash160

    def test_hash160(self):
        def do_test(blob, expected_hash):
            self.assertEqual(hash160(blob), expected_hash)

        do_test(b"This is a test", h2b("18ac98fa2a2412ddb75de60459b52acd98f2d972"))
        do_test(b"The quick brown fox jumps over the lazy dogs",
                h2b("76c9d1f3aa5226554e20475f919aadd174f7e9b7"))
        do_test(b'\x74' * 10000, h2b("a961070296677401a57eae0d96d14d5a880a2c41"))
开发者ID:alanxu89,项目名称:pycoin,代码行数:8,代码来源:encoding_test.py

示例5: test_p2sh

    def test_p2sh(self):
        def do_test(h160, redeem_script, address):
            self.assertEqual(GroestlcoinMainnet.contract.for_p2sh(h160), redeem_script)
            self.assertEqual(GroestlcoinMainnet.address.for_p2sh(h160), address)
            self.assertEqual(GroestlcoinMainnet.parse.p2sh(address).address(), address)

        do_test(
            h2b('2a84cf00d47f699ee7bbc1dea5ec1bdecb4ac154'),
            h2b('a9142a84cf00d47f699ee7bbc1dea5ec1bdecb4ac15487'), '35ZqQJcBQMZ1rsv8aSuJ2wkC7ohUFNJZ77')
开发者ID:richardkiss,项目名称:pycoin,代码行数:9,代码来源:grs_encoding_test.py

示例6: test_to_from_long

    def test_to_from_long(self):
        def do_test(as_int, prefix, as_rep, base):
            self.assertEqual((as_int, prefix), to_long(base, lambda v: v, iterbytes(as_rep)))
            self.assertEqual(as_rep, from_long(as_int, prefix, base, lambda v: v))

        do_test(10000101, 2, h2b("00009896e5"), 256)
        do_test(10000101, 3, h2b("0000009896e5"), 256)
        do_test(1460765565493402645157733592332121663123460211377, 1,
                h2b("00ffdefe4f4875cf119fc3d8f4a09ae37ec4cc42b1"), 256)
开发者ID:alanxu89,项目名称:pycoin,代码行数:9,代码来源:encoding_test.py

示例7: test_double_sha256

    def test_double_sha256(self):
        def do_test(blob, expected_hash):
            self.assertEqual(double_sha256(blob), expected_hash)

        do_test(b"This is a test",
                h2b("eac649d431aa3fc2d5749d1a5021bba7812ec83b8a59fa840bff75c17f8a665c"))
        do_test(b"The quick brown fox jumps over the lazy dogs",
                h2b("8a356588797a901a11031779d4787ad0457eb082c56bd9b657157acf31bae6c4"))
        do_test(b'\x74' * 10000,
                h2b("6e4d7736aa373c4718eef2b94528fed57519a0bdc3a8f4300aee372cbedea9a0"))
开发者ID:alanxu89,项目名称:pycoin,代码行数:10,代码来源:encoding_test.py

示例8: tx

def tx(args, parser):
    (network, txs, spendables, payables, keychain, tx_db, warning_spendables) = parse_context(args, parser)

    for tx in txs:
        if tx.missing_unspents() and (args.augment or tx_db):
            if tx_db is None:
                tx_db = create_tx_db(network)
            tx.unspents_from_db(tx_db, ignore_missing=True)

    # build p2sh_lookup
    warnings = parse_scripts(args, keychain)
    for w in warnings:
        print(w)

    tx = generate_tx(network, txs, spendables, payables, args)

    signature_hints = [h2b(sig) for sig in (args.signature or [])]
    sec_hints = network.tx.solve.build_sec_lookup([h2b(sec) for sec in (args.sec or [])])

    is_fully_signed = do_signing(tx, keychain, keychain, sec_hints, signature_hints, network)

    include_unspents = not is_fully_signed

    if args.dump_signatures or args.dump_secs:
        if args.dump_signatures:
            dump_signatures_hex(tx, network)

        if args.dump_secs:
            dump_secs_hex(tx, network)

        return

    print_output(tx, include_unspents, args.output_file, args.show_unspents, network,
                 args.verbose_signature, args.disassemble, args.trace, args.pdb)

    tx_db = cache_result(tx, tx_db, args.cache, network)

    tx_db = validate_against_bitcoind(tx, tx_db, args.network, args.bitcoind_url)

    if args.dump_inputs:
        dump_inputs(tx, network)

    if not args.show_unspents:
        tx_db = validate_tx(tx, tx_db, network)

    # print warnings
    if tx_db:
        for m in [tx_db.warning_tx_cache, tx_db.warning_tx_for_tx_hash]:
            if m:
                print("warning: %s" % m, file=sys.stderr)
    if warning_spendables:
        print("warning: %s" % warning_spendables, file=sys.stderr)
开发者ID:richardkiss,项目名称:pycoin,代码行数:52,代码来源:tx.py

示例9: test_wif

    def test_wif(self):
        def do_test(sec_bytes, wif, address):
            parsed = GroestlcoinMainnet.parse.wif(wif)
            self.assertEqual(to_bytes_32(parsed.secret_exponent()), sec_bytes)
            self.assertEqual(parsed.wif(), wif)
            self.assertEqual(parsed.address(), address)

        do_test(
            h2b('0000000000000000000000000000000000000000000000000000000000000001'),
            '5HpHagT65TZzG1PH3CSu63k8DbpvD8s5ip4nEB3kEsreAmVmAPb', 'FiT6218RsUiTMyG5DA8bDjrNNuofYV2MdF')
        do_test(
            h2b('0000000000000000000000000000000000000000000000000000000000000001'),
            'KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFU73sX6ptSt', 'Ffqz14cyvZYJavD76t6oHNDJnGiWcZMVxR')
开发者ID:richardkiss,项目名称:pycoin,代码行数:13,代码来源:grs_encoding_test.py

示例10: test_to_from_base58

    def test_to_from_base58(self):
        def do_test(as_text, as_bin):
            self.assertEqual(as_bin, a2b_base58(as_text))
            self.assertEqual(as_text, b2a_base58(as_bin))

        do_test("1abcdefghijkmnpqrst", h2b("0001935c7cf22ab9be1962aee48c7b"))
        do_test("1CASrvcpMMTa4dz4DmYtAqcegCtdkhjvdn",
                h2b("007a72b6fa63de36c4abc60a68b52d7f33e3d7cd3ec4babd39"))
        do_test("1111111111111111aaaa11aa",
                h2b("00000000000000000000000000000000436e7a51290b"))
        do_test("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",
                h2b("000111d38e5fc9071ffcd20b4a763cc9ae4f252bb4e48fd66a835e252ada93ff480d6d"
                    "d43dc62a641155a5"))
开发者ID:alanxu89,项目名称:pycoin,代码行数:13,代码来源:encoding_test.py

示例11: test_to_from_hashed_base58

    def test_to_from_hashed_base58(self):
        def do_test(as_text, as_bin):
            self.assertEqual(as_text, b2a_hashed_base58(as_bin))
            self.assertEqual(as_bin, a2b_hashed_base58(as_text))
            self.assertTrue(is_hashed_base58_valid(as_text))
            bogus_text = as_text[:-1] + chr(1+ord(as_text[-1]))
            self.assertFalse(is_hashed_base58_valid(bogus_text))

        do_test("14nr3dMd4VwNpFhFECU1A6imi", h2b("0001935c7cf22ab9be1962aee48c7b"))
        do_test("1CASrvcpMMTa4dz4DmYtAqcegCtdkhjvdn", h2b("007a72b6fa63de36c4abc60a68b52d7f33e3d7cd3e"))
        do_test("11111111111111114njGbaozZJui9o",
                h2b("00000000000000000000000000000000436e7a51290b"))
        do_test("1mLRia5CbfDB9752zxvtrpnkigecaYWUSQNLJGECA8641ywusqomjhfdb6EM7bXGj1Gb",
                h2b("000111d38e5fc9071ffcd20b4a763cc9ae4f252bb4e48fd66a835e252ada93ff480d6dd43dc62a641155a561616161"))
开发者ID:alanxu89,项目名称:pycoin,代码行数:14,代码来源:encoding_test.py

示例12: spendables_for_address

 def spendables_for_address(self, address):
     """
     Return a list of Spendable objects for the
     given bitcoin address.
     """
     URL = self.api_domain + "/unspent?active=%s" % address
     r = json.loads(urlopen(URL).read().decode("utf8"))
     spendables = []
     for u in r["unspent_outputs"]:
         coin_value = u["value"]
         script = h2b(u["script"])
         previous_hash = h2b(u["tx_hash"])
         previous_index = u["tx_output_n"]
         spendables.append(Tx.Spendable(coin_value, script, previous_hash, previous_index))
     return spendables
开发者ID:alanxu89,项目名称:pycoin,代码行数:15,代码来源:blockchain_info.py

示例13: make_script_test

def make_script_test(script_in, script_out, flags_string, comment, expected, coin_value, script_witness):
    script_in_bin = network.script.compile(script_in)
    script_out_bin = network.script.compile(script_out)
    script_witness_bin = [h2b(w) for w in script_witness]
    flags = parse_flags(flags_string)

    def f(self):
        try:
            credit_tx = build_credit_tx(script_out_bin, coin_value)
            spend_tx = build_spending_tx(script_in_bin, credit_tx)
            spend_tx.txs_in[0].witness = script_witness_bin
            msg = ''
            spend_tx.check_solution(tx_in_idx=0, flags=flags)
            r = 0
        except ScriptError as se:
            r = se.error_code()
            msg = se.args[0]
        except Exception:
            r = -1
        # for now, just deal with 0 versus nonzero
        expect_error = getattr(errno, expected)
        if r != expect_error:
            dump_failure_info(spend_tx, script_in, script_out, flags, flags_string, expected, r, msg, comment)
        self.assertEqual(r, expect_error)
    return f
开发者ID:richardkiss,项目名称:pycoin,代码行数:25,代码来源:vm_script_test.py

示例14: test_h2b

 def test_h2b(self):
     h = "000102"
     b = b"\x00\x01\x02"
     self.assertEqual(h2b(h), b)
     self.assertEqual(b2h(b), h)
     self.assertEqual(h2b_rev(h), b[::-1])
     self.assertEqual(b2h_rev(b), "020100")
开发者ID:alanxu89,项目名称:pycoin,代码行数:7,代码来源:serialize_test.py

示例15: test_block

    def test_block(self):
        expected_checksum = '0000000000089F7910F6755C10EA2795EC368A29B435D80770AD78493A6FECF1'.lower()

        block_data = h2b(
            "010000007480150B299A16BBCE5CCDB1D1BBC65CFC5893B01E6619107C552000000000"
            "007900A2B203D24C69710AB6A94BEB937E1B1ADD64C2327E268D8C3E5F8B41DBED8796"
            "974CED66471B204C324703010000000100000000000000000000000000000000000000"
            "00000000000000000000000000FFFFFFFF0804ED66471B024001FFFFFFFF0100F2052A"
            "010000004341045FEE68BAB9915C4EDCA4C680420ED28BBC369ED84D48AC178E1F5F7E"
            "EAC455BBE270DABA06802145854B5E29F0A7F816E2DF906E0FE4F6D5B4C9B92940E4F0"
            "EDAC000000000100000001F7B30415D1A7BF6DB91CB2A272767C6799D721A4178AA328"
            "E0D77C199CB3B57F010000008A4730440220556F61B84F16E637836D2E74B8CB784DE4"
            "0C28FE3EF93CCB7406504EE9C7CAA5022043BD4749D4F3F7F831AC696748AD8D8E79AE"
            "B4A1C539E742AA3256910FC88E170141049A414D94345712893A828DE57B4C2054E2F5"
            "96CDCA9D0B4451BA1CA5F8847830B9BE6E196450E6ABB21C540EA31BE310271AA00A49"
            "ED0BA930743D1ED465BAD0FFFFFFFF0200E1F505000000001976A914529A63393D63E9"
            "80ACE6FA885C5A89E4F27AA08988ACC0ADA41A000000001976A9145D17976537F30886"
            "5ED533CCCFDD76558CA3C8F088AC00000000010000000165148D894D3922EF5FFDA962"
            "BE26016635C933D470C8B0AB7618E869E3F70E3C000000008B48304502207F5779EBF4"
            "834FEAEFF4D250898324EB5C0833B16D7AF4C1CB0F66F50FCF6E85022100B78A65377F"
            "D018281E77285EFC31E5B9BA7CB7E20E015CF6B7FA3E4A466DD195014104072AD79E0A"
            "A38C05FA33DD185F84C17F611E58A8658CE996D8B04395B99C7BE36529CAB7606900A0"
            "CD5A7AEBC6B233EA8E0FE60943054C63620E05E5B85F0426FFFFFFFF02404B4C000000"
            "00001976A914D4CAA8447532CA8EE4C80A1AE1D230A01E22BFDB88AC8013A0DE010000"
            "001976A9149661A79AE1F6D487AF3420C13E649D6DF3747FC288AC00000000")

        # try to parse a block

        block = Block.parse(io.BytesIO(block_data))
        assert b2h_rev(block.hash()) == expected_checksum
        block.check_merkle_hash()

        # parse already validated block
        block = Block.parse(io.BytesIO(block_data), check_merkle_hash=False)
        assert block.as_bin() == block_data
开发者ID:richardkiss,项目名称:pycoin,代码行数:35,代码来源:parse_block_test.py


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