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

const resolvedOps: ResolvedOperation[] = [];

export const pushResolvedOp = (op: ResolvedOperation | ResolvedOperation[]) => {
  if (Array.isArray(op)) {
    resolvedOps.push(...op);
  } else {
    resolvedOps.push(op);
  }
};

export const shiftResolvedOp = () =>
  ({
    isOp: resolvedOps.length > 0,
    op: resolvedOps.shift(),
  }) as
    | {
        isOp: true;
        op: ResolvedOperation | null;
      }
    | {
        isOp: false;
        op: undefined;
      };
