本文整理汇总了Python中bitcoin.core.script.OP_HASH160属性的典型用法代码示例。如果您正苦于以下问题:Python script.OP_HASH160属性的具体用法?Python script.OP_HASH160怎么用?Python script.OP_HASH160使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类bitcoin.core.script
的用法示例。
在下文中一共展示了script.OP_HASH160属性的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: build_atomic_swap_contract
# 需要导入模块: from bitcoin.core import script [as 别名]
# 或者: from bitcoin.core.script import OP_HASH160 [as 别名]
def build_atomic_swap_contract(self):
self.contract = script.CScript([
script.OP_IF,
script.OP_RIPEMD160,
self.secret_hash,
script.OP_EQUALVERIFY,
script.OP_DUP,
script.OP_HASH160,
CBitcoinAddress(self.recipient_address),
script.OP_ELSE,
int(self.locktime.replace(tzinfo=timezone.utc).timestamp()),
script.OP_CHECKLOCKTIMEVERIFY,
script.OP_DROP,
script.OP_DUP,
script.OP_HASH160,
CBitcoinAddress(self.sender_address),
script.OP_ENDIF,
script.OP_EQUALVERIFY,
script.OP_CHECKSIG,
])
示例2: is_valid_contract_script
# 需要导入模块: from bitcoin.core import script [as 别名]
# 或者: from bitcoin.core.script import OP_HASH160 [as 别名]
def is_valid_contract_script(script_ops) -> bool:
'''Checking if contract script is an Atomic Swap contract.'''
try:
is_valid = (
script_ops[0] == script.OP_IF
and script_ops[1] == script.OP_RIPEMD160
and script_ops[3] == script_ops[15] == script.OP_EQUALVERIFY
and script_ops[4] == script_ops[11] == script.OP_DUP
and script_ops[5] == script_ops[12] == script.OP_HASH160
and script_ops[7] == script.OP_ELSE
and script_ops[9] == script.OP_CHECKLOCKTIMEVERIFY
and script_ops[10] == script.OP_DROP
and script_ops[14] == script.OP_ENDIF
and script_ops[16] == script.OP_CHECKSIG
)
except IndexError:
is_valid = False
return is_valid
示例3: mock_listunspent
# 需要导入模块: from bitcoin.core import script [as 别名]
# 或者: from bitcoin.core.script import OP_HASH160 [as 别名]
def mock_listunspent(self, addrs):
output1 = {'outpoint': COutPoint(lx('34eb81bc0d1a822369f75174fd4916b1ec490d8fbcba33168e820cc78a52f608'), 0),
'confirmations': 62952, 'address': P2PKHBitcoinAddress('mz7poFND7hVGRtPWjiZizcCnjf6wEDWjjT'),
'spendable': False, 'amount': 49000000, 'solvable': False, 'scriptPubKey': CScript(
[OP_DUP, OP_HASH160, x('cc0a909c4c83068be8b45d69b60a6f09c2be0fda'), OP_EQUALVERIFY, OP_CHECKSIG]),
'account': ''}
output2 = {'address': P2PKHBitcoinAddress('mz7poFND7hVGRtPWjiZizcCnjf6wEDWjjT'), 'amount': 2750, 'account': '',
'spendable': False, 'solvable': False, 'confirmations': 62932,
'outpoint': COutPoint(lx('6773785b4dc5d2cced67d26fc0820329307a8e10dfaef50d506924984387bf0b'), 1),
'scriptPubKey': CScript(
[OP_DUP, OP_HASH160, x('cc0a909c4c83068be8b45d69b60a6f09c2be0fda'), OP_EQUALVERIFY,
OP_CHECKSIG])}
output3 = {'address': P2PKHBitcoinAddress('mz7poFND7hVGRtPWjiZizcCnjf6wEDWjjT'), 'amount': 2750, 'account': '',
'spendable': False, 'solvable': False, 'confirmations': 62932,
'outpoint': COutPoint(lx('6773785b4dc5d2cced67d26fc0820329307a8e10dfaef50d506924984387bf0b'), 5),
'scriptPubKey': CScript(
[OP_DUP, OP_HASH160, x('cc0a909c4c83068be8b45d69b60a6f09c2be0fda'), OP_EQUALVERIFY,
OP_CHECKSIG])}
unspent_outputs = [output1, output2, output3]
return unspent_outputs
示例4: to_scriptPubKey
# 需要导入模块: from bitcoin.core import script [as 别名]
# 或者: from bitcoin.core.script import OP_HASH160 [as 别名]
def to_scriptPubKey(self):
"""Convert an address to a scriptPubKey"""
assert self.nVersion == bitcoin.params.BASE58_PREFIXES['SCRIPT_ADDR']
return script.CScript([script.OP_HASH160, self, script.OP_EQUAL])
示例5: get_first_vout_from_tx_json
# 需要导入模块: from bitcoin.core import script [as 别名]
# 或者: from bitcoin.core.script import OP_HASH160 [as 别名]
def get_first_vout_from_tx_json(cls, tx_json: dict) -> CTxOut:
'''
Adapter method for returning first vout.
Args:
tx_json (dict): dictionary with transaction details
Returns:
CTxOut: transaction output
'''
incorrect_cscript = script.CScript.fromhex(tx_json['outputs'][0]['script'])
correct_cscript = script.CScript([script.OP_HASH160, list(incorrect_cscript)[2], script.OP_EQUAL])
nValue = to_base_units(tx_json['outputs'][0]['amount'])
return CTxOut(nValue, correct_cscript)
示例6: get_hash160_from_cscript
# 需要导入模块: from bitcoin.core import script [as 别名]
# 或者: from bitcoin.core.script import OP_HASH160 [as 别名]
def get_hash160_from_cscript(self,script):
if script[0] == OP_DUP and script[1] == OP_HASH160 and script[-2] == OP_EQUALVERIFY and script[-1] == OP_CHECKSIG: #P2PKH
script = script[2:]
script = script[1:script[0]+1]
return self.convert_hash160_to_addr(script)
elif script[0] == OP_HASH160 and script[-1] == OP_EQUAL:#P2SH
script = script[1:]
script = script[1:script[0]+1]
return self.convert_hash160_to_addr(script,network_id=b'\x05') #Multi-Sign Address
elif script[-1] == OP_CHECKSIG: #V1 Validation With Public Key
return self.convert_hash160_to_addr(self.convert_public_key_to_hash160(script))
raise AttributeError("CScript Format not supported")
示例7: from_scriptPubKey
# 需要导入模块: from bitcoin.core import script [as 别名]
# 或者: from bitcoin.core.script import OP_HASH160 [as 别名]
def from_scriptPubKey(cls, scriptPubKey, accept_non_canonical_pushdata=True, accept_bare_checksig=True):
"""Convert a scriptPubKey to a P2PKH address
Raises CBitcoinAddressError if the scriptPubKey isn't of the correct
form.
accept_non_canonical_pushdata - Allow non-canonical pushes (default True)
accept_bare_checksig - Treat bare-checksig as P2PKH scriptPubKeys (default True)
"""
if accept_non_canonical_pushdata:
# Canonicalize script pushes
scriptPubKey = script.CScript(scriptPubKey) # in case it's not a CScript instance yet
try:
scriptPubKey = script.CScript(tuple(scriptPubKey)) # canonicalize
except bitcoin.core.script.CScriptInvalidError:
raise CBitcoinAddressError('not a P2PKH scriptPubKey: script is invalid')
if (len(scriptPubKey) == 25
and _bord(scriptPubKey[0]) == script.OP_DUP
and _bord(scriptPubKey[1]) == script.OP_HASH160
and _bord(scriptPubKey[2]) == 0x14
and _bord(scriptPubKey[23]) == script.OP_EQUALVERIFY
and _bord(scriptPubKey[24]) == script.OP_CHECKSIG):
return cls.from_bytes(scriptPubKey[3:23], bitcoin.params.BASE58_PREFIXES['PUBKEY_ADDR'])
elif accept_bare_checksig:
pubkey = None
# We can operate on the raw bytes directly because we've
# canonicalized everything above.
if (len(scriptPubKey) == 35 # compressed
and _bord(scriptPubKey[0]) == 0x21
and _bord(scriptPubKey[34]) == script.OP_CHECKSIG):
pubkey = scriptPubKey[1:34]
elif (len(scriptPubKey) == 67 # uncompressed
and _bord(scriptPubKey[0]) == 0x41
and _bord(scriptPubKey[66]) == script.OP_CHECKSIG):
pubkey = scriptPubKey[1:65]
if pubkey is not None:
return cls.from_pubkey(pubkey, accept_invalid=True)
raise CBitcoinAddressError('not a P2PKH scriptPubKey')
示例8: get_transaction
# 需要导入模块: from bitcoin.core import script [as 别名]
# 或者: from bitcoin.core.script import OP_HASH160 [as 别名]
def get_transaction(cls, tx_address: str) -> Optional[dict]:
'''
Getting transaction details.
Args:
tx_address (str): transaction address
Returns:
dict, None: dictionary with transaction details or None if transaction doesn't exist
Example:
>>> from clove.network import Bitcoin
>>> network = Bitcoin()
>>> network.get_transaction('a82213fd237a2b4bf05c805611dc913125aef138bf2874f0668133a4bb5f3b64')
{'blockhash': '0000000000000000000e2d8d964b4da69f2f30b79aaa58597848719bf0b86a1b',
'blockheight': 544987,
'blocktime': 1539068621,
'confirmations': 3,
'fees': 0.0011,
'locktime': 0,
'size': 192,
'time': 1539068621,
'txid': 'a82213fd237a2b4bf05c805611dc913125aef138bf2874f0668133a4bb5f3b64',
'valueIn': 0.60725408,
'valueOut': 0.60615408,
'version': 1,
'vin': [{'addr': '163o7ig87TnUnp1QF1rBrsjU1uhfEW9nNU',
'doubleSpentTxID': None,
'n': 0,
'scriptSig': {
'asm': '3045022100ad5db8c05d7f702c8328ae5a817a13dd7f0fda876e3bb3b7729b041bb612275502200af30b833c06c8485ccec95de48c2238a4ffa4e4820dd6466b95dc5d26e883ae[ALL] 03b504de54d5940a81cf5f8c483025c6f39bfc7eed60a022549513fd8d6e41d74f', # noqa: E50
'hex': '483045022100ad5db8c05d7f702c8328ae5a817a13dd7f0fda876e3bb3b7729b041bb612275502200af30b833c06c8485ccec95de48c2238a4ffa4e4820dd6466b95dc5d26e883ae012103b504de54d5940a81cf5f8c483025c6f39bfc7eed60a022549513fd8d6e41d74f'}, # noqa: E501
'sequence': 4294967295,
'txid': '101cc115cc6882e1fd150c35efd056d18a73c12a3321c406960844561922dfc0',
'value': 0.60725408,
'valueSat': 60725408,
'vout': 0}],
'vout': [{'n': 0,
'scriptPubKey': {'addresses': ['13xMGnw7sTTVXT26YpfZQkk2rvuvJFoMvi'],
'asm': 'OP_DUP OP_HASH160 20680d49e72e1de6af9a0180b3293f2cbd0d0666 OP_EQUALVERIFY OP_CHECKSIG',
'hex': '76a91420680d49e72e1de6af9a0180b3293f2cbd0d066688ac',
'type': 'pubkeyhash'},
'spentHeight': None,
'spentIndex': None,
'spentTxId': None,
'value': '0.60615408'}]}
'''
return clove_req_json(f'{cls.cryptoid_url()}/api.dws?q=txinfo&t={tx_address}')
示例9: from_scriptPubKey
# 需要导入模块: from bitcoin.core import script [as 别名]
# 或者: from bitcoin.core.script import OP_HASH160 [as 别名]
def from_scriptPubKey(cls, scriptPubKey, accept_non_canonical_pushdata=True, accept_bare_checksig=True):
"""Convert a scriptPubKey to a P2PKH address
Raises CBitcoinAddressError if the scriptPubKey isn't of the correct
form.
accept_non_canonical_pushdata - Allow non-canonical pushes (default True)
accept_bare_checksig - Treat bare-checksig as P2PKH scriptPubKeys (default True)
"""
if accept_non_canonical_pushdata:
# Canonicalize script pushes
scriptPubKey = script.CScript(scriptPubKey) # in case it's not a CScript instance yet
try:
scriptPubKey = script.CScript(tuple(scriptPubKey)) # canonicalize
except bitcoin.core.script.CScriptInvalidError:
raise CBitcoinAddressError('not a P2PKH scriptPubKey: script is invalid')
if scriptPubKey.is_witness_v0_keyhash():
return cls.from_bytes(scriptPubKey[2:22], bitcoin.params.BASE58_PREFIXES['PUBKEY_ADDR'])
elif scriptPubKey.is_witness_v0_nested_keyhash():
return cls.from_bytes(scriptPubKey[3:23], bitcoin.params.BASE58_PREFIXES['PUBKEY_ADDR'])
elif (len(scriptPubKey) == 25
and _bord(scriptPubKey[0]) == script.OP_DUP
and _bord(scriptPubKey[1]) == script.OP_HASH160
and _bord(scriptPubKey[2]) == 0x14
and _bord(scriptPubKey[23]) == script.OP_EQUALVERIFY
and _bord(scriptPubKey[24]) == script.OP_CHECKSIG):
return cls.from_bytes(scriptPubKey[3:23], bitcoin.params.BASE58_PREFIXES['PUBKEY_ADDR'])
elif accept_bare_checksig:
pubkey = None
# We can operate on the raw bytes directly because we've
# canonicalized everything above.
if (len(scriptPubKey) == 35 # compressed
and _bord(scriptPubKey[0]) == 0x21
and _bord(scriptPubKey[34]) == script.OP_CHECKSIG):
pubkey = scriptPubKey[1:34]
elif (len(scriptPubKey) == 67 # uncompressed
and _bord(scriptPubKey[0]) == 0x41
and _bord(scriptPubKey[66]) == script.OP_CHECKSIG):
pubkey = scriptPubKey[1:65]
if pubkey is not None:
return cls.from_pubkey(pubkey, accept_invalid=True)
raise CBitcoinAddressError('not a P2PKH scriptPubKey')