import { Context } from '@coinweb/contract-kit';

import { HISTORY_CODES } from '../../module/history/shared';
import { Exception } from '../features/exception';

let context: Context | null = null;

export const setContext = (newContext: Context) => {
  context = newContext;
};

export const getContext = (): Context => {
  if (!context) {
    throw new Exception({
      code: HISTORY_CODES.ERROR,
      message: 'Context not found. Do not use getContext outside a handler',
    });
  }

  return context;
};
