       Agent.start_link(fn ->
         %{
           low_cnt: block_cnt - 100,
-          high_cnt: block_cnt - 100
+          high_cnt: block_cnt - 100,
+          pkh_index: Map.new
          }
       end, name: @agent_name)
       # Init the task supervisor

    [prev_block | _] = blocks
    block = :rpc |> Gold.getblock!(prev_block.previousblockhash)

    cnt = blocks |> Enum.count
    div = cnt/100
    if (Float.ceil(div) == div) do
      IO.puts cnt
    end

    block |> process_block

    unless (block.height == low) do

  end

  defp process_block(block) do
    @tasksup_name
    |> Task.Supervisor.async(fn () ->
      txns = block.txns
      |> Enum.map(fn(txn_id) ->
        txn = txn_id |> RPC.gettransaction!

        outputs = txn.outputs
        |> Enum.map(&(parse_pkh(&1)))

        inputs = txn.inputs
        |> Enum.map(&(parse_pkh(&1)))

        %{id: txn_id, outputs: outputs, inputs: inputs}
      end)

      # Update the pkh_index
      txns
      |> Enum.each(fn(txn) ->
        txn.outputs
        |> Enum.each(&(add_to_pkh(&1, txn.id)))
        txn.inputs
        |> Enum.each(&(add_to_pkh(&1, txn.id)))
      end)

      %{height: block.height}
    end)
  end

  defp parse_pkh(inoutput) do
    parsed = inoutput |> Script.parse_address
    case parsed do
      {:ok, addr} -> {:ok, Address.raw(addr)}
      {:error, :empty} -> {:error, :empty}
      {:error, :op_return} -> {:error, :op_return}
      {:error, :coinbase} -> {:error, :coinbase}
      other ->
        Logger.error "Explorer: Failed to parse PKH from script:"
        IO.inspect inoutput
        other
    end
  end

end
