Skip to content

Commit

Permalink
feat: rescan gRPC method (#489)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael1011 committed Feb 19, 2024
1 parent 4972f31 commit 8f3cf44
Show file tree
Hide file tree
Showing 14 changed files with 627 additions and 28 deletions.
24 changes: 24 additions & 0 deletions lib/cli/commands/Rescan.ts
@@ -0,0 +1,24 @@
import { Arguments } from 'yargs';
import { RescanRequest } from '../../proto/boltzrpc_pb';
import BuilderComponents from '../BuilderComponents';
import { callback, loadBoltzClient } from '../Command';

export const command = 'rescan <symbol> <startHeight>';

export const describe = 'rescans the chain of a symbol';

export const builder = {
symbol: BuilderComponents.symbol,
startHeight: {
describe: 'block height to start the rescan from',
type: 'number',
},
};

export const handler = (argv: Arguments<any>): void => {
const request = new RescanRequest();
request.setSymbol(argv.symbol);
request.setStartHeight(argv.startHeight);

loadBoltzClient(argv).rescan(request, callback());
};
1 change: 1 addition & 0 deletions lib/grpc/GrpcServer.ts
Expand Up @@ -27,6 +27,7 @@ class GrpcServer {
updateTimeoutBlockDelta: grpcService.updateTimeoutBlockDelta,
addReferral: grpcService.addReferral,
sweepSwaps: grpcService.sweepSwaps,
rescan: grpcService.rescan,
});
}

Expand Down
17 changes: 17 additions & 0 deletions lib/grpc/GrpcService.ts
Expand Up @@ -203,6 +203,23 @@ class GrpcService {
});
};

public rescan: handleUnaryCall<
boltzrpc.RescanRequest,
boltzrpc.RescanResponse
> = async (call, callback) => {
await this.handleCallback(call, callback, async () => {
const { symbol, startHeight } = call.request.toObject();

const endHeight = await this.service.rescan(symbol, startHeight);

const response = new boltzrpc.RescanResponse();
response.setStartHeight(startHeight);
response.setEndHeight(endHeight);

return response;
});
};

private handleCallback = async <R, T>(
call: R,
callback: (error: any, res: T | null) => void,
Expand Down
17 changes: 17 additions & 0 deletions lib/proto/boltzrpc_grpc_pb.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions lib/proto/boltzrpc_grpc_pb.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions lib/proto/boltzrpc_pb.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8f3cf44

Please sign in to comment.