-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wallet: add config, make reservations time based
- Loading branch information
1 parent
441f570
commit cee8d7b
Showing
4 changed files
with
198 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package wallet | ||
|
||
import ( | ||
"time" | ||
|
||
"go.uber.org/zap" | ||
) | ||
|
||
type ( | ||
config struct { | ||
DefragThreshold int | ||
MaxInputsForDefrag int | ||
MaxDefragUTXOs int | ||
ReservationDuration time.Duration | ||
|
||
Log *zap.Logger | ||
} | ||
|
||
Option func(*config) | ||
) | ||
|
||
// WithDefragThreshold sets the transaction defrag threshold. | ||
func WithDefragThreshold(n int) Option { | ||
return func(c *config) { | ||
c.DefragThreshold = n | ||
} | ||
} | ||
|
||
// WithMaxInputsForDefrag sets the maximum number of inputs a transaction can | ||
// have to be considered for defragging | ||
func WithMaxInputsForDefrag(n int) Option { | ||
return func(c *config) { | ||
c.MaxInputsForDefrag = n | ||
} | ||
} | ||
|
||
// WithMaxDefragUTXOs sets the maximum number of additional utxos that will be | ||
// added to a transaction when defragging | ||
func WithMaxDefragUTXOs(n int) Option { | ||
return func(c *config) { | ||
c.MaxDefragUTXOs = n | ||
} | ||
} | ||
|
||
// WithReservationDuration sets the duration that a reservation will be held | ||
// on spent utxos | ||
func WithReservationDuration(d time.Duration) Option { | ||
if d <= 0 { | ||
panic("reservation duration must be positive") // developer error | ||
} | ||
|
||
return func(c *config) { | ||
c.ReservationDuration = d | ||
} | ||
} | ||
|
||
// WithLogger sets the logger for the wallet | ||
func WithLogger(l *zap.Logger) Option { | ||
return func(c *config) { | ||
c.Log = l | ||
} | ||
} |
Oops, something went wrong.