Create and send a tx with an output to a given scriptPubKey/amount, plus a change output to our internal address. To keep things simple, a fixed fee given in Satoshi is used. Note that this method fails if there is no single internal utxo available that can
(self, *, from_node, scriptPubKey, amount, fee=1000)
| 161 | return tx |
| 162 | |
| 163 | def send_to(self, *, from_node, scriptPubKey, amount, fee=1000): |
| 164 | """ |
| 165 | Create and send a tx with an output to a given scriptPubKey/amount, |
| 166 | plus a change output to our internal address. To keep things simple, a |
| 167 | fixed fee given in Satoshi is used. |
| 168 | |
| 169 | Note that this method fails if there is no single internal utxo |
| 170 | available that can cover the cost for the amount and the fixed fee |
| 171 | (the utxo with the largest value is taken). |
| 172 | |
| 173 | Returns a tuple (txid, n) referring to the created external utxo outpoint. |
| 174 | """ |
| 175 | tx = self.create_self_transfer(from_node=from_node, fee_rate=0, mempool_valid=False)['tx'] |
| 176 | assert_greater_than_or_equal(tx.vout[0].nValue.getAmount(), amount + fee) |
| 177 | tx.vout[0].nValue.setToAmount(tx.vout[0].nValue.getAmount() - (amount + fee)) # change output -> MiniWallet |
| 178 | tx.vout[1].nValue.setToAmount(fee) # ELEMENTS explicitly set fee output value |
| 179 | tx.vout.append(CTxOut(amount, scriptPubKey)) # arbitrary output -> to be returned |
| 180 | txid = self.sendrawtransaction(from_node=from_node, tx_hex=tx.serialize().hex()) |
| 181 | return txid, 1 |
| 182 | |
| 183 | def create_self_transfer(self, *, fee_rate=Decimal("0.003"), from_node=None, utxo_to_spend=None, mempool_valid=True, locktime=0, sequence=0): |
| 184 | """Create and return a tx with the specified fee_rate. Fee may be exact or at most one satoshi higher than needed.""" |