Last active
June 8, 2019 21:23
-
-
Save EyeOfPython/3b8ca35e30cbfac7199f65be2c85eafd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"v": 3, | |
"q": { | |
"db": ["u", "c"], | |
"aggregate": [ | |
{ | |
"$match": { | |
"$or": [ | |
{"in.e.a": this._baseAddress}, | |
{"out.e.a": this._baseAddress}, | |
], | |
}, | |
}, | |
{ | |
"$unwind": "$in", | |
}, | |
{ | |
"$lookup": { | |
"from": "confirmed", | |
"localField": "in.e.h", | |
"foreignField": "tx.h", | |
"as": "prevConfirmedTx", | |
}, | |
}, | |
{ | |
"$lookup": { | |
"from": "unconfirmed", | |
"localField": "in.e.h", | |
"foreignField": "tx.h", | |
"as": "prevUnconfirmedTx", | |
}, | |
}, | |
{ | |
"$addFields": { | |
"prevTx": { | |
"$arrayElemAt": [ | |
{"$concatArrays": ["$prevConfirmedTx", "$prevUnconfirmedTx"]}, | |
0, | |
], | |
}, | |
}, | |
}, | |
{ | |
"$addFields": { | |
"slpOutput": {"$arrayElemAt": ["$prevTx.out", 0]}, | |
"satoshiOutput": { | |
"$arrayElemAt": [ | |
"$prevTx.out", | |
"$in.e.i", | |
], | |
}, | |
}, | |
}, | |
{ | |
"$group": { | |
"_id": "$tx.h", | |
"prevSlpInput": {"$push": "$slpOutput"}, | |
"prevInputs": {"$push": "$satoshiOutput"}, | |
"txInputs": {"$push": "$in"}, | |
"outputs": {"$first": "$out"}, | |
"timestamp": {"$first": "$blk.t"}, | |
}, | |
}, | |
{ | |
"$sort": { | |
"timestamp": 1, | |
}, | |
}, | |
], | |
}, | |
"r": { | |
"f": `[.[] | { | |
txid: ._id, | |
inputs: [ | |
. as $tx | | |
.txInputs | length | range(.) | | |
{ | |
slpAmountHex: $tx.prevSlpInput[.][("h" + (($tx.txInputs[.].e.i + 4) | tostring))], | |
satoshiAmount: $tx.prevInputs[.].e.v, | |
address: $tx.prevInputs[.].e.a, | |
} | |
], | |
outputs: [ | |
. as $tx | | |
.outputs | length | range(.) | | |
select($tx.outputs[.].b1 != "${SLP_B64}") | | |
{ | |
slpAmountHex: $tx.outputs[0][("h" + ((. + 4) | tostring))], | |
satoshiAmount: $tx.outputs[.].e.v, | |
address: $tx.outputs[.].e.a, | |
vout: $tx.outputs[.].e.i, | |
} | |
], | |
isSlp: (.outputs[0].b1 == "${SLP_B64}"), | |
tokenId: .outputs[0].h4, | |
timestamp: .timestamp, | |
}]`.replace(/\r?\n|\r/g, ''), | |
}, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment