Returns a utxo and marks it as spent (pops it from the internal list) Args: txid: get the first utxo we find from a specific transaction
(self, *, txid: Optional[str]='', mark_as_spent=True)
| 138 | return self._address |
| 139 | |
| 140 | def get_utxo(self, *, txid: Optional[str]='', mark_as_spent=True): |
| 141 | """ |
| 142 | Returns a utxo and marks it as spent (pops it from the internal list) |
| 143 | |
| 144 | Args: |
| 145 | txid: get the first utxo we find from a specific transaction |
| 146 | """ |
| 147 | index = -1 # by default the last utxo |
| 148 | self._utxos = sorted(self._utxos, key=lambda k: (k['value'], -k['height'])) # Put the largest utxo last |
| 149 | if txid: |
| 150 | utxo = next(filter(lambda utxo: txid == utxo['txid'], self._utxos)) |
| 151 | index = self._utxos.index(utxo) |
| 152 | if mark_as_spent: |
| 153 | return self._utxos.pop(index) |
| 154 | else: |
| 155 | return self._utxos[index] |
| 156 | |
| 157 | def send_self_transfer(self, **kwargs): |
| 158 | """Create and send a tx with the specified fee_rate. Fee may be exact or at most one satoshi higher than needed.""" |