MCPcopy Create free account
hub / github.com/ElementsProject/lightning / estimatefees_callback

Function estimatefees_callback

lightningd/bitcoind.c:166–225  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

164};
165
166static void estimatefees_callback(const char *buf, const jsmntok_t *toks,
167 const jsmntok_t *idtok,
168 struct estimatefee_call *call)
169{
170 const jsmntok_t *resulttok, *feeratetok;
171 u32 *feerates = tal_arr(call, u32, NUM_FEERATES);
172
173 resulttok = json_get_member(buf, toks, "result");
174 if (!resulttok)
175 bitcoin_plugin_error(call->bitcoind, buf, toks,
176 "estimatefees",
177 "bad 'result' field");
178
179 for (int f = 0; f < NUM_FEERATES; f++) {
180 feeratetok = json_get_member(buf, resulttok, feerate_name(f));
181 if (!feeratetok)
182 bitcoin_plugin_error(call->bitcoind, buf, toks,
183 "estimatefees",
184 "missing '%s' field", feerate_name(f));
185 /* We still use the bcli plugin for min and max, even with
186 * force_feerates */
187 if (f < tal_count(call->bitcoind->ld->force_feerates)) {
188 feerates[f] = call->bitcoind->ld->force_feerates[f];
189 continue;
190 }
191
192 /* FIXME: We could trawl recent blocks for median fee... */
193 if (!json_to_u32(buf, feeratetok, &feerates[f])) {
194 if (chainparams->testnet)
195 log_debug(call->bitcoind->log,
196 "Unable to estimate %s fees",
197 feerate_name(f));
198 else
199 log_unusual(call->bitcoind->log,
200 "Unable to estimate %s fees",
201 feerate_name(f));
202
203#if DEVELOPER
204 /* This is needed to test for failed feerate estimates
205 * in DEVELOPER mode */
206 feerates[f] = 0;
207#else
208 /* If we are in testnet mode we want to allow payments
209 * with the minimal fee even if the estimate didn't
210 * work out. This is less disruptive than erring out
211 * all the time. */
212 if (chainparams->testnet)
213 feerates[f] = FEERATE_FLOOR;
214 else
215 feerates[f] = 0;
216#endif
217 } else
218 /* Rate in satoshi per kw. */
219 feerates[f] = feerate_from_style(feerates[f],
220 FEERATE_PER_KBYTE);
221 }
222
223 call->cb(call->bitcoind, feerates, call->arg);

Callers

nothing calls this directly

Calls 6

bitcoin_plugin_errorFunction · 0.85
feerate_nameFunction · 0.85
feerate_from_styleFunction · 0.85
tal_freeFunction · 0.85
json_get_memberFunction · 0.50
json_to_u32Function · 0.50

Tested by

no test coverage detected