All files / tools/consolidator/interactions list.ts

75% Statements 9/12
66.67% Branches 8/12
100% Functions 1/1
75% Lines 9/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 46 47 48            1x         71x 32x         39x             39x           39x           39x 39x             39x      
import { Remark } from "../remark";
import { List } from "../../../rmrk1.0.0/classes/list";
import { NFT } from "../../..";
import { OP_TYPES } from "../../constants";
import { Change } from "../../../rmrk1.0.0/changelog";
 
export const listForSaleInteraction = (
  remark: Remark,
  listEntity: List,
  nft?: NFT
): void => {
  if (!nft) {
    throw new Error(
      `[${OP_TYPES.LIST}] Attempting to list non-existant NFT ${listEntity.id}`
    );
  }
 
  Iif (nft.burned != "") {
    throw new Error(
      `[${OP_TYPES.LIST}] Attempting to list burned NFT ${listEntity.id}`
    );
  }
 
  // Check if allowed to issue send - if owner == caller
  Iif (nft.owner != remark.caller) {
    throw new Error(
      `[${OP_TYPES.LIST}] Attempting to list non-owned NFT ${listEntity.id}, real owner: ${nft.owner}`
    );
  }
 
  Iif (nft.transferable === 0 || nft.transferable >= remark.block) {
    throw new Error(
      `[${OP_TYPES.LIST}] Attempting to list non-transferable NFT ${listEntity.id}.`
    );
  }
 
  Eif (listEntity.price !== nft.forsale) {
    nft.addChange({
      field: "forsale",
      old: nft.forsale,
      new: listEntity.price,
      caller: remark.caller,
      block: remark.block,
    } as Change);
    nft.forsale = listEntity.price;
  }
};