Skip to content

Instantly share code, notes, and snippets.

@EyeOfPython
Last active May 4, 2019 21:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EyeOfPython/7096e30d57e99e1327fd5dab25eada0f to your computer and use it in GitHub Desktop.
Save EyeOfPython/7096e30d57e99e1327fd5dab25eada0f to your computer and use it in GitHub Desktop.
{
"v": 3,
"q":
{
"db": ["c", "u"],
"aggregate": [
{"$match":{
"in.h0": "45584348",
"in.b1.op": 82,
"slp.valid": true
}},
{"$addFields": {
"txHash": {"$concat": ["$tx.h", ":1"]}
}},
{"$lookup": {
"from": "utxos",
"localField": "txHash",
"foreignField": "utxo",
"as": "foundUtxo"
}},
{"$addFields": {
"exchInput": {
"$arrayElemAt": [
{"$filter": {
"input": "$in",
"as": "input",
"cond": {
"$and": [
{"$eq": ["$$input.b0", "RVhDSA=="]},
{"$eq": ["$$input.b1.op", 82]}
]
}
}},
0
]
},
"hasUtxo": {
"$size": "$foundUtxo"
}
}},
{"$sort": {
"hasUtxo": -1,
"blk.t": -1
}},
{"$group": {
"_id": "$slp.detail.tokenIdHex",
"numberOfOpenOffers": { "$sum": "$hasUtxo" },
"numberOfClosedOffers": { "$sum": {"$subtract": [1, "$hasUtxo"] }},
"slp": { "$first": "$slp" },
"lastTrade": {"$first": {
"timestamp": "$blk.t",
"txHash": "$txHash",
"price": "$exchInput.b3",
"isAccepted": {"$ne": ["$foundUtxo", []]}
}}
}}
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment