-func (uk *utxoKeeper) ReserveByAddress(address string, assetID *bc.AssetID, amount uint64, useUnconfirmed bool, isReserved bool) (*reservation, error) {
- uk.mtx.Lock()
- defer uk.mtx.Unlock()
-
- utxos, immatureAmount := uk.findUtxosByAddress(address, assetID, useUnconfirmed)
- optUtxos, optAmount, reservedAmount := uk.optUTXOs(utxos, amount)
- if optAmount+reservedAmount+immatureAmount < amount {
- return nil, ErrInsufficient
- }
- if optAmount+reservedAmount < amount {
- return nil, ErrImmature
- }
-
- if optAmount < amount {
- return nil, ErrReserved
- }
-
- result := &reservation{
- id: atomic.AddUint64(&uk.nextIndex, 1),
- utxos: optUtxos,
- change: optAmount - amount,
- }
-
- uk.reservations[result.id] = result
- if isReserved {
- for _, u := range optUtxos {
- uk.reserved[u.OutputID] = result.id
- }
- }
-
- return result, nil
-}
-