本文整理汇总了Python中pycoin.tx.Tx类的典型用法代码示例。如果您正苦于以下问题:Python Tx类的具体用法?Python Tx怎么用?Python Tx使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Tx类的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: process_tx_initial
def process_tx_initial(tx_obj: Tx):
found_relevant_address = False
for out in tx_obj.txs_out:
address = out.bitcoin_address()
if address in all_addresses:
found_relevant_address = True
break
if not found_relevant_address:
logging.info('Found irrelevant tx %s' % hash_to_hex(tx_obj.hash()))
return
tx_hash = tx_obj.hash()
txid = hash_to_hex(tx_hash).decode()
if tx_hash in known_txs:
return
known_txs.add(tx_hash)
txs[tx_hash] = tx_obj.as_hex()
for out in tx_obj.txs_out:
address = out.bitcoin_address()
if address in all_addresses and address is not None:
unprocessed_txs.add(tx_hash)
uid = addr_to_uid[address]
account = Account(uid)
account.txs.add(tx_hash)
account.unconf_minutes.incr(calc_node_minutes(satoshi_amount=out.coin_value, exchange_rate=exchange_rate.get()))
account.add_msg('Found tx for %.08f, %s' % (out.coin_value / COIN, txid))
nodes_recently_updated.append(account.uid)
开发者ID:rnicoll,项目名称:nodeup-xk-io,代码行数:27,代码来源:wallet.py
示例3: multisig_M_of_N_individually
def multisig_M_of_N_individually(self, M, N):
keys = [Key(secret_exponent=i) for i in range(1, N+2)]
tx_in = TxIn.coinbase_tx_in(script=b'')
script = ScriptMultisig(n=M, sec_keys=[key.sec() for key in keys[:N]]).script()
tx_out = TxOut(1000000, script)
tx1 = Tx(version=1, txs_in=[tx_in], txs_out=[tx_out])
for partial_key_list in itertools.permutations(keys[:N], M):
tx2 = tx_utils.create_tx(tx1.tx_outs_as_spendable(), [keys[-1].address()])
for key in partial_key_list:
self.assertEqual(tx2.bad_signature_count(), 1)
hash160_lookup = build_hash160_lookup([key.secret_exponent()])
tx2.sign(hash160_lookup=hash160_lookup)
self.assertEqual(tx2.bad_signature_count(), 0)
开发者ID:Stevengu999,项目名称:pycoin,代码行数:13,代码来源:pay_to_multisig.py
示例4: multisig_N_of_M
def multisig_N_of_M(self, N, M, unsigned_id, signed_id):
keys = [Key(secret_exponent=i) for i in range(1, M+2)]
tx_in = TxIn.coinbase_tx_in(script=b'')
script = ScriptMultisig(n=N, sec_keys=[key.sec() for key in keys[:M]]).script()
tx_out = TxOut(1000000, script)
tx1 = Tx(version=1, txs_in=[tx_in], txs_out=[tx_out])
tx2 = tx_utils.create_tx(tx1.tx_outs_as_spendable(), [keys[-1].address()])
self.assertEqual(tx2.id(), unsigned_id)
self.assertEqual(tx2.bad_signature_count(), 1)
hash160_lookup = build_hash160_lookup(key.secret_exponent() for key in keys)
tx2.sign(hash160_lookup=hash160_lookup)
self.assertEqual(tx2.id(), signed_id)
self.assertEqual(tx2.bad_signature_count(), 0)
开发者ID:Bluejudy,项目名称:pycoin,代码行数:13,代码来源:pay_to_test.py
示例5: test_sign_pay_to_script_multisig
def test_sign_pay_to_script_multisig(self):
N, M = 3, 3
keys = [Key(secret_exponent=i) for i in range(1, M+2)]
tx_in = TxIn.coinbase_tx_in(script=b'')
underlying_script = ScriptMultisig(n=N, sec_keys=[key.sec() for key in keys[:M]]).script()
address = address_for_pay_to_script(underlying_script)
self.assertEqual(address, "39qEwuwyb2cAX38MFtrNzvq3KV9hSNov3q")
script = standard_tx_out_script(address)
tx_out = TxOut(1000000, script)
tx1 = Tx(version=1, txs_in=[tx_in], txs_out=[tx_out])
tx2 = tx_utils.create_tx(tx1.tx_outs_as_spendable(), [address])
hash160_lookup = build_hash160_lookup(key.secret_exponent() for key in keys[:M])
p2sh_lookup = build_p2sh_lookup([underlying_script])
tx2.sign(hash160_lookup=hash160_lookup, p2sh_lookup=p2sh_lookup)
self.assertEqual(tx2.bad_signature_count(), 0)
开发者ID:Bluejudy,项目名称:pycoin,代码行数:15,代码来源:pay_to_test.py
示例6: main
def main():
if len(sys.argv) != 2:
print("usage: %s address" % sys.argv[0])
sys.exit(-1)
# validate the address
address = sys.argv[1]
assert is_address_valid(address)
print("creating coinbase transaction to %s" % address)
tx_in = TxIn.coinbase_tx_in(script=b'')
tx_out = TxOut(50*1e8, standard_tx_out_script(address))
tx = Tx(1, [tx_in], [tx_out])
print("Here is the tx as hex:\n%s" % tx.as_hex())
开发者ID:Stevengu999,项目名称:pycoin,代码行数:15,代码来源:2-create-coinbase-tx.py
示例7: standard_tx
def standard_tx(coins_from, coins_to):
txs_in = []
unspents = []
for h, idx, tx_out in coins_from:
txs_in.append(TxIn(h, idx))
unspents.append(tx_out)
txs_out = []
for coin_value, bitcoin_address in coins_to:
txs_out.append(TxOut(coin_value, standard_tx_out_script(bitcoin_address)))
version, lock_time = 1, 0
tx = Tx(version, txs_in, txs_out, lock_time)
tx.set_unspents(unspents)
return tx
开发者ID:Bluejudy,项目名称:pycoin,代码行数:15,代码来源:build_tx_test.py
示例8: broadcastTransaction
def broadcastTransaction (self, transaction):
print (transaction)
t = Tx.tx_from_hex (transaction)
deserializer = serializers.TxSerializer ()
tx = deserializer.deserialize (BytesIO (bytearray.fromhex(transaction)))
h = t.id ()
print ('BROADCAST:', str (tx.calculate_hash ())[2:-1], h)
#try:
# t = Tx.tx_from_hex (transaction)
# print ('OMG',t.id ())
#except Exception as e:
# print (e)
if not h in self.db['mempool']:
mp = self.db['mempool']
mp[h] = tx
self.db['mempool'] = mp
self.db.sync ()
self.mempooltimer = Timer (1.0, self.announceTransactions)
self.mempooltimer.start ()
return h
开发者ID:openbitlab,项目名称:bitpeer.py,代码行数:25,代码来源:node.py
示例9: 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
示例10: get_tx
def get_tx(self, tx_hash):
URL = "%s/api/rawtx/%s" % (self.base_url, b2h_rev(tx_hash))
r = json.loads(urlopen(URL).read().decode("utf8"))
tx = Tx.tx_from_hex(r['rawtx'])
if tx.hash() == tx_hash:
return tx
return None
开发者ID:NinjaDevelper,项目名称:btctxstore,代码行数:7,代码来源:insight.py
示例11: sign_tx
def sign_tx(certificate_metadata, last_input, allowable_wif_prefixes=None):
"""sign the transaction with private key"""
with open(certificate_metadata.unsigned_tx_file_name, 'rb') as in_file:
hextx = str(in_file.read(), 'utf-8')
logging.info(
'Signing tx with private key for recipient id: %s ...', certificate_metadata.uid)
tx = Tx.from_hex(hextx)
if allowable_wif_prefixes:
wif = wif_to_secret_exponent(
helpers.import_key(), allowable_wif_prefixes)
else:
wif = wif_to_secret_exponent(helpers.import_key())
lookup = build_hash160_lookup([wif])
tx.set_unspents(
[TxOut(coin_value=last_input.amount, script=last_input.script_pub_key)])
signed_tx = tx.sign(lookup)
signed_hextx = signed_tx.as_hex()
with open(certificate_metadata.unsent_tx_file_name, 'wb') as out_file:
out_file.write(bytes(signed_hextx, 'utf-8'))
logging.info('Finished signing transaction for certificate uid=%s',
certificate_metadata.uid)
开发者ID:Akiiki,项目名称:cert-issuer,代码行数:27,代码来源:create_certificates.py
示例12: get_tx
def get_tx(self, tx_hash):
url = "%s/rawtx/%s" % (self.base_url, b2h_rev(tx_hash))
result = json.loads(urlopen(url).read().decode("utf8"))
tx = Tx.from_hex(result["rawtx"])
if tx.hash() == tx_hash:
return tx
return None
开发者ID:StorjOld,项目名称:btctxstore,代码行数:7,代码来源:blockexplorer.py
示例13: check_unprocessed
def check_unprocessed(top_height):
for tx_hash in unprocessed_txs.members():
txid = hash_to_hex(tx_hash).decode()
tx = Tx.tx_from_hex(txs[tx_hash].decode())
tx_blockchain = get_tx(txid)
logging.info('Checking %s' % txid)
if tx_blockchain.block_height == -1:
continue
if top_height - tx_blockchain.block_height + 1 >= REQUIRED_CONFIRMATIONS: # off by one error - if tx in top block that is 1 conf
unprocessed_txs.remove(tx_hash)
for out in tx.txs_out:
address = out.bitcoin_address()
if address not in all_addresses:
continue
account = Account(addr_to_uid[address])
satoshis = out.coin_value
satoshis = int(satoshis / (1 + account.tip.get())) # scale for tip
account.total_coins.incr(satoshis)
node_minutes_d = calc_node_minutes(satoshis, exchange_rate=exchange_rate.get())
account.total_minutes.incr(node_minutes_d)
total_nodeminutes.incr(node_minutes_d)
nodes_recently_updated.append(account.uid)
account.add_msg('Detected payment via txid: %s' % (txid,))
account.add_msg('Increased total paid by %.8f to %.8f (considering tip of %d %%)' % (satoshis / COIN, account.total_coins.get() / COIN, account.tip.get() * 100))
account.add_msg('Increased node life by %d minutes; expiring around %s' % (node_minutes_d, account.get_expiry().isoformat()))
开发者ID:XertroV,项目名称:nodeup-xk-io,代码行数:25,代码来源:monitor_payments.py
示例14: test_validate_multisig
def test_validate_multisig(self):
# this is a transaction in the block chain
# the unspents are included too, so it can be validated
f = io.BytesIO(h2b("01000000025718fb915fb8b3a802bb699ddf04dd91261ef6715f5f2820a2b1b9b7e38b4f27000000004a004830450221008c2107ed4e026ab4319a591e8d9ec37719cdea053951c660566e3a3399428af502202ecd823d5f74a77cc2159d8af2d3ea5d36a702fef9a7edaaf562aef22ac35da401ffffffff038f52231b994efb980382e4d804efeadaee13cfe01abe0d969038ccb45ec17000000000490047304402200487cd787fde9b337ab87f9fe54b9fd46d5d1692aa58e97147a4fe757f6f944202203cbcfb9c0fc4e3c453938bbea9e5ae64030cf7a97fafaf460ea2cb54ed5651b501ffffffff0100093d00000000001976a9144dc39248253538b93d3a0eb122d16882b998145888ac0000000002000000000000004751210351efb6e91a31221652105d032a2508275f374cea63939ad72f1b1e02f477da782100f2b7816db49d55d24df7bdffdbc1e203b424e8cd39f5651ab938e5e4a193569e52ae404b4c00000000004751210351efb6e91a31221652105d032a2508275f374cea63939ad72f1b1e02f477da7821004f0331742bbc917ba2056a3b8a857ea47ec088dd10475ea311302112c9d24a7152ae"))
tx = Tx.parse(f)
tx.parse_unspents(f)
self.assertEqual(tx.id(), "70c4e749f2b8b907875d1483ae43e8a6790b0c8397bbb33682e3602617f9a77a")
self.assertEqual(tx.bad_signature_count(), 0)
开发者ID:Bluejudy,项目名称:pycoin,代码行数:8,代码来源:pay_to_test.py
示例15: get_tx
def get_tx(tx_hash):
"""
Get a Tx by its hash.
"""
URL = "http://btc.blockr.io/api/v1/tx/raw/%s" % b2h_rev(tx_hash)
r = json.loads(urlopen(URL).read().decode("utf8"))
tx = Tx.parse(io.BytesIO(h2b(r.get("data").get("tx").get("hex"))))
return tx
开发者ID:Bluejudy,项目名称:pycoin,代码行数:8,代码来源:blockr_io.py
示例16: get_tx
def get_tx(tx_hash):
"""
Get a Tx by its hash.
"""
URL = "%s/tx/raw/%s" % (blockrendpoint.url, b2h_rev(tx_hash))
r = json.loads(urlopen(URL).read().decode("utf8"))
tx = Tx.parse(io.BytesIO(h2b(r.get("data").get("tx").get("hex"))))
return tx
开发者ID:newexo,项目名称:pycoin,代码行数:8,代码来源:blockr_io.py
示例17: main
def main():
tx = Tx.tx_from_hex(sys.argv[1])
print('Input Scripts:')
for inp in tx.txs_in:
print(' - ' + disassemble(inp.script))
print('Output Scripts:')
for out in tx.txs_out:
print(' - ' + disassemble(out.script))
开发者ID:superscud,项目名称:multisig-core,代码行数:8,代码来源:decode_tx_scripts.py
示例18: write_opreturn
def write_opreturn(bitcoin_address, bitcoin_private_key, raw_message, fee=5000, push=False):
message = hexlify(raw_message.encode()).decode('utf8')
spendables = spendables_for_address(bitcoin_address)
spendables = [s for s in spendables]
bitcoin_sum = sum([spendable.coin_value for spendable in spendables])
inputs = [spendable.tx_in() for spendable in spendables]
outputs = []
if (bitcoin_sum > fee):
change_output_script = standard_tx_out_script(bitcoin_address)
print change_output_script
outputs.append(TxOut(bitcoin_sum - fee, change_output_script))
## Build the OP_RETURN output with our message
op_return_output_script = script.tools.compile("OP_RETURN %s" % message)
outputs.append(TxOut(0, op_return_output_script))
## Create the transaction and sign it with the private key
tx = Tx(version=1, txs_in=inputs, txs_out=outputs)
tx.set_unspents(spendables)
sign_tx(tx, wifs=[bitcoin_private_key])
print tx.as_hex()
if not push:
return tx.as_hex()
else:
pushtx(tx.as_hex())
else:
print "INADEQUATE FUNDS"
开发者ID:barisser,项目名称:chainscribe,代码行数:27,代码来源:txs.py
示例19: test_build_spends
def test_build_spends(self):
# first, here is the tx database
TX_DB = {}
# create a coinbase Tx where we know the public & private key
exponent = wif_to_secret_exponent("5JMys7YfK72cRVTrbwkq5paxU7vgkMypB55KyXEtN5uSnjV7K8Y")
compressed = False
public_key_sec = public_pair_to_sec(
ecdsa.public_pair_for_secret_exponent(ecdsa.generator_secp256k1, exponent), compressed=compressed
)
the_coinbase_tx = Tx.coinbase_tx(public_key_sec, int(50 * 1e8), COINBASE_BYTES_FROM_80971)
TX_DB[the_coinbase_tx.hash()] = the_coinbase_tx
# now create a Tx that spends the coinbase
compressed = False
exponent_2 = int("137f3276686959c82b454eea6eefc9ab1b9e45bd4636fb9320262e114e321da1", 16)
bitcoin_address_2 = public_pair_to_bitcoin_address(
ecdsa.public_pair_for_secret_exponent(ecdsa.generator_secp256k1, exponent_2), compressed=compressed
)
self.assertEqual("12WivmEn8AUth6x6U8HuJuXHaJzDw3gHNZ", bitcoin_address_2)
coins_from = [(the_coinbase_tx.hash(), 0, the_coinbase_tx.txs_out[0])]
coins_to = [(int(50 * 1e8), bitcoin_address_2)]
unsigned_coinbase_spend_tx = standard_tx(coins_from, coins_to)
solver = build_hash160_lookup([exponent])
coinbase_spend_tx = unsigned_coinbase_spend_tx.sign(solver)
# now check that it validates
self.assertEqual(coinbase_spend_tx.bad_signature_count(), 0)
TX_DB[coinbase_spend_tx.hash()] = coinbase_spend_tx
## now try to respend from priv_key_2 to priv_key_3
compressed = True
exponent_3 = int("f8d39b8ecd0e1b6fee5a340519f239097569d7a403a50bb14fb2f04eff8db0ff", 16)
bitcoin_address_3 = public_pair_to_bitcoin_address(
ecdsa.public_pair_for_secret_exponent(ecdsa.generator_secp256k1, exponent_3), compressed=compressed
)
self.assertEqual("13zzEHPCH2WUZJzANymow3ZrxcZ8iFBrY5", bitcoin_address_3)
coins_from = [(coinbase_spend_tx.hash(), 0, coinbase_spend_tx.txs_out[0])]
unsigned_spend_tx = standard_tx(coins_from, [(int(50 * 1e8), bitcoin_address_3)])
solver.update(build_hash160_lookup([exponent_2]))
spend_tx = unsigned_spend_tx.sign(solver)
# now check that it validates
self.assertEqual(spend_tx.bad_signature_count(), 0)
开发者ID:mperklin,项目名称:pycoin,代码行数:57,代码来源:build_tx_test.py
示例20: get_tx
def get_tx(self, tx_hash):
"""
Get a Tx by its hash.
"""
url_append = "tx/raw/%s" %(tx_hash)
URL = self.base_url("%s" %url_append)
r = json.loads(urlopen(URL).read().decode("utf8"))
tx = Tx.parse(io.BytesIO(h2b(r.get("data").get("tx").get("hex"))))
return tx
开发者ID:shayanb,项目名称:pycoin,代码行数:9,代码来源:blockr_io.py
注:本文中的pycoin.tx.Tx类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论