Created
November 20, 2018 22:40
-
-
Save davidabram/13e1010e66c24123b0f056f4c06d3af5 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
/* | |
* Creates a new websocket client that connects to the Loom Instance | |
*/ | |
const client = new Client( | |
'default', | |
'ws://127.0.0.1:46658/websocket', | |
'ws://127.0.0.1:46658/queryws', | |
) | |
/* | |
* Creates our Elasticsearch client | |
*/ | |
const esclient = new elasticsearch.Client({ | |
host: 'localhost:9200', | |
log: 'trace' | |
}); | |
/* | |
* Creates web3 provider that allows us to call Solidity functions via javascript | |
*/ | |
const web3 = new Web3(new LoomProvider(client, indexerPrivateKey)) | |
const ABI = HackerNoon.abi; | |
const indexerClientInstance = new web3.eth.Contract( | |
ABI, | |
HackerNoon.networks.default.address, | |
{ | |
from: indexerUserAddress | |
} | |
); | |
/* | |
* Sends a new Document to the Elasticsearch index every time a StoryPublished is emitted | |
* The document contains title, text and the author address | |
*/ | |
indexerClientInstance.events.StoryPublished((err, event) => { | |
if (err) console.error('Error on event', err); | |
const {storyId, owner, title, text} = event.returnValues; | |
esclient.create({ | |
index: 'stories', | |
type: '_doc', | |
id: storyId.toString(), | |
body: { | |
title: title, | |
text: text, | |
writer: owner, | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment