Page MenuHomePhabricator

[chronik] add a macro to define an electrum method
DraftPublic

Authored by PiRK on Sat, Dec 14, 21:37.
This is a draft revision that has not yet been submitted for review.

Details

Reviewers
None
Group Reviewers
Restricted Project
Summary

This removes some of the boilerplate code

Depends on D17347

Test Plan

ninja check-functional

Event Timeline

Tail of the build log:

   Doc-tests chronik-bridge

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

   Doc-tests chronik-db

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

   Doc-tests chronik-http

running 1 test
test chronik/chronik-http/src/protobuf.rs - protobuf::Protobuf (line 29) ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.35s

   Doc-tests chronik-indexer

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

   Doc-tests chronik-plugin

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

   Doc-tests chronik-plugin-common

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

   Doc-tests chronik-plugin-impl

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

   Doc-tests chronik-proto

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

   Doc-tests chronik-util

running 2 tests
test chronik/chronik-util/src/log.rs - log::log (line 65) ... ignored
test chronik/chronik-util/src/log.rs - log::log_chronik (line 87) ... ignored

test result: ok. 0 passed; 0 failed; 2 ignored; 0 measured; 0 filtered out; finished in 0.00s

ninja: build stopped: cannot make progress due to previous errors.
Build build-chronik failed with exit code 1

Tail of the build log:

    Checking memoffset v0.9.1
    Checking serde_urlencoded v0.7.1
    Checking tokio-tungstenite v0.24.0
   Compiling karyon_jsonrpc_macro v0.1.8
    Checking futures-executor v0.3.31
    Checking serde_path_to_error v0.1.16
    Checking unicode-segmentation v1.12.0
    Checking base64 v0.22.1
    Checking matchit v0.7.3
    Checking unindent v0.2.3
    Checking futures v0.3.31
    Checking tower-http v0.5.2
   Compiling chronik-bridge v0.1.0 (/work/chronik/chronik-bridge)
    Checking convert_case v0.6.0
   Compiling librocksdb-sys v0.11.0+8.1.1
    Checking toml_edit v0.22.22
    Checking axum v0.7.9
   Compiling pyo3-macros v0.23.3
    Checking toml v0.8.19
    Checking chronik-plugin-impl v0.1.0 (/work/chronik/chronik-plugin-impl)
   Compiling aws-lc-rs v1.11.1
   Compiling rustls v0.23.19
    Checking rustls-webpki v0.102.8
    Checking futures-rustls v0.26.0
    Checking karyon_async_rustls v0.1.8
    Checking karyon_net v0.1.8
    Checking karyon_jsonrpc v0.1.8
    Checking rocksdb v0.21.0
    Checking chronik-db v0.1.0 (/work/chronik/chronik-db)
    Checking chronik-indexer v0.1.0 (/work/chronik/chronik-indexer)
    Checking chronik-http v0.1.0 (/work/chronik/chronik-http)
error: try not to call a closure in the expression where it is declared
   --> chronik/chronik-http/src/electrum.rs:248:53
    |
248 |         Some(Box::new(move |params: Value| Box::pin($handler(params))))
    |                                                     ^^^^^^^^^^^^^^^^
...
259 |             "ping" => define_method!(|params| self.ping(params)),
    |                       ------------------------------------------ in this macro invocation
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure_call
    = note: `-D clippy::redundant-closure-call` implied by `-D warnings`
    = help: to override `-D warnings` add `#[allow(clippy::redundant_closure_call)]`
    = note: this error originates in the macro `define_method` (in Nightly builds, run with -Z macro-backtrace for more info)

error: try not to call a closure in the expression where it is declared
   --> chronik/chronik-http/src/electrum.rs:248:53
    |
248 |         Some(Box::new(move |params: Value| Box::pin($handler(params))))
    |                                                     ^^^^^^^^^^^^^^^^
...
279 |                 define_method!(|params| self.transaction_get(params))
    |                 ----------------------------------------------------- in this macro invocation
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure_call
    = note: this error originates in the macro `define_method` (in Nightly builds, run with -Z macro-backtrace for more info)

error: could not compile `chronik-http` (lib) due to 2 previous errors
ninja: build stopped: cannot make progress due to previous errors.
Build build-chronik-plugins failed with exit code 1
tobias_ruck added inline comments.
chronik/chronik-http/src/electrum.rs
247–248

otherwise this will run into the issue of macro hygiene (code untested)

259

maybe you can try to make the macro call look like this? (code untested)