2

I was checking the project eosio-project-demux-example since I want to use demux.js in my own project. I have doubts about the mongoose model BlockIndexState.

I would like to know what is it used for. Is it required? Is it for querying? Thanks for your help!

1 Answer 1

1

BlockIndexState, is a mongoose defined schema, where dapp know about the processed blocks,

Demux watch the node block from particular defined block[ eg:153343 https://github.com/EOSIO/demux-js#example, check NodeosActionReader ] block and store the state of block that being watched and continue from that point.

async updateIndexState (state, block, isReplay) {
const { blockInfo } = block
try {
  await state.blockIndexState.update({}, {
    blockNumber: blockInfo.blockNumber,
    blockHash: blockInfo.blockHash,
    isReplay
  }, { upsert: true }).exec()
} catch (err) {
  console.error(err)
}
}

async loadIndexState () {
try {
  let blockHash
  let blockNumber
  const indexState = await BlockIndexState.findOne({}).exec()
  if (indexState) {
    ({ blockHash, blockNumber } = indexState)
  }
  if (blockNumber && blockHash) {
    return { blockNumber, blockHash }
  }
  return { blockNumber: 0, blockHash: '' }
} catch (err) {
  console.error(err)
}

one can clearly see that updateIndexState,loadIndexState alters/reads BlockIndexState

references https://github.com/EOSIO/eosio-project-demux-example/issues/31

2
  • Can you suggest me some source so that i can learn demux and use in my project. Commented Oct 12, 2018 at 8:38
  • 1
    Yes most of the github examples are mocking EOS main project,I am planning to give a demo soon . I struggled a lot at first ,now I am comfortable with it.I'll get you know Commented Oct 14, 2018 at 6:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.