Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- app.get('/api/getHistory/:contractAddress/:method', function (req, res) {
- const contractAddress = req.params.contractAddress
- const method = req.params.method
- let contract = null
- // First we obtain the contract.
- return Parity.getContract(contractAddress)
- // Then, we get the history of transactions
- .then(function (parsedContract) {
- contract = parsedContract
- return Parity.getHistory(contractAddress)
- })
- .then(function (events) {
- // console.log(events)
- Parity.generateDataPoints(events, contract, method, res)
- // return res.status(200).json(history)
- })
- .then(results => res.status(200).json(results))
- .catch(function (err) {
- console.log(err)
- return res.status(400).json(err.message)
- })
- })
- /////////////////////////////////////////////
- generateDataPoints: function (events, contract, method, res) {
- Promise.all(
- events.map(function(event) {
- console.log('mapping')
- return Promise.all([
- Parity.getBlockTime(event.blockNumber.valueOf()),
- Parity.queryAtBlock(contract[method], event.blockNumber.valueOf())
- ])
- })
- )
- .then(function (pairs) {
- console.log('filtering')
- let prevTime = 0
- return pairs.filter(([time, val]) => {
- if (time !== prevTime) {
- prevTime = time;
- return true;
- } else {
- return false;
- }
- })
- })
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement