Skip to content

Commit

Permalink
refine query more
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Coats committed Jan 22, 2024
1 parent 3573a43 commit bd148ab
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/db/mongodb/collections/outputs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,10 @@ impl OutputCollection {
{ "$eq": [ "$details.address", &address ] },
{ "$cond": [
// And the output has no expiration or is not expired
{ "$not": { "$lte": [ "$output.expiration_unlock_condition.timestamp", ledger_ms.milestone_timestamp ] } },
{ "$or": [
{ "$lte": [ "$output.expiration_unlock_condition", null ] },
{ "$gt": [ "$output.expiration_unlock_condition.timestamp", ledger_ms.milestone_timestamp ] }
] },
{ "$toDecimal": "$output_amount" }, 0
] },
// Otherwise, if this output has expiring funds that will be returned to this address
Expand All @@ -469,9 +472,15 @@ impl OutputCollection {
{ "$cond": [
{ "$and": [
// And the output has no expiration or is not expired
{ "$not": { "$lte": [ "$output.expiration_unlock_condition.timestamp", ledger_ms.milestone_timestamp ] } },
{ "$or": [
{ "$lte": [ "$output.expiration_unlock_condition", null ] },
{ "$gt": [ "$output.expiration_unlock_condition.timestamp", ledger_ms.milestone_timestamp ] }
] },
// and has no timelock or is past the lock period
{ "$not": { "$gt": [ "$output.timelock_unlock_condition.timestamp", ledger_ms.milestone_timestamp ] } }
{ "$or": [
{ "$lte": [ "$output.timelock_unlock_condition", null ] },
{ "$lte": [ "$output.timelock_unlock_condition.timestamp", ledger_ms.milestone_timestamp ] }
] }
] },
{ "$toDecimal": "$output_amount" }, 0
] },
Expand Down

0 comments on commit bd148ab

Please sign in to comment.