From 84f4d5845f6f31f2ba488957c97c510bb9126a78 Mon Sep 17 00:00:00 2001 From: Daniel McNally Date: Thu, 11 Jun 2020 14:29:03 -0400 Subject: [PATCH] feat(connext): log created outgoing hashlock xfers This handles the http request xud receives from connext when an outgoing hash lock transfer is created by logging an appropriate message. Previously this would be logged as a `warn` due to an unknown incoming transfer. --- lib/connextclient/ConnextClient.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/connextclient/ConnextClient.ts b/lib/connextclient/ConnextClient.ts index 5617524df..36f5834d7 100644 --- a/lib/connextclient/ConnextClient.ts +++ b/lib/connextclient/ConnextClient.ts @@ -91,11 +91,14 @@ class ConnextClient extends SwapClient { public address?: string; /** A map of currency symbols to token addresses. */ public tokenAddresses = new Map(); - /** A map of expected invoices by hash. + /** + * A map of expected invoices by hash. * This is equivalent to invoices of lnd with the difference * being that we're managing the state of invoice on xud level. */ private expectedIncomingTransfers = new Map(); + /** The set of hashes for outgoing transfers. */ + private outgoingTransferHashes = new Set(); private port: number; private host: string; private webhookport: number; @@ -146,11 +149,18 @@ class ConnextClient extends SwapClient { timelock, rHash, } = transferReceivedRequest; + + if (this.outgoingTransferHashes.has(rHash)) { + this.outgoingTransferHashes.delete(rHash); + this.logger.debug(`outgoing hash lock transfer with rHash ${rHash} created`); + return; + } const expectedIncomingTransfer = this.expectedIncomingTransfers.get(rHash); if (!expectedIncomingTransfer) { this.logger.warn(`received unexpected incoming transfer created event with rHash ${rHash}`); return; } + const { units: expectedUnits, expiry: expectedTimelock, @@ -588,6 +598,7 @@ class ConnextClient extends SwapClient { */ private executeHashLockTransfer = async (payload: TokenPaymentRequest): Promise => { this.logger.debug(`sending payment of ${payload.amount} with hash ${payload.lockHash} to ${payload.recipient}`); + this.outgoingTransferHashes.add(payload.lockHash); const res = await this.sendRequest('/hashlock-transfer', 'POST', payload); const { appId } = await parseResponseBody(res); return appId;