-
Notifications
You must be signed in to change notification settings - Fork 123
staticaddr: method to fetch deposits by outpoints #959
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -149,6 +149,48 @@ func (s *SqlStore) GetDeposit(ctx context.Context, id ID) (*Deposit, error) { | |
return deposit, nil | ||
} | ||
|
||
// DepositForOutpoint retrieves the deposit with the given outpoint from the | ||
// database. | ||
func (s *SqlStore) DepositForOutpoint(ctx context.Context, | ||
outpoint string) (*Deposit, error) { | ||
|
||
var deposit *Deposit | ||
err := s.baseDB.ExecTx(ctx, loopdb.NewSqlReadOpts(), | ||
func(q *sqlc.Queries) error { | ||
op, err := wire.NewOutPointFromString(outpoint) | ||
if err != nil { | ||
return err | ||
} | ||
params := sqlc.DepositForOutpointParams{ | ||
TxHash: op.Hash[:], | ||
OutIndex: int32(op.Index), | ||
} | ||
row, err := q.DepositForOutpoint(ctx, params) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
latestUpdate, err := q.GetLatestDepositUpdate( | ||
ctx, row.DepositID, | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
Comment on lines
+168
to
+178
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can do it with SQL join and avoid making an explicit DB transaction (ExecTx). |
||
|
||
deposit, err = s.toDeposit(row, latestUpdate) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return deposit, nil | ||
} | ||
|
||
// AllDeposits retrieves all known deposits to our static address. | ||
func (s *SqlStore) AllDeposits(ctx context.Context) ([]*Deposit, error) { | ||
var allDeposits []*Deposit | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where would we use the function? Could you please add coverage?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes sure, it is used to restore deposits of a swap after fetching it from the db, see hieblmi@349b930#diff-2c26627ef62d3f06764cb007a83924ef8abb36066a183b4d05e7f42e7c6a7ac9R23-R283
Ideally this would all be handled by
GetLoopInByHash
, but it isn't currently.