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

Change responses to return full channel states and transfers #400

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions modules/browser-node/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ export class BrowserNode implements INodeService {
try {
const rpc = constructRpcRequest<"chan_deposit">(ChannelRpcMethods.chan_deposit, params);
const res = await this.channelProvider!.send(rpc);
return Result.ok({ channelAddress: res.channelAddress });
return Result.ok(res);
} catch (e) {
return Result.fail(e);
}
Expand All @@ -410,8 +410,8 @@ export class BrowserNode implements INodeService {
): Promise<Result<NodeResponses.RequestCollateral, BrowserNodeError>> {
try {
const rpc = constructRpcRequest<"chan_requestCollateral">(ChannelRpcMethods.chan_requestCollateral, params);
await this.channelProvider!.send(rpc);
return Result.ok({ channelAddress: params.channelAddress });
const res = await this.channelProvider!.send(rpc);
return Result.ok(res);
} catch (e) {
return Result.fail(e);
}
Expand All @@ -427,6 +427,7 @@ export class BrowserNode implements INodeService {
channelAddress: res.channelAddress,
transferId: (res.latestUpdate.details as CreateUpdateDetails).transferId,
routingId: (res.latestUpdate.details as CreateUpdateDetails).meta?.routingId,
channel: res,
});
} catch (e) {
return Result.fail(e);
Expand All @@ -442,7 +443,7 @@ export class BrowserNode implements INodeService {
return Result.ok({
channelAddress: res.channelAddress,
transferId: (res.latestUpdate.details as CreateUpdateDetails).transferId,
routingId: (res.latestUpdate.details as CreateUpdateDetails).meta?.routingId,
channel: res,
});
} catch (e) {
return Result.fail(e);
Expand All @@ -459,6 +460,7 @@ export class BrowserNode implements INodeService {
channelAddress: res.channel.channelAddress,
transferId: (res.channel.latestUpdate.details as CreateUpdateDetails).transferId,
transactionHash: res.transactionHash,
channel: res.channel,
});
} catch (e) {
return Result.fail(e);
Expand All @@ -471,7 +473,7 @@ export class BrowserNode implements INodeService {
try {
const rpc = constructRpcRequest<"chan_restoreState">(ChannelRpcMethods.chan_restoreState, params);
const res = await this.channelProvider!.send(rpc);
return Result.ok({ channelAddress: res.channelAddress });
return Result.ok(res);
} catch (e) {
return Result.fail(e);
}
Expand Down
2 changes: 1 addition & 1 deletion modules/router/src/forwarding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ export async function forwardTransferResolution(

logger.info({ method, methodId }, "Method complete");
return Result.ok({
...resolution.getValue(),
...resolution.getValue() as any,
assetId: incomingTransfer.assetId,
});
}
Expand Down
2 changes: 1 addition & 1 deletion modules/router/src/listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ export async function setupListeners(
"Error forwarding resolution",
);
}
const resolved = res.getValue();
const resolved: any = res.getValue();
if (!!resolved) {
// was not queued, use receiver transfer for values
const amount = BigNumber.from(data.transfer.balance.amount[0]).add(data.transfer.balance.amount[1]);
Expand Down
2 changes: 1 addition & 1 deletion modules/router/src/services/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const attemptTransferWithCollateralization = async (
logger: BaseLogger,
requireOnline = true,
errorContext?: ForwardTransferCreationErrorContext,
): Promise<Result<NodeResponses.ConditionalTransfer | undefined, ForwardTransferCreationError>> => {
): Promise<Result<any | undefined, ForwardTransferCreationError>> => {
const method = "attemptTransferWithCollateralization";
const methodId = getRandomBytes32();
logger.debug(
Expand Down
10 changes: 7 additions & 3 deletions modules/router/src/test/collateral.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe(testName, () => {
node = Sinon.createStubInstance(RestServerNodeService);
node.conditionalTransfer.resolves(Result.ok({} as any));
node.sendDepositTx.resolves(Result.ok({ txHash: getRandomBytes32() }));
node.reconcileDeposit.resolves(Result.ok({ channelAddress: mkAddress() }));
node.reconcileDeposit.resolves(Result.ok(createTestChannelState("deposit").channel));

chainReader = Sinon.createStubInstance(VectorChainReader);
chainReader.getTotalDepositedA.resolves(Result.ok(BigNumber.from(0)));
Expand Down Expand Up @@ -258,7 +258,9 @@ describe(testName, () => {
],
});
node.getStateChannel.resolves(Result.ok(channel));
node.withdraw.resolves(Result.ok({ channelAddress: channel.channelAddress, transferId: getRandomBytes32() }));
node.withdraw.resolves(
Result.ok({ channelAddress: channel.channelAddress, transferId: getRandomBytes32(), channel }),
);
const res = await adjustCollateral(
channel.channelAddress,
AddressZero,
Expand Down Expand Up @@ -331,7 +333,9 @@ describe(testName, () => {
const profile = { ...ethProfile, target: "0" };
getRebalanceProfile.returns(Result.ok(profile));
node.getStateChannel.resolves(Result.ok(channel));
node.withdraw.resolves(Result.ok({ channelAddress: channel.channelAddress, transferId: getRandomBytes32() }));
node.withdraw.resolves(
Result.ok({ channelAddress: channel.channelAddress, transferId: getRandomBytes32(), channel }),
);
const res = await adjustCollateral(
channel.channelAddress,
AddressZero,
Expand Down
2 changes: 1 addition & 1 deletion modules/router/src/test/forwarding.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ describe(testName, () => {
node.getStateChannelByParticipants.resolves(Result.ok(receiverChannel));
node.conditionalTransfer.resolves(Result.ok({} as any));
node.sendDepositTx.resolves(Result.ok({ txHash: getRandomBytes32() }));
node.reconcileDeposit.resolves(Result.ok({ channelAddress: data.channelAddress }));
node.reconcileDeposit.resolves(Result.ok(senderChannel));

store = Sinon.createStubInstance(PrismaStore);

Expand Down
4 changes: 3 additions & 1 deletion modules/server-node/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ server.post<{ Body: NodeParams.RequestSetup }>(
});
try {
const result = await engine.request<"chan_requestSetup">(rpc);
logger.info({ result }, "Request collateral completed");
logger.info({ result }, "Request setup completed");
return reply.status(200).send({ ...result, channelAddress: result.channelAddress });
} catch (e) {
logger.error({ error: jsonifyError(e) });
Expand Down Expand Up @@ -754,6 +754,7 @@ server.post<{ Body: NodeParams.ConditionalTransfer }>(
channelAddress: res.channelAddress,
transferId: (res.latestUpdate.details as CreateUpdateDetails).transferId,
routingId: (res.latestUpdate.details as CreateUpdateDetails).meta?.routingId,
channel: res,
} as NodeResponses.ConditionalTransfer);
} catch (e) {
logger.error({ error: jsonifyError(e) });
Expand Down Expand Up @@ -787,6 +788,7 @@ server.post<{ Body: NodeParams.ResolveTransfer }>(
return reply.status(200).send({
channelAddress: res.channelAddress,
transferId: (res.latestUpdate.details as ResolveUpdateDetails).transferId,
channel: res,
} as NodeResponses.ResolveTransfer);
} catch (e) {
logger.error({ error: jsonifyError(e) });
Expand Down
8 changes: 4 additions & 4 deletions modules/test-runner/src/load/helpers/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ export class Agent {
if (createRes.isError) {
throw createRes.getError()!;
}
logger.debug({ ...createRes.getValue() }, "Created transfer");
return { ...createRes.getValue(), preImage, routingId };
logger.debug({ ...(createRes.getValue() as any) }, "Created transfer");
return { ...(createRes.getValue() as any), preImage, routingId };
}

async resolveHashlockTransfer(
Expand All @@ -159,8 +159,8 @@ export class Agent {
if (resolveRes.isError) {
throw resolveRes.getError()!;
}
logger.debug({ ...resolveRes.getValue() }, "Resolved transfer");
return { ...resolveRes.getValue()!, preImage };
logger.debug({ ...(resolveRes.getValue() as any) }, "Resolved transfer");
return { ...(resolveRes.getValue() as any), preImage };
}

async fundChannelToTarget(assetId: string, target: BigNumber): Promise<void> {
Expand Down
28 changes: 20 additions & 8 deletions modules/types/src/schemas/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,23 +223,23 @@ const PostSetupResponseSchema = BasicChannelServerResponseSchema;
// POST REQUEST SETUP
const PostRequestSetupBodySchema = PostSetupBodySchema;

const PostRequestSetupResponseSchema = BasicChannelServerResponseSchema;
const PostRequestSetupResponseSchema = { 200: TFullChannelState };

// POST DEPOSIT
const PostDepositBodySchema = Type.Intersect([
EngineParams.DepositSchema,
Type.Object({ publicIdentifier: TPublicIdentifier }),
]);

const PostDepositResponseSchema = BasicChannelServerResponseSchema;
const PostDepositResponseSchema = { 200: TFullChannelState };

// POST DEPOSIT
const PostRequestCollateralBodySchema = Type.Intersect([
EngineParams.RequestCollateralSchema,
Type.Object({ publicIdentifier: TPublicIdentifier }),
]);

const PostRequestCollateralResponseSchema = BasicChannelServerResponseSchema;
const PostRequestCollateralResponseSchema = { 200: TFullChannelState };

// POST SEND DEPOSIT TX
const PostSendDepositTxBodySchema = Type.Object({
Expand All @@ -262,15 +262,28 @@ const PostConditionalTransferBodySchema = Type.Intersect([
Type.Object({ publicIdentifier: TPublicIdentifier }),
]);

const PostConditionalTransferResponseSchema = BasicTransferServerResponseSchema;
const PostConditionalTransferResponseSchema = {
200: {
channelAddress: TAddress,
transferId: TBytes32,
routingId: TBytes32,
channel: TFullChannelState,
},
};

// POST RESOLVE CONDITIONAL TRANSFER
const PostResolveTransferBodySchema = Type.Intersect([
EngineParams.ResolveTransferSchema,
Type.Object({ publicIdentifier: TPublicIdentifier }),
]);

const PostResolveTransferResponseSchema = BasicTransferServerResponseSchema;
const PostResolveTransferResponseSchema = {
200: {
channelAddress: TAddress,
transferId: TBytes32,
channel: TFullChannelState,
},
};

// POST WITHDRAW TRANSFER
const PostWithdrawTransferBodySchema = Type.Intersect([
Expand All @@ -283,6 +296,7 @@ const PostWithdrawTransferResponseSchema = {
channelAddress: TAddress,
transferId: TBytes32,
transactionHash: Type.Optional(TBytes32),
channel: TFullChannelState,
}),
};

Expand All @@ -305,9 +319,7 @@ const PostRestoreStateBodySchema = Type.Intersect([
]);

const PostRestoreStateResponseSchema = {
200: Type.Object({
channelAddress: TAddress,
}),
200: TFullChannelState,
};

// CREATE NODE
Expand Down