本文整理汇总了Python中pycoin.tx.script.tools.compile函数的典型用法代码示例。如果您正苦于以下问题:Python compile函数的具体用法?Python compile怎么用?Python compile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了compile函数的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: test_nulldata
def test_nulldata(self):
OP_RETURN = tools.compile("OP_RETURN")
# note that because chr() is used samples with length > 255 will not work
for sample in [b'test', b'me', b'a', b'39qEwuwyb2cAX38MFtrNzvq3KV9hSNov3q', b'', b'0'*80]:
sample_script = OP_RETURN + tools.bin_script([sample])
nd = ScriptNulldata(sample)
self.assertEqual(nd.nulldata, sample)
self.assertEqual(nd.script(), sample_script)
nd2 = ScriptNulldata.from_script(sample_script)
self.assertEqual(nd.nulldata, nd2.nulldata)
out = TxOut(1, nd.script())
tx = Tx(0, [], [out]) # ensure we can create a tx
self.assertEqual(nd.script(), tools.compile(tools.disassemble(nd.script()))) # convert between asm and back to ensure no bugs with compilation
开发者ID:Stevengu999,项目名称:pycoin,代码行数:13,代码来源:pay_to_test.py
示例3: f
def f(self):
script_in_bin = compile(script_in)
script_out_bin = compile(script_out)
flags = parse_flags(flags_string)
try:
credit_tx = build_credit_tx(script_out_bin)
spend_tx = build_spending_tx(script_in_bin, credit_tx)
r = spend_tx.is_signature_ok(tx_in_idx=0, flags=flags)
except ScriptError:
r = False
except:
r = -1
if r != expect_valid:
dump_failure_info(spend_tx, script_in, script_out, flags, comment)
self.assertEqual(r, expect_valid)
开发者ID:DomSteil,项目名称:pycoin,代码行数:15,代码来源:vm_script_test.py
示例4: 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
示例5: 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
示例6: 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
示例7: 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
示例8: test_issue_225
def test_issue_225(self):
script = tools.compile("OP_RETURN 'foobar'")
tx_out = TxOut(1, script)
address = tx_out.bitcoin_address(netcode="XTN")
self.assertEqual(address, "(nulldata 666f6f626172)")
address = tx_out.bitcoin_address(netcode="BTC")
self.assertEqual(address, "(nulldata 666f6f626172)")
开发者ID:onestarshang,项目名称:pycoin,代码行数:7,代码来源:pay_to_test.py
示例9: 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
示例10: add_coins
def add_coins(self):
script = tools.compile(
"OP_DUP OP_HASH160 {0} OP_EQUALVERIFY OP_CHECKSIG".format(
self.address0.rawPubkey().encode("hex"))).encode("hex")
self.model.utxo_man.store.add_utxo(self.addr0, self.txhash,
0, 100, script)
script = tools.compile(
"OP_DUP OP_HASH160 {0} OP_EQUALVERIFY OP_CHECKSIG".format(
self.baddress.rawPubkey().encode("hex"))).encode("hex")
self.model.utxo_man.store.add_utxo(self.baddr, self.txhash,
1, 20000, script)
self.model.ccc.metastore.set_as_scanned(self.colorid0, self.blockhash)
self.model.ccc.cdstore.add(self.colorid0, self.txhash, 0, 100, '')
开发者ID:Andymeows,项目名称:ngcccbase,代码行数:16,代码来源:test_txcons.py
示例11: solve_timeout
def solve_timeout(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"]
)
return tools.compile("{sig} OP_0 OP_0".format(sig=b2h(sig)))
开发者ID:super3,项目名称:picopayments,代码行数:8,代码来源:scripts.py
示例12: setUp
def setUp(self):
self.path = ":memory:"
self.config = {'dw_master_key': 'test', 'testnet': True, 'ccc': {
'colordb_path' : self.path
}, 'bip0032': False }
self.pwallet = PersistentWallet(self.path, self.config)
self.pwallet.init_model()
self.model = self.pwallet.get_model()
self.wc = WalletController(self.model)
self.wc.testing = True
self.wc.debug = True
self.colormap = self.model.get_color_map()
self.bcolorset = ColorSet(self.colormap, [''])
wam = self.model.get_address_manager()
self.baddress = wam.get_new_address(self.bcolorset)
self.baddr = self.baddress.get_address()
self.blockhash = '00000000c927c5d0ee1ca362f912f83c462f644e695337ce3731b9f7c5d1ca8c'
self.txhash = '4fe45a5ba31bab1e244114c4555d9070044c73c98636231c77657022d76b87f7'
script = tools.compile(
"OP_DUP OP_HASH160 {0} OP_EQUALVERIFY OP_CHECKSIG".format(
self.baddress.rawPubkey().encode("hex"))).encode("hex")
self.model.utxo_man.store.add_utxo(self.baddr, self.txhash,
0, 100, script)
script = tools.compile(
"OP_DUP OP_HASH160 {0} OP_EQUALVERIFY OP_CHECKSIG".format(
self.baddress.rawPubkey().encode("hex"))).encode("hex")
self.model.utxo_man.store.add_utxo(self.baddr, self.txhash,
1, 1000000000, script)
self.model.ccc.blockchain_state.bitcoind = MockBitcoinD('test')
def x(s):
return self.blockhash, True
self.model.ccc.blockchain_state.get_tx_blockhash = x
self.moniker = 'test'
self.wc.issue_coins(self.moniker, 'obc', 10000, 1)
self.asset = self.model.get_asset_definition_manager(
).get_asset_by_moniker(self.moniker)
self.basset = self.model.get_asset_definition_manager(
).get_asset_by_moniker('bitcoin')
self.color_id = list(self.asset.color_set.color_id_set)[0]
self.model.ccc.metastore.set_as_scanned(self.color_id, self.blockhash)
开发者ID:MattFaus,项目名称:ngcccbase,代码行数:46,代码来源:test_wallet_controller.py
示例13: txout
def txout(testnet, targetaddress, value):
testnet = flag(testnet)
targetaddress = address(testnet, targetaddress)
value = positive_integer(value)
prefix = b'\x6f' if testnet else b"\0"
hash160 = b2h(bitcoin_address_to_hash160_sec(targetaddress, prefix))
script_text = "OP_DUP OP_HASH160 %s OP_EQUALVERIFY OP_CHECKSIG" % hash160
script_bin = tools.compile(script_text)
return TxOut(value, script_bin)
开发者ID:NinjaDevelper,项目名称:btctxstore,代码行数:9,代码来源:deserialize.py
示例14: main
def main():
the_hash = sys.argv[1]
j = get_json_for_hash(the_hash)
txs_in = []
for j_in in j.get("in"):
txs_in.append(
TxIn(h2b_rev(j_in["prev_out"]["hash"]), int(j_in["prev_out"]["n"]), tools.compile(j_in["scriptSig"]))
)
txs_out = []
for j_out in j.get("out"):
txs_out.append(TxOut(int(float(j_out["value"]) * 1e8 + 0.5), tools.compile(j_out["scriptPubKey"])))
tx = Tx(int(j["ver"]), txs_in, txs_out, int(j["lock_time"]))
assert tx.id() == the_hash
s = io.BytesIO()
tx.stream(s)
v = s.getvalue()
print(linebreak(binascii.b2a_base64(v).decode("utf8"), 72))
开发者ID:j3itchtits,项目名称:pycoin,代码行数:19,代码来源:Tx_from_hash.py
示例15: compile_commit_script
def compile_commit_script(payer_pubkey, payee_pubkey, spend_secret_hash,
revoke_secret_hash, delay_time):
script_text = COMMIT_SCRIPT.format(
payer_pubkey=payer_pubkey,
payee_pubkey=payee_pubkey,
spend_secret_hash=spend_secret_hash,
revoke_secret_hash=revoke_secret_hash,
delay_time=str(delay_time)
)
return tools.compile(script_text)
开发者ID:super3,项目名称:picopayments,代码行数:10,代码来源:scripts.py
示例16: __init__
def __init__(self, secret_exponents):
super(OfflineAwareSolver, self).__init__(secret_exponents)
STANDARD_SCRIPT_OUT = "OP_DUP OP_HASH160 %s OP_EQUALVERIFY OP_CHECKSIG"
self.script_hash160 = []
for se in secret_exponents:
pp = public_pair_for_secret_exponent(generator_secp256k1, se)
h160sec = public_pair_to_hash160_sec(pp, False)
script_text = STANDARD_SCRIPT_OUT % b2h(h160sec)
print script_text
self.script_hash160.append(compile(script_text))
开发者ID:nelisky,项目名称:pycoin,代码行数:10,代码来源:proxy.py
示例17: 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
示例18: fake_transaction
def fake_transaction(model=MockModel()):
key = "5Kb8kLf9zgWQnogidDA76MzPL6TsZZY36hWXMssSzNydYXYB9KF"
address = LooseAddressRecord(address_data=key)
script = tools.compile(
"OP_DUP OP_HASH160 {0} OP_EQUALVERIFY OP_CHECKSIG".format(
address.rawPubkey().encode("hex"))).encode("hex")
txin = utxodb.UTXO("D34DB33F", 0, 1, script)
txin.address_rec = address
txout = txspec.ComposedTxSpec.TxOut(1, address.get_address())
composed = txspec.ComposedTxSpec([txin], [txout])
return txcons.RawTxSpec.from_composed_tx_spec(model, composed), address
开发者ID:MattFaus,项目名称:ngcccbase,代码行数:13,代码来源:test_txdb.py
示例19: __call__
def __call__(self, tx_out_script, signature_hash, signature_type):
"""Figure out how to create a signature for the incoming transaction, and sign it.
tx_out_script: the tx_out script that needs to be "solved"
signature_hash: the bignum hash value of the new transaction reassigning the coins
signature_type: always SIGHASH_ALL (1)
"""
if signature_hash == 0:
raise SolvingError("signature_hash can't be 0")
tx_script = TxScript(tx_out_script)
opcode_value_list = tx_script.match_script_to_templates()
ba = bytearray()
compressed = True
for opcode, v in opcode_value_list:
if opcode == opcodes.OP_PUBKEY:
public_pair = sec_to_public_pair(v)
bitcoin_address = public_pair_to_bitcoin_address(public_pair, compressed=compressed)
elif opcode == opcodes.OP_PUBKEYHASH:
bitcoin_address = hash160_sec_to_bitcoin_address(v)
else:
raise SolvingError("can't determine how to sign this script")
secret_exponent = self.wallet.getsecretexponent(bitcoin_address)
r, s = ecdsa.sign(ecdsa.generator_secp256k1, secret_exponent, signature_hash)
sig = der.sigencode_der(r, s) + bytes_from_int(signature_type)
ba += tools.compile(binascii.hexlify(sig).decode("utf8"))
if opcode == opcodes.OP_PUBKEYHASH:
public_pair = ecdsa.public_pair_for_secret_exponent(ecdsa.generator_secp256k1, secret_exponent)
ba += tools.compile(
binascii.hexlify(public_pair_to_sec(public_pair, compressed=compressed)).decode("utf8")
)
return bytes(ba)
开发者ID:CounterpartyXCP,项目名称:pyrpcwallet,代码行数:38,代码来源:secret_exponent_solver.py
示例20: construct_standard_tx
def construct_standard_tx(composed_tx_spec, is_test):
txouts = []
STANDARD_SCRIPT_OUT = "OP_DUP OP_HASH160 %s OP_EQUALVERIFY OP_CHECKSIG"
for txout in composed_tx_spec.get_txouts():
hash160 = bitcoin_address_to_hash160_sec(txout.target_addr, is_test)
script_text = STANDARD_SCRIPT_OUT % b2h(hash160)
script_bin = tools.compile(script_text)
txouts.append(TxOut(txout.value, script_bin))
txins = []
for cts_txin in composed_tx_spec.get_txins():
txins.append(TxIn(cts_txin.get_txhash(), cts_txin.prevout.n))
version = 1
lock_time = 0
return Tx(version, txins, txouts, lock_time)
开发者ID:hankhero,项目名称:ngcccbase,代码行数:14,代码来源:pycoin_txcons.py
注:本文中的pycoin.tx.script.tools.compile函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论