Skip to content
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
8 changes: 5 additions & 3 deletions metro.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { getDefaultConfig } = require('expo/metro-config');

const config = getDefaultConfig(__dirname);

// Enable debug logging and better error reporting
// Configure supported platforms for module resolution
config.resolver.platforms = ['ios', 'android', 'native', 'web'];

// Polyfill Node.js modules for React Native
Expand All @@ -24,13 +24,15 @@ config.transformer.minifierConfig = {
config.server = {
enhanceMiddleware: (middleware) => {
return (req, res, next) => {
console.log(`[Metro] ${req.method} ${req.url}`);
if (process.env.NODE_ENV !== 'production') {
console.log(`[Metro] ${req.method} ${req.url}`);
}
return middleware(req, res, next);
};
},
};

// Enable better error handling
// Configure Metro transformer options for imports and inline requires
config.transformer.getTransformOptions = async () => ({
transform: {
experimentalImportSupport: false,
Expand Down
13 changes: 9 additions & 4 deletions services/rbf-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
*/
const NON_RBF_SEQUENCE = 0xFFFFFFFF;

/**
* Minimum required fee increase (as a fraction of the original fee)
* to consider a replacement transaction for RBF.
* For example, 0.1 means a 10% minimum fee increase.
*/
const MIN_RBF_FEE_INCREASE_RATE = 0.1;

/**
* Validates the given ECC library by checking basic functionality.
* Throws an error if validation fails.
Expand All @@ -36,8 +43,6 @@
if (!publicKey || publicKey.length !== 33) {
throw new Error('ECC point generation failed');
}

console.log('✅ ECC library validation passed');
}

export interface RBFTransaction {
Expand All @@ -54,7 +59,7 @@
isValid: boolean;
canReplace: boolean;
reason?: string;
originalTx?: any;
originalTx?: Transaction;
utxos?: UTXO[];
}

Expand Down Expand Up @@ -414,7 +419,7 @@

// Get our inputs from the original transaction
const walletAddressesSet = new Set(walletAddresses);
const ourInputs = originalTx.vin?.filter((input: any) => {

Check failure on line 422 in services/rbf-service.ts

View workflow job for this annotation

GitHub Actions / TypeScript Build Check

Property 'vin' does not exist on type 'Transaction'.
return input.prevout?.scriptpubkey_address &&
walletAddressesSet.has(input.prevout.scriptpubkey_address);
});
Expand Down Expand Up @@ -472,7 +477,7 @@

// Calculate outputs (same as original transaction)
let totalOutputValue = 0;
for (const output of originalTx.vout) {

Check failure on line 480 in services/rbf-service.ts

View workflow job for this annotation

GitHub Actions / TypeScript Build Check

Property 'vout' does not exist on type 'Transaction'.
// Handle different output types
if (output.scriptpubkey_address) {
// P2PKH, P2WPKH, P2SH outputs
Expand All @@ -493,8 +498,8 @@
let changeOutputValue = 0;

// Look for a change output (typically the last output that goes to our wallet)
for (let i = originalTx.vout.length - 1; i >= 0; i--) {

Check failure on line 501 in services/rbf-service.ts

View workflow job for this annotation

GitHub Actions / TypeScript Build Check

Property 'vout' does not exist on type 'Transaction'.
const output = originalTx.vout[i];

Check failure on line 502 in services/rbf-service.ts

View workflow job for this annotation

GitHub Actions / TypeScript Build Check

Property 'vout' does not exist on type 'Transaction'.
if (output.scriptpubkey_address && walletAddressesSet.has(output.scriptpubkey_address)) {
changeOutputIndex = i;
changeOutputValue = output.value;
Expand All @@ -506,7 +511,7 @@
const originalFee = totalInputValue - totalOutputValue;

// Calculate the original fee rate
const originalSize = estimateTransactionSize(ourInputs.length, originalTx.vout.length);

Check failure on line 514 in services/rbf-service.ts

View workflow job for this annotation

GitHub Actions / TypeScript Build Check

Property 'vout' does not exist on type 'Transaction'.
const originalFeeRate = originalFee / originalSize;

// Calculate the target fee based on the desired fee rate
Expand All @@ -519,7 +524,7 @@

// Ensure the new fee meets RBF requirements (must be higher than original)
// Only apply minimum increase if user's requested fee is too low
const minFeeIncrease = Math.ceil(originalFee * 0.1); // 10% increase minimum for RBF
const minFeeIncrease = Math.ceil(originalFee * MIN_RBF_FEE_INCREASE_RATE); // minimum increase for RBF
const actualTargetFee = Math.max(targetFee, originalFee + minFeeIncrease);

const feeIncrease = actualTargetFee - originalFee;
Expand All @@ -542,7 +547,7 @@
}

// Calculate actual output values and transaction size
let actualOutputCount = originalTx.vout.length;

Check failure on line 550 in services/rbf-service.ts

View workflow job for this annotation

GitHub Actions / TypeScript Build Check

Property 'vout' does not exist on type 'Transaction'.
let actualOutputValue: number;
let newChangeValue = 0;

Expand All @@ -551,7 +556,7 @@
newChangeValue = changeOutputValue - feeIncrease;
if (newChangeValue <= 546) { // Dust threshold
// Change output would be dust, remove it entirely
actualOutputCount = originalTx.vout.length - 1;

Check failure on line 559 in services/rbf-service.ts

View workflow job for this annotation

GitHub Actions / TypeScript Build Check

Property 'vout' does not exist on type 'Transaction'.
actualOutputValue = totalOutputValue - changeOutputValue;
console.log(`🗑️ Removing dust change output: ${changeOutputValue} sats`);
} else {
Expand Down Expand Up @@ -583,12 +588,12 @@
}

// Re-add outputs with correct values
for (let i = 0; i < originalTx.vout.length; i++) {

Check failure on line 591 in services/rbf-service.ts

View workflow job for this annotation

GitHub Actions / TypeScript Build Check

Property 'vout' does not exist on type 'Transaction'.
if (i === changeOutputIndex) {
// This is the change output
if (newChangeValue > 546) {
// Keep the change output with adjusted value
const output = originalTx.vout[i];

Check failure on line 596 in services/rbf-service.ts

View workflow job for this annotation

GitHub Actions / TypeScript Build Check

Property 'vout' does not exist on type 'Transaction'.
if (output.scriptpubkey_address) {
txb.addOutput(output.scriptpubkey_address, newChangeValue);
} else if (output.scriptpubkey) {
Expand All @@ -598,7 +603,7 @@
// If newChangeValue <= 546, skip this output (dust)
} else {
// Regular output, keep original value
const output = originalTx.vout[i];

Check failure on line 606 in services/rbf-service.ts

View workflow job for this annotation

GitHub Actions / TypeScript Build Check

Property 'vout' does not exist on type 'Transaction'.
if (output.scriptpubkey_address) {
txb.addOutput(output.scriptpubkey_address, output.value);
} else if (output.scriptpubkey) {
Expand Down
Loading