Merge pull request #735 from hieblmi/static-addr-fix-scopes

StaticAddr: public scope for deposit methods
pull/737/head
Slyghtning 3 weeks ago committed by GitHub
commit 1dba70eb24
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -71,28 +71,28 @@ func (d *Deposit) IsInFinalState() bool {
return d.state == Expired || d.state == Failed return d.state == Expired || d.state == Failed
} }
func (d *Deposit) isExpired(currentHeight, expiry uint32) bool { func (d *Deposit) IsExpired(currentHeight, expiry uint32) bool {
d.Lock() d.Lock()
defer d.Unlock() defer d.Unlock()
return currentHeight >= uint32(d.ConfirmationHeight)+expiry return currentHeight >= uint32(d.ConfirmationHeight)+expiry
} }
func (d *Deposit) getState() fsm.StateType { func (d *Deposit) GetState() fsm.StateType {
d.Lock() d.Lock()
defer d.Unlock() defer d.Unlock()
return d.state return d.state
} }
func (d *Deposit) setState(state fsm.StateType) { func (d *Deposit) SetState(state fsm.StateType) {
d.Lock() d.Lock()
defer d.Unlock() defer d.Unlock()
d.state = state d.state = state
} }
func (d *Deposit) isInState(state fsm.StateType) bool { func (d *Deposit) IsInState(state fsm.StateType) bool {
d.Lock() d.Lock()
defer d.Unlock() defer d.Unlock()

@ -103,7 +103,7 @@ func NewFSM(ctx context.Context, deposit *Deposit, cfg *ManagerConfig,
if recoverStateMachine { if recoverStateMachine {
depoFsm.StateMachine = fsm.NewStateMachineWithState( depoFsm.StateMachine = fsm.NewStateMachineWithState(
depositStates, deposit.getState(), depositStates, deposit.GetState(),
DefaultObserverSize, DefaultObserverSize,
) )
} else { } else {
@ -146,8 +146,8 @@ func (f *FSM) handleBlockNotification(currentHeight uint32) error {
// If the deposit is expired but not yet sufficiently confirmed, we // If the deposit is expired but not yet sufficiently confirmed, we
// republish the expiry sweep transaction. // republish the expiry sweep transaction.
if f.deposit.isExpired(currentHeight, params.Expiry) { if f.deposit.IsExpired(currentHeight, params.Expiry) {
if f.deposit.isInState(WaitForExpirySweep) { if f.deposit.IsInState(WaitForExpirySweep) {
f.PublishDepositExpirySweepAction(nil) f.PublishDepositExpirySweepAction(nil)
} else { } else {
go func() { go func() {
@ -231,13 +231,13 @@ func (f *FSM) updateDeposit(notification fsm.Notification) {
notification.Event, notification.Event,
) )
f.deposit.setState(notification.NextState) f.deposit.SetState(notification.NextState)
// Don't update the deposit if we are in an initial state or if we // Don't update the deposit if we are in an initial state or if we
// are transitioning from an initial state to a failed state. // are transitioning from an initial state to a failed state.
d := f.deposit d := f.deposit
if d.isInState(fsm.EmptyState) || d.isInState(Deposited) || if d.IsInState(fsm.EmptyState) || d.IsInState(Deposited) ||
(notification.PreviousState == Deposited && d.isInState( (notification.PreviousState == Deposited && d.IsInState(
Failed, Failed,
)) { )) {

@ -44,7 +44,7 @@ func (s *SqlStore) CreateDeposit(ctx context.Context, deposit *Deposit) error {
updateArgs := sqlc.InsertDepositUpdateParams{ updateArgs := sqlc.InsertDepositUpdateParams{
DepositID: deposit.ID[:], DepositID: deposit.ID[:],
UpdateTimestamp: s.clock.Now().UTC(), UpdateTimestamp: s.clock.Now().UTC(),
UpdateState: string(deposit.getState()), UpdateState: string(deposit.GetState()),
} }
return s.baseDB.ExecTx(ctx, &loopdb.SqliteTxOptions{}, return s.baseDB.ExecTx(ctx, &loopdb.SqliteTxOptions{},
@ -63,7 +63,7 @@ func (s *SqlStore) UpdateDeposit(ctx context.Context, deposit *Deposit) error {
insertUpdateArgs := sqlc.InsertDepositUpdateParams{ insertUpdateArgs := sqlc.InsertDepositUpdateParams{
DepositID: deposit.ID[:], DepositID: deposit.ID[:],
UpdateTimestamp: s.clock.Now().UTC(), UpdateTimestamp: s.clock.Now().UTC(),
UpdateState: string(deposit.getState()), UpdateState: string(deposit.GetState()),
} }
var ( var (

Loading…
Cancel
Save