{"size": 712, "ext": "js", "max_stars_repo_path": "remote/src/blockchain.js", "max_stars_repo_name": "input-output-hk/symphony", "max_stars_repo_stars_event_min_datetime": "2018-03-04T07:26:09.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T01:28:02.000Z", "max_issues_repo_path": "remote/src/blockchain.js", "max_issues_repo_name": "kenetalan/symphony", "max_issues_repo_issues_event_min_datetime": "2018-02-13T12:27:49.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-27T16:04:57.000Z", "max_forks_repo_path": "remote/src/blockchain.js", "max_forks_repo_name": "kenetalan/symphony", "max_forks_repo_forks_event_min_datetime": "2018-03-30T03:25:49.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-02T20:55:03.000Z"}
{"max_stars_count": 55, "max_issues_count": 5, "max_forks_count": 17, "avg_line_length": 37.4736842105, "max_line_length": 125, "alphanum_fraction": 0.7261235955}
import { addBlock } from './db'
const btc = require('blockchain.info/blockexplorer')
export const apiCode = 'f1dd94da-bfc0-46b2-932c-935f53bb352d'
export const getLatestFullBlock = async () => btc.getLatestBlock({apiCode}).then(({ hash }) => btc.getBlock(hash, {apiCode}))

// Builds the chain of blocks from the latest to the current hash
export const getLatestBlocksSince = async function (lastKnownHash) {
  let block = await getLatestFullBlock()
  let blockhash = block.hash

  while (block.next_block !== lastKnownHash) {
    console.log('adding', block)
    await addBlock(block)
    block = await btc.getBlock(block.prev_block, {apiCode})
    block.next_block = blockhash
    blockhash = block.hash
  }
}
