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 30, 2019
1 parent 41fe517 commit 19f46d6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 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 { 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";

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

router!: RpcRouter;

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

Expand Down

0 comments on commit 19f46d6

Please sign in to comment.