Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion observer/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ func (node *Node) httpListDeposits(w http.ResponseWriter, r *http.Request, param
holder := r.URL.Query().Get("holder")
chain, _ := strconv.ParseInt(r.URL.Query().Get("chain"), 10, 32)
offset, _ := strconv.ParseInt(r.URL.Query().Get("offset"), 10, 64)
deposits, err := node.store.ListDeposits(r.Context(), int(chain), holder, common.RequestStateDone, offset)
deposits, err := node.store.ListDeposits(r.Context(), int(chain), holder, 0, offset)
if err != nil {
common.RenderError(w, r, err)
return
Expand Down Expand Up @@ -837,6 +837,10 @@ func (node *Node) listPendingBitcoinUTXOsForHolder(ctx context.Context, holder s
func (node *Node) viewDeposits(ctx context.Context, deposits []*Deposit, sent map[string]string) []map[string]any {
view := make([]map[string]any, 0)
for _, d := range deposits {
state := "done"
if d.State == common.RequestStateInitial {
state = "pending"
}
dm := map[string]any{
"transaction_hash": d.TransactionHash,
"output_index": d.OutputIndex,
Expand All @@ -847,6 +851,7 @@ func (node *Node) viewDeposits(ctx context.Context, deposits []*Deposit, sent ma
"sent_hash": sent[d.TransactionHash],
"chain": d.Chain,
"change": false,
"state": state,
"updated_at": d.UpdatedAt,
"created_at": d.CreatedAt,
}
Expand Down
13 changes: 9 additions & 4 deletions observer/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,12 +397,17 @@ func (s *SQLite3Store) ListProposedAccountsWithSig(ctx context.Context) ([]*Acco
}

func (s *SQLite3Store) ListDeposits(ctx context.Context, chain int, holder string, state int, offset int64) ([]*Deposit, error) {
query := fmt.Sprintf("SELECT %s FROM deposits WHERE chain=? AND state=? AND updated_at>=? ORDER BY updated_at ASC LIMIT 100", strings.Join(depositsCols, ","))
params := []any{chain, state, time.Unix(0, offset)}
query := fmt.Sprintf("SELECT %s FROM deposits WHERE chain=? AND updated_at>=?", strings.Join(depositsCols, ","))
params := []any{chain, time.Unix(0, offset)}
if state > 0 {
query += " AND state=?"
params = append(params, state)
}
if holder != "" {
query = fmt.Sprintf("SELECT %s FROM deposits WHERE holder=? AND chain=? AND state=? AND updated_at>=? ORDER BY updated_at ASC LIMIT 100", strings.Join(depositsCols, ","))
params = []any{holder, chain, state, time.Unix(0, offset)}
query += " AND holder=?"
params = append(params, holder)
}
query += " ORDER BY updated_at ASC LIMIT 100"
rows, err := s.db.QueryContext(ctx, query, params...)
if err != nil {
return nil, err
Expand Down
Loading