fetch allLpEvents from lastBlockStored
This commit is contained in:
parent
ade8b1bdfc
commit
ac844c4722
|
@ -25,10 +25,11 @@ export const batchAddEvents = async events => {
|
|||
lpEvent.blockNumber = blockNumber
|
||||
})
|
||||
})
|
||||
console.log({batch})
|
||||
return await database.action(async () => await database.batch(...batch))
|
||||
}
|
||||
|
||||
//TODO getProfileEvents
|
||||
|
||||
|
||||
export const getLpEventById = async id => {
|
||||
const event = await lpCollection.query(
|
||||
|
@ -39,8 +40,8 @@ export const getLpEventById = async id => {
|
|||
|
||||
export const getLastBlockStored = async () => {
|
||||
const col = await lpCollection.query().fetch()
|
||||
const sorted = col.sort(
|
||||
(a,b) => b.blockNumber - a.blockNumber
|
||||
)
|
||||
return sorted[0].blockNumber
|
||||
const blockNumber = col.length
|
||||
? col.sort((a,b) => b.blockNumber - a.blockNumber)[0].blockNumber
|
||||
: 0
|
||||
return blockNumber
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
import LiquidPledging from 'Embark/contracts/LiquidPledging'
|
||||
import LPVault from 'Embark/contracts/LPVault'
|
||||
import web3 from 'Embark/web3'
|
||||
import { getLastBlockStored } from '../actions/lpEvents'
|
||||
|
||||
|
||||
const AUTHORIZE_PAYMENT = 'AuthorizePayment'
|
||||
const GIVER_ADDED = 'GiverAdded'
|
||||
|
@ -63,12 +65,13 @@ export const formatFundProfileEvent = async event => {
|
|||
}
|
||||
}
|
||||
|
||||
const getPastEvents = async (event, raw = false) => {
|
||||
const getPastEvents = async (event, raw = false, fromBlock = 0) => {
|
||||
const events = await LiquidPledging.getPastEvents(event, {
|
||||
addr: await web3.eth.getCoinbase(),
|
||||
fromBlock: 0,
|
||||
fromBlock,
|
||||
toBlock: 'latest'
|
||||
})
|
||||
if (raw) console.log({events, fromBlock})
|
||||
if (raw) return events
|
||||
const formattedEvents = await Promise.all(
|
||||
events.map(formatFundProfileEvent)
|
||||
|
@ -87,7 +90,11 @@ export const lpEventsSubscription = async () => {
|
|||
export const getFunderProfiles = async () => await getPastEvents(GIVER_ADDED)
|
||||
export const getDelegateProfiles = async () => await getPastEvents(DELEGATE_ADDED)
|
||||
export const getProjectProfiles = async () => await getPastEvents(PROJECT_ADDED)
|
||||
export const getAllLPEvents = async () => await getPastEvents(ALL_EVENTS, true)
|
||||
export const getAllLPEvents = async () => await getPastEvents(
|
||||
ALL_EVENTS,
|
||||
true,
|
||||
await getLastBlockStored() + 1
|
||||
)
|
||||
export const getAuthorizedPayments = async () => getPastVaultEvents(AUTHORIZE_PAYMENT)
|
||||
export const getAllVaultEvents = async () => getPastVaultEvents(ALL_EVENTS,true)
|
||||
export const getProfileEvents = async () => {
|
||||
|
|
Loading…
Reference in New Issue