• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python serialize.b2h函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: make_transaction

def make_transaction( src_priv_key, dst_address, value, data ):
    src_address = b2h( utils.privtoaddr(src_priv_key) )
    nonce = get_num_transactions( src_address )
    gas_price = get_gas_price_in_wei()
    data_as_string = b2h(data)
    start_gas = eval_startgas( src_address, dst_address, value, data_as_string, gas_price )
    
    nonce = int( nonce, 16 )
    gas_price = int( gas_price, 16 )
    start_gas = int( start_gas, 16 ) + 100000
    
    tx = transactions.Transaction( nonce,
                                   gas_price,
                                   start_gas,
                                   dst_address,
                                   value,
                                   data ).sign(src_priv_key)
    
    
                                   
    tx_hex  = b2h(rlp.encode(tx))
    tx_hash = b2h( tx.hash )
    if use_ether_scan:
        params = [{"hex" : "0x" + tx_hex }]
    else:
        params = ["0x" + tx_hex]
    return_value = json_call( "eth_sendRawTransaction", params )                       
    if return_value == "0x0000000000000000000000000000000000000000000000000000000000000000":
        print "Transaction failed"
        return False
    wait_for_confirmation(tx_hash)
    return return_value        
开发者ID:yaronvel,项目名称:smart_contracts,代码行数:32,代码来源:post_contract_ui.py


示例2: solve_finalize_commit

    def solve_finalize_commit(self, **kwargs):
        hash160_lookup = kwargs.get("hash160_lookup")
        sign_value = kwargs.get("sign_value")
        signature_type = kwargs.get("signature_type")
        existing_script = kwargs.get("existing_script")

        # FIXME validate on receiving the commit
        # validate payer sig
        opcode, data, pc = tools.get_opcode(existing_script, 0)  # OP_0
        opcode, payer_sig, pc = tools.get_opcode(existing_script, pc)
        sig_pair, actual_signature_type = parse_signature_blob(payer_sig)
        try:
            public_pair = encoding.sec_to_public_pair(self.payer_sec)
            sig_pair, signature_type = parse_signature_blob(payer_sig)
            valid = ecdsa.verify(ecdsa.generator_secp256k1, public_pair,
                                 sign_value, sig_pair)
            if not valid:
                raise Exception("Invalid payer public_pair!")
        except (encoding.EncodingError, UnexpectedDER):
            raise Exception("Invalid payer public_pair!")

        # sign
        private_key = hash160_lookup.get(encoding.hash160(self.payee_sec))
        secret_exponent, public_pair, compressed = private_key
        payee_sig = self._create_script_signature(
            secret_exponent, sign_value, signature_type
        )

        script_text = "OP_0 {payer_sig} {payee_sig} OP_1".format(
            payer_sig=b2h(payer_sig), payee_sig=b2h(payee_sig)
        )
        return tools.compile(script_text)
开发者ID:super3,项目名称:picopayments,代码行数:32,代码来源:scripts.py


示例3: __init__

 def __init__(self, payer_sec, payee_sec, spend_secret_hash, expire_time):
     self.payer_sec = payer_sec
     self.payee_sec = payee_sec
     self.spend_secret_hash = spend_secret_hash
     self.expire_time = expire_time
     self.script = compile_deposit_script(b2h(payer_sec), b2h(payee_sec),
                                          spend_secret_hash, expire_time)
开发者ID:super3,项目名称:picopayments,代码行数:7,代码来源:scripts.py


示例4: main

def main():
    parser = argparse.ArgumentParser(description="Bitcoin utilities. WARNING: obsolete. Use ku instead.")

    parser.add_argument('-a', "--address", help='show as Bitcoin address', action='store_true')
    parser.add_argument('-1', "--hash160", help='show as hash 160', action='store_true')
    parser.add_argument('-v', "--verbose", help='dump all information available', action='store_true')
    parser.add_argument('-w', "--wif", help='show as Bitcoin WIF', action='store_true')
    parser.add_argument('-n', "--uncompressed", help='show in uncompressed form', action='store_true')
    parser.add_argument('item', help='a WIF, secret exponent, X/Y public pair, SEC (as hex), hash160 (as hex), Bitcoin address', nargs="+")
    args = parser.parse_args()

    for c in args.item:
        # figure out what it is:
        #  - secret exponent
        #  - WIF
        #  - X/Y public key (base 10 or hex)
        #  - sec
        #  - hash160
        #  - Bitcoin address
        secret_exponent = parse_as_private_key(c)
        if secret_exponent:
            public_pair = ecdsa.public_pair_for_secret_exponent(secp256k1.generator_secp256k1, secret_exponent)
            print("secret exponent: %d" % secret_exponent)
            print("  hex:           %x" % secret_exponent)
            print("WIF:             %s" % encoding.secret_exponent_to_wif(secret_exponent, compressed=True))
            print("  uncompressed:  %s" % encoding.secret_exponent_to_wif(secret_exponent, compressed=False))
        else:
            public_pair = parse_as_public_pair(c)
        if public_pair:
            bitcoin_address_uncompressed = encoding.public_pair_to_bitcoin_address(public_pair, compressed=False)
            bitcoin_address_compressed = encoding.public_pair_to_bitcoin_address(public_pair, compressed=True)
            print("public pair x:   %d" % public_pair[0])
            print("public pair y:   %d" % public_pair[1])
            print("  x as hex:      %x" % public_pair[0])
            print("  y as hex:      %x" % public_pair[1])
            print("y parity:        %s" % "odd" if (public_pair[1] & 1) else "even")
            print("key pair as sec: %s" % b2h(encoding.public_pair_to_sec(public_pair, compressed=True)))
            s = b2h(encoding.public_pair_to_sec(public_pair, compressed=False))
            print("  uncompressed:  %s\\\n                   %s" % (s[:66], s[66:]))
            hash160 = encoding.public_pair_to_hash160_sec(public_pair, compressed=True)
            hash160_unc = encoding.public_pair_to_hash160_sec(public_pair, compressed=False)
            myeccpoint = encoding.public_pair_to_sec(public_pair, compressed=True)
            myhash     = encoding.ripemd160( myeccpoint ).digest(  )
            print("BTSX PubKey:     %s" % BTS_ADDRESS_PREFIX + encoding.b2a_base58(myeccpoint + myhash[ :4 ]))
        else:
            hash160 = parse_as_address(c)
            hash160_unc = None
        if not hash160:
            sys.stderr.write("can't decode input %s\n" % c)
            sys.exit(1)
        print("hash160:         %s" % b2h(hash160))
        if hash160_unc:
            print("  uncompressed:  %s" % b2h(hash160_unc))
        print("Bitcoin address: %s" % encoding.hash160_sec_to_bitcoin_address(hash160))
        if hash160_unc:
            print("  uncompressed:  %s" % encoding.hash160_sec_to_bitcoin_address(hash160_unc))
开发者ID:fedaykinofdune,项目名称:pytshares,代码行数:56,代码来源:bu-mod.py


示例5: fix_input_script

def fix_input_script(inp, redeem_script):
    """replace dummy signatures with OP_0 and add redeem script for digitaloracle compatibility"""
    dummy = b2h(dummy_signature(1))
    ops1 = []
    for op in opcode_list(inp.script):
        if op == dummy:
            op = 'OP_0'
        ops1.append(op)
    # FIXME hack to add redeem script omitted by pycoin
    ops1.append(b2h(redeem_script))
    inp.script = compile(' '.join(ops1))
开发者ID:tomholub,项目名称:multisig-core,代码行数:11,代码来源:oracle.py


示例6: test_verify_transaction

    def test_verify_transaction(self):
        bitcoin.SelectParams('testnet')
        b = h2b('8443b07464c762d7fb404ea918a5ac9b3618d5cd6a0c5ea6e4dd5d7bbe28b154')
        tx_input = Spendable(200, b'18eKkAWyU9kvRNHPKxnZb6wwtPMrNmRRRA', b, 0)
        tx_outs = [tx_utils.create_transaction_output('mgAqW5ZCnEp7fjvpj8RUL3WxsBy8rcDcCi', 0.0000275)]
        op_return_val = h2b('e9cee71ab932fde863338d08be4de9dfe39ea049bdafb342ce659ec5450b69ae')
        tx = tx_utils.create_trx(op_return_val, 3, 'mgAqW5ZCnEp7fjvpj8RUL3WxsBy8rcDcCi', tx_outs, [tx_input])

        hextx = b2h(tx.serialize())

        tx_utils.verify_transaction(hextx, b2h(op_return_val))
开发者ID:NunoEdgarGub1,项目名称:cert-issuer,代码行数:11,代码来源:test_tx_utils.py


示例7: create_public_pair_output

def create_public_pair_output(key, add_output):
    public_pair = key.public_pair()

    if public_pair:
        add_output("public_pair_x", '%d' % public_pair[0])
        add_output("public_pair_y", '%d' % public_pair[1])
        add_output("public_pair_x_hex", '%x' % public_pair[0], " x as hex")
        add_output("public_pair_y_hex", '%x' % public_pair[1], " y as hex")
        add_output("y_parity", "odd" if (public_pair[1] & 1) else "even")

        add_output("key_pair_as_sec", b2h(key.sec(use_uncompressed=False)))
        add_output("key_pair_as_sec_uncompressed", b2h(key.sec(use_uncompressed=True)), " uncompressed")
开发者ID:onestarshang,项目名称:pycoin,代码行数:12,代码来源:ku.py


示例8: solve_create_commit

 def solve_create_commit(self, **kwargs):
     hash160_lookup = kwargs["hash160_lookup"]
     private_key = hash160_lookup.get(encoding.hash160(self.payer_sec))
     secret_exponent, public_pair, compressed = private_key
     sig = self._create_script_signature(
         secret_exponent, kwargs["sign_value"], kwargs["signature_type"]
     )
     signature_placeholder = kwargs.get("signature_placeholder",
                                        DEFAULT_PLACEHOLDER_SIGNATURE)
     script_text = "OP_0 {payer_sig} {payee_sig} OP_1".format(
         payer_sig=b2h(sig), payee_sig=b2h(signature_placeholder)
     )
     return tools.compile(script_text)
开发者ID:super3,项目名称:picopayments,代码行数:13,代码来源:scripts.py


示例9: from_script

 def from_script(cls, script):
     r = cls.match(script)
     if r:
         delay_time = get_commit_delay_time(cls.TEMPLATE)
         spend_secret_hash = b2h(r["PUBKEYHASH_LIST"][0])
         payee_sec = r["PUBKEY_LIST"][0]
         revoke_secret_hash = b2h(r["PUBKEYHASH_LIST"][1])
         payer_sec = r["PUBKEY_LIST"][1]
         obj = cls(delay_time, spend_secret_hash,
                   payee_sec, payer_sec, revoke_secret_hash)
         assert(obj.script == script)
         return obj
     raise ValueError("bad script")
开发者ID:super3,项目名称:picopayments,代码行数:13,代码来源:scripts.py


示例10: test_batch_handler_web_prepare

    def test_batch_handler_web_prepare(self):
        web_request = json.dumps([{'allyourbasearebelongtous': True}])
        web_handler, certificates_to_issue = self._get_certificate_batch_web_handler()
        web_handler.set_certificates_in_batch(web_request)
        single_item_batch = web_handler.prepare_batch()

        self.assertEqual(
                b2h(single_item_batch),
                '38451f557bc2b5ad74012d3389798281b993fc7375c024615ed73fb147670ba7')

        web_handler, certificates_to_issue = self._get_certificate_batch_web_handler()
        web_handler.set_certificates_in_batch(
                [{'allyourbasearebelongtous': True}, {'allyourbasearebelongtous': False}])
        multi_batch = web_handler.prepare_batch()
        self.assertNotEqual(b2h(single_item_batch), b2h(multi_batch))
开发者ID:NiclausLiu,项目名称:cert-issuer,代码行数:15,代码来源:test_certificate_handler.py


示例11: solve_change

 def solve_change(self, **kwargs):
     hash160_lookup = kwargs["hash160_lookup"]
     spend_secret = kwargs["spend_secret"]
     private_key = hash160_lookup.get(encoding.hash160(self.payer_sec))
     secret_exponent, public_pair, compressed = private_key
     sig = self._create_script_signature(
         secret_exponent, kwargs["sign_value"], kwargs["signature_type"]
     )
     spend_secret_hash = get_deposit_spend_secret_hash(self.script)
     provided_spend_secret_hash = b2h(hash160(h2b(spend_secret)))
     assert(spend_secret_hash == provided_spend_secret_hash)
     script_text = "{sig} {secret} OP_1 OP_0".format(
         sig=b2h(sig), secret=spend_secret
     )
     return tools.compile(script_text)
开发者ID:super3,项目名称:picopayments,代码行数:15,代码来源:scripts.py


示例12: verify_script

def verify_script(script_signature, script_public_key, signature_for_hash_type_f, expected_hash_type=None):
    stack = []

    is_p2h = (len(script_public_key) == 23 and script_public_key[0] == opcodes.OP_HASH160
                and script_public_key[-1] == opcodes.OP_EQUAL)

    if not eval_script(script_signature, signature_for_hash_type_f, expected_hash_type, stack):
        logging.debug("script_signature did not evaluate")
        return False

    if is_p2h:
        signatures, alt_script_public_key = stack[:-1], stack[-1]
        from pycoin.tx.script import tools
        from pycoin import serialize
        def sub(x):
            if x == '00':
                return '0'
            return x
        s1 = [sub(serialize.b2h(s)) for s in signatures]
        alt_script_signature = tools.compile(" ".join(s1))

    if not eval_script(script_public_key, signature_for_hash_type_f, expected_hash_type, stack):
        logging.debug("script_public_key did not evaluate")
        return False

    if is_p2h and stack[-1] == VCH_TRUE:
        return verify_script(alt_script_signature, alt_script_public_key,
                             signature_for_hash_type_f, expected_hash_type=expected_hash_type)

    return stack[-1] == VCH_TRUE
开发者ID:RagnarDanneskjold,项目名称:pycoin,代码行数:30,代码来源:vm.py


示例13: create_key

def create_key(asset, netcode="BTC"):
    secure_random_data = os.urandom(32)
    key = BIP32Node.from_master_secret(secure_random_data, netcode=netcode)
    return {
        "asset": asset, "pubkey": b2h(key.sec()),
        "wif": key.wif(), "address": key.address(),
    }
开发者ID:StorjRND,项目名称:picopayments,代码行数:7,代码来源:lib.py


示例14: reformat

 def reformat(spendable):
     return {
         "txid": b2h_rev(spendable.tx_hash),
         "index": spendable.tx_out_index,
         "value": spendable.coin_value,
         "script": b2h(spendable.script),
     }
开发者ID:hfeeki,项目名称:btctxstore,代码行数:7,代码来源:serialize.py


示例15: issue_transaction

 def issue_transaction(self, blockchain_bytes):
     eth_data_field = b2h(blockchain_bytes)
     prepared_tx = self.create_transaction(blockchain_bytes)
     signed_tx = self.sign_transaction(prepared_tx)
     self.verify_transaction(signed_tx, eth_data_field)
     txid = self.broadcast_transaction(signed_tx)
     return txid
开发者ID:NiclausLiu,项目名称:cert-issuer,代码行数:7,代码来源:transaction_handlers.py


示例16: save_spendable

 def save_spendable(self, spendable):
     tx_hash = b2h_rev(spendable.tx_hash)
     script = b2h(spendable.script)
     c = self._exec_sql("insert or replace into Spendable values (?, ?, ?, ?, ?, ?, ?)", tx_hash,
                         spendable.tx_out_index, spendable.coin_value, script,
                         spendable.block_index_available, spendable.does_seem_spent,
                         spendable.block_index_spent)
开发者ID:DOGEtools,项目名称:doge-millionaire,代码行数:7,代码来源:SQLite3Persistence.py


示例17: hash160data_txout

def hash160data_txout(hexdata, value=548):
    data = binary(hexdata)
    if len(data) != 20:  # 160 bit
        raise exceptions.InvalidHash160DataSize(len(data))
    script_text = "OP_DUP OP_HASH160 %s OP_EQUALVERIFY OP_CHECKSIG" % b2h(data)
    script_bin = tools.compile(script_text)
    return TxOut(value, script_bin)
开发者ID:NinjaDevelper,项目名称:btctxstore,代码行数:7,代码来源:deserialize.py


示例18: 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:E-LLP,项目名称:pycoin,代码行数:7,代码来源:test_serialize.py


示例19: nulldata_txout

def nulldata_txout(hexdata):
    data = binary(hexdata)
    if len(data) > 40:
        raise exceptions.MaxNulldataExceeded(len(data))
    script_text = "OP_RETURN %s" % b2h(data)
    script_bin = tools.compile(script_text)
    return TxOut(0, script_bin)
开发者ID:NinjaDevelper,项目名称:btctxstore,代码行数:7,代码来源:deserialize.py


示例20: hash160data_txout

def hash160data_txout(hexdata, dust_limit=common.DUST_LIMIT):
    data = binary(hexdata)
    if len(data) != 20:  # 160 bit
        raise exceptions.InvalidHash160DataSize(len(data))
    script_text = "OP_DUP OP_HASH160 %s OP_EQUALVERIFY OP_CHECKSIG" % b2h(data)
    script_bin = tools.compile(script_text)
    return TxOut(dust_limit, script_bin)
开发者ID:robertsdotpm,项目名称:btctxstore,代码行数:7,代码来源:deserialize.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python serialize.b2h_rev函数代码示例发布时间:2022-05-25
下一篇:
Python BIP32Node.BIP32Node类代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap