Breaking-Change: Extremely rough update to work with Kioks wallet
This commit is contained in:
@@ -2,8 +2,14 @@ import { hexToBin } from "@bitauth/libauth";
|
||||
|
||||
import { bold, dim } from "../utils.js";
|
||||
import type { CommandDependencies, CommandIO } from "./types.js";
|
||||
import type { UnspentOutputData } from "@xo-cash/state";
|
||||
import { CommandError } from "./types.js";
|
||||
import type { XOTemplate } from "@xo-cash/types";
|
||||
import { generateTemplateIdentifier } from "@xo-cash/engine";
|
||||
import {
|
||||
buildScriptHashDataMap,
|
||||
enrichUnspentOutput,
|
||||
type UnspentOutputWithMetadata,
|
||||
} from "../../utils/utxo-metadata.js";
|
||||
|
||||
/**
|
||||
* Prints the help message for the resource command.
|
||||
@@ -27,9 +33,12 @@ ${bold("Sub-commands:")}
|
||||
* Formats a single UTXO for display, optionally including reservation info.
|
||||
*/
|
||||
function formatResource(
|
||||
resource: UnspentOutputData,
|
||||
resource: UnspentOutputWithMetadata & { template?: XOTemplate },
|
||||
showReserved = false,
|
||||
): string {
|
||||
// Format the template
|
||||
const template = resource.template ? dim(`[${generateTemplateIdentifier(resource.template)}]`) : "";
|
||||
|
||||
// Format the outpoint
|
||||
const outpoint = bold(
|
||||
`${resource.outpointTransactionHash}:${resource.outpointIndex}`,
|
||||
@@ -39,7 +48,9 @@ function formatResource(
|
||||
const value = dim(`${resource.valueSatoshis} sats`);
|
||||
|
||||
// Format the output
|
||||
const output = dim(resource.outputIdentifier);
|
||||
const output = resource.outputIdentifier
|
||||
? dim(resource.outputIdentifier)
|
||||
: "";
|
||||
|
||||
// Format the height
|
||||
const height = dim(`(height ${resource.minedAtHeight})`);
|
||||
@@ -47,11 +58,11 @@ function formatResource(
|
||||
// If the resource is reserved, format the reservation info
|
||||
if (showReserved && resource.reservedBy) {
|
||||
const inv = dim(`reserved for ${resource.reservedBy}`);
|
||||
return `${outpoint} ${value} ${output} ${height} ${inv}`;
|
||||
return `${template} ${outpoint} ${value} ${output} ${height} ${inv}`;
|
||||
}
|
||||
|
||||
// Otherwise, format the resource without reservation info
|
||||
return `${outpoint} ${value} ${output} ${height}`;
|
||||
return `${template} ${outpoint} ${value} ${output} ${height}`;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -108,9 +119,30 @@ export const handleResourceCommand = async (
|
||||
return { count: 0 };
|
||||
}
|
||||
|
||||
const scriptHashDataByScriptHash = await buildScriptHashDataMap(
|
||||
deps.app.engine,
|
||||
);
|
||||
|
||||
const resourcesWithTemplateInformation = await Promise.all(
|
||||
filtered.map(async (resource) => {
|
||||
const enriched = enrichUnspentOutput(
|
||||
resource,
|
||||
scriptHashDataByScriptHash,
|
||||
);
|
||||
const template = enriched.templateIdentifier
|
||||
? await deps.app.engine.getTemplate(enriched.templateIdentifier)
|
||||
: undefined;
|
||||
|
||||
return {
|
||||
...enriched,
|
||||
template,
|
||||
};
|
||||
}),
|
||||
);
|
||||
|
||||
// Format the resources into a list of strings that we can display to the user
|
||||
const showReserved = qualifier === "all" || qualifier === "reserved";
|
||||
const formattedResources = filtered.map((r) =>
|
||||
const formattedResources = resourcesWithTemplateInformation.map((r) =>
|
||||
formatResource(r, showReserved),
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user