Skip to content

Instantly share code, notes, and snippets.

@EyeOfPython
Last active June 8, 2019 21:23
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/3b8ca35e30cbfac7199f65be2c85eafd to your computer and use it in GitHub Desktop.
Save EyeOfPython/3b8ca35e30cbfac7199f65be2c85eafd to your computer and use it in GitHub Desktop.
{
"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