Use xo-cash/utils sse. Add vending machine template. Greatly improve startup times.
This commit is contained in:
+15
-3
@@ -18,10 +18,13 @@ import { EventEmitter } from "../utils/event-emitter.js";
|
||||
|
||||
// TODO: Remove this. Exists to hash the seed for database namespace.
|
||||
import { createHash } from "crypto";
|
||||
import { p2pkhTemplate } from "@xo-cash/templates";
|
||||
import { hexToBin } from "@bitauth/libauth";
|
||||
import { parseTemplate } from "@xo-cash/engine";
|
||||
|
||||
import { p2pkhTemplate } from "@xo-cash/templates";
|
||||
import { vendingMachineTemplate } from "../templates/vending-machine.js";
|
||||
import { wrapBCHTemplate } from "../templates/wrap-template.js";
|
||||
|
||||
export type AppEventMap = {
|
||||
"invitation-added": Invitation;
|
||||
"invitation-removed": Invitation;
|
||||
@@ -53,6 +56,12 @@ export class AppService extends EventEmitter<AppEventMap> {
|
||||
public settings: SettingsService;
|
||||
|
||||
public invitations: Invitation[] = [];
|
||||
/**
|
||||
* Incremented whenever the invitation list or any invitation's data/status changes.
|
||||
* Used by TUI hooks so useSyncExternalStore snapshots change on in-place mutations.
|
||||
*/
|
||||
public invitationsRevision = 0;
|
||||
private invitationRevisions = new Map<string, number>();
|
||||
private invitationEventCleanup = new Map<
|
||||
string,
|
||||
{
|
||||
@@ -82,7 +91,9 @@ export class AppService extends EventEmitter<AppEventMap> {
|
||||
// TODO: We *technically* dont want this here, but we also need some initial templates for the wallet, so im doing it here
|
||||
// Import the default P2PKH template
|
||||
await engine.importTemplate(p2pkhTemplate);
|
||||
|
||||
await engine.importTemplate(vendingMachineTemplate);
|
||||
await engine.importTemplate(wrapBCHTemplate);
|
||||
|
||||
// Update all the unspents for every template, and subscribe to the locking bytecodes for changes
|
||||
// TODO: Remove the above lines that do the same thing. Minimising changes for BLISS.
|
||||
const updateTemplates = async () => {
|
||||
@@ -160,8 +171,9 @@ export class AppService extends EventEmitter<AppEventMap> {
|
||||
// Create the invitation
|
||||
const invitationInstance = await Invitation.create(invitation, deps);
|
||||
|
||||
// Add the invitation to the invitations array
|
||||
// Attach listeners before SSE connects so updates are not missed.
|
||||
await this.addInvitation(invitationInstance);
|
||||
await invitationInstance.start();
|
||||
|
||||
return invitationInstance;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user