当前位置: 首页>>代码示例>>Python>>正文


Python CTransaction.deserialize方法代码示例

本文整理汇总了Python中bitcoin.core.CTransaction.deserialize方法的典型用法代码示例。如果您正苦于以下问题:Python CTransaction.deserialize方法的具体用法?Python CTransaction.deserialize怎么用?Python CTransaction.deserialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在bitcoin.core.CTransaction的用法示例。


在下文中一共展示了CTransaction.deserialize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: calculate_tx_fees

# 需要导入模块: from bitcoin.core import CTransaction [as 别名]
# 或者: from bitcoin.core.CTransaction import deserialize [as 别名]
def calculate_tx_fees(coins, currency, tx_hex):
    #Process source TX.
    rpc = coins[currency]["rpc"]["sock"]
    tx = CTransaction.deserialize(binascii.unhexlify(tx_hex))

    #Tally input coins.
    input_total = decimal.Decimal(0)
    for vin in tx.vin:
        txid = b2lx(vin.prevout.hash) 
        vin_tx_hex = rpc.getrawtransaction(txid)
        vin_tx = CTransaction.deserialize(binascii.unhexlify(vin_tx_hex))
        input_value = vin_tx.vout[vin.prevout.n].nValue
        input_total += decimal.Decimal(str_money_value(input_value))

    #Tally output coins.
    output_total = decimal.Decimal(0)
    for vout in tx.vout:
        output_value = decimal.Decimal(str_money_value(vout.nValue))
        output_total += output_value

    #TX fees are the difference between the source and 
    fees = input_total - output_total
    
    #Return totals and fees.
    return [input_total, output_total, fees]
开发者ID:robertsdotpm,项目名称:coinbend,代码行数:27,代码来源:coinlib.py

示例2: getrawtransaction

# 需要导入模块: from bitcoin.core import CTransaction [as 别名]
# 或者: from bitcoin.core.CTransaction import deserialize [as 别名]
    def getrawtransaction(self, txid, verbose=False):
        """Return transaction with hash txid

        Raises IndexError if transaction not found.

        verbose - If true a dict is returned instead with additional
        information on the transaction.

        Note that if all txouts are spent and the transaction index is not
        enabled the transaction may not be available.
        """
        try:
            r = self._call("getrawtransaction", b2lx(txid), 1 if verbose else 0)
        except JSONRPCError as ex:
            raise IndexError(
                "%s.getrawtransaction(): %s (%d)" % (self.__class__.__name__, ex.error["message"], ex.error["code"])
            )
        if verbose:
            r["tx"] = CTransaction.deserialize(unhexlify(r["hex"]))
            del r["hex"]
            del r["txid"]
            del r["version"]
            del r["locktime"]
            del r["vin"]
            del r["vout"]
            r["blockhash"] = lx(r["blockhash"]) if "blockhash" in r else None
        else:
            r = CTransaction.deserialize(unhexlify(r))

        return r
开发者ID:sdaftuar,项目名称:replace-by-fee-tools,代码行数:32,代码来源:rpc.py

示例3: getrawtransaction

# 需要导入模块: from bitcoin.core import CTransaction [as 别名]
# 或者: from bitcoin.core.CTransaction import deserialize [as 别名]
    def getrawtransaction(self, txid, verbose=False):
        """Return transaction with hash txid

        Raises IndexError if transaction not found.

        verbse - If true a dict is returned instead with additional information
                 on the transaction.

        Note that if all txouts are spent and the transaction index is not
        enabled the transaction may not be available.
        """
        try:
            r = self._call('getrawtransaction', b2lx(txid), 1 if verbose else 0)
        except JSONRPCException as ex:
            raise IndexError('%s.getrawtransaction(): %s (%d)' %
                    (self.__class__.__name__, ex.error['message'], ex.error['code']))
        if verbose:
            r['tx'] = CTransaction.deserialize(unhexlify(r['hex']))
            del r['hex']
            del r['txid']
            del r['version']
            del r['locktime']
            del r['vin']
            del r['vout']
            r['blockhash'] = lx(r['blockhash']) if 'blockhash' in r else None
        else:
            r = CTransaction.deserialize(unhexlify(r))

        return r
