Skip to content

Commit

Permalink
feat: add gRPC method to send coins
Browse files Browse the repository at this point in the history
  • Loading branch information
michael1011 committed Feb 19, 2019
1 parent 985cb10 commit 0cb6f51
Show file tree
Hide file tree
Showing 18 changed files with 619 additions and 30 deletions.
2 changes: 1 addition & 1 deletion lib/cli/commands/BroadcastTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import BuilderComponents from '../BuilderComponents';

export const command = 'broadcasttransaction <currency> <transaction_hex>';

export const describe = 'get a new address for the specified coin';
export const describe = 'broadcasts a hex encoded transaction on the specified network';

export const builder = {
currency: BuilderComponents.currency,
Expand Down
2 changes: 1 addition & 1 deletion lib/cli/commands/CreateSwap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { CreateSwapRequest } from '../../proto/boltzrpc_pb';
export const command = 'createswap <base_currency> <quote_currency> <order_side> <rate> <invoice>' +
'<refund_public_key> [timeout_block_number] [output_type]';

export const describe = 'create a new swap from the chain to Lightning';
export const describe = 'creates a new swap from the chain to Lightning';

export const builder = {
base_currency: BuilderComponents.base_currency,
Expand Down
2 changes: 1 addition & 1 deletion lib/cli/commands/GetBalance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import BuilderComponents from '../BuilderComponents';

export const command = 'getbalance [currency]';

export const describe = 'get the balance of all wallets or a specific one';
export const describe = 'gets the balance for either all wallets or just a single one if specified';

export const builder = {
currency: BuilderComponents.currency,
Expand Down
2 changes: 1 addition & 1 deletion lib/cli/commands/GetInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { GetInfoRequest } from '../../proto/boltzrpc_pb';

export const command = 'getinfo';

export const describe = 'get information about the Boltz instance';
export const describe = 'gets information about the Boltz instance and the nodes it is connected to';

export const handler = (argv: Arguments<any>) => {
loadBoltzClient(argv).getInfo(new GetInfoRequest(), callback);
Expand Down
2 changes: 1 addition & 1 deletion lib/cli/commands/NewAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import BuilderComponents from '../BuilderComponents';

export const command = 'newaddress <currency> [type]';

export const describe = 'get a new address for the specified coin';
export const describe = 'gets a new address of a specified wallet';

export const builder = {
currency: BuilderComponents.currency,
Expand Down
2 changes: 1 addition & 1 deletion lib/cli/commands/NewKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { printResponse } from '../Command';

export const command = 'newkeys <network>';

export const describe = 'get new keys for the specified network';
export const describe = 'gets new keys for the specified network';

export const builder = {
network: {
Expand Down
32 changes: 32 additions & 0 deletions lib/cli/commands/SendCoins.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Arguments } from 'yargs';
import BuilderComponents from '../BuilderComponents';
import { callback, loadBoltzClient } from '../Command';
import { SendCoinsRequest } from '../../proto/boltzrpc_pb';

export const command = 'sendcoins <currency> <address> <amount> [fee_per_byte]';

export const describe = 'sends coins to a specified address';

export const builder = {
currency: BuilderComponents.currency,
address: {
describe: 'address to which the funds should be sent',
type: 'string',
},
amount: {
describe: 'amount that should be sent',
type: 'number',
},
fee_per_byte: BuilderComponents.feePerByte,
};

export const handler = (argv: Arguments<any>) => {
const request = new SendCoinsRequest();

request.setCurrency(argv.currency);
request.setAddress(argv.address);
request.setAmount(argv.amount);
request.setSatPerVbyte(argv.fee_per_byte);

loadBoltzClient(argv).sendCoins(request, callback);
};
3 changes: 2 additions & 1 deletion lib/grpc/GrpcServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class GrpcServer {
subscribeInvoices: grpcService.subscribeInvoices,
createSwap: grpcService.createSwap,
createReverseSwap: grpcService.createReverseSwap,
sendCoins: grpcService.sendCoins,
});
}

Expand Down Expand Up @@ -66,7 +67,7 @@ class GrpcServer {
public close = async () => {
return new Promise((resolve) => {
this.server.tryShutdown(() => {
this.logger.info('GRPC server completed shutdown');
this.logger.info('gRPC server completed shutdown');
resolve();
});
});
Expand Down
19 changes: 15 additions & 4 deletions lib/grpc/GrpcService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,16 @@ class GrpcService {

this.service.on('transaction.confirmed', (transactionHash: string, outputAddress: string) => {
const response = new boltzrpc.SubscribeTransactionsResponse();

response.setTransactionHash(transactionHash);
response.setOutputAddress(outputAddress);

call.write(response);
});
}

public subscribeInvoices: grpc.handleServerStreamingCall<boltzrpc.SubscribeInvoicesRequest, boltzrpc.SubscribeInvoicesResponse> = async (call) => {
this.service.on('invoice.paid', (invoice: string) => {
const response = new boltzrpc.SubscribeInvoicesResponse();

response.setEvent(boltzrpc.InvoiceEvent.PAID);
response.setInvoice(invoice);

Expand All @@ -105,7 +104,6 @@ class GrpcService {

this.service.on('invoice.settled', (invoice: string, preimage: string) => {
const response = new boltzrpc.SubscribeInvoicesResponse();

response.setEvent(boltzrpc.InvoiceEvent.SETTLED);
response.setInvoice(invoice);
response.setPreimage(preimage);
Expand All @@ -132,7 +130,6 @@ class GrpcService {

public createReverseSwap: grpc.handleUnaryCall<boltzrpc.CreateReverseSwapRequest, boltzrpc.CreateReverseSwapResponse> =
async (call, callback) => {

try {
const {
invoice,
Expand All @@ -154,6 +151,20 @@ class GrpcService {
callback(error, null);
}
}

public sendCoins: grpc.handleUnaryCall<boltzrpc.SendCoinsRequest, boltzrpc.SendCoinsResponse> = async (call, callback) => {
try {
const { vout, transactionHash } = await this.service.sendCoins(call.request.toObject());

const response = new boltzrpc.SendCoinsResponse();
response.setTransactionHash(transactionHash);
response.setVout(vout);

callback(null, response);
} catch (error) {
callback(error, null);
}
}
}

export default GrpcService;
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.

58 changes: 58 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 0cb6f51

Please sign in to comment.