Skip to content

Commit

Permalink
add support for gift tokens in open command
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbosworth committed Sep 17, 2020
1 parent 641981c commit b43296d
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Versions

## Version 5.47.0

- `open`: Add the option to gift funds to the peer on channel open

## Version 5.46.9

- `accounting`: Add fix for a regression in `accounting chain-fees` causing error
Expand Down
4 changes: 3 additions & 1 deletion bos
Original file line number Diff line number Diff line change
Expand Up @@ -772,10 +772,11 @@ prog
})

// Open channels
.command('open', 'Open channels')
.command('open', 'Open channels using an external wallet for funding')
.help('Create channels from an external wallet. Note: do not self-broadcast')
.argument('<peer_public_keys...>', 'With nodes with public keys')
.option('--amount <channel_capacity>', 'Capacities to open', REPEATABLE)
.option('--give <give_amount>', 'Amount to gift to peer', REPEATABLE)
.option('--node <node_name>', 'Node to open channels')
.action((args, options, logger) => {
return new Promise(async (resolve, reject) => {
Expand All @@ -785,6 +786,7 @@ prog
request,
ask: (n, cbk) => inquirer.prompt([n]).then(res => cbk(res)),
capacities: flatten([options.amount].filter(n => !!n)),
gives: flatten([options.give].filter(n => !!n)),
lnd: (await authenticatedLnd({logger, node: options.node})).lnd,
public_keys: args.peerPublicKeys,
},
Expand Down
13 changes: 12 additions & 1 deletion network/open_channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const utxoPollingTimes = 20;
{
ask: <Ask For Input Function>
capacities: [<New Channel Capacity Tokens Number>]
gives: [<New Channel Give Tokens Number>]
lnd: <Authenticated LND API Object>
logger: <Winston Logger Object>
public_keys: [<Public Key Hex String>]
Expand All @@ -71,6 +72,10 @@ module.exports = (args, cbk) => {
return cbk([400, 'ExpectedChannelCapacitiesToOpenChannels']);
}

if (!isArray(args.gives)) {
return cbk([400, 'ExpectedArrayOfGivesToOpenChannels']);
}

if (!args.lnd) {
return cbk([400, 'ExpectedLndToInitiateOpenChannelRequests']);
}
Expand All @@ -84,12 +89,17 @@ module.exports = (args, cbk) => {
}

const hasCapacities = !!args.capacities.length;
const hasGives = !!args.gives.length;
const publicKeysLength = args.public_keys.length;

if (!!hasCapacities && publicKeysLength !== args.capacities.length) {
return cbk([400, 'CapacitiesMustBeSpecifiedForEveryPublicKey']);
}

if (!!hasGives && publicKeysLength !== args.gives.length) {
return cbk([400, 'GivesMustBeSpecifiedForEveryPublicKey']);
}

if (!args.request) {
return cbk([400, 'ExpectedRequestFunctionToOpenChannels']);
}
Expand Down Expand Up @@ -210,8 +220,9 @@ module.exports = (args, cbk) => {
openChannels: ['connect', 'getWalletVersion', ({}, cbk) => {
const channels = args.public_keys.map((key, i) => {
const capacity = args.capacities[i] || defaultChannelCapacity;
const give = args.gives[i] || undefined;

return {capacity, partner_public_key: key};
return {capacity, give_tokens: give, partner_public_key: key};
});

return openChannels({channels, lnd: args.lnd}, cbk);
Expand Down
80 changes: 75 additions & 5 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"ini": "1.3.5",
"inquirer": "7.3.3",
"ln-accounting": "4.1.10",
"ln-service": "49.10.0",
"ln-service": "49.11.0",
"ln-sync": "0.2.0",
"moment": "2.28.0",
"probing": "1.2.0",
Expand Down Expand Up @@ -69,5 +69,5 @@
"postpublish": "docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t alexbosworth/balanceofsatoshis --push .",
"test": "tap test/arrays/*.js test/balances/*.js test/chain/*.js test/display/*.js test/encryption/*.js test/fiat/*.js test/lnd/*.js test/network/*.js test/nodes/*.js test/responses/*.js test/routing/*.js test/swaps/*.js test/telegram/*.js test/wallets/*.js"
},
"version": "5.46.9"
"version": "5.47.0"
}

0 comments on commit b43296d

Please sign in to comment.