All files / tools/consolidator/interactions changeIssuer.ts

91.67% Statements 11/12
83.33% Branches 5/6
100% Functions 2/2
91.67% Lines 11/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45            1x 3x   3x         3x     1x         3x 1x         2x 1x         1x               1x    
import { Collection } from "../../..";
import { OP_TYPES } from "../../constants";
import { Change } from "../../../rmrk1.0.0/changelog";
import { Remark } from "../remark";
import { ChangeIssuer } from "../../../rmrk1.0.0/classes/changeissuer";
 
export const getChangeIssuerEntity = (remark: Remark): ChangeIssuer => {
  const changeIssuerEntity = ChangeIssuer.fromRemark(remark.remark);
 
  Iif (typeof changeIssuerEntity === "string") {
    throw new Error(
      `[${OP_TYPES.CHANGEISSUER}] Dead before instantiation: ${changeIssuerEntity}`
    );
  }
  return changeIssuerEntity;
};
 
export const changeIssuerInteraction = (
  remark: Remark,
  changeIssuerEntity: ChangeIssuer,
  collection?: Collection // Collection in current state
) => {
  if (!collection) {
    throw new Error(
      `This ${OP_TYPES.CHANGEISSUER} remark is invalid - no such collection with ID ${changeIssuerEntity.id} found before block ${remark.block}!`
    );
  }
 
  if (remark.caller != collection.issuer) {
    throw new Error(
      `Attempting to change issuer of collection ${changeIssuerEntity.id} when not issuer!`
    );
  }
 
  collection.addChange({
    field: "issuer",
    old: collection.issuer,
    new: changeIssuerEntity.issuer,
    caller: remark.caller,
    block: remark.block,
  } as Change);
 
  collection.issuer = changeIssuerEntity.issuer;
};