开发者ID:jimmy0x52,项目名称:python-bitcoinlib,代码行数:31,代码来源:rpc.py

示例4: provide_transaction

# 需要导入模块: from bitcoin.core import CTransaction [as 别名]
# 或者: from bitcoin.core.CTransaction import deserialize [as 别名]
	def provide_transaction(self, transaction_data):
		self.send_lock.acquire()

		if self.send_transaction_cache.contains(transaction_data):
			self.send_lock.release()
			return
		if len(transaction_data) > self.MAX_RELAY_TRANSACTION_BYTES and (len(transaction_data) > self.MAX_RELAY_OVERSIZE_TRANSACTION_BYTES or self.send_transaction_cache.get_flag_count() >= MAX_EXTRA_OVERSIZE_TRANSACTIONS):
			self.send_lock.release()
			return

		try:
			relay_data = pack('>3I', self.MAGIC_BYTES, self.TRANSACTION_TYPE, len(transaction_data))
			relay_data += transaction_data
			self.relay_sock.sendall(relay_data)
			self.send_transaction_cache.add(transaction_data, len(transaction_data) > self.MAX_RELAY_OVERSIZE_TRANSACTION_BYTES)

			if deserialize_utils:
				transaction = CTransaction.deserialize(transaction_data)
				print("Sent transaction " + str(b2lx(transaction.GetHash())) + " of size " + str(len(transaction_data)))
			else:
				print("Sent transaction of size " + str(len(transaction_data)))
		except (OSError, socket.error) as err:
			print("Failed to send to relay node: ", err)

		self.send_lock.release()
开发者ID:fudong1127,项目名称:RelayNode,代码行数:27,代码来源:RelayNetworkClient.py

示例5: cmd_mkwitness

# 需要导入模块: from bitcoin.core import CTransaction [as 别名]
# 或者: from bitcoin.core.CTransaction import deserialize [as 别名]
def cmd_mkwitness(args):
    tx = None
    if args.tx is not None:
        serialized_tx = args.tx
        tx = CTransaction.deserialize(serialized_tx)

    else:
        tx = args.proxy.getrawtransaction(args.txid)

    txproof = TxProof(tx=tx)

    for seal_fd in args.seal_fds:
        seal = BitcoinSingleUseSeal.deserialize(seal_fd.read())

        txinproof = None
        txoutproof = None
        for i, txin in enumerate(txproof.tx.vin):
            if txin.prevout == seal.outpoint:
                txinproof = TxInProof(i=i, txproof=txproof)
                txoutproof = TxOutProof(i=0, txproof=txproof)
                break

        else:
            args.parser.error("Seal '%s' not closed by this transaction" % seal_fd.name)

        witness = BitcoinSealWitness(seal=seal, txinproof=txinproof, txoutproof=txoutproof)

        witness_filename = seal_fd.name + '.witness'
        logging.info("Creating witness file '%s'" % witness_filename)
        with open(seal_fd.name + '.witness', 'xb') as witness_fd:
            witness_fd.write(witness.serialize())
开发者ID:cbrightly,项目名称:python-proofchains,代码行数:33,代码来源:sus-tool.py

示例6: check_refund_works

# 需要导入模块: from bitcoin.core import CTransaction [as 别名]
# 或者: from bitcoin.core.CTransaction import deserialize [as 别名]
    def check_refund_works(self, tx_hex, owner_first_sig, owner_second_sig, recipient_sig, actor):
        global error_log_path

        try:
            tx = CTransaction.deserialize(binascii.unhexlify(tx_hex))
            redeem_script = bond_redeem_script(self.ecdsa_us, self.ecdsa_them, self.factory.ecdsa_arbiters[0], actor)
            redeem_script_hash160 = hash160_script(redeem_script)

            print(tx_hex)
            print(redeem_script)

            tx.vin[0].scriptSig = CScript([OP_0, owner_first_sig, owner_second_sig, recipient_sig, redeem_script["bin"]])
            p2sh_script_pub_key = CScript([OP_HASH160, redeem_script_hash160["bin"], OP_EQUAL])
            print(redeem_script_hash160)

            VerifyScript(tx.vin[0].scriptSig, p2sh_script_pub_key, tx, 0, (SCRIPT_VERIFY_P2SH,))
            signed_tx_hex = b2x(tx.serialize())
            return {
                "tx_hex": signed_tx_hex,
                "txid": calculate_txid(signed_tx_hex)
            }
        except Exception as e:
            error = parse_exception(e)
            log_exception(error_log_path, error)
            print(error)
            print("Check refund failed.")
            return None
开发者ID:robertsdotpm,项目名称:coinbend,代码行数:29,代码来源:microtransfer_contract.py

示例7: createrawtransaction

# 需要导入模块: from bitcoin.core import CTransaction [as 别名]
# 或者: from bitcoin.core.CTransaction import deserialize [as 别名]
    def createrawtransaction(self, *args):
        """Get rawtransactions when provided vin and vout

        FIXME: Implement options and accept outpoints instead of user args
        """
        r = self._call('createrawtransaction', *args)
        r = str(r)
        tx = CTransaction.deserialize(unhexlify(r))
        return tx
开发者ID:bloomark,项目名称:python-bitcoinlib,代码行数:11,代码来源:rpc.py

示例8: signrawtransaction

# 需要导入模块: from bitcoin.core import CTransaction [as 别名]
# 或者: from bitcoin.core.CTransaction import deserialize [as 别名]
    def signrawtransaction(self, tx, *args):
        """Sign inputs for transaction

        FIXME: implement options
        """
        hextx = hexlify(tx.serialize())
        r = self._call('signrawtransaction', hextx, *args)
        r['tx'] = CTransaction.deserialize(unhexlify(r['hex']))
        del r['hex']
        return r
开发者ID:jimmy0x52,项目名称:python-bitcoinlib,代码行数:12,代码来源:rpc.py

示例9: mutate_tx

# 需要导入模块: from bitcoin.core import CTransaction [as 别名]
# 或者: from bitcoin.core.CTransaction import deserialize [as 别名]
def mutate_tx(tx_hex):
    """
    Mutates a raw transaction using TX malleability in the scriptSig (specifically, the OP codes.) This function shouldn't be used beyond testing as it uses an ugly eval() hack.

    https://en.bitcoin.it/wiki/Transaction_Malleability
    """
    tx = CTransaction.deserialize(binascii.unhexlify(tx_hex))
    script_sig = repr(tx.vin[0].scriptSig)[9:]
    script_sig = eval("CScript([OP_1, OP_DROP, " + script_sig)
    tx.vin[0].scriptSig = script_sig
    return b2x(tx.serialize())
开发者ID:robertsdotpm,项目名称:coinbend,代码行数:13,代码来源:coinlib.py

示例10: sign_refund_tx

# 需要导入模块: from bitcoin.core import CTransaction [as 别名]
# 或者: from bitcoin.core.CTransaction import deserialize [as 别名]
 def sign_refund_tx(self, tx_hex, key_no=1, actor="us"):
     key_no -= 1
     if key_no == 0:
         ecdsa = self.ecdsa_us[0]
     if key_no == 1:
         ecdsa = self.ecdsa_us[1]
     tx = CTransaction.deserialize(binascii.unhexlify(tx_hex))
     sighash = SignatureHash(bond_redeem_script(self.ecdsa_us, self.ecdsa_them, self.factory.ecdsa_arbiters[0], actor)["bin"], tx, 0, SIGHASH_ALL)
     seckey = CBitcoinSecret.from_secret_bytes(ecdsa.get_private_key("bin"), compressed=True)
     sig = seckey.sign(sighash) + bytes([SIGHASH_ALL])
     return sig
开发者ID:robertsdotpm,项目名称:coinbend,代码行数:13,代码来源:microtransfer_contract.py

示例11: set_tx

# 需要导入模块: from bitcoin.core import CTransaction [as 别名]
# 或者: from bitcoin.core.CTransaction import deserialize [as 别名]
 def set_tx(self):
     """Set the spending transaction and (en|dis)able the input index box."""
     txt = str(self.tx_edit.toPlainText())
     if not txt:
         self.tx = None
         self.input_idx.setEnabled(False)
         self.tx_edit.setToolTip('')
         return
     self.tx = CTransaction.deserialize(txt.decode('hex'))
     self.tx_edit.setToolTip(''.join(['Tx ID: ', bitcoin.core.b2lx(self.tx.GetHash())]))
     self.input_idx.setRange(0, len(self.tx.vin) - 1)
     self.input_idx.setEnabled(True)
