From 19f46d668c692e0391c75d3506babd53c53d7f8b Mon Sep 17 00:00:00 2001 From: Liam Horne Date: Thu, 24 Oct 2019 14:46:52 -0400 Subject: [PATCH] Fix the deposit confirmed test --- .../handle-protocol-message.ts | 28 ++++++++++++++++++- packages/node/src/request-handler.ts | 9 ++---- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/packages/node/src/message-handling/handle-protocol-message.ts b/packages/node/src/message-handling/handle-protocol-message.ts index 37d7d3dc3..2d030a264 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 { NO_PROPOSED_APP_INSTANCE_FOR_APP_INSTANCE_ID } from "../methods/errors" import { StateChannel } from "../models"; 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 27770edb0..0cd1985b1 100644 --- a/packages/node/src/request-handler.ts +++ b/packages/node/src/request-handler.ts @@ -24,7 +24,6 @@ import { prettyPrintObject } from "./utils"; */ export class RequestHandler { private readonly methods = new Map(); - public readonly processQueue = new ProcessQueue(); router!: RpcRouter; @@ -39,7 +38,7 @@ export class RequestHandler { readonly provider: BaseProvider, readonly wallet: Signer, readonly blocksNeededForConfirmation: number, - public readonly processQueue: ProcessQueue + readonly processQueue: ProcessQueue ) {} injectRouter(router: RpcRouter) { @@ -113,12 +112,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); }