Skip to content
This repository has been archived by the owner on Dec 13, 2019. It is now read-only.

Commit

Permalink
Fix the deposit confirmed test
Browse files Browse the repository at this point in the history
  • Loading branch information
snario committed Oct 24, 2019
1 parent 7d529f3 commit 24ec730
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 28 deletions.
28 changes: 27 additions & 1 deletion packages/node/src/message-handling/handle-protocol-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

/**
Expand All @@ -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(
Expand Down Expand Up @@ -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);
}
Expand Down
30 changes: 3 additions & 27 deletions packages/node/src/request-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -32,7 +25,6 @@ import { prettyPrintObject } from "./utils";
*/
export class RequestHandler {
private readonly methods = new Map();
public readonly processQueue = new ProcessQueue();

router!: RpcRouter;

Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand All @@ -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);
}

Expand Down

0 comments on commit 24ec730

Please sign in to comment.