Add variable step
This commit is contained in:
@@ -4,7 +4,7 @@ import type {
|
||||
Engine,
|
||||
GetSpendableResourcesParameters,
|
||||
} from "@xo-cash/engine";
|
||||
import { hasInvitationExpired, mergeInvitationCommits } from "@xo-cash/engine";
|
||||
import { generateTemplateIdentifier, hasInvitationExpired, mergeInvitationCommits } from "@xo-cash/engine";
|
||||
import type {
|
||||
XOInvitation,
|
||||
XOInvitationCommit,
|
||||
@@ -498,16 +498,38 @@ export class Invitation extends EventEmitter<InvitationEventMap> {
|
||||
);
|
||||
}
|
||||
|
||||
const resolvedOptions: GetSpendableResourcesParameters = {
|
||||
templateIdentifier,
|
||||
outputIdentifier: options.outputIdentifier ?? fallbackOutputIdentifier ?? "",
|
||||
};
|
||||
// const resolvedOptions: GetSpendableResourcesParameters = {
|
||||
// templateIdentifier,
|
||||
// outputIdentifier: options.outputIdentifier ?? fallbackOutputIdentifier ?? "",
|
||||
// };
|
||||
|
||||
// Find the suitable resources
|
||||
const { unspentOutputs } = await this.engine.getSpendableResources(
|
||||
this.data,
|
||||
resolvedOptions,
|
||||
);
|
||||
// There are disagreements around whether all spendables should be returned from getSpendableResources.
|
||||
// I had a fix merged in, but it got overwritten. So, im just going to get all of them manually and go around
|
||||
// The engine's expectations.
|
||||
// To do this, we are going to grab all out templates
|
||||
const templates = await this.engine.listImportedTemplates();
|
||||
|
||||
// For each template, we need to create a 2d array of all the outputs
|
||||
const outputs = templates.map(template => {
|
||||
return Object.keys(template.outputs).map(output => {
|
||||
const templateIdentifier = generateTemplateIdentifier(template);
|
||||
|
||||
return {
|
||||
templateIdentifier,
|
||||
outputIdentifier: output,
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
// then, for each output, we need to get the spendable resources
|
||||
const spendableResources = await Promise.all(outputs.flat().map(output => {
|
||||
return this.engine.getSpendableResources(this.data, {
|
||||
templateIdentifier: output.templateIdentifier,
|
||||
outputIdentifier: output.outputIdentifier,
|
||||
});
|
||||
}));
|
||||
|
||||
const unspentOutputs = spendableResources.flatMap(resource => resource.unspentOutputs);
|
||||
|
||||
// Update the status of the invitation
|
||||
await this.updateStatus();
|
||||
|
||||
Reference in New Issue
Block a user