def __init__(self, unspent): """Create ElementsUTXO from scanutxoset (processed) output""" self.txid = h2b_rev(unspent.get('txid')) self.vout = unspent.get('vout') self.script_pubkey = h2b(unspent.get('scriptPubKey')) self.address = unspent.get('address') self.height = unspent.get('height') # blinded data is_unblinded = 'asset' in unspent and 'amount' in unspent self.asset = h2b_rev(unspent['asset']) if is_unblinded else None self.value = round(unspent['amount'] * 10**8) if is_unblinded else None self.abf = b'\x00' * 32 if self.asset else None self.vbf = b'\x00' * 32 if self.value else None self.asset_commitment = \ b'\x01' + self.asset if is_unblinded else \ h2b(unspent.get('assetcommitment')) self.value_commitment = \ wally.tx_confidential_value_from_satoshi(self.value) if is_unblinded else \ h2b(unspent.get('amountcommitment')) self.nonce_commitment = \ b'' if is_unblinded else \ h2b(unspent.get('noncecommitment')) self.rangeproof = \ b'' if is_unblinded else \ h2b(unspent.get('rangeproof'))
def _get_sighash(self, wally_tx, index, utxo): flags = wally.WALLY_TX_FLAG_USE_WITNESS prevout_script = wally.hex_to_bytes(utxo['prevout_script']) if utxo['confidential']: value = bytes.fromhex(utxo['commitment']) else: value = wally.tx_confidential_value_from_satoshi(utxo['satoshi']) return wally.tx_get_elements_signature_hash( wally_tx, index, prevout_script, value, wally.WALLY_SIGHASH_ALL, flags)
def add_unblinded_output(tx_, script, asset, amount): wally.tx_add_elements_raw_output( tx_, script, b'\x01' + h2b_rev(asset), wally.tx_confidential_value_from_satoshi(btc2sat(amount)), None, # nonce None, # surjection proof None, # range proof 0)
abfs_in, asset_generators_in) wally.tx_add_elements_raw_output(output_tx, script_pubkey, generator, value_commitment, ephemeral_pubkey, surjectionproof, rangeproof, 0) # end-create_outputs # start-add_fee BITCOIN = "5ac9f65c0efcc4775e0baec4ec03abdde22473cd3cf33c0419ca290e0751b225" BITCOIN = wally.hex_to_bytes(BITCOIN)[::-1] wally.tx_add_elements_raw_output( output_tx, None, bytearray([0x01]) + BITCOIN, wally.tx_confidential_value_from_satoshi(fee), None, # nonce None, # surjection proof None, # range proof 0) # end-add_fee # start-sign vout = 0 prev_txid = wally.tx_get_txid(tx) for vin, script_pubkey in zip(vouts_in, script_pubkeys_in): wally.tx_add_elements_raw_input( output_tx, prev_txid, vin,