@@ -31,10 +31,23 @@ using namespace std::placeholders;
3131
3232BC_PUSH_WARNING (NO_THROW_IN_NOEXCEPT )
3333
34+ using mode_t = node::estimator::mode;
35+ mode_t mode_from_string (const std::string& mode) NOEXCEPT
36+ {
37+ if (mode.empty ()) return mode_t ::basic;
38+ if (mode == " basic" ) return mode_t ::basic;
39+ if (mode == " geometric" ) return mode_t ::geometric;
40+ if (mode == " economical" ) return mode_t ::economical;
41+ if (mode == " conservative" ) return mode_t ::conservative;
42+ return mode_t ::unknown;
43+ }
44+
3445void protocol_electrum::handle_blockchain_estimate_fee (const code& ec,
3546 rpc_interface::blockchain_estimate_fee, double number,
3647 const std::string& mode) NOEXCEPT
3748{
49+ BC_ASSERT (stranded ());
50+
3851 if (stopped (ec))
3952 return ;
4053
@@ -51,23 +64,57 @@ void protocol_electrum::handle_blockchain_estimate_fee(const code& ec,
5164 return ;
5265 }
5366
54- if (!mode.empty () &&
55- !at_least (electrum::version::v1_6))
67+ if (!mode.empty () && !at_least (electrum::version::v1_6))
68+ {
69+ send_code (error::invalid_argument);
70+ return ;
71+ }
72+
73+ const auto mode_ = mode_from_string (mode);
74+ if (mode_ == mode_t ::unknown)
5675 {
5776 send_code (error::invalid_argument);
5877 return ;
5978 }
6079
61- // TODO: integrate fee estimator.
62- // //send_code(error::not_implemented);
80+ estimate (target, mode_, BIND (handle_estimate_fee, _1, _2));
81+ }
82+
83+ void protocol_electrum::handle_estimate_fee (const code& ec,
84+ uint64_t fee) NOEXCEPT
85+ {
86+ POST (complete_estimate_fee, ec, fee);
87+ }
88+
89+ void protocol_electrum::complete_estimate_fee (const code& ec,
90+ uint64_t fee) NOEXCEPT
91+ {
92+ BC_ASSERT (stranded ());
93+
94+ if (stopped ())
95+ return ;
96+
97+ const auto disabled =
98+ ec == node::error::estimate_false ||
99+ ec == node::error::estimate_disabled ||
100+ ec == node::error::estimate_premature;
101+
102+ if (!disabled && ec)
103+ {
104+ // node::error::estimates_failed, implies store fault.
105+ send_code (error::server_error);
106+ return ;
107+ }
63108
64109 // If not enough information to make an estimate, -1 is returned.
65- send_result (- 1 , 42 );
110+ send_result (disabled ? - 1 : possible_narrow_sign_cast< int64_t >(fee) , 42 );
66111}
67112
68113void protocol_electrum::handle_blockchain_relay_fee (const code& ec,
69114 rpc_interface::blockchain_relay_fee) NOEXCEPT
70115{
116+ BC_ASSERT (stranded ());
117+
71118 if (stopped (ec))
72119 return ;
73120
0 commit comments