开发者ID:kryptoc,项目名称:hashmal,代码行数:14,代码来源:stack.py

示例12: signrawtransaction

# 需要导入模块: from bitcoin.core import CTransaction [as 别名]
# 或者: from bitcoin.core.CTransaction import deserialize [as 别名]
    def signrawtransaction(self, tx, *args):
        """Sign inputs for transaction

        FIXME: implement options
        """
        if getattr(tx, "serialize", None) is not None:
            hextx = hexlify(tx.serialize())
        else:
            # then assume we got a raw string already
            hextx = tx
        r = self._call('signrawtransaction', hextx, *args)
        r['tx'] = CTransaction.deserialize(unhexlify(r['hex']))
        del r['hex']
        return r
开发者ID:skeebuzz,项目名称:python-bitcoinlib,代码行数:16,代码来源:rpc.py

示例13: sign_setup_tx

# 需要导入模块: from bitcoin.core import CTransaction [as 别名]
# 或者: from bitcoin.core.CTransaction import deserialize [as 别名]
def sign_setup_tx(tx_hex, redeem_script, ecdsa):
    tx = CTransaction.deserialize(binascii.unhexlify(tx_hex))
    sighash = SignatureHash(redeem_script["bin"], tx, 0, SIGHASH_ALL)

    print(b"Signing = " + sighash)
    
    print(ecdsa.get_public_key())

    seckey = CBitcoinSecret.from_secret_bytes(ecdsa.get_private_key("bin"), compressed=True)
    sig = seckey.sign(sighash) + bytes([SIGHASH_ALL])
    print(b"Pub key = " + ecdsa.get_public_key("bin"))

    print(b"Sig = " + sig)
    print()
    return sig
开发者ID:robertsdotpm,项目名称:coinbend,代码行数:17,代码来源:microtransfer_contract.py

示例14: get_utxo

# 需要导入模块: from bitcoin.core import CTransaction [as 别名]
# 或者: from bitcoin.core.CTransaction import deserialize [as 别名]
 def get_utxo(self, address):
     """Gets all the Unspent Transaction Outs from a given <address>
     """
     script_pubkey = CBitcoinAddress(address).to_scriptPubKey()
     txs = self.get_response("blockchain.address.get_history", [address])
     spent = {}
     utxos = []
     for tx in txs:
         raw = self.get_raw_transaction(tx["tx_hash"], tx["height"])
         data = CTransaction.deserialize(to_binary(raw))
         for vin in data.vin:
             spent[(to_little_endian_hex(vin.prevout.hash), vin.prevout.n)] = 1
         for outindex, vout in enumerate(data.vout):
             if vout.scriptPubKey == script_pubkey:
                 utxos += [(tx["tx_hash"], outindex, vout.nValue, to_hex(vout.scriptPubKey))]
     return [u for u in utxos if not u[0:2] in spent]
开发者ID:petertodd,项目名称:ngcccbase,代码行数:18,代码来源:electrum.py

示例15: deserialize

# 需要导入模块: from bitcoin.core import CTransaction [as 别名]
# 或者: from bitcoin.core.CTransaction import deserialize [as 别名]
    def deserialize(self):
        self.clear()
        txt = str(self.raw_tx_edit.toPlainText())
        try:
            txt = txt.decode('hex')
        except Exception:
            self.status_message('Raw transaction must be hex.', True)
            return
        try:
            self.tx = tx = CTransaction.deserialize(txt)
        except Exception:
            self.status_message('Cannot deserialize transaction.', True)
            return

        self.tx_widget.set_tx(tx)

        self.status_message('Deserialized transaction {}'.format(bitcoin.core.b2lx(tx.GetHash())))
开发者ID:kryptoc,项目名称:hashmal,代码行数:19,代码来源:tx_deserializer.py


注:本文中的bitcoin.core.CTransaction.deserialize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。