Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logs rewrite #98

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open

Logs rewrite #98

wants to merge 11 commits into from

Conversation

shkfnly
Copy link
Collaborator

@shkfnly shkfnly commented Dec 22, 2018

Beginning to rewrite the logs to use consistent patterns and have greater resiliency

@@ -1,6 +1,6 @@
let obj = require('./build/contracts/ProjectLibrary.json')

const ProjectLibraryAddress = obj.networks['5777'].address
const ProjectLibraryAddress = Object.keys(obj.networks).sort()[Object.keys(obj.networks).length - 1].address
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about making network id an environment var?

VoteRecord: {
voter: (vote) => User.findOne({account: vote.voter}).then(user => user),
task: (vote) => Task.findById(vote.task).then(voteRecord => voteRecord)
votes: (user) => Vote.find({voter: user.id}).then(votes => votes)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fun fact, you don't need the code after then then unless it's tranforming the result in some way. You can just write Vote.find({voter: user.id})

}}, {upsert: true})
if (!vote) console.error('vote not added successfully')
} catch (err) {
console.error('Error Adding Vote')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonder if you want to rethrow here, so it bubbles up to what gets returned by graphql? What does this mutation return?

await new Token({ userId: user.id, amount: amountMinted, ether: totalCost }).save()
const network = await Network.findOneAndUpdate({},
{
lastBlock: event.blockNumber,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we guaranteed to have finished processing the block here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't remember how events filtering works too well

module.exports = function () {
const HyphaTokenContract = new web3.eth.Contract(HyphaTokenABI, HyphaTokenAddress)

HyphaTokenContract.events.LogMint({fromBlock: netStatus.lastBlock}).on('data', async event => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Building some redundancy in here would be nice, like fromBlock: netStatus.lastBlock-100 - at some point you may need to be sure your node isn't on a fork too, and lag a few blocks behind

logIndex: String
})

processedTxsSchema.index({transactionHash: 1, logIndex: 1}, 
{unique: true})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to go through the app code, see what other params you query by, and add indexes for them

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants