Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return new Promise((resolve, reject) => {
return asyncAuto({
// Credentials
credentials: cbk => lndCredentials({logger, node}, cbk),
// Lnd
lnd: ['credentials', ({credentials}, cbk) => {
return cbk(null, authenticatedLndGrpc({
cert: credentials.cert,
macaroon: credentials.macaroon,
socket: credentials.socket,
}));
}],
},
returnResult({reject, resolve, of: 'lnd'}, cbk));
});
};
},
cbk);
}],
// Final swaps result
swaps: [
'attempt',
'claim',
'funding',
'refund',
({attempt, claim, funding, refund}, cbk) =>
{
return cbk(null, {attempt, claim, funding, refund});
}],
},
returnResult({of: 'swaps'}, cbk));
};
}
return setJsonInCache({
key,
type,
cache: 'memory',
ms: cacheSwapsMs,
value: swaps,
},
cbk);
}],
// Final swaps result
detectedSwaps: ['swaps', ({swaps}, cbk) => cbk(null, {swaps})],
},
returnResult({of: 'detectedSwaps'}, cbk));
};
},
cbk);
}],
// Final block placement info
blockPlacement: ['getCached', 'getFresh', ({getCached, getFresh}, cbk) => {
const block = getFresh || getCached;
return cbk(null, {
created_at: block.created_at,
current_confirmation_count: block.current_confirmation_count,
previous_block: block.previous_block,
});
}],
},
returnResult({of: 'blockPlacement'}, cbk));
};
// Get network
getNetwork: ['lnd', ({lnd}, cbk) => getNetwork({lnd}, cbk)],
// Swap service
service: ['getNetwork', ({getNetwork}, cbk) => {
const {network} = getNetwork;
try {
return cbk(null, lightningLabsSwapService({network}));
} catch (err) {
return cbk([400, 'FailedToFindSupportedSwapService', {err}]);
}
}],
},
returnResult({reject, resolve, of: 'service'}));
});
};
break;
}
// Report unanticipated errors
if (!text) {
return returnResult({reject, resolve, of: 'getPayment'}, cbk)(err);
}
sendMessage({id, key, request, text}, err => {});
return returnResult({reject, resolve, of: 'getPayment'}, cbk)(null, {
getPayment: {tokens: 0},
});
}
return returnResult({reject, resolve, of: 'getPayment'}, cbk)(err, res);
});
});
utxo: ['getBlock', 'getUtxo', ({getBlock, getUtxo}, cbk) => {
if (!getUtxo.utxo) {
return cbk(null, {});
}
const utxo = {
block: getBlock || undefined,
conf_count: getUtxo.utxo.conf_count || undefined,
output_script: getUtxo.utxo.output_script,
tokens: getUtxo.utxo.tokens,
};
return cbk(null, {utxo});
}],
},
returnResult({reject, resolve, of: 'utxo'}, cbk));
});
};
}
return asyncMap(decrypt, ({credentials, macaroon, node}, cbk) => {
return putSavedCredentials({
fs,
macaroon,
node,
cert: credentials.cert,
socket: credentials.socket,
},
cbk);
},
cbk);
}],
},
returnResult({reject, resolve}));
});
};