Skip to content

Commit

Permalink
docs: swagger specs for API V2 endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
michael1011 committed Jan 14, 2024
1 parent 83965bb commit 798b4a7
Show file tree
Hide file tree
Showing 8 changed files with 773 additions and 82 deletions.
395 changes: 330 additions & 65 deletions lib/api/v2/routers/SwapRouter.ts

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions lib/service/Errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,8 @@ export default {
message: 'incorrect preimage',
code: concatErrorCode(ErrorCodePrefix.Service, 36),
}),
INVALID_VIN: (): Error => ({
message: 'input index is out of range',
code: concatErrorCode(ErrorCodePrefix.Service, 37),
}),
};
6 changes: 5 additions & 1 deletion lib/service/MusigSigner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ class MusigSigner {
rawTransaction: Buffer | string,
vin: number,
): Promise<PartialSignature> => {
const tx = parseTransaction(currency.type, rawTransaction);
if (vin < 0 || tx.ins.length <= vin) {
throw Errors.INVALID_VIN();
}

const wallet = this.walletManager.wallets.get(currency.symbol)!;

const ourKeys = wallet.getKeysByIndex(keyIndex);
Expand All @@ -153,7 +158,6 @@ class MusigSigner {

musig.aggregateNonces([[theirPublicKey, theirNonce]]);

const tx = parseTransaction(currency.type, rawTransaction);
const hash = await hashForWitnessV1(currency, tx, vin);
musig.initializeSession(hash);

Expand Down
28 changes: 28 additions & 0 deletions lib/service/Service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,34 @@ class Service {
await this.nodeInfo.init();
};

public convertToPairAndSide = (
from: string,
to: string,
isReverse: boolean,
): { pairId: string; orderSide: string } => {
const pair = (
[
[getPairId({ base: from, quote: to }), false],
[getPairId({ base: to, quote: from }), true],
] as [string, boolean][]
).find(([val]) => this.rateProvider.pairs.has(val));

if (pair === undefined) {
throw Errors.PAIR_NOT_FOUND(getPairId({ base: from, quote: to }));
}

return {
pairId: pair[0],
orderSide: isReverse
? pair[1]
? 'sell'
: 'buy'
: pair[1]
? 'buy'
: 'sell',
};
};

/**
* Gets general information about this Boltz instance and the nodes it is connected to
*/
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"precompile": "node parseGitCommit.js",
"compile": "npm run swagger && tsc && cross-os postcompile",
"swagger": "node swagger.js",
"swagger-ui": "docker run --rm -p 8082:8080 -e SWAGGER_JSON=/boltz-backend/swagger-spec.json -v .:/boltz-backend swaggerapi/swagger-ui",
"compile:watch": "tsc -w",
"start": "node bin/boltzd",
"dev": "npm run compile && npm run start",
Expand Down
Loading

0 comments on commit 798b4a7

Please sign in to comment.