Пример #1
0
    def get_raw_unsigned(self, fee_satoshi):
        """Return raw transaction ready for signing

        May return a transaction with amount=0 if the input amount is not enough to cover fees
        """
        amount_satoshi = wally.tx_get_output_satoshi(self.tx, self.vout)

        if fee_satoshi >= amount_satoshi:
            logging.warning('Insufficient funds to cover fee')
            logging.warning('txout has value of {}, fee = {}'.format(
                amount_satoshi, fee_satoshi))

        # Calculate adjusted amount = input amount - fee
        adjusted_amount_satoshi = max(0, amount_satoshi - fee_satoshi)
        logging.debug('tx amount = amount - fee = {} - {} = {}'.format(
            amount_satoshi, fee_satoshi, adjusted_amount_satoshi))
        assert adjusted_amount_satoshi >= 0

        logging.debug("Create tx: {} sat -> {}".format(adjusted_amount_satoshi,
                                                       self.dest_address))

        # Set nlocktime to the current blockheight to discourage 'fee sniping', as per the core
        # wallet implementation
        tx = txutil.new(util.get_current_blockcount() or 0, version=1)
        seq = gaconstants.MAX_BIP125_RBF_SEQUENCE
        txutil.add_input(tx, self.txhash_bin, self.vout, seq)
        scriptpubkey = util.scriptpubkey_from_address(self.dest_address)
        txutil.add_output(tx, adjusted_amount_satoshi, scriptpubkey)
        return txutil.to_hex(tx)
Пример #2
0
    def sign(self):
        """Return raw signed transaction"""
        type_map = {'p2wsh': gaconstants.P2SH_P2WSH_FORTIFIED_OUT, 'p2sh': 0}
        txdata = {
            'prevout_scripts': [self.witness.redeem_script_hex],
            'prevout_script_types': [type_map[self.witness.type_]],
            'prevout_values':
            [wally.tx_get_output_satoshi(self.tx, self.vout)]
        }
        signatories = [
            gacommon.ActiveSignatory(key) for key in self.keyset.private_keys
        ]

        def sign_(fee):
            txdata['tx'] = self.get_raw_unsigned(fee)
            return gacommon.sign(
                txdata,
                signatories,
            )

        signed_no_fee = sign_(fee=1000)
        fee_satoshi = self.get_fee(signed_no_fee)
        signed_fee = sign_(fee=fee_satoshi)
        return txutil.to_hex(signed_fee)
Пример #3
0
 def get_raw_tx_or_dust(tx_wif, _):
     if not gacommon.is_liquid(clargs.args.network) and \
             wally.tx_get_total_output_satoshi(tx_wif[0]) == 0:
         return '** dust **'
     return txutil.to_hex(tx_wif[0])
Пример #4
0
 def getrawtransaction(self, txid):
     return txutil.to_hex(self.tx_by_id[txid])
Пример #5
0
 def get_raw_tx_or_dust(tx_wif, _):
     if wally.tx_get_total_output_satoshi(tx_wif[0]) == 0:
         return '** dust **'
     return txutil.to_hex(tx_wif[0])