gn-provider 1.2.6 → 1.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/gn-provider.js +17 -21
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -122,7 +122,7 @@ Creates a new provider instance.
|
|
|
122
122
|
| `listUnspent(address: string): Promise<UTXO[]>` | Lists UTXOs for an address |
|
|
123
123
|
| `getBalance(address: string): Promise<{confirmed: number, unconfirmed: number}>` | Gets address balance |
|
|
124
124
|
| `getTransaction(txHash: string): Promise<Transaction>` | Retrieves transaction details |
|
|
125
|
-
| `getFeePerKb(): Promise<number>` |
|
|
125
|
+
| `getFeePerKb(): Promise<number>` | Enhanced estimation of the fee rate based on current block stats |
|
|
126
126
|
|
|
127
127
|
## Features
|
|
128
128
|
|
package/dist/gn-provider.js
CHANGED
|
@@ -87,32 +87,28 @@ class GNProvider extends abstract_provider_1.Provider {
|
|
|
87
87
|
yield this._ready();
|
|
88
88
|
const headers = this._getHeaders();
|
|
89
89
|
try {
|
|
90
|
-
|
|
91
|
-
const chainInfoRes = yield superagent.get(`${this.apiPrefix()}/chain/info`)
|
|
92
|
-
.set(headers);
|
|
90
|
+
const chainInfoRes = yield superagent.get(`${this.apiPrefix()}/chain/info`).set(headers);
|
|
93
91
|
const currentHeight = chainInfoRes.body.blocks;
|
|
94
|
-
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
const
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
// Calcular tarifa por kilobyte: (total_fee * 1024) / size
|
|
105
|
-
const feePerKb = (totalFee * 1024) / size;
|
|
106
|
-
// Aplicar un multiplicador para asegurar una tarifa competitiva (1.5x)
|
|
92
|
+
const blockStatsRes = yield superagent.get(`${this.apiPrefix()}/block/height/${currentHeight}/stats`).set(headers);
|
|
93
|
+
const stats = blockStatsRes.body;
|
|
94
|
+
// 1. Extraer mediana de fee y tamaño medio de transacción
|
|
95
|
+
const medianFeePerTx = stats.median_fee; // Satoshis por transacción
|
|
96
|
+
const medianSizePerTx = stats.median_tx_size; // Bytes por transacción
|
|
97
|
+
if (!medianSizePerTx || medianSizePerTx === 0)
|
|
98
|
+
throw new Error('Invalid block stats');
|
|
99
|
+
// 2. Calcular la tasa: (Satoshis / Bytes) * 1000 para obtener sat/kb
|
|
100
|
+
const feePerKb = (medianFeePerTx / medianSizePerTx) * 1000;
|
|
101
|
+
// 3. Aplicar multiplicador competitivo (1.5x es seguro en BSV)
|
|
107
102
|
const competitiveFee = feePerKb * 1.5;
|
|
108
|
-
//
|
|
109
|
-
|
|
110
|
-
|
|
103
|
+
// 4. SafeFee con tus nuevos límites
|
|
104
|
+
// Nota: Subimos el mínimo a 1.1 para asegurar prioridad sobre el polvo de la red
|
|
105
|
+
const safeFee = Math.max(1.1, Math.min(competitiveFee, 500));
|
|
106
|
+
console.log(`Calculated MEDIAN fee rate: ${safeFee.toFixed(2)} sat/kb`);
|
|
111
107
|
return Math.round(safeFee * 100) / 100;
|
|
112
108
|
}
|
|
113
109
|
catch (error) {
|
|
114
|
-
console.warn('Fee estimation
|
|
115
|
-
return
|
|
110
|
+
console.warn('Fee estimation failed, using fallback');
|
|
111
|
+
return 1.1; // Fallback mucho más realista para BSV que 500
|
|
116
112
|
}
|
|
117
113
|
});
|
|
118
114
|
this.isConnected = () => this._isConnected;
|