Skip to content

Instantly share code, notes, and snippets.

@nnn-gif
Created December 5, 2018 10:17
Show Gist options
  • Save nnn-gif/5a96e7cf6a58e0a0f84ec536f899251d to your computer and use it in GitHub Desktop.
Save nnn-gif/5a96e7cf6a58e0a0f84ec536f899251d to your computer and use it in GitHub Desktop.
db.createView('uncles', 'blocks', [
{ $sort: { _id: -1 } },
{ $unwind: { path: '$uncles', includeArrayIndex: "position" } },
{ $project: { hash: 1, number: 1, timestamp: '$header.timestamp', index: 1, uncle: '$uncles'} },
{
$addFields: {
'uncle.timestamp': '$timestamp',
'uncle.index': '$index',
}
},
{
$project: {
parentHash: '$uncle.parentHash',
position: '$uncle.index',
blockHeight: '$uncle.number',
position: '$uncle.position',
sha3Uncles: '$uncle.sha3Uncles',
hash: '$uncle.hash',
timestamp: '$uncle.timestamp',
nonce: '$uncle.nonce',
miner: '$uncle.miner',
rewards: '$uncle.rewards',
difficulty: '$uncle.difficulty',
totalDifficulty: '$uncle.totalDifficulty',
stateRoot: '$uncle.stateRoot',
transactionsRoot: '$uncle.transactionsRoot',
receiptsRoot: '$uncle.receiptsRoot',
logsBloom: '$uncle.logsBloom',
gasLimit: '$uncle.gasLimit',
gasUsed: '$uncle.gasUsed',
mixHash: '$uncle.mixHash',
extraData: '$uncle.extraData'
}
}
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment