本文整理汇总了Python中bitcoin.core.b2x方法的典型用法代码示例。如果您正苦于以下问题:Python core.b2x方法的具体用法?Python core.b2x怎么用?Python core.b2x使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bitcoin.core
的用法示例。
在下文中一共展示了core.b2x方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_to_p2sh_scriptPubKey
# 需要导入模块: from bitcoin import core [as 别名]
# 或者: from bitcoin.core import b2x [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()
示例2: set_fields
# 需要导入模块: from bitcoin import core [as 别名]
# 或者: from bitcoin.core import b2x [as 别名]
def set_fields(self, script=None, txTo=None, inIdx=None, hashType=None):
"""Populate model.
Args:
script (str): Human-readable script.
txTo (Transaction): Transaction.
inIdx (int): Input index.
hashType (int): SigHash type.
"""
if script is not None:
self.setData(self.index(0, 0), QVariant(script))
if txTo is not None:
self.setData(self.index(0, 1), QVariant(b2x(txTo.serialize())))
if inIdx is not None:
self.setData(self.index(0, 2), QVariant(inIdx))
if hashType is not None:
self.setData(self.index(0, 3), QVariant(hashType & 0x1f), RawRole)
self.setData(self.index(0, 4), QVariant(hashType & SIGHASH_ANYONECANPAY))
示例3: test_to_scriptPubKey
# 需要导入模块: from bitcoin import core [as 别名]
# 或者: from bitcoin.core import b2x [as 别名]
def test_to_scriptPubKey(self):
"""CBitcoinAddress.to_scriptPubKey() works"""
def T(str_addr, expected_scriptPubKey_hexbytes):
addr = CBitcoinAddress(str_addr)
actual_scriptPubKey = addr.to_scriptPubKey()
self.assertEqual(b2x(actual_scriptPubKey), expected_scriptPubKey_hexbytes)
T('31h1vYVSYuKP6AhS86fbRdMw9XHieotbST',
'a914000000000000000000000000000000000000000087')
T('1111111111111111111114oLvT2',
'76a914000000000000000000000000000000000000000088ac')
示例4: test
# 需要导入模块: from bitcoin import core [as 别名]
# 或者: from bitcoin.core import b2x [as 别名]
def test(self):
def T(base58_privkey, expected_hex_pubkey, expected_is_compressed_value):
key = CBitcoinSecret(base58_privkey)
self.assertEqual(b2x(key.pub), expected_hex_pubkey)
self.assertEqual(key.is_compressed, expected_is_compressed_value)
T('5KJvsngHeMpm884wtkJNzQGaCErckhHJBGFsvd3VyK5qMZXj3hS',
'0478d430274f8c5ec1321338151e9f27f4c676a008bdf8638d07c0b6be9ab35c71a1518063243acd4dfe96b66e3f2ec8013c8e072cd09b3834a19f81f659cc3455',
False)
T('L3p8oAcQTtuokSCRHQ7i4MhjWc9zornvpJLfmg62sYpLRJF9woSu',
'0378d430274f8c5ec1321338151e9f27f4c676a008bdf8638d07c0b6be9ab35c71',
True)
示例5: raw_transaction
# 需要导入模块: from bitcoin import core [as 别名]
# 或者: from bitcoin.core import b2x [as 别名]
def raw_transaction(self):
return b2x(self.tx.serialize())
示例6: extract_secret
# 需要导入模块: from bitcoin import core [as 别名]
# 或者: from bitcoin.core import b2x [as 别名]
def extract_secret(cls, raw_transaction: str=None, scriptsig: str=None) -> str:
'''
Extracting secret from Alice redeem transaction (first redeem in the Atomic Swao).
Args:
raw_transaction (str): raw transaction to extract secret from
scriptSig (str): value of the scriptSig field from the first vin
Returns:
str: transaction secret
Raises:
ValueError: if something goes wrong
Example:
>>> from clove.network import Litecoin
>>> network = Litecoin()
>>> network.extract_secret(raw_transaction='0100000001aa25fd5f63cb41d6ee7dd495256046b4c3f17d4540a1b258a06bfefac30da60900000000fdff0047304402201c8869d359b5599ecffd51a96f0a8799392c98c4e15242762ba455e37b1f5d6302203f2974e9afc8d641f9363167df48e5a845a8deba1381bf5a1b549ac04718a1ac01410459cdb91eb7298bc2578dc4e7ac2109ac3cfd9dc9818795c5583e720d2114d540724bf26b4541f683ff51968db627a04eecd1f5cff615b6350dad5fb595f8adf420c480afb333623864901c968022a07dd93fe3c06f5684ea728b8113e17fa91bd9514c5163a61450314a793bf317665ecdc54c2e843bb106aeee158876a91485c0522f6e23beb11cc3d066cd20ed732648a4e66704926db75bb17576a914621f617c765c3caa5ce1bb67f6a3e51382b8da296888ac00000000015a7b0100000000001976a91485c0522f6e23beb11cc3d066cd20ed732648a4e688ac00000000') # noqa: E501
'c480afb333623864901c968022a07dd93fe3c06f5684ea728b8113e17fa91bd9'
>>> network.extract_secret(scriptsig='0c480afb333623864901c968022a07dd93fe3c06f5684ea728b8113e17fa91bd9514c5163a61450314a793bf317665ecdc54c2e843bb106aeee158876a91485c0522f6e23beb11cc3d066cd20') # noqa: E501
'c480afb333623864901c968022a07dd93fe3c06f5684ea728b8113e17fa91bd9'
'''
if not raw_transaction and not scriptsig:
raise ValueError('raw_transaction or scriptsig have to be provided.')
if raw_transaction:
tx = cls.deserialize_raw_transaction(raw_transaction)
if not tx.vin:
raise ValueError('Given transaction has no inputs.')
secret_tx_in = tx.vin[0]
script_ops = list(secret_tx_in.scriptSig)
else:
script_ops = list(script.CScript.fromhex(scriptsig))
if script_ops[-2] == 1:
return b2x(script_ops[-3])
raise ValueError('Unable to extract secret.')
示例7: test_audit_contract_empty_transaction
# 需要导入模块: from bitcoin import core [as 别名]
# 或者: from bitcoin.core import b2x [as 别名]
def test_audit_contract_empty_transaction():
btc_network = BitcoinTestNet()
tx = b2x(CTransaction().serialize())
with raises(
ValueError, match='Given transaction has no outputs.'
):
btc_network.audit_contract('', tx)
示例8: to_raw_tx
# 需要导入模块: from bitcoin import core [as 别名]
# 或者: from bitcoin.core import b2x [as 别名]
def to_raw_tx(self):
"""
return the raw, serialized transaction
"""
return b2x(self.tx.serialize())
示例9: copy_serialized
# 需要导入模块: from bitcoin import core [as 别名]
# 或者: from bitcoin.core import b2x [as 别名]
def copy_serialized(self):
data = b2x(self.model.header.serialize())
QApplication.clipboard().setText(data)
示例10: context_menu
# 需要导入模块: from bitcoin import core [as 别名]
# 或者: from bitcoin.core import b2x [as 别名]
def context_menu(self):
menu = QMenu()
copy = menu.addMenu('Copy')
copy.addAction('Previous Transaction ID', self.copy_prev_tx)
copy.addAction('Input Script', self.copy_script)
copy.addAction('Input Script (Hex)', self.copy_script_hex)
def copy_serialized():
row = self.view.selectedIndexes()[0].row()
inp = self.model.tx.vin[row]
data = b2x(inp.serialize())
QApplication.clipboard().setText(data)
copy.addAction('Serialized Input', copy_serialized)
return menu
示例11: test_clams_fields
# 需要导入模块: from bitcoin import core [as 别名]
# 或者: from bitcoin.core import b2x [as 别名]
def test_clams_fields(self):
chainparams.set_to_preset('Clams')
blk = Block.deserialize(clams_raw_block)
self.assertEqual(clams_raw_block.encode('hex'), blk.as_hex())
self.assertEqual('3045022100b4e1b24eff6f0c7945c1cabc2d37ac88df861fe37f9bc22ac3c8594bac58f6f9022044e8dfde90dc28d06ba17d5c2b9b3a65ad1cdc03c3e0f8f5655d1f5b9c8cfa0b', b2x(blk.blockSig))
示例12: as_hex
# 需要导入模块: from bitcoin import core [as 别名]
# 或者: from bitcoin.core import b2x [as 别名]
def as_hex(self):
return b2x(self.serialize())
# Known serializer classes
示例13: raw
# 需要导入模块: from bitcoin import core [as 别名]
# 或者: from bitcoin.core import b2x [as 别名]
def raw(self):
return b2x(self.value.serialize())
示例14: raw
# 需要导入模块: from bitcoin import core [as 别名]
# 或者: from bitcoin.core import b2x [as 别名]
def raw(self):
return b2x(self.value.to_bytes())
示例15: decode_address
# 需要导入模块: from bitcoin import core [as 别名]
# 或者: from bitcoin.core import b2x [as 别名]
def decode_address(self):
txt = str(self.address_line.text())
try:
addr_bytes, version = decode_address(txt)
except Exception:
self.hash_line.setText('Could not decode address.')
self.addr_version.setValue(0)
return
self.hash_line.setText(b2x(addr_bytes))
self.addr_version.setValue(version)