Unverified Commit 2ba21fda authored by Tankred Hase's avatar Tankred Hase Committed by GitHub

Merge pull request #1082 from lightninglabs/dev/commit-fee

Dev/commit fee
parents 9946311f 6e15b94c
...@@ -111,6 +111,7 @@ class ChannelAction { ...@@ -111,6 +111,7 @@ class ChannelAction {
capacity: channel.capacity, capacity: channel.capacity,
localBalance: channel.localBalance, localBalance: channel.localBalance,
remoteBalance: channel.remoteBalance, remoteBalance: channel.remoteBalance,
commitFee: channel.commitFee,
channelPoint: channel.channelPoint, channelPoint: channel.channelPoint,
fundingTxId: this._parseChannelPoint(channel.channelPoint) fundingTxId: this._parseChannelPoint(channel.channelPoint)
.fundingTxidStr, .fundingTxidStr,
...@@ -136,6 +137,7 @@ class ChannelAction { ...@@ -136,6 +137,7 @@ class ChannelAction {
capacity: channel.capacity, capacity: channel.capacity,
localBalance: channel.localBalance, localBalance: channel.localBalance,
remoteBalance: channel.remoteBalance, remoteBalance: channel.remoteBalance,
commitFee: channel.commitFee || 0,
channelPoint: channel.channelPoint, channelPoint: channel.channelPoint,
fundingTxId: this._parseChannelPoint(channel.channelPoint) fundingTxId: this._parseChannelPoint(channel.channelPoint)
.fundingTxidStr, .fundingTxidStr,
...@@ -144,8 +146,6 @@ class ChannelAction { ...@@ -144,8 +146,6 @@ class ChannelAction {
...mapPendingAttributes(poc.channel), ...mapPendingAttributes(poc.channel),
confirmationHeight: poc.confirmationHeight, confirmationHeight: poc.confirmationHeight,
blocksTillOpen: poc.blocksTillOpen, blocksTillOpen: poc.blocksTillOpen,
commitFee: poc.commitFee,
commitWeight: poc.commitWeight,
feePerKw: poc.feePerKw, feePerKw: poc.feePerKw,
status: 'pending-open', status: 'pending-open',
})); }));
......
...@@ -38,7 +38,7 @@ const ComputedChannel = store => { ...@@ -38,7 +38,7 @@ const ComputedChannel = store => {
get channelBalanceOpenSatoshis() { get channelBalanceOpenSatoshis() {
return (store.channels || []) return (store.channels || [])
.filter(c => c.active) .filter(c => c.active)
.map(c => c.localBalance) .map(c => c.localBalance + c.commitFee)
.reduce((a, b) => a + b, 0); .reduce((a, b) => a + b, 0);
}, },
get channelBalanceOpenLabel() { get channelBalanceOpenLabel() {
...@@ -48,7 +48,7 @@ const ComputedChannel = store => { ...@@ -48,7 +48,7 @@ const ComputedChannel = store => {
get channelBalanceInactiveSatoshis() { get channelBalanceInactiveSatoshis() {
return (store.channels || []) return (store.channels || [])
.filter(c => !c.active) .filter(c => !c.active)
.map(c => c.localBalance) .map(c => c.localBalance + c.commitFee)
.reduce((a, b) => a + b, 0); .reduce((a, b) => a + b, 0);
}, },
get channelBalanceInactiveLabel() { get channelBalanceInactiveLabel() {
...@@ -58,7 +58,7 @@ const ComputedChannel = store => { ...@@ -58,7 +58,7 @@ const ComputedChannel = store => {
get channelBalancePendingSatoshis() { get channelBalancePendingSatoshis() {
return (store.pendingChannels || []) return (store.pendingChannels || [])
.filter(c => c.status.includes('open')) .filter(c => c.status.includes('open'))
.map(c => c.localBalance) .map(c => c.localBalance + c.commitFee)
.reduce((a, b) => a + b, 0); .reduce((a, b) => a + b, 0);
}, },
get channelBalancePendingLabel() { get channelBalancePendingLabel() {
...@@ -68,7 +68,7 @@ const ComputedChannel = store => { ...@@ -68,7 +68,7 @@ const ComputedChannel = store => {
get channelBalanceClosingSatoshis() { get channelBalanceClosingSatoshis() {
return (store.pendingChannels || []) return (store.pendingChannels || [])
.filter(c => !c.status.includes('open')) .filter(c => !c.status.includes('open'))
.map(c => c.localBalance) .map(c => c.localBalance + c.commitFee)
.reduce((a, b) => a + b, 0); .reduce((a, b) => a + b, 0);
}, },
get channelBalanceClosingLabel() { get channelBalanceClosingLabel() {
...@@ -78,7 +78,7 @@ const ComputedChannel = store => { ...@@ -78,7 +78,7 @@ const ComputedChannel = store => {
get channelBalanceForceClosingSatoshis() { get channelBalanceForceClosingSatoshis() {
return (store.pendingChannels || []) return (store.pendingChannels || [])
.filter(c => c.status === 'pending-force-closing') .filter(c => c.status === 'pending-force-closing')
.map(c => c.localBalance) .map(c => c.localBalance + c.commitFee)
.reduce((a, b) => a + b, 0); .reduce((a, b) => a + b, 0);
}, },
get channelBalanceForceClosingLabel() { get channelBalanceForceClosingLabel() {
......
...@@ -21,15 +21,17 @@ const ComputedWallet = store => { ...@@ -21,15 +21,17 @@ const ComputedWallet = store => {
}, },
get totalBalanceSatoshis() { get totalBalanceSatoshis() {
const { const {
balanceSatoshis, balanceSatoshis: onChainBalanceSatoshis,
pendingBalanceSatoshis, channelBalancePendingSatoshis,
channelBalanceSatoshis, channelBalanceOpenSatoshis,
channelBalanceInactiveSatoshis,
channelBalanceForceClosingSatoshis, channelBalanceForceClosingSatoshis,
} = store; } = store;
return ( return (
balanceSatoshis + onChainBalanceSatoshis +
pendingBalanceSatoshis + channelBalancePendingSatoshis +
channelBalanceSatoshis + channelBalanceOpenSatoshis +
channelBalanceInactiveSatoshis +
channelBalanceForceClosingSatoshis channelBalanceForceClosingSatoshis
); );
}, },
......
...@@ -101,6 +101,7 @@ describe('Action Channels Unit Tests', () => { ...@@ -101,6 +101,7 @@ describe('Action Channels Unit Tests', () => {
capacity: 100, capacity: 100,
localBalance: 10, localBalance: 10,
remoteBalance: 90, remoteBalance: 90,
commitFee: 15,
channelPoint: 'FFFF:1', channelPoint: 'FFFF:1',
}, },
{ {
...@@ -109,6 +110,7 @@ describe('Action Channels Unit Tests', () => { ...@@ -109,6 +110,7 @@ describe('Action Channels Unit Tests', () => {
capacity: 102, capacity: 102,
localBalance: 11, localBalance: 11,
remoteBalance: 91, remoteBalance: 91,
commitFee: 16,
channelPoint: 'FFFF:2', channelPoint: 'FFFF:2',
}, },
], ],
...@@ -118,11 +120,13 @@ describe('Action Channels Unit Tests', () => { ...@@ -118,11 +120,13 @@ describe('Action Channels Unit Tests', () => {
id: 42, id: 42,
fundingTxId: 'FFFF', fundingTxId: 'FFFF',
status: 'open', status: 'open',
commitFee: 15,
}); });
expect(store.channels[1], 'to satisfy', { expect(store.channels[1], 'to satisfy', {
id: 43, id: 43,
fundingTxId: 'FFFF', fundingTxId: 'FFFF',
status: 'open', status: 'open',
commitFee: 16,
}); });
}); });
...@@ -139,6 +143,7 @@ describe('Action Channels Unit Tests', () => { ...@@ -139,6 +143,7 @@ describe('Action Channels Unit Tests', () => {
capacity: 100, capacity: 100,
localBalance: 10, localBalance: 10,
remoteBalance: 90, remoteBalance: 90,
commitFee: 15,
channelPoint: 'FFFF:1', channelPoint: 'FFFF:1',
}; };
...@@ -160,6 +165,7 @@ describe('Action Channels Unit Tests', () => { ...@@ -160,6 +165,7 @@ describe('Action Channels Unit Tests', () => {
expect(store.pendingChannels[0], 'to satisfy', { expect(store.pendingChannels[0], 'to satisfy', {
remotePubkey: 'some-key', remotePubkey: 'some-key',
fundingTxId: 'FFFF', fundingTxId: 'FFFF',
commitFee: 15,
}); });
expect(store.pendingChannels[2], 'to satisfy', { expect(store.pendingChannels[2], 'to satisfy', {
timeTilAvailable: '3 days and 5 hours', timeTilAvailable: '3 days and 5 hours',
......
...@@ -14,6 +14,7 @@ describe('Computed Channels Unit Tests', () => { ...@@ -14,6 +14,7 @@ describe('Computed Channels Unit Tests', () => {
capacity: 2005000, capacity: 2005000,
localBalance: 1990000, localBalance: 1990000,
remoteBalance: 10000, remoteBalance: 10000,
commitFee: 500,
channelPoint: 'some-channel-point', channelPoint: 'some-channel-point',
active: true, active: true,
status: 'open', status: 'open',
...@@ -24,6 +25,7 @@ describe('Computed Channels Unit Tests', () => { ...@@ -24,6 +25,7 @@ describe('Computed Channels Unit Tests', () => {
capacity: 2005000, capacity: 2005000,
localBalance: 1990000, localBalance: 1990000,
remoteBalance: 10000, remoteBalance: 10000,
commitFee: 400,
channelPoint: 'some-channel-point', channelPoint: 'some-channel-point',
active: false, active: false,
status: 'open', status: 'open',
...@@ -34,6 +36,7 @@ describe('Computed Channels Unit Tests', () => { ...@@ -34,6 +36,7 @@ describe('Computed Channels Unit Tests', () => {
capacity: 1005000, capacity: 1005000,
localBalance: 600000, localBalance: 600000,
remoteBalance: 400000, remoteBalance: 400000,
commitFee: 300,
channelPoint: 'some-channel-point', channelPoint: 'some-channel-point',
status: 'pending-open', status: 'pending-open',
}); });
...@@ -43,6 +46,7 @@ describe('Computed Channels Unit Tests', () => { ...@@ -43,6 +46,7 @@ describe('Computed Channels Unit Tests', () => {
capacity: 805000, capacity: 805000,
localBalance: 500000, localBalance: 500000,
remoteBalance: 300000, remoteBalance: 300000,
commitFee: 200,
channelPoint: 'some-channel-point', channelPoint: 'some-channel-point',
status: 'pending-closing', status: 'pending-closing',
}); });
...@@ -52,6 +56,7 @@ describe('Computed Channels Unit Tests', () => { ...@@ -52,6 +56,7 @@ describe('Computed Channels Unit Tests', () => {
capacity: 705000, capacity: 705000,
localBalance: 400000, localBalance: 400000,
remoteBalance: 300000, remoteBalance: 300000,
commitFee: 100,
channelPoint: 'some-channel-point', channelPoint: 'some-channel-point',
status: 'pending-force-closing', status: 'pending-force-closing',
}); });
...@@ -94,11 +99,15 @@ describe('Computed Channels Unit Tests', () => { ...@@ -94,11 +99,15 @@ describe('Computed Channels Unit Tests', () => {
expect(pendingCloseCh.statusLabel, 'to equal', 'Pending Closing'); expect(pendingCloseCh.statusLabel, 'to equal', 'Pending Closing');
expect(pendingCloseCh.statusType, 'to equal', 'error'); expect(pendingCloseCh.statusType, 'to equal', 'error');
expect(store.channelBalanceOpenLabel, 'to match', /0[,.]0199/); expect(store.channelBalanceOpenLabel, 'to match', /^0[,.]019905$/);
expect(store.channelBalanceInactiveLabel, 'to match', /0[,.]0199/); expect(store.channelBalanceInactiveLabel, 'to match', /^0[,.]019904$/);
expect(store.channelBalancePendingLabel, 'to match', /0[,.]006/); expect(store.channelBalancePendingLabel, 'to match', /^0[,.]006003$/);
expect(store.channelBalanceClosingLabel, 'to match', /0[,.]009/); expect(store.channelBalanceClosingLabel, 'to match', /^0[,.]009003$/);
expect(store.channelBalanceForceClosingLabel, 'to match', /0[,.]004/); expect(
store.channelBalanceForceClosingLabel,
'to match',
/^0[,.]004001$/
);
expect(store.channelStatus, 'to equal', 'success'); expect(store.channelStatus, 'to equal', 'success');
}); });
...@@ -111,11 +120,11 @@ describe('Computed Channels Unit Tests', () => { ...@@ -111,11 +120,11 @@ describe('Computed Channels Unit Tests', () => {
expect(ch.capacityLabel, 'to match', /138[,.]25/); expect(ch.capacityLabel, 'to match', /138[,.]25/);
expect(ch.localBalanceLabel, 'to match', /137[,.]21/); expect(ch.localBalanceLabel, 'to match', /137[,.]21/);
expect(ch.remoteBalanceLabel, 'to match', /0[,.]69/); expect(ch.remoteBalanceLabel, 'to match', /0[,.]69/);
expect(store.channelBalanceOpenLabel, 'to match', /137[,.]21/); expect(store.channelBalanceOpenLabel, 'to match', /137[,.]25/);
expect(store.channelBalanceInactiveLabel, 'to match', /137[,.]21/); expect(store.channelBalanceInactiveLabel, 'to match', /137[,.]24/);
expect(store.channelBalancePendingLabel, 'to match', /41[,.]37/); expect(store.channelBalancePendingLabel, 'to match', /41[,.]39/);
expect(store.channelBalanceClosingLabel, 'to match', /62[,.]06/); expect(store.channelBalanceClosingLabel, 'to match', /62[,.]08/);
expect(store.channelBalanceForceClosingLabel, 'to match', /27[,.]58/); expect(store.channelBalanceForceClosingLabel, 'to match', /27[,.]59/);
}); });
it('should display pending status', () => { it('should display pending status', () => {
......
...@@ -10,6 +10,9 @@ describe('Computed Wallet Unit Tests', () => { ...@@ -10,6 +10,9 @@ describe('Computed Wallet Unit Tests', () => {
describe('ComputedWallet()', () => { describe('ComputedWallet()', () => {
it('should work with initial store', () => { it('should work with initial store', () => {
store.channelBalancePendingSatoshis = 0;
store.channelBalanceOpenSatoshis = 0;
store.channelBalanceInactiveSatoshis = 0;
store.channelBalanceForceClosingSatoshis = 0; store.channelBalanceForceClosingSatoshis = 0;
ComputedWallet(store); ComputedWallet(store);
expect(store.walletAddressUri, 'to equal', ''); expect(store.walletAddressUri, 'to equal', '');
...@@ -37,8 +40,9 @@ describe('Computed Wallet Unit Tests', () => { ...@@ -37,8 +40,9 @@ describe('Computed Wallet Unit Tests', () => {
store.settings.displayFiat = true; store.settings.displayFiat = true;
store.settings.exchangeRate.usd = 0.00014503; store.settings.exchangeRate.usd = 0.00014503;
store.balanceSatoshis = 50000000; store.balanceSatoshis = 50000000;
store.pendingBalanceSatoshis = 50000000; store.channelBalancePendingSatoshis = 50000000;
store.channelBalanceSatoshis = 10000; store.channelBalanceOpenSatoshis = 5000;
store.channelBalanceInactiveSatoshis = 5000;
store.channelBalanceForceClosingSatoshis = 100; store.channelBalanceForceClosingSatoshis = 100;
ComputedWallet(store); ComputedWallet(store);
expect(store.balanceLabel, 'to match', /3[,.]447[,.]56/); expect(store.balanceLabel, 'to match', /3[,.]447[,.]56/);
...@@ -53,8 +57,9 @@ describe('Computed Wallet Unit Tests', () => { ...@@ -53,8 +57,9 @@ describe('Computed Wallet Unit Tests', () => {
store.settings.displayFiat = false; store.settings.displayFiat = false;
store.settings.exchangeRate.usd = 0.00014503; store.settings.exchangeRate.usd = 0.00014503;
store.balanceSatoshis = 50000001; store.balanceSatoshis = 50000001;
store.pendingBalanceSatoshis = 50000000; store.channelBalancePendingSatoshis = 50000000;
store.channelBalanceSatoshis = 10000; store.channelBalanceOpenSatoshis = 5000;
store.channelBalanceInactiveSatoshis = 5000;
store.channelBalanceForceClosingSatoshis = 100; store.channelBalanceForceClosingSatoshis = 100;
store.settings.unit = 'bit'; store.settings.unit = 'bit';
ComputedWallet(store); ComputedWallet(store);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment