gn-provider 1.1.9 → 1.2.0
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/dist/gn-provider.js +22 -12
- package/package.json +1 -1
package/dist/gn-provider.js
CHANGED
|
@@ -83,22 +83,32 @@ class GNProvider extends abstract_provider_1.Provider {
|
|
|
83
83
|
yield this._ready();
|
|
84
84
|
const headers = this._getHeaders();
|
|
85
85
|
try {
|
|
86
|
-
|
|
87
|
-
const
|
|
88
|
-
const res = yield superagent.get(`${this.apiPrefix()}/miner/fees?from=${from}&to=${now}`)
|
|
86
|
+
// Paso 1: Obtener la información de la cadena para obtener la altura actual
|
|
87
|
+
const chainInfoRes = yield superagent.get(`${this.apiPrefix()}/chain/info`)
|
|
89
88
|
.set(headers);
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
89
|
+
const currentHeight = chainInfoRes.body.blocks;
|
|
90
|
+
// Paso 2: Obtener las estadísticas del bloque actual
|
|
91
|
+
const blockStatsRes = yield superagent.get(`${this.apiPrefix()}/block/height/${currentHeight}/stats`)
|
|
92
|
+
.set(headers);
|
|
93
|
+
const blockStats = blockStatsRes.body;
|
|
94
|
+
const totalFee = blockStats.total_fee;
|
|
95
|
+
const size = blockStats.size;
|
|
96
|
+
// Si el tamaño es 0, evitar división por cero
|
|
97
|
+
if (size === 0) {
|
|
98
|
+
throw new Error('Block size is zero');
|
|
97
99
|
}
|
|
98
|
-
|
|
100
|
+
// Calcular tarifa por kilobyte: (total_fee * 1024) / size
|
|
101
|
+
const feePerKb = (totalFee * 1024) / size;
|
|
102
|
+
// Aplicar un multiplicador para asegurar una tarifa competitiva (1.5x)
|
|
103
|
+
const competitiveFee = feePerKb * 1.5;
|
|
104
|
+
// Establecer un mínimo de 50 sat/kb y un máximo de 5000 sat/kb para evitar valores extremos
|
|
105
|
+
const safeFee = Math.max(50, Math.min(competitiveFee, 5000));
|
|
106
|
+
console.log(`Calculated fee rate: ${safeFee.toFixed(2)} sat/kb from block ${currentHeight}`);
|
|
107
|
+
return Math.round(safeFee * 100) / 100;
|
|
99
108
|
}
|
|
100
109
|
catch (error) {
|
|
101
|
-
|
|
110
|
+
console.warn('Fee estimation from block stats failed, using fallback');
|
|
111
|
+
return 500; // Fallback a 500 sat/kb
|
|
102
112
|
}
|
|
103
113
|
});
|
|
104
114
|
this.isConnected = () => this._isConnected;
|