diff --git a/packages/node/src/message-handling/handle-protocol-message.ts b/packages/node/src/message-handling/handle-protocol-message.ts index 0401bbf12..dc2b277f1 100644 --- a/packages/node/src/message-handling/handle-protocol-message.ts +++ b/packages/node/src/message-handling/handle-protocol-message.ts @@ -17,7 +17,11 @@ import { StateChannel } from "../models"; import { UNASSIGNED_SEQ_NO } from "../protocol/utils/signature-forwarder"; import { RequestHandler } from "../request-handler"; import RpcRouter from "../rpc-router"; -import { NODE_EVENTS, NodeMessageWrappedProtocolMessage } from "../types"; +import { + DepositConfirmationMessage, + NODE_EVENTS, + NodeMessageWrappedProtocolMessage +} from "../types"; import { bigNumberifyJson, getCreate2MultisigAddress } from "../utils"; /** @@ -43,6 +47,16 @@ export async function handleReceivedProtocolMessage( if (seq === UNASSIGNED_SEQ_NO) return; + // FIXME: Very ugly hack for this one-off "event" style use case + let thisIsADepositConfirmed = false; + if (protocol === Protocol.Uninstall) { + const appInstanceId = (data.params as UninstallParams).appIdentityHash; + const appInstance = await store.getAppInstance(appInstanceId); + if (appInstance.appInterface.addr === networkContext.CoinBalanceRefundApp) { + thisIsADepositConfirmed = true; + } + } + await protocolRunner.runProtocolWithMessage(data); const outgoingEventData = getOutgoingEventDataFromProtocol( @@ -83,6 +97,18 @@ export async function handleReceivedProtocolMessage( } } + if (thisIsADepositConfirmed) { + router.emit( + NODE_EVENTS.DEPOSIT_CONFIRMED, + { + from: publicIdentifier, + type: NODE_EVENTS.DEPOSIT_CONFIRMED, + data: {} // TODO: Validate correct values for the amount, token, etc + } as DepositConfirmationMessage, + "outgoing" + ); + } + if (outgoingEventData) { await emitOutgoingNodeMessage(router, outgoingEventData); } diff --git a/packages/node/src/request-handler.ts b/packages/node/src/request-handler.ts index 08bb4b37d..8762bdc43 100644 --- a/packages/node/src/request-handler.ts +++ b/packages/node/src/request-handler.ts @@ -5,23 +5,16 @@ import EventEmitter from "eventemitter3"; import { methodNameToImplementation } from "./api"; import { ProtocolRunner } from "./machine"; -import { - handleReceivedProposalMessage, - handleReceivedProposeVirtualMessage, - handleRejectProposalMessage -} from "./message-handling/handle-node-message"; +import { handleRejectProposalMessage } from "./message-handling/handle-node-message"; import { handleReceivedProtocolMessage } from "./message-handling/handle-protocol-message"; import ProcessQueue from "./process-queue"; import RpcRouter from "./rpc-router"; import { Store } from "./store"; import { - InstallMessage, - InstallVirtualMessage, NODE_EVENTS, NodeEvents, NodeMessageWrappedProtocolMessage, ProposeMessage, - ProposeVirtualMessage, RejectProposalMessage } from "./types"; import { prettyPrintObject } from "./utils"; @@ -32,7 +25,6 @@ import { prettyPrintObject } from "./utils"; */ export class RequestHandler { private readonly methods = new Map(); - public readonly processQueue = new ProcessQueue(); router!: RpcRouter; @@ -47,7 +39,7 @@ export class RequestHandler { readonly provider: BaseProvider, readonly wallet: Signer, readonly blocksNeededForConfirmation: number, - public readonly processQueue: ProcessQueue + readonly processQueue: ProcessQueue ) {} injectRouter(router: RpcRouter) { @@ -105,18 +97,6 @@ export class RequestHandler { ); break; - case NODE_EVENTS.PROPOSE_INSTALL: - // TODO: Replace type cast with input validation - await handleReceivedProposalMessage(this, msg as ProposeMessage); - break; - - case NODE_EVENTS.PROPOSE_INSTALL_VIRTUAL: - await handleReceivedProposeVirtualMessage( - this, - msg as ProposeVirtualMessage - ); - break; - case NODE_EVENTS.REJECT_INSTALL: case NODE_EVENTS.REJECT_INSTALL_VIRTUAL: // TODO: Replace type cast with input validation @@ -133,12 +113,8 @@ export class RequestHandler { public async hasMessageHandler(event: NodeEvents) { return [ NODE_EVENTS.PROTOCOL_MESSAGE_EVENT, - NODE_EVENTS.PROPOSE_INSTALL, - NODE_EVENTS.PROPOSE_INSTALL_VIRTUAL, NODE_EVENTS.REJECT_INSTALL, - NODE_EVENTS.REJECT_INSTALL_VIRTUAL, - NODE_EVENTS.INSTALL, - NODE_EVENTS.INSTALL_VIRTUAL + NODE_EVENTS.REJECT_INSTALL_VIRTUAL ].includes(event); }