-
Notifications
You must be signed in to change notification settings - Fork 65
relay_fee
result should be strongly typed
#164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ use log::{debug, error, info, trace, warn}; | |
|
||
use bitcoin::consensus::encode::deserialize; | ||
use bitcoin::hex::{DisplayHex, FromHex}; | ||
use bitcoin::{Script, Txid}; | ||
use bitcoin::{Amount, Script, Txid}; | ||
|
||
#[cfg(feature = "use-openssl")] | ||
use openssl::ssl::{SslConnector, SslMethod, SslStream, SslVerifyMode}; | ||
|
@@ -879,17 +879,18 @@ impl<T: Read + Write> ElectrumApi for RawClient<T> { | |
.ok_or_else(|| Error::InvalidResponse(result.clone())) | ||
} | ||
|
||
fn relay_fee(&self) -> Result<f64, Error> { | ||
fn relay_fee(&self) -> Result<Amount, Error> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know the docs aren't clear in this regard but I think it would make sense for this to return a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know the electrum protocol, my interpretation of the docs was this is an absolute fee that a transaction must have, so an If this is actually a fee rate in bitcoin per vbyte then the docs should be updated accordingly before any attempt at a PR to return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also interpret the docs as this one being an absolute fee, but some validation on electrum code besides documentation is needed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be clear I'm referring to "relay fee" as described in I agree that the value can be parsed as an amount in BTC (same for
If you consider There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At least it seems both romanz/electrs and blockstream/electrs rely on the RPC you mentioned, basically propagating the |
||
let req = Request::new_id( | ||
self.last_id.fetch_add(1, Ordering::SeqCst), | ||
"blockchain.relayfee", | ||
vec![], | ||
); | ||
let result = self.call(req)?; | ||
|
||
result | ||
let amount_float = result | ||
.as_f64() | ||
.ok_or_else(|| Error::InvalidResponse(result.clone())) | ||
.ok_or_else(|| Error::InvalidResponse(result.clone()))?; | ||
Amount::from_btc(amount_float).map_err(|_| Error::InvalidResponse(result.clone())) | ||
} | ||
|
||
fn script_subscribe(&self, script: &Script) -> Result<Option<ScriptStatus>, Error> { | ||
|
@@ -1195,7 +1196,7 @@ mod test { | |
let client = RawClient::new(get_test_server(), None).unwrap(); | ||
|
||
let resp = client.relay_fee().unwrap(); | ||
assert_eq!(resp, 0.00001); | ||
assert_eq!(resp, bitcoin::Amount::from_btc(0.00001).unwrap()); | ||
} | ||
|
||
#[test] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.