本文整理汇总了Python中bitcoin.core.CTransaction.from_tx方法的典型用法代码示例。如果您正苦于以下问题:Python CTransaction.from_tx方法的具体用法?Python CTransaction.from_tx怎么用?Python CTransaction.from_tx使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bitcoin.core.CTransaction
的用法示例。
在下文中一共展示了CTransaction.from_tx方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: as_tx
# 需要导入模块: from bitcoin.core import CTransaction [as 别名]
# 或者: from bitcoin.core.CTransaction import from_tx [as 别名]
def as_tx(self):
sum_in = sum(prevtx.nValue for _,prevtx,_ in self.prevouts)
sig_size = sum(redeemer.spendbytes for _,_,redeemer in self.prevouts)
tx_size = (4 + # version field
2 + # # of txins
len(self.prevouts) * 41 + # txins, excluding sigs
sig_size + # txins, sigs only
1 + # # of txouts
34 + # txout
4 # nLockTime field
)
feerate = int(self.proxy._call('estimatefee', 1) * COIN)
# satoshi's per KB
if feerate <= 0:
feerate = 10000
fees = int(tx_size * feerate / 1000)
tx = CMutableTransaction(
[CTxIn(outpoint, nSequence=0)
for outpoint,_,_ in self.prevouts],
[CTxOut(sum_in - fees, self.payto.to_scriptPubKey())],
0)
for n,(_,_,redeemer) in enumerate(self.prevouts):
redeemer.mutate_spend(tx, n)
unsigned_tx = CTransaction.from_tx(tx)
for n,(_,_,redeemer) in enumerate(self.prevouts):
txin = CMutableTxIn.from_txin(tx.vin[n])
txin.scriptSig = redeemer.sign_spend(unsigned_tx, n)
tx.vin[n] = CTxIn.from_txin(txin)
print(b2x(tx.serialize()))
示例2: __init__
# 需要导入模块: from bitcoin.core import CTransaction [as 别名]
# 或者: from bitcoin.core.CTransaction import from_tx [as 别名]
def __init__(self, nVersion=2, hashPrevBlock=b'\x00'*32,
hashMerkleRoot=b'\x00'*32, nTime=0, nBits=0, nNonce=0,
auxpow=None, vtx=()):
"""Create a new block"""
super(CAltcoinBlock, self).__init__(nVersion, hashPrevBlock,
hashMerkleRoot, nTime, nBits,
nNonce, auxpow)
vMerkleTree = tuple(bitcoin.core.CBlock.build_merkle_tree_from_txs(vtx))
object.__setattr__(self, 'vMerkleTree', vMerkleTree)
object.__setattr__(self, 'vtx', tuple(CTransaction.from_tx(tx)
for tx in vtx))