Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fee Bumping #1368

Merged
merged 14 commits into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ import Utxo from './views/UTXOs/UTXO';
import Accounts from './views/Accounts/Accounts';
import ImportAccount from './views/Accounts/ImportAccount';
import ImportAccountQRScanner from './views/Accounts/ImportAccountQRScanner';
import BumpFee from './views/BumpFee';

// POS
import Order from './views/Order';
Expand Down Expand Up @@ -261,6 +262,9 @@ const AppScenes = {
},
PaymentsSettings: {
screen: PaymentsSettings
},
BumpFee: {
screen: BumpFee
}
};

Expand Down
1 change: 1 addition & 0 deletions backends/CLightningREST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,5 +221,6 @@ export default class CLightningREST extends LND {
singleFeesEarnedTotal = () => true;
supportsAddressTypeSelection = () => false;
supportsTaproot = () => false;
supportsBumpFee = () => false;
isLNDBased = () => false;
}
1 change: 1 addition & 0 deletions backends/Eclair.ts
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,7 @@ export default class Eclair {
singleFeesEarnedTotal = () => false;
supportsAddressTypeSelection = () => false;
supportsTaproot = () => false;
supportsBumpFee = () => false;
isLNDBased = () => false;
}

Expand Down
1 change: 1 addition & 0 deletions backends/LND.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,5 +376,6 @@ export default class LND {
singleFeesEarnedTotal = () => false;
supportsAddressTypeSelection = () => true;
supportsTaproot = () => this.supports('v0.15.0');
supportsBumpFee = () => true;
isLNDBased = () => true;
}
1 change: 1 addition & 0 deletions backends/LightningNodeConnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,5 +345,6 @@ export default class LightningNodeConnect {
singleFeesEarnedTotal = () => false;
supportsAddressTypeSelection = () => true;
supportsTaproot = () => this.supports('v0.15.0');
supportsBumpFee = () => true;
isLNDBased = () => true;
}
1 change: 1 addition & 0 deletions backends/LndHub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,5 +135,6 @@ export default class LndHub extends LND {
singleFeesEarnedTotal = () => false;
supportsAddressTypeSelection = () => false;
supportsTaproot = () => false;
supportsBumpFee = () => false;
isLNDBased = () => false;
}
1 change: 1 addition & 0 deletions backends/Spark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,5 +327,6 @@ export default class Spark {
singleFeesEarnedTotal = () => false;
supportsAddressTypeSelection = () => false;
supportsTaproot = () => false;
supportsBumpFee = () => false;
isLNDBased = () => false;
}
7 changes: 5 additions & 2 deletions components/FeeBreakdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ interface FeeBreakdownProps {
peerDisplay?: string;
initiator?: boolean;
isActive?: boolean;
isClosed?: boolean;
total_satoshis_received?: string;
total_satoshis_sent?: string;
commit_weight?: number;
Expand All @@ -48,6 +49,7 @@ export default class FeeBreakdown extends React.Component<
ChannelsStore,
NodeInfoStore,
isActive,
isClosed,
total_satoshis_received,
total_satoshis_sent,
commit_weight,
Expand Down Expand Up @@ -80,7 +82,7 @@ export default class FeeBreakdown extends React.Component<
return (
<React.Fragment>
{loading && <LoadingIndicator />}
{!loading && localPolicy && remotePolicy ? (
{!loading && localPolicy && remotePolicy && (
<React.Fragment>
<KeyValue
keyValue={localeString('views.Channel.channelFees')}
Expand Down Expand Up @@ -133,7 +135,8 @@ export default class FeeBreakdown extends React.Component<
sensitive
/>
</React.Fragment>
) : (
)}
{isClosed && (
<React.Fragment>
{!loading && (
<View style={styles.title}>
Expand Down
8 changes: 8 additions & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"general.fiat": "Fiat",
"general.true": "True",
"general.false": "False",
"general.force": "Force",
"general.fiatFetchError": "Error fetching exchange rates",
"components.CollapsedQr.show": "Show QR",
"components.CollapsedQr.hide": "Hide QR",
Expand Down Expand Up @@ -269,6 +270,8 @@
"views.Channel.settledBalance": "Settled balance",
"views.Channel.timeLockedBalance": "Time locked balance",
"views.Channel.closed": "Closed",
"views.Channel.pendingClose": "Pending close",
"views.Channel.pendingOpen": "Pending open",
"views.UTXOs.CoinControl.noUTXOs": "No UTXOs available",
"views.EditFee.mainText": "Edit network fee",
"views.EditFee.fastestFee": "Fastest fee",
Expand Down Expand Up @@ -558,6 +561,11 @@
"views.Gods.title": "Gods",
"views.Mortals.title": "Mortals",
"views.Splash.scanConfig": "Scan node config",
"views.BumpFee.title": "Speed up transaction",
"views.BumpFee.titleAlt": "Speed up channel open",
"views.BumpFee.targetConfs": "Target confirmations",
"views.BumpFee.success": "Succesfully bumped fee!",
"views.BumpFee.error": "Error bumping fee",
"components.UTXOPicker.modal.title": "Select UTXOs to use",
"components.UTXOPicker.modal.description": "Select the UTXOs to be used in this operation. You may want to only use specific UTXOs to preserve your privacy.",
"components.UTXOPicker.modal.set": "Set UTXOs",
Expand Down
29 changes: 29 additions & 0 deletions models/Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,24 @@ import BaseModel from './BaseModel';
import DateTimeUtils from './../utils/DateTimeUtils';
import { localeString } from './../utils/LocaleUtils';

interface OutputDetail {
address: string;
amount: string;
is_our_address: boolean;
output_index: string;
output_type: string;
pk_script: string;
}

interface PreviousOutpoint {
raw_tx_hex: string;
is_our_output: boolean;
outpoint: string;
timestamp: string;
total_fees: string;
tx_hash: string;
}

export default class Transaction extends BaseModel {
public amount: number;
public block_hash: string;
Expand All @@ -12,6 +30,8 @@ export default class Transaction extends BaseModel {
public time_stamp: string;
public tx_hash: string;
public total_fees: string;
public output_details: Array<OutputDetail>;
public previous_outpoints: Array<PreviousOutpoint>;
// c-lightning
public value: number | string;
public blockheight: number;
Expand Down Expand Up @@ -62,4 +82,13 @@ export default class Transaction extends BaseModel {
@computed public get destAddresses(): Array<string> {
return this.dest_addresses || [this.address];
}

@computed public get getOutpoint(): string {
let outpoint = '';
this.output_details.map((output: OutputDetail) => {
if (output.is_our_address)
outpoint = `${this.tx}:${output.output_index}`;
});
return outpoint;
}
}
11 changes: 8 additions & 3 deletions stores/ChannelsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,12 @@ export default class ChannelsStore {
}

@action
reset = () => {
resetOpenChannel = () => {
this.loading = false;
this.error = false;
this.errorPeerConnect = false;
this.errorMsgChannel = null;
this.errorMsgPeer = null;
this.nodes = {};
this.channels = [];
this.output_index = null;
this.funding_txid_str = null;
this.openingChannel = false;
Expand All @@ -117,6 +115,13 @@ export default class ChannelsStore {
this.peerSuccess = false;
this.channelSuccess = false;
this.channelRequest = null;
};

@action
reset = () => {
this.resetOpenChannel();
this.nodes = {};
this.channels = [];
this.largestChannelSats = 0;
this.totalOutbound = 0;
this.totalInbound = 0;
Expand Down
80 changes: 80 additions & 0 deletions stores/FeeStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ export default class FeeStore {
@observable public lastOffsetIndex: number;
@observable public forwardingHistoryError = false;

@observable public bumpFeeSuccess = false;
@observable public bumpFeeError = false;
@observable public bumpFeeErrorMsg = '';

getOnchainFeesToken: any;

settingsStore: SettingsStore;
Expand Down Expand Up @@ -66,6 +70,8 @@ export default class FeeStore {
resetFees = () => {
this.fees = {};
this.loadingFees = false;
this.bumpFeeSuccess = false;
this.bumpFeeError = false;
};

@action
Expand Down Expand Up @@ -194,4 +200,78 @@ export default class FeeStore {
this.forwardingError();
});
};

@action
public bumpFee = (params?: any) => {
this.loading = true;
this.bumpFeeSuccess = false;
this.bumpFeeError = false;
const [txid_str, output_index] = params.outpoint.split(':');
BackendUtils.bumpFee({
...params,
outpoint: {
txid_str,
output_index: Number(output_index) || 0
}
})
.then(() => {
this.bumpFeeSuccess = true;
this.loading = false;
})
.catch((err: Error) => {
this.bumpFeeError = true;
this.bumpFeeErrorMsg = err.toString();
this.loading = false;
});
};

@action
public bumpFeeOpeningChannel = (params?: any) => {
this.loading = true;
this.bumpFeeSuccess = false;
this.bumpFeeError = false;
const [txid_str, output_index] = params.outpoint.split(':');
BackendUtils.bumpFee({
...params,
outpoint: {
txid_str,
output_index: Number(output_index) || 0
}
})
.then(() => {
this.bumpFeeSuccess = true;
this.loading = false;
})
.catch((err: Error) => {
// if output isn't correct (it'll be index 0 or 1), try alternate input
// NOTE: this will only work for single-party funded channels
if (
err.toString() ===
'Error: the passed output does not belong to the wallet'
) {
const newOutputIndex = output_index === '0' ? 1 : 0;
this.bumpFeeErrorMsg = `${err}. Retrying with input ${newOutputIndex}`;
BackendUtils.bumpFee({
...params,
outpoint: {
txid_str,
output_index: newOutputIndex
}
})
.then(() => {
this.bumpFeeError = false;
this.bumpFeeSuccess = true;
this.loading = false;
})
.catch((err: Error) => {
this.bumpFeeError = true;
this.bumpFeeErrorMsg = err.toString();
this.loading = false;
});
} else {
this.bumpFeeErrorMsg = err.toString();
this.loading = false;
}
});
};
}
1 change: 1 addition & 0 deletions utils/BackendUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ class BackendUtils {
supportsAddressTypeSelection = () =>
this.call('supportsAddressTypeSelection');
supportsTaproot = () => this.call('supportsTaproot');
supportsBumpFee = () => this.call('supportsBumpFee');
isLNDBased = () => this.call('isLNDBased');

// LNC
Expand Down
Loading