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

Python serialize.h2b_rev函数代码示例

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

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



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

示例1: 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 = tools.compile(scriptSig.get("asm"))
            previous_index = vin.get("vout")
        sequence = vin.get("sequence")
        txs_in.append(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 = tools.compile(vout.get("scriptPubKey").get("asm"))
        txs_out.append(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:Stevengu999,项目名称:pycoin,代码行数:30,代码来源:insight.py


示例2: main

def main():
    parser = argparse.ArgumentParser(description="Add a transaction to tx cache.")
    parser.add_argument("tx_id_or_path", nargs="+",
                        help='The id of the transaction to fetch from web services or the path to it.')

    args = parser.parse_args()

    TX_RE = re.compile(r"^[0-9a-fA-F]{64}$")

    tx_db = get_tx_db()

    for p in args.tx_id_or_path:
        if TX_RE.match(p):
            tx = tx_db.get(h2b_rev(p))
            if not tx:
                parser.error("can't find Tx with id %s" % p)
        else:
            f = open(p, "rb")
            try:
                if f.name.endswith("hex"):
                    f = io.BytesIO(codecs.getreader("hex_codec")(f).read())
                tx = Tx.parse(f)
            except Exception:
                parser.error("can't parse %s" % f.name)

        tx_db[tx.hash()] = tx
        print("cached %s" % tx.id())
开发者ID:Bluejudy,项目名称:pycoin,代码行数:27,代码来源:cache_tx.py


示例3: main

def main():
    logging.basicConfig(
        level=logging.DEBUG,
        format=('%(asctime)s [%(process)d] [%(levelname)s] '
                '%(filename)s:%(lineno)d %(message)s'))

    from pycoinnet.helpers.networks import MAINNET
    from pycoinnet.util.BlockChainView import BlockChainView
    from pycoinnet.bloom import BloomFilter
    from pycoin.tx import Spendable
    from pycoin.serialize import h2b_rev, h2b
    network = MAINNET
    initial_blockchain_view = BlockChainView()
    bloom_filter = BloomFilter(2048, hash_function_count=8, tweak=3)
    bloom_filter.add_address("14gZfnEn8Xd3ofkjr5s7rKoC3bi8J4Yfyy")
    # bloom_filter.add_address("1GL6i1ty44RnERgqYLKS1CrnhrahW4JhQZ")
    bloom_filter.add_item(h2b("0478abb18c0c7c95348fa77eb5fd43ce963e450d797cf4878894230ca528e6c8e866c3"
                              "8ad93746e04f2161a01787c82a858ee24940e9a06e41fddb3494dfe29380"))
    spendable = Spendable(
        0, b'', h2b_rev("0437cd7f8525ceed2324359c2d0ba26006d92d856a9c20fa0241106ee5a597c9"), 0)
    bloom_filter.add_spendable(spendable)
    merkle_block_index_queue = asyncio.Queue()
    spv = SPVClient(
        network, initial_blockchain_view, bloom_filter, merkle_block_index_queue, host_port_q=None)

    def fetch(merkle_block_index_queue):
        while True:
            merkle_block, index = yield from merkle_block_index_queue.get()
            logging.info(
                "block #%d %s with %d transactions", index, merkle_block.id(), len(merkle_block.txs))

    t = asyncio.Task(fetch(merkle_block_index_queue))

    asyncio.get_event_loop().run_forever()
开发者ID:dzyk,项目名称:pycoinnet,代码行数:34,代码来源:spvclient.py


示例4: populate_unspents

def populate_unspents(nodes):
    global balance
    global unspents
    
    if nodes['used'] == {}:
        return
    
    addresses = nodes['used'].keys()
    response = json.load( urlopen("http://%s.blockr.io/api/v1/address/unspent/" % BLOCKR + \
                        ','.join(addresses)) )
    data = response['data']
    if type(data) == type({}):
        data = [data]
    
    for entry in data:
        if entry['unspent'] == []:
            continue
        
        for unspent in entry['unspent']:
            balance += Decimal(unspent['amount'])
            amount = convention.btc_to_satoshi(unspent['amount'])
            script = serialize.h2b(unspent['script'])
            txid = serialize.h2b_rev(unspent['tx'])
            
            unspent_spendable = Spendable( amount, script, txid, unspent['n'] )
            unspents.append(unspent_spendable)
            
    time.sleep(1)       # Don't overload blockr.io API
开发者ID:metamarcdw,项目名称:pycoin_wallet,代码行数:28,代码来源:wallet.py


示例5: 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


示例6: parse_tx

def parse_tx(arg, parser, tx_db, network):
    # hex transaction id
    tx = None

    if TX_ID_RE.match(arg):
        if tx_db is None:
            tx_db = create_tx_db(network)
        tx = tx_db.get(h2b_rev(arg))
        if not tx:
            parser.error("can't find Tx with id %s" % arg)
        return tx, tx_db

    # hex transaction data
    try:
        return Tx.from_hex(arg), tx_db
    except Exception:
        pass

    if os.path.exists(arg):
        try:
            with open(arg, "rb") as f:
                if f.name.endswith("hex"):
                    f = io.BytesIO(codecs.getreader("hex_codec")(f).read())
                tx = Tx.parse(f)
                tx.parse_unspents(f)
        except Exception:
            pass

    return tx, tx_db
开发者ID:onestarshang,项目名称:pycoin,代码行数:29,代码来源:tx.py


示例7: request_blocks

	def request_blocks(self, block_ids):
		invs = []
		for id in block_ids:
			inv = bitcoin.net.CInv()
			inv.type = self.INV_BLOCK
			inv.hash = h2b_rev(id)
			invs.append(inv)
		self.request_objects(invs)
开发者ID:bit-oasis,项目名称:sniffer,代码行数:8,代码来源:node.py


示例8: get_blockheader_with_transaction_hashes

 def get_blockheader_with_transaction_hashes(self, block_hash):
     URL = "%s/api/block/%s" % (self.base_url, b2h_rev(block_hash))
     r = json.loads(urlopen(URL).read().decode("utf8"))
     version = r.get("version")
     previous_block_hash = h2b_rev(r.get("previousblockhash"))
     merkle_root = h2b_rev(r.get("merkleroot"))
     timestamp = r.get("time")
     difficulty = int(r.get("bits"), 16)
     nonce = int(r.get("nonce"))
     tx_hashes = [h2b_rev(tx_hash) for tx_hash in r.get("tx")]
     blockheader = BlockHeader(version, previous_block_hash, merkle_root, timestamp, difficulty, nonce)
     if blockheader.hash() != block_hash:
         return None, None
     calculated_hash = merkle(tx_hashes, double_sha256)
     if calculated_hash != merkle_root:
         return None, None
     blockheader.height = r.get("height")
     return blockheader, tx_hashes
开发者ID:Stevengu999,项目名称:pycoin,代码行数:18,代码来源:insight.py


示例9: spendables_for_address

 def spendables_for_address(self, bitcoin_address):
     url = "{0}/addr/{1}/utxo".format(self.base_url, bitcoin_address)
     result = json.loads(urlopen(url).read().decode("utf8"))
     spendables = []
     for utxo in result:
         value = btc_to_satoshi(str(utxo["amount"]))
         prev_index = utxo["vout"]
         prev_hash = h2b_rev(utxo["txid"])
         script = h2b(utxo["scriptPubKey"])
         spendable = Spendable(value, script, prev_hash, prev_index)
         spendables.append(spendable)
     return spendables
开发者ID:StorjOld,项目名称:btctxstore,代码行数:12,代码来源:blockexplorer.py


示例10: spendables_for_address

 def spendables_for_address(self, bitcoin_address):
     URL = "%s/api/addr/%s/utxo" % (self.base_url, bitcoin_address)
     r = json.loads(urlopen(URL).read().decode("utf8"))
     spendables = []
     for u in r:
         value = btc_to_satoshi(str(u.get("amount")))
         script = h2b(u.get("scriptPubKey"))
         prev_hash = h2b_rev(u.get("txid"))
         prev_index = u.get("vout")
         spendable = Spendable(value, script, prev_hash, prev_index)
         spendables.append(spendable)
     return spendables
开发者ID:hfeeki,项目名称:btctxstore,代码行数:12,代码来源:insight.py


示例11: spendables_for_address

 def spendables_for_address(self, bitcoin_address):
     """
     Return a list of Spendable objects for the
     given bitcoin address.
     """
     URL = "%s/api/addr/%s/utxo" % (self.base_url, bitcoin_address)
     r = json.loads(urlopen(URL).read().decode("utf8"))
     spendables = []
     for u in r:
         coin_value = btc_to_satoshi(str(u.get("amount")))
         script = h2b(u.get("scriptPubKey"))
         previous_hash = h2b_rev(u.get("txid"))
         previous_index = u.get("vout")
         spendables.append(Spendable(coin_value, script, previous_hash, previous_index))
     return spendables
开发者ID:Stevengu999,项目名称:pycoin,代码行数:15,代码来源:insight.py


示例12: spendables_for_address

def spendables_for_address(bitcoin_address):
    """
    Return a list of Spendable objects for the
    given bitcoin address.
    """
    URL = "http://btc.blockr.io/api/v1/address/unspent/%s" % bitcoin_address
    r = json.loads(urlopen(URL).read().decode("utf8"))
    spendables = []
    for u in r.get("data", {}).get("unspent", []):
        coin_value = btc_to_satoshi(u.get("amount"))
        script = h2b(u.get("script"))
        previous_hash = h2b_rev(u.get("tx"))
        previous_index = u.get("n")
        spendables.append(Spendable(coin_value, script, previous_hash, previous_index))
    return spendables
开发者ID:Bluejudy,项目名称:pycoin,代码行数:15,代码来源:blockr_io.py


示例13: unspents_for_address

    def unspents_for_address(self, address):
        """
        Return a list of Spendable objects for the
        given bitcoin address.
        """
        spendables = []
        r = json.loads(urlopen(self.base_url('get_tx_unspent', address)).read().decode("utf8"))

        for u in r['data']['txs']:
            coin_value = int (float (u['value']) * 100000000)
            script = h2b(u["script_hex"])
            previous_hash = h2b_rev(u["txid"])
            previous_index = u["output_no"]
            spendables.append(Spendable(coin_value, script, previous_hash, previous_index))

        return spendables
开发者ID:Udala,项目名称:docforever,代码行数:16,代码来源:chain_so.py


示例14: spendables_for_address

 def spendables_for_address(self, address):
     """
     Return a list of Spendable objects for the
     given bitcoin address.
     """
     spendables = []
     url_append = "?unspentOnly=true&token=%s&includeScript=true" % self.api_key
     url = self.base_url("addrs/%s%s" % (address, url_append))
     result = json.loads(urlopen(url).read().decode("utf8"))
     for txn in result.get("txrefs", []):
         coin_value = txn.get("value")
         script = h2b(txn.get("script"))
         previous_hash = h2b_rev(txn.get("tx_hash"))
         previous_index = txn.get("tx_output_n")
         spendables.append(Spendable(coin_value, script, previous_hash, previous_index))
     return spendables
开发者ID:Stevengu999,项目名称:pycoin,代码行数:16,代码来源:blockcypher.py


示例15: spendables_for_address

def spendables_for_address(bitcoin_address):
    """
    Return a list of Spendable objects for the
    given bitcoin address.
    """
    json_response = fetch_json(
        "addresses/%s/unspent-outputs" % bitcoin_address)
    spendables = []
    for tx_out_info in json_response.get("data", {}).get("outputs"):
        if tx_out_info.get("to_address") == bitcoin_address:
            coin_value = tx_out_info["value"]
            script = tools.compile(tx_out_info.get("script_pub_key"))
            previous_hash = h2b_rev(tx_out_info.get("transaction_hash"))
            previous_index = tx_out_info.get("transaction_index")
            spendables.append(
                Spendable(coin_value, script, previous_hash, previous_index))
    return spendables
开发者ID:Gaff,项目名称:pycoin,代码行数:17,代码来源:biteasy.py


示例16: spendables_for_addresses

 def spendables_for_addresses(self, bitcoin_addresses):
     """
     Return a list of Spendable objects for the
     given bitcoin address.
     """
     r = []
     for i in xrange(0, len(bitcoin_addresses), CHUNK_SIZE):
         addresses = bitcoin_addresses[i:i+CHUNK_SIZE]
         url = "%s/api/addrs/%s/utxo" % (self.base_url, ",".join(addresses))
         r.extend(json.loads(urlopen(url).read().decode("utf8")))
     spendables = []
     for u in r:
         coin_value = btc_to_satoshi(str(u.get("amount")))
         script = h2b(u.get("scriptPubKey"))
         previous_hash = h2b_rev(u.get("txid"))
         previous_index = u.get("vout")
         spendables.append(Spendable(coin_value, script, previous_hash, previous_index))
     return spendables
开发者ID:superscud,项目名称:multisig-core,代码行数:18,代码来源:insight.py


示例17: txs_from_json

def txs_from_json(path):
    """
    Read tests from ./data/tx_??valid.json
    Format is an array of arrays
    Inner arrays are either [ "comment" ]
    or [[[prevout hash, prevout index, prevout scriptPubKey], [input 2], ...], serializedTransaction, verifyFlags]
    ... where all scripts are stringified scripts.

    verifyFlags is a comma separated list of script verification flags to apply, or "NONE"
    """
    comments = None
    with open(path, 'r') as f:
        for tvec in json.load(f):
            if len(tvec) == 1:
                comments = tvec[0]
                continue
            assert len(tvec) == 3
            prevouts = tvec[0]
            for prevout in prevouts:
                assert len(prevout) in (3, 4)

            tx_hex = tvec[1]

            flag_mask = parse_flags(tvec[2])
            try:
                tx = Tx.from_hex(tx_hex)
            except:
                print("Cannot parse tx_hex: %s" % tx_hex)
                raise

            spendable_db = {}
            blank_spendable = Spendable(0, b'', b'\0' * 32, 0)
            for prevout in prevouts:
                coin_value = 1000000
                if len(prevout) == 4:
                    coin_value = prevout[3]
                spendable = Spendable(coin_value=coin_value,
                                      script=compile(prevout[2]),
                                      tx_hash=h2b_rev(prevout[0]), tx_out_index=prevout[1])
                spendable_db[(spendable.tx_hash, spendable.tx_out_index)] = spendable
            unspents = [
                spendable_db.get((tx_in.previous_hash, tx_in.previous_index), blank_spendable) for tx_in in tx.txs_in]
            tx.set_unspents(unspents)
            yield (tx, flag_mask, comments)
开发者ID:onestarshang,项目名称:pycoin,代码行数:44,代码来源:bc_transaction_test.py


示例18: test_is_invalid

    def test_is_invalid(self):
        for (prevouts, tx_hex, flags) in txs_from_json(TX_INVALID_JSON):
            try:
                tx = Tx.from_hex(tx_hex)
                if not check_transaction(tx):
                    continue
                unspents = [Spendable(coin_value=1000000,
                                  script=compile_script(prevout[2]),
                                  tx_hash=h2b_rev(prevout[0]), tx_out_index=prevout[1])
                        for prevout in prevouts]
                tx.set_unspents(unspents)

                bs = tx.bad_signature_count()
                self.assertEqual(bs, 0)
            except:
                continue

            self.fail("Invalid transaction: " + tx.id() +
                      " appears to be valid.")
开发者ID:simulationcoin,项目名称:pycoin,代码行数:19,代码来源:bc_transaction_test.py


示例19: spendables_for_address

def spendables_for_address(bitcoin_address):
    """
    Return a list of Spendable objects for the
    given bitcoin address.
    """
    URL = "https://api.biteasy.com/blockchain/v1/addresses/%s/unspent-outputs" % bitcoin_address
    r = Request(URL,
                headers={"content-type": "application/json", "accept": "*/*", "User-Agent": "curl/7.29.0"})
    d = urlopen(r).read()
    json_response = json.loads(d.decode("utf8"))
    spendables = []
    for tx_out_info in json_response.get("data", {}).get("outputs"):
        if tx_out_info.get("to_address") == bitcoin_address:
            coin_value = tx_out_info["value"]
            script = tools.compile(tx_out_info.get("script_pub_key"))
            previous_hash = h2b_rev(tx_out_info.get("transaction_hash"))
            previous_index = tx_out_info.get("transaction_index")
            spendables.append(Spendable(coin_value, script, previous_hash, previous_index))
    return spendables
开发者ID:Meebleforp79,项目名称:pycoin,代码行数:19,代码来源:biteasy.py


示例20: json_to_tx

def json_to_tx(json_text):
    # transactions with non-standard lock time are not decoded properly
    # for example, d1ef46055a84fd02ee82580d691064780def18614d98646371c3448ca20019ac
    # there is no way to fix this until biteasy add a lock_time field to their output
    d = json.loads(json_text).get("data")
    txs_in = []
    for d1 in d.get("inputs"):
        previous_hash = h2b_rev(d1.get("outpoint_hash"))
        previous_index = d1.get("outpoint_index")
        script = h2b(d1.get("script_sig"))
        sequence = 4294967295 # BRAIN DAMAGE
        txs_in.append(TxIn(previous_hash, previous_index, script, sequence))
    txs_out = []
    for d1 in d.get("outputs"):
        coin_value = d1.get("value")
        script = h2b(d1.get("script_pub_key"))
        txs_out.append(TxOut(coin_value, script))
    version = d.get("version")
    lock_time = 0 # BRAIN DAMAGE
    return Tx(version, txs_in, txs_out, lock_time)
开发者ID:Bluejudy,项目名称:pycoin,代码行数:20,代码来源:biteasy.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python tx.Tx类代码示例发布时间:2022-05-25
下一篇:
Python serialize.h2b函数代码示例发布时间: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