本文整理汇总了Python中pycoin.tx.Tx.Tx类的典型用法代码示例。如果您正苦于以下问题:Python Tx类的具体用法?Python Tx怎么用?Python Tx使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Tx类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: store_nulldata
def store_nulldata(service, testnet, nulldatatxout, keys,
changeaddress=None, txouts=None, fee=10000,
locktime=0, publish=True):
# get required satoshis
txouts = txouts if txouts else []
required = sum(list(map(lambda txout: txout.coin_value, txouts))) + fee
# get txins
addresses = list(map(lambda key: key.address(), keys))
txins, total = find_txins(service, addresses, required)
if total < required:
raise exceptions.InsufficientFunds(required, total)
# setup txouts
changeaddress = changeaddress if changeaddress else addresses[0]
changeout = deserialize.txout(testnet, changeaddress, total - required)
txouts = txouts + [nulldatatxout, changeout]
# create, sign and publish tx
tx = Tx(1, txins, txouts, locktime)
tx = sign_tx(service, testnet, tx, keys)
if publish:
service.send_tx(tx)
return tx.hash()
开发者ID:NinjaDevelper,项目名称:btctxstore,代码行数:25,代码来源:control.py
示例2: 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:onestarshang,项目名称:pycoin,代码行数:30,代码来源:insight.py
示例3: check_bip143_tx
def check_bip143_tx(self, tx_u_hex, tx_s_hex, txs_out_value_scripthex_pair, tx_in_count, tx_out_count, version, lock_time):
tx_u = Tx.from_hex(tx_u_hex)
tx_s = Tx.from_hex(tx_s_hex)
txs_out = [
TxOut(int(coin_value * 1e8), h2b(script_hex)) for coin_value, script_hex in txs_out_value_scripthex_pair
]
for tx in (tx_u, tx_s):
self.assertEqual(len(tx.txs_in), tx_in_count)
self.assertEqual(len(tx.txs_out), tx_out_count)
self.assertEqual(tx.version, version)
self.assertEqual(tx.lock_time, lock_time)
tx.set_unspents(txs_out)
self.check_unsigned(tx_u)
self.check_signed(tx_s)
tx_hex = tx_u.as_hex()
self.assertEqual(tx_hex, tx_u_hex)
tx_hex = tx_s.as_hex()
self.assertEqual(tx_hex, tx_s_hex)
tx_u_prime = self.unsigned_copy(tx_s)
tx_hex = tx_u_prime.as_hex()
self.assertEqual(tx_hex, tx_u_hex)
self.assertEqual(b2h_rev(double_sha256(h2b(tx_s_hex))), tx_s.w_id())
self.assertEqual(b2h_rev(double_sha256(h2b(tx_u_hex))), tx_u.w_id())
self.assertEqual(b2h_rev(double_sha256(h2b(tx_u_hex))), tx_u.id())
return tx_u, tx_s
开发者ID:Stevengu999,项目名称:pycoin,代码行数:25,代码来源:segwit_test.py
示例4: 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
示例5: multisig_M_of_N
def multisig_M_of_N(self, M, N, unsigned_id, signed_id):
keys = [Key(secret_exponent=i) for i in range(1, N+2)]
tx_in = TxIn.coinbase_tx_in(script=b'')
script = ScriptMultisig(m=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])
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:onestarshang,项目名称:pycoin,代码行数:13,代码来源:pay_to_test.py
示例6: 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(m=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 = 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:onestarshang,项目名称:pycoin,代码行数:13,代码来源:multisig_individual_test.py
示例7: 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, script_for_address(address))
tx = Tx(1, [tx_in], [tx_out])
print("Here is the tx as hex:\n%s" % tx.as_hex())
开发者ID:alanxu89,项目名称:pycoin,代码行数:15,代码来源:2_create_coinbase_tx.py
示例8: 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:onestarshang,项目名称:pycoin,代码行数:15,代码来源:build_tx_test.py
示例9: test_sign_pay_to_script_multisig
def test_sign_pay_to_script_multisig(self):
M, N = 3, 3
keys = [Key(secret_exponent=i) for i in range(1, N+2)]
tx_in = TxIn.coinbase_tx_in(script=b'')
underlying_script = ScriptMultisig(m=M, sec_keys=[key.sec() for key in keys[:N]]).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[:N])
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:onestarshang,项目名称:pycoin,代码行数:15,代码来源:pay_to_test.py
示例10: test_pay_to_script_file
def test_pay_to_script_file(self):
the_dir = self.set_cache_dir()
p2sh_file = tempfile.NamedTemporaryFile()
p2sh_file.write(
"52210279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f817982102c60"
"47f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee52102f9308a019258"
"c31049344f85f89d5229b531c845836f99b08601f113bce036f953ae\n".encode("utf8"))
p2sh_file.write(
"53210279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f817982102c60"
"47f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee52102f9308a019258"
"c31049344f85f89d5229b531c845836f99b08601f113bce036f953ae\n".encode("utf8"))
p2sh_file.flush()
tx_source_hex = (
"01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0"
"0ffffffff0200f902950000000017a91415fc0754e73eb85d1cbce08786fadb7320ecb8dc8700f90295"
"0000000017a914594f349df0bac3084ffea8a477bba5f03dcd45078700000000")
self.launch_tool("tx -C %s" % tx_source_hex)
tx_to_sign = (
"01000000020a316ea8980ef9ba02f4e6637c88229bf059f39b06238d48d06a8e"
"f672aea2bb0000000000ffffffff0a316ea8980ef9ba02f4e6637c88229bf059"
"f39b06238d48d06a8ef672aea2bb0100000000ffffffff01f0ca052a01000000"
"1976a914751e76e8199196d454941c45d1b3a323f1433bd688ac0000000000f9"
"02950000000017a91415fc0754e73eb85d1cbce08786fadb7320ecb8dc8700f9"
"02950000000017a914594f349df0bac3084ffea8a477bba5f03dcd450787")
wifs = ' '.join(Key(_).wif() for _ in (1, 2, 3))
signed = tempfile.mktemp(suffix=".hex")
self.launch_tool("tx -a -P %s --db %s %s %s -o %s" % (
p2sh_file.name, tx_source_hex, tx_to_sign, wifs, signed), env=dict(PYCOIN_CACHE_DIR=the_dir))
tx = Tx.from_hex(open(signed).read())
self.assertEqual(tx.id(), "9d991ddccf77e33cb4584e4fc061a36da0da43589232b2e78a1aa0748ac3254b")
开发者ID:onestarshang,项目名称:pycoin,代码行数:30,代码来源:tx_test.py
示例11: main
def main():
if len(sys.argv) != 4:
print("usage: %s tx-hex-file-path wif-file-path p2sh-file-path" % sys.argv[0])
sys.exit(-1)
# get the tx
with open(sys.argv[1], "r") as f:
tx_hex = f.readline().strip()
tx = Tx.from_hex(tx_hex)
# get the WIF
with open(sys.argv[2], "r") as f:
wif = f.readline().strip()
assert is_wif_valid(wif)
# create the p2sh_lookup
with open(sys.argv[3], "r") as f:
p2sh_script_hex = f.readline().strip()
p2sh_script = h2b(p2sh_script_hex)
# build a dictionary of script hashes to scripts
p2sh_lookup = build_p2sh_lookup([p2sh_script])
# sign the transaction with the given WIF
sign_tx(tx, wifs=[wif], p2sh_lookup=p2sh_lookup)
bad_signature_count = tx.bad_signature_count()
print("tx %s now has %d bad signature(s)" % (tx.id(), bad_signature_count))
include_unspents = (bad_signature_count > 0)
print("Here is the tx as hex:\n%s" % tx.as_hex(include_unspents=include_unspents))
开发者ID:alanxu89,项目名称:pycoin,代码行数:31,代码来源:4_sign_tx.py
示例12: test_tx_api
def test_tx_api(self):
tx = Tx.tx_from_hex(TX_E1A18B843FC420734DEEB68FF6DF041A2585E1A0D7DBF3B82AAB98291A6D9952_HEX)
# this transaction is a pay-to-hash transaction
self.assertEqual(tx.id(), "e1a18b843fc420734deeb68ff6df041a2585e1a0d7dbf3b82aab98291a6d9952")
self.assertEqual(tx.txs_out[0].bitcoin_address(), "19LemzJ3XPdUxp113uynqCAivDbXZBdBy3")
# TODO: fix this when pay-to-hash properly parsed
self.assertEqual(tx.txs_out[1].bitcoin_address(), "3KmkA7hvqG2wKkWUGz1BySioUywvcmdPLR")
开发者ID:SF-Bitcoindevs,项目名称:pycoin,代码行数:7,代码来源:tx_test.py
示例13: 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:nelisky,项目名称:pycoin,代码行数:17,代码来源:Tx_from_hash.py
示例14: test_cache_tx
def test_cache_tx(self):
the_dir = self.set_cache_dir()
tx = Tx.from_hex(
"01000000010000000000000000000000000000000000000000000000000000000000000000"
"ffffffff0704ffff001d0104ffffffff0100f2052a0100000043410496b538e853519c726a"
"2c91e61ec11600ae1390813a627c66fb8be7947be63c52da7589379515d4e0a604f8141781"
"e62294721166bf621e73a82cbf2342c858eeac00000000")
self.launch_tool("tx -C %s --db %s" % (tx.id(), tx.as_hex()), env=dict(PYCOIN_CACHE_DIR=the_dir))
self.assertTrue(os.path.exists(os.path.join(the_dir, "txs", "%s_tx.bin" % tx.id())))
开发者ID:onestarshang,项目名称:pycoin,代码行数:9,代码来源:tx_test.py
示例15: load_tx
def load_tx(self, txid):
p = subprocess.Popen(['electrum', 'gettransaction', txid], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
raw_data = p.communicate()[0]
data = json.loads(raw_data)
txhex = data['hex']
tx = Tx.from_hex(txhex)
return tx
开发者ID:ulrichard,项目名称:bitcoinutilities,代码行数:9,代码来源:electrum_client.py
示例16: tx_to_b64
def tx_to_b64(tx_hex):
# use this to dump raw transactions in the data above
import io
tx = Tx.tx_from_hex(tx_hex)
f = io.BytesIO()
tx.stream(f)
d = f.getvalue()
for idx in range(0, len(d), 45):
print('"%s"' % binascii.b2a_base64(d[idx:idx+45]).decode("utf8")[:-1])
开发者ID:bitcoinwallet,项目名称:pycoin,代码行数:9,代码来源:tx_test.py
示例17: test_coinbase_tx
def test_coinbase_tx(self):
tx = Tx.coinbase_tx(COINBASE_PUB_KEY_FROM_80971, int(50 * 1e8), COINBASE_BYTES_FROM_80971)
s = io.BytesIO()
tx.stream(s)
tx1 = s.getvalue()
s = io.BytesIO()
block_80971.txs[0].stream(s)
tx2 = s.getvalue()
self.assertEqual(tx1, tx2)
开发者ID:onestarshang,项目名称:pycoin,代码行数:9,代码来源:build_tx_test.py
示例18: tx_for_tx_hash
def tx_for_tx_hash(self, tx_hash):
"""
Get a Tx by its hash.
"""
url = "%s/rawtx/%s" % (self.url, b2h_rev(tx_hash))
d = urlopen(url).read()
j = json.loads(d.decode("utf8"))
tx = Tx.from_hex(j.get("rawtx", ""))
if tx.hash() == tx_hash:
return tx
开发者ID:onestarshang,项目名称:pycoin,代码行数:10,代码来源:blockexplorer.py
示例19: test_multisig_one_at_a_time
def test_multisig_one_at_a_time(self):
M = 3
N = 3
keys = [Key(secret_exponent=i) for i in range(1, N+2)]
tx_in = TxIn.coinbase_tx_in(script=b'')
script = ScriptMultisig(m=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])
tx2 = tx_utils.create_tx(tx1.tx_outs_as_spendable(), [keys[-1].address()])
ids = ["403e5bfc59e097bb197bf77a692d158dd3a4f7affb4a1fa41072dafe7bec7058",
"5931d9995e83721243dca24772d7012afcd4378996a8b953c458175f15a544db",
"9bb4421088190bbbb5b42a9eaa9baed7ec7574a407c25f71992ba56ca43d9c44",
"03a1dc2a63f93a5cf5a7cb668658eb3fc2eda88c06dc287b85ba3e6aff751771"]
for i in range(1, N+1):
self.assertEqual(tx2.bad_signature_count(), 1)
self.assertEqual(tx2.id(), ids[i-1])
hash160_lookup = build_hash160_lookup(key.secret_exponent() for key in keys[i-1:i])
tx2.sign(hash160_lookup=hash160_lookup)
self.assertEqual(tx2.id(), ids[i])
self.assertEqual(tx2.bad_signature_count(), 0)
开发者ID:onestarshang,项目名称:pycoin,代码行数:20,代码来源:pay_to_test.py
示例20: tx_for_tx_hash
def tx_for_tx_hash(self, tx_hash):
"""
returns the pycoin.tx object for tx_hash
"""
try:
url_append = "?token=%s&includeHex=true" % self.api_key
url = self.base_url("txs/%s%s" % (b2h_rev(tx_hash), url_append))
result = json.loads(urlopen(url).read().decode("utf8"))
tx = Tx.parse(io.BytesIO(h2b(result.get("hex"))))
return tx
except:
raise Exception
开发者ID:onestarshang,项目名称:pycoin,代码行数:12,代码来源:blockcypher.py
注:本文中的pycoin.tx.Tx.Tx类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论