pineappleworkshop / ntc-services

0 stars 0 forks source link

Implement proper logic for sourcing inscriptions #13

Open berryhill opened 1 year ago

berryhill commented 1 year ago
      for await (const inscription of ixs) {
        if (!inscription.satpoint) {
          throw new Error("satpoint not found on inscription!");
        }

        if (inscription.content_url && inscription.mime_type) {
          const response = await getContent(inscription.content_url);
          const ixInfo = await fetchInscriptionInfo(inscription.inscription_id);
          inscription.content = response;
          if (typeof response === "object") {
            inscription.isJson = true;
            if (response?.tick && response.op) {
              const brcValidityCheck = await getTickerValidity(
                inscription.inscription_id
              );
              const validity = brcValidityCheck[`${response.op}_info`];
              inscription.isBrc = true;
              inscription.ticker = response.tick;
              inscription.operation = response.op;
              inscription.isValidTransfer = isValidTransferIx(ixInfo);
              inscription.amount = response.amt;
              inscription.validity = validity;
            } else if (response?.content?.p) {
              inscription.isSns = true;
              inscription.operation = response.op;
            } else {
              inscription.name = response.name;
            }
          }
        }

        const foundUnspent = await findUnspentForAddressBySatPoint(
          unspents,
          inscription.satpoint
        );

        if (!foundUnspent) {
          console.error(
            `couldn't find the ${inscription.satpoint} when adding the confirmations to the inscription for address: ${address}`
          );
          continue;
        }

        const ixWithConfirmations = {
          ...inscription,
          confirmations: foundUnspent.confirmations,
        };

        inscriptionsWithConfirmations.push(ixWithConfirmations);
      }
hathbanger commented 1 year ago

info

We need to build this logic into the endpoint that returns the inscriptions.

Here's the JS code: https://github.com/pineappleworkshop/nakamoto-trading-co/blob/dev/apps/nakamoto/hooks/useTradeState.tsx#L398-L463

we can most likely remove this: https://github.com/pineappleworkshop/nakamoto-trading-co/blob/dev/apps/nakamoto/hooks/useTradeState.tsx#L439-L449

this adds the confirmations to the inscription object. we can derive that subtracting the current block height from the return from /api/statspool so we don't need the call for the unspents.