Compare commits
1 Commits
master
...
0.24.1/add
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4bbfc612d5 |
9
.github/workflows/cont_integration.yml
vendored
9
.github/workflows/cont_integration.yml
vendored
@ -62,10 +62,13 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: dtolnay/rust-toolchain@v1
|
||||
- uses: dtolnay/rust-toolchain@stable
|
||||
with:
|
||||
toolchain: 1.90.0
|
||||
toolchain: 1.84.0
|
||||
components: clippy
|
||||
- name: Rust Cache
|
||||
uses: Swatinem/rust-cache@v2.2.1
|
||||
- run: cargo clippy --all-features --all-targets -- -D warnings
|
||||
- uses: actions-rs/clippy-check@v1
|
||||
with:
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
args: --all-features --all-targets -- -D warnings
|
||||
|
||||
34
justfile
34
justfile
@ -1,34 +0,0 @@
|
||||
alias b := build
|
||||
alias c := check
|
||||
alias f := fmt
|
||||
alias t := test
|
||||
alias p := pre-push
|
||||
|
||||
_default:
|
||||
@just --list
|
||||
|
||||
# Build the project
|
||||
build:
|
||||
cargo build
|
||||
|
||||
# Check code: formatting, compilation, linting, doc comments, and commit signature
|
||||
check:
|
||||
cargo +nightly fmt --all -- --check
|
||||
cargo check --all-features --all-targets
|
||||
cargo clippy --all-features --all-targets -- -D warnings
|
||||
RUSTDOCFLAGS="-D warnings" cargo doc --all-features --no-deps
|
||||
@[ "$(git log --pretty='format:%G?' -1 HEAD)" = "N" ] && \
|
||||
echo "\n⚠️ Unsigned commit: BDK requires that commits be signed." || \
|
||||
true
|
||||
|
||||
# Format all code
|
||||
fmt:
|
||||
cargo +nightly fmt
|
||||
|
||||
# Run all tests on the workspace with all features
|
||||
test:
|
||||
cargo test --all-features -- --test-threads=1
|
||||
|
||||
# Run pre-push suite: format, check, and test
|
||||
pre-push: fmt check test
|
||||
|
||||
19
src/api.rs
19
src/api.rs
@ -172,6 +172,13 @@ where
|
||||
(**self).server_features()
|
||||
}
|
||||
|
||||
fn server_add_peer<S>(&self, features: &S) -> Result<bool, Error>
|
||||
where
|
||||
S: serde::Serialize,
|
||||
{
|
||||
(**self).server_add_peer(features)
|
||||
}
|
||||
|
||||
fn ping(&self) -> Result<(), Error> {
|
||||
(**self).ping()
|
||||
}
|
||||
@ -398,6 +405,11 @@ pub trait ElectrumApi {
|
||||
/// Returns the capabilities of the server.
|
||||
fn server_features(&self) -> Result<ServerFeaturesRes, Error>;
|
||||
|
||||
/// Announce a server to get it listed in the peer list.
|
||||
fn server_add_peer<S>(&self, features: &S) -> Result<bool, Error>
|
||||
where
|
||||
S: serde::Serialize;
|
||||
|
||||
/// Pings the server. This method can also be used as a "dummy" call to trigger the processing
|
||||
/// of incoming block header or script notifications.
|
||||
fn ping(&self) -> Result<(), Error>;
|
||||
@ -607,6 +619,13 @@ mod test {
|
||||
unreachable!()
|
||||
}
|
||||
|
||||
fn server_add_peer<S>(&self, _: &S) -> Result<bool, crate::Error>
|
||||
where
|
||||
S: serde::Serialize,
|
||||
{
|
||||
unreachable!()
|
||||
}
|
||||
|
||||
fn ping(&self) -> Result<(), super::Error> {
|
||||
unreachable!()
|
||||
}
|
||||
|
||||
@ -88,7 +88,7 @@ impl Batch {
|
||||
}
|
||||
|
||||
/// Returns an iterator on the batch
|
||||
pub fn iter(&self) -> BatchIter<'_> {
|
||||
pub fn iter(&self) -> BatchIter {
|
||||
BatchIter {
|
||||
batch: self,
|
||||
index: 0,
|
||||
|
||||
@ -367,6 +367,14 @@ impl ElectrumApi for Client {
|
||||
impl_inner_call!(self, ping)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn server_add_peer<S>(&self, features: &S) -> Result<bool, Error>
|
||||
where
|
||||
S: serde::Serialize,
|
||||
{
|
||||
impl_inner_call!(self, server_add_peer, features)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[cfg(feature = "debug-calls")]
|
||||
fn calls_made(&self) -> Result<usize, Error> {
|
||||
@ -448,9 +456,7 @@ mod tests {
|
||||
let now = Instant::now();
|
||||
let client = Client::from_config(
|
||||
&endpoint,
|
||||
crate::config::ConfigBuilder::new()
|
||||
.timeout(Some(Duration::from_secs(5)))
|
||||
.build(),
|
||||
crate::config::ConfigBuilder::new().timeout(Some(5)).build(),
|
||||
);
|
||||
let elapsed = now.elapsed();
|
||||
|
||||
|
||||
@ -55,8 +55,8 @@ impl ConfigBuilder {
|
||||
}
|
||||
|
||||
/// Sets the timeout
|
||||
pub fn timeout(mut self, timeout: Option<Duration>) -> Self {
|
||||
self.config.timeout = timeout;
|
||||
pub fn timeout(mut self, timeout: Option<u8>) -> Self {
|
||||
self.config.timeout = timeout.map(|t| Duration::from_secs(t as u64));
|
||||
self
|
||||
}
|
||||
|
||||
|
||||
@ -1179,6 +1179,21 @@ impl<T: Read + Write> ElectrumApi for RawClient<T> {
|
||||
Ok(serde_json::from_value(result)?)
|
||||
}
|
||||
|
||||
fn server_add_peer<S>(&self, features: &S) -> Result<bool, Error>
|
||||
where
|
||||
S: serde::Serialize,
|
||||
{
|
||||
let json = serde_json::to_value(features)?;
|
||||
let req = Request::new_id(
|
||||
self.last_id.fetch_add(1, Ordering::SeqCst),
|
||||
"server.add_peer",
|
||||
vec![Param::Json(json)],
|
||||
);
|
||||
let result = self.call(req)?;
|
||||
|
||||
Ok(serde_json::from_value(result)?)
|
||||
}
|
||||
|
||||
fn ping(&self) -> Result<(), Error> {
|
||||
let req = Request::new_id(
|
||||
self.last_id.fetch_add(1, Ordering::SeqCst),
|
||||
|
||||
@ -18,7 +18,12 @@ fn read_response(socket: &mut TcpStream) -> io::Result<SocketAddrV4> {
|
||||
|
||||
match response.read_u8()? {
|
||||
90 => {}
|
||||
91 => return Err(io::Error::other("request rejected or failed")),
|
||||
91 => {
|
||||
return Err(io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
"request rejected or failed",
|
||||
))
|
||||
}
|
||||
92 => {
|
||||
return Err(io::Error::new(
|
||||
io::ErrorKind::PermissionDenied,
|
||||
|
||||
@ -37,7 +37,10 @@ fn read_addr<R: Read>(socket: &mut R) -> io::Result<TargetAddr> {
|
||||
ip, port, 0, 0,
|
||||
))))
|
||||
}
|
||||
_ => Err(io::Error::other("unsupported address type")),
|
||||
_ => Err(io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
"unsupported address type",
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
@ -51,15 +54,35 @@ fn read_response(socket: &mut TcpStream) -> io::Result<TargetAddr> {
|
||||
|
||||
match socket.read_u8()? {
|
||||
0 => {}
|
||||
1 => return Err(io::Error::other("general SOCKS server failure")),
|
||||
2 => return Err(io::Error::other("connection not allowed by ruleset")),
|
||||
3 => return Err(io::Error::other("network unreachable")),
|
||||
4 => return Err(io::Error::other("host unreachable")),
|
||||
5 => return Err(io::Error::other("connection refused")),
|
||||
6 => return Err(io::Error::other("TTL expired")),
|
||||
7 => return Err(io::Error::other("command not supported")),
|
||||
8 => return Err(io::Error::other("address kind not supported")),
|
||||
_ => return Err(io::Error::other("unknown error")),
|
||||
1 => {
|
||||
return Err(io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
"general SOCKS server failure",
|
||||
))
|
||||
}
|
||||
2 => {
|
||||
return Err(io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
"connection not allowed by ruleset",
|
||||
))
|
||||
}
|
||||
3 => return Err(io::Error::new(io::ErrorKind::Other, "network unreachable")),
|
||||
4 => return Err(io::Error::new(io::ErrorKind::Other, "host unreachable")),
|
||||
5 => return Err(io::Error::new(io::ErrorKind::Other, "connection refused")),
|
||||
6 => return Err(io::Error::new(io::ErrorKind::Other, "TTL expired")),
|
||||
7 => {
|
||||
return Err(io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
"command not supported",
|
||||
))
|
||||
}
|
||||
8 => {
|
||||
return Err(io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
"address kind not supported",
|
||||
))
|
||||
}
|
||||
_ => return Err(io::Error::new(io::ErrorKind::Other, "unknown error")),
|
||||
}
|
||||
|
||||
if socket.read_u8()? != 0 {
|
||||
@ -204,11 +227,14 @@ impl Socks5Stream {
|
||||
}
|
||||
|
||||
if selected_method == 0xff {
|
||||
return Err(io::Error::other("no acceptable auth methods"));
|
||||
return Err(io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
"no acceptable auth methods",
|
||||
));
|
||||
}
|
||||
|
||||
if selected_method != auth.id() && selected_method != Authentication::None.id() {
|
||||
return Err(io::Error::other("unknown auth method"));
|
||||
return Err(io::Error::new(io::ErrorKind::Other, "unknown auth method"));
|
||||
}
|
||||
|
||||
match *auth {
|
||||
|
||||
@ -33,6 +33,8 @@ pub enum Param {
|
||||
Bool(bool),
|
||||
/// Bytes array parameter
|
||||
Bytes(Vec<u8>),
|
||||
/// JSON parameter
|
||||
Json(serde_json::Value),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Clone)]
|
||||
|
||||
@ -13,7 +13,7 @@ use bitcoin::Txid;
|
||||
/// otherwise.
|
||||
///
|
||||
/// [`transaction_get_merkle`]: crate::ElectrumApi::transaction_get_merkle
|
||||
/// [`BlockHeader`]: bitcoin::block::Header
|
||||
/// [`BlockHeader`]: bitcoin::BlockHeader
|
||||
pub fn validate_merkle_proof(
|
||||
txid: &Txid,
|
||||
merkle_root: &TxMerkleNode,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user