|
@@ -84,10 +84,12 @@ const getEraAtHash = (api: Api, hash: string) =>
|
|
const getEraAtBlock = async (api: Api, block: number) =>
|
|
const getEraAtBlock = async (api: Api, block: number) =>
|
|
getEraAtHash(api, await getBlockHash(api, block))
|
|
getEraAtHash(api, await getBlockHash(api, block))
|
|
|
|
|
|
-const getTimestamp = async (api: Api, hash?: string) =>
|
|
|
|
- hash
|
|
|
|
- ? moment.utc(await api.query.timestamp.now.at(hash)).valueOf()
|
|
|
|
- : moment.utc(await api.query.timestamp.now()).valueOf()
|
|
|
|
|
|
+const getTimestamp = async (api: Api, hash?: string) => {
|
|
|
|
+ const timestamp = hash
|
|
|
|
+ ? await api.query.timestamp.now.at(hash)
|
|
|
|
+ : await api.query.timestamp.now()
|
|
|
|
+ return moment.utc(timestamp.toNumber()).valueOf()
|
|
|
|
+}
|
|
|
|
|
|
const findCouncilAtBlock = (api: Api, block: number) =>
|
|
const findCouncilAtBlock = (api: Api, block: number) =>
|
|
Council.findOne({
|
|
Council.findOne({
|
|
@@ -137,12 +139,16 @@ const addBlock = async (
|
|
}
|
|
}
|
|
|
|
|
|
const processBlock = async (api: Api, id: number) => {
|
|
const processBlock = async (api: Api, id: number) => {
|
|
|
|
+ const exists = await Block.findByPk(id)
|
|
|
|
+ if (exists) return exists
|
|
|
|
+
|
|
processing = `block ${id}`
|
|
processing = `block ${id}`
|
|
const last = await Block.findByPk(id - 1)
|
|
const last = await Block.findByPk(id - 1)
|
|
const [block] = await Block.findOrCreate({ where: { id } })
|
|
const [block] = await Block.findOrCreate({ where: { id } })
|
|
block.hash = await getBlockHash(api, id)
|
|
block.hash = await getBlockHash(api, id)
|
|
block.timestamp = await getTimestamp(api, block.hash)
|
|
block.timestamp = await getTimestamp(api, block.hash)
|
|
- block.blocktime = last ? block.timestamp - last.timestamp : 6000
|
|
|
|
|
|
+ block.blocktime =
|
|
|
|
+ last && last.timestamp > 0 ? block.timestamp - last.timestamp : 6000
|
|
block.save()
|
|
block.save()
|
|
|
|
|
|
processEvents(api, id, block.hash)
|
|
processEvents(api, id, block.hash)
|