本文整理汇总了Python中bitcoin.core.CMutableTxIn方法的典型用法代码示例。如果您正苦于以下问题:Python core.CMutableTxIn方法的具体用法?Python core.CMutableTxIn怎么用?Python core.CMutableTxIn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bitcoin.core
的用法示例。
在下文中一共展示了core.CMutableTxIn方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: select_coins
# 需要导入模块: from bitcoin import core [as 别名]
# 或者: from bitcoin.core import CMutableTxIn [as 别名]
def select_coins(amount):
"""Get a txin set and change to spend amount."""
coins = g.bit.listunspent()
out = []
for coin in coins:
if not coin['spendable']:
continue
out.append(CMutableTxIn(coin['outpoint']))
amount -= coin['amount']
if amount <= 0:
break
if amount > 0:
raise Exception("Not enough money")
change = CMutableTxOut(
-amount, g.bit.getrawchangeaddress().to_scriptPubKey())
return out, change
示例2: tx_in
# 需要导入模块: from bitcoin import core [as 别名]
# 或者: from bitcoin.core import CMutableTxIn [as 别名]
def tx_in(self):
return CMutableTxIn(self.outpoint, scriptSig=script.CScript(self.unsigned_script_sig), nSequence=0)
示例3: make_unsigned
# 需要导入模块: from bitcoin import core [as 别名]
# 或者: from bitcoin.core import CMutableTxIn [as 别名]
def make_unsigned(cls, outpoints, outputs, tx_fee=TRANSACTION_FEE, testnet=False, out_value=None):
"""
Build an unsigned transaction.
Args:
outpoints: A `list` of `dict` objects which contain a txid, vout, value, and scriptPubkey.
outputs: If a single address the full value of the inputs (minus the tx fee) will be sent there.
Otherwise it should be a `list` of `dict` objects containing address and value.
tx_fee: The Bitcoin network fee to be paid on this transaction.
testnet: Should this transaction be built for testnet?
out_value: used if you want to specify a specific output value otherwise the full value
of the inputs (minus the tx fee) will be used.
"""
# build the inputs from the outpoints object
SelectParams("testnet" if testnet else "mainnet")
txins = []
in_value = 0
for outpoint in outpoints:
in_value += outpoint["value"]
txin = CMutableTxIn(COutPoint(lx(outpoint["txid"]), outpoint["vout"]))
txin.scriptSig = CScript(x(outpoint["scriptPubKey"]))
txins.append(txin)
# build the outputs
txouts = []
if isinstance(outputs, list):
for output in outputs:
value = output["value"]
address = output["address"]
txouts.append(CMutableTxOut(value, CBitcoinAddress(address).to_scriptPubKey()))
else:
value = out_value if out_value is not None else (in_value - tx_fee)
txouts.append(CMutableTxOut(value, CBitcoinAddress(outputs).to_scriptPubKey()))
# make the transaction
tx = CMutableTransaction(txins, txouts)
return BitcoinTransaction(tx)
示例4: commitment
# 需要导入模块: from bitcoin import core [as 别名]
# 或者: from bitcoin.core import CMutableTxIn [as 别名]
def commitment(self, ours=False):
"""Return an unsigned commitment transaction."""
first = CMutableTxOut(self.our_balance, self.our_addr.to_scriptPubKey())
second = CMutableTxOut(self.their_balance, self.their_addr.to_scriptPubKey())
if not ours:
first, second = second, first
return CMutableTransaction([CMutableTxIn(self.anchor_point)],
[first, second])
示例5: settlement
# 需要导入模块: from bitcoin import core [as 别名]
# 或者: from bitcoin.core import CMutableTxIn [as 别名]
def settlement(self):
"""Generate the settlement transaction."""
# Put outputs in the order of the inputs, so that both versions are the same
first = CMutableTxOut(self.our_balance,
self.our_addr.to_scriptPubKey())
second = CMutableTxOut(self.their_balance,
self.their_addr.to_scriptPubKey())
if self.anchor_index == 0:
pass
elif self.anchor_index == 1:
first, second = second, first
else:
raise Exception("Unknown index", self.anchor_index)
return CMutableTransaction([CMutableTxIn(self.anchor_point)],
[first, second])
示例6: test_json_roundtrip
# 需要导入模块: from bitcoin import core [as 别名]
# 或者: from bitcoin.core import CMutableTxIn [as 别名]
def test_json_roundtrip(self):
VALUES = [
42, 0, -42, 2100000000000000, -2100000000000000,
"basic string", "\u1111Unicode", "\U00010000Wide Unicode",
"\x00\n\t\r\nEscape codes", "\"'\"Quotes", "",
None,
b"\x00\x01\xFFBinary data", b"",
CBase58Data.from_bytes(b'\x00\x01\xFF', 42),
P2SHBitcoinAddress.from_bytes(b'\x00\x01\xFF'),
P2PKHBitcoinAddress.from_bytes(b'\x00\x01\xFF'),
CMutableTxIn(COutPoint(b'\x00'*16+b'\xFF'*16, 42),
CScript(b'\x00\x01\xFF'),
42),
CMutableTxOut(42, CScript(b'\x00\x01\xFF')),
CMutableTransaction([CMutableTxIn(COutPoint(b'\x00'*32, 42),
CScript(b'\x00\x01\xFF'),
42),
CMutableTxIn(COutPoint(b'\xFF'*32, 42),
CScript(b'\xFF\x01\x00'),
43)],
[CMutableTxOut(42, CScript(b'\x00\x01\xFF')),
CMutableTxOut(43, CScript(b'\xFF\x01\x00'))],
42, 3),
[1, b'\x00\x01\xFF', "List Test",],
{'a':1, 'key':b'\xFF\x01\x00', 1:'Dictionary Test'},
[{3: [0, 1, 2,],}, [[b'\xFFRecursion Test',],],],
]
for value in VALUES:
self.assertEqual(from_json(to_json(value)), value)
示例7: build_spending_tx
# 需要导入模块: from bitcoin import core [as 别名]
# 或者: from bitcoin.core import CMutableTxIn [as 别名]
def build_spending_tx(script_sig, credit_tx):
tx = Transaction(version=1, locktime=0)
txin = CMutableTxIn(CMutableOutPoint(credit_tx.GetHash(), 0), script_sig)
tx.vin = [txin]
txout = CMutableTxOut(0, Script())
tx.vout = [txout]
return tx
示例8: build_crediting_tx
# 需要导入模块: from bitcoin import core [as 别名]
# 或者: from bitcoin.core import CMutableTxIn [as 别名]
def build_crediting_tx(script_pubkey):
tx = Transaction(version=1, locktime=0)
txin = CMutableTxIn()
txin.scriptSig = Script.from_human('0x00 0x00')
tx.vin = [txin]
txout = CMutableTxOut(0, script_pubkey)
tx.vout = [txout]
return tx
示例9: create_inputs_tab
# 需要导入模块: from bitcoin import core [as 别名]
# 或者: from bitcoin.core import CMutableTxIn [as 别名]
def create_inputs_tab(self):
form = QFormLayout()
self.inputs_tree = InputsTree()
self.inputs_tree.view.setWhatsThis('The inputs of your transaction are displayed here.')
self.inputs_editor = InputsEditor(self.handler.gui, self.inputs_tree)
self.inputs_editor.setEnabled(False)
def update_enabled_widgets():
num_inputs = len(self.inputs_tree.get_inputs())
self.inputs_editor.setEnabled(num_inputs > 0)
def add_input():
outpoint = CMutableOutPoint(n=0)
new_input = CMutableTxIn(prevout=outpoint)
self.inputs_tree.add_input(new_input)
update_enabled_widgets()
if len(self.inputs_tree.get_inputs()) > 0:
self.inputs_tree.view.selectRow(self.inputs_tree.model.rowCount() - 1)
update_enabled_widgets()
add_input_button = QPushButton('New input')
add_input_button.setToolTip('Add a new input')
add_input_button.setWhatsThis('Clicking this button will add a new input to your transaction.')
add_input_button.clicked.connect(add_input)
form.addRow(self.inputs_tree)
form.addRow(Separator())
form.addRow(self.inputs_editor)
form.addRow(Separator())
form.addRow(floated_buttons([add_input_button]))
w = QWidget()
w.setLayout(form)
return w