Skip to content

Commit

Permalink
feat: add gRPC method to estimate fee
Browse files Browse the repository at this point in the history
  • Loading branch information
michael1011 committed Feb 19, 2019
1 parent 525e75f commit 985cb10
Show file tree
Hide file tree
Showing 10 changed files with 479 additions and 13 deletions.
2 changes: 1 addition & 1 deletion lib/chain/ChainClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class ChainClient extends BaseClient implements ChainClientInterface {
const feeResponse = await this.rpcClient.call<number>('estimatefee', numberBlocks);
const feePerKb = feeResponse * 100000000;

return Math.ceil(feePerKb / 1000);
return Math.round(feePerKb / 1000);
}

public generate = (blocks: number): Promise<string[]> => {
Expand Down
5 changes: 3 additions & 2 deletions lib/grpc/GrpcServer.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import fs from 'fs';
import assert from 'assert';
import { pki, md } from 'node-forge';
import grpc, { Server } from 'grpc';
import Logger from '../Logger';
import Errors from './Errors';
import Logger from '../Logger';
import GrpcService from './GrpcService';
import Service from '../service/Service';
import { BoltzService } from '../proto/boltzrpc_grpc_pb';
import assert from 'assert';

type GrpcConfig = {
host: string,
Expand All @@ -27,6 +27,7 @@ class GrpcServer {
getBalance: grpcService.getBalance,
newAddress: grpcService.newAddress,
getTransaction: grpcService.getTransaction,
getFeeEstimation: grpcService.getFeeEstimation,
broadcastTransaction: grpcService.broadcastTransaction,
listenOnAddress: grpcService.listenOnAddress,
subscribeTransactions: grpcService.subscribeTransactions,
Expand Down
8 changes: 8 additions & 0 deletions lib/grpc/GrpcService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ class GrpcService {
}
}

public getFeeEstimation: grpc.handleUnaryCall<boltzrpc.GetFeeEstimationRequest, boltzrpc.GetFeeEstimationResponse> = async (call, callback) => {
try {
callback(null, await this.service.getFeeEstimation(call.request.toObject()));
} catch (error) {
callback(error, null);
}
}

public broadcastTransaction: grpc.handleUnaryCall<boltzrpc.BroadcastTransactionRequest,
boltzrpc.BroadcastTransactionResponse> = async (call, callback) => {

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.

34 changes: 34 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.

48 changes: 48 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 985cb10

Please sign in to comment.