diff --git a/Cargo.lock b/Cargo.lock index 0dd19c4..ccb1541 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7,9 +7,9 @@ name = "acceptevm" version = "0.0.2" dependencies = [ "alloy", + "async-std", "bincode", "log", - "log4rs", "reqwest", "serde", "sha2", @@ -451,33 +451,6 @@ dependencies = [ "url", ] -[[package]] -name = "android-tzdata" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" - -[[package]] -name = "android_system_properties" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" -dependencies = [ - "libc", -] - -[[package]] -name = "anyhow" -version = "1.0.83" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25bdb32cbbdce2b519a9cd7df3a678443100e265d5e25ca763b7572a5104f5f3" - -[[package]] -name = "arc-swap" -version = "1.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69f7f8c3906b62b754cd5326047894316021dcfe5a194c8ea52bdd94934a3457" - [[package]] name = "ark-ff" version = "0.3.0" @@ -608,6 +581,142 @@ version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" +[[package]] +name = "async-channel" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81953c529336010edd6d8e358f886d9581267795c61b19475b71314bffa46d35" +dependencies = [ + "concurrent-queue", + "event-listener 2.5.3", + "futures-core", +] + +[[package]] +name = "async-channel" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89b47800b0be77592da0afd425cc03468052844aff33b84e33cc696f64e77b6a" +dependencies = [ + "concurrent-queue", + "event-listener-strategy 0.5.2", + "futures-core", + "pin-project-lite", +] + +[[package]] +name = "async-executor" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b10202063978b3351199d68f8b22c4e47e4b1b822f8d43fd862d5ea8c006b29a" +dependencies = [ + "async-task", + "concurrent-queue", + "fastrand 2.1.0", + "futures-lite 2.3.0", + "slab", +] + +[[package]] +name = "async-global-executor" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05b1b633a2115cd122d73b955eadd9916c18c8f510ec9cd1686404c60ad1c29c" +dependencies = [ + "async-channel 2.3.1", + "async-executor", + "async-io 2.3.2", + "async-lock 3.3.0", + "blocking", + "futures-lite 2.3.0", + "once_cell", +] + +[[package]] +name = "async-io" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fc5b45d93ef0529756f812ca52e44c221b35341892d3dcc34132ac02f3dd2af" +dependencies = [ + "async-lock 2.8.0", + "autocfg", + "cfg-if", + "concurrent-queue", + "futures-lite 1.13.0", + "log", + "parking", + "polling 2.8.0", + "rustix 0.37.27", + "slab", + "socket2 0.4.10", + "waker-fn", +] + +[[package]] +name = "async-io" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcccb0f599cfa2f8ace422d3555572f47424da5648a4382a9dd0310ff8210884" +dependencies = [ + "async-lock 3.3.0", + "cfg-if", + "concurrent-queue", + "futures-io", + "futures-lite 2.3.0", + "parking", + "polling 3.7.0", + "rustix 0.38.34", + "slab", + "tracing", + "windows-sys 0.52.0", +] + +[[package]] +name = "async-lock" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "287272293e9d8c41773cec55e365490fe034813a2f172f502d6ddcf75b2f582b" +dependencies = [ + "event-listener 2.5.3", +] + +[[package]] +name = "async-lock" +version = "3.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d034b430882f8381900d3fe6f0aaa3ad94f2cb4ac519b429692a1bc2dda4ae7b" +dependencies = [ + "event-listener 4.0.3", + "event-listener-strategy 0.4.0", + "pin-project-lite", +] + +[[package]] +name = "async-std" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62565bb4402e926b29953c785397c6dc0391b7b446e45008b0049eb43cec6f5d" +dependencies = [ + "async-channel 1.9.0", + "async-global-executor", + "async-io 1.13.0", + "async-lock 2.8.0", + "crossbeam-utils", + "futures-channel", + "futures-core", + "futures-io", + "futures-lite 1.13.0", + "gloo-timers", + "kv-log-macro", + "log", + "memchr", + "once_cell", + "pin-project-lite", + "pin-utils", + "slab", + "wasm-bindgen-futures", +] + [[package]] name = "async-stream" version = "0.3.5" @@ -630,6 +739,12 @@ dependencies = [ "syn 2.0.60", ] +[[package]] +name = "async-task" +version = "4.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b75356056920673b02621b35afd0f7dda9306d03c79a30f5c56c44cf256e3de" + [[package]] name = "async-trait" version = "0.1.80" @@ -641,6 +756,12 @@ dependencies = [ "syn 2.0.60", ] +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "auto_impl" version = "1.2.0" @@ -748,6 +869,20 @@ dependencies = [ "generic-array", ] +[[package]] +name = "blocking" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "495f7104e962b7356f0aeb34247aca1fe7d2e783b346582db7f2904cb5717e88" +dependencies = [ + "async-channel 2.3.1", + "async-lock 3.3.0", + "async-task", + "futures-io", + "futures-lite 2.3.0", + "piper", +] + [[package]] name = "blst" version = "0.3.11" @@ -814,15 +949,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] -name = "chrono" -version = "0.4.38" +name = "concurrent-queue" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" +checksum = "4ca0197aee26d1ae37445ee532fefce43251d24cc7c166799f4d46817f1d3973" dependencies = [ - "android-tzdata", - "iana-time-zone", - "num-traits", - "windows-targets 0.52.5", + "crossbeam-utils", ] [[package]] @@ -974,12 +1106,6 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "destructure_traitobject" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c877555693c14d2f84191cfd3ad8582790fc52b5e2274b40b59cf5f5cea25c7" - [[package]] name = "digest" version = "0.9.0" @@ -1071,6 +1197,63 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "event-listener" +version = "2.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" + +[[package]] +name = "event-listener" +version = "4.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67b215c49b2b248c855fb73579eb1f4f26c38ffdc12973e20e07b91d78d5646e" +dependencies = [ + "concurrent-queue", + "parking", + "pin-project-lite", +] + +[[package]] +name = "event-listener" +version = "5.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d9944b8ca13534cdfb2800775f8dd4902ff3fc75a50101466decadfdf322a24" +dependencies = [ + "concurrent-queue", + "parking", + "pin-project-lite", +] + +[[package]] +name = "event-listener-strategy" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "958e4d70b6d5e81971bebec42271ec641e7ff4e170a6fa605f2b8a8b65cb97d3" +dependencies = [ + "event-listener 4.0.3", + "pin-project-lite", +] + +[[package]] +name = "event-listener-strategy" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f214dc438f977e6d4e3500aaa277f5ad94ca83fbbd9b1a15713ce2344ccc5a1" +dependencies = [ + "event-listener 5.3.0", + "pin-project-lite", +] + +[[package]] +name = "fastrand" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e51093e27b0797c359783294ca4f0a911c270184cb10f85783b118614a1501be" +dependencies = [ + "instant", +] + [[package]] name = "fastrand" version = "2.1.0" @@ -1204,6 +1387,34 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" +[[package]] +name = "futures-lite" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49a9d51ce47660b1e808d3c990b4709f2f415d928835a17dfd16991515c46bce" +dependencies = [ + "fastrand 1.9.0", + "futures-core", + "futures-io", + "memchr", + "parking", + "pin-project-lite", + "waker-fn", +] + +[[package]] +name = "futures-lite" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52527eb5074e35e9339c6b4e8d12600c7128b68fb25dcb9fa9dec18f7c25f3a5" +dependencies = [ + "fastrand 2.1.0", + "futures-core", + "futures-io", + "parking", + "pin-project-lite", +] + [[package]] name = "futures-macro" version = "0.3.30" @@ -1294,6 +1505,18 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" +[[package]] +name = "gloo-timers" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b995a66bb87bebce9a0f4a95aed01daca4872c050bfcb21653361c03bc35e5c" +dependencies = [ + "futures-channel", + "futures-core", + "js-sys", + "wasm-bindgen", +] + [[package]] name = "group" version = "0.13.0" @@ -1416,12 +1639,6 @@ version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" -[[package]] -name = "humantime" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" - [[package]] name = "hyper" version = "1.3.1" @@ -1471,36 +1688,13 @@ dependencies = [ "http-body", "hyper", "pin-project-lite", - "socket2", + "socket2 0.5.7", "tokio", "tower", "tower-service", "tracing", ] -[[package]] -name = "iana-time-zone" -version = "0.1.60" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141" -dependencies = [ - "android_system_properties", - "core-foundation-sys", - "iana-time-zone-haiku", - "js-sys", - "wasm-bindgen", - "windows-core", -] - -[[package]] -name = "iana-time-zone-haiku" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" -dependencies = [ - "cc", -] - [[package]] name = "idna" version = "0.5.0" @@ -1550,6 +1744,17 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "io-lifetimes" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" +dependencies = [ + "hermit-abi", + "libc", + "windows-sys 0.48.0", +] + [[package]] name = "ipnet" version = "2.9.0" @@ -1612,6 +1817,15 @@ dependencies = [ "sha3-asm", ] +[[package]] +name = "kv-log-macro" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0de8b303297635ad57c9f5059fd9cee7a47f8e8daa09df0fcd07dd39fb22977f" +dependencies = [ + "log", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -1630,6 +1844,12 @@ version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" +[[package]] +name = "linux-raw-sys" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" + [[package]] name = "linux-raw-sys" version = "0.4.13" @@ -1652,41 +1872,7 @@ version = "0.4.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" dependencies = [ - "serde", -] - -[[package]] -name = "log-mdc" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a94d21414c1f4a51209ad204c1776a3d0765002c76c6abcb602a6f09f1e881c7" - -[[package]] -name = "log4rs" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0816135ae15bd0391cf284eab37e6e3ee0a6ee63d2ceeb659862bd8d0a984ca6" -dependencies = [ - "anyhow", - "arc-swap", - "chrono", - "derivative", - "fnv", - "humantime", - "libc", - "log", - "log-mdc", - "once_cell", - "parking_lot 0.12.2", - "rand", - "serde", - "serde-value", - "serde_json", - "serde_yaml", - "thiserror", - "thread-id", - "typemap-ors", - "winapi", + "value-bag", ] [[package]] @@ -1847,15 +2033,6 @@ dependencies = [ "vcpkg", ] -[[package]] -name = "ordered-float" -version = "2.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68f19d67e5a2795c94e73e0bb1cc1a7edeb2e28efd39e2e1c9b7a40c1108b11c" -dependencies = [ - "num-traits", -] - [[package]] name = "parity-scale-codec" version = "3.6.9" @@ -1882,6 +2059,12 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "parking" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb813b8af86854136c6922af0598d719255ecb2179515e6e7730d468f05c9cae" + [[package]] name = "parking_lot" version = "0.11.2" @@ -1893,16 +2076,6 @@ dependencies = [ "parking_lot_core 0.8.6", ] -[[package]] -name = "parking_lot" -version = "0.12.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" -dependencies = [ - "lock_api", - "parking_lot_core 0.9.10", -] - [[package]] name = "parking_lot_core" version = "0.8.6" @@ -1985,6 +2158,17 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +[[package]] +name = "piper" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "464db0c665917b13ebb5d453ccdec4add5658ee1adc7affc7677615356a8afaf" +dependencies = [ + "atomic-waker", + "fastrand 2.1.0", + "futures-io", +] + [[package]] name = "pkcs8" version = "0.10.2" @@ -2001,6 +2185,37 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" +[[package]] +name = "polling" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b2d323e8ca7996b3e23126511a523f7e62924d93ecd5ae73b333815b0eb3dce" +dependencies = [ + "autocfg", + "bitflags 1.3.2", + "cfg-if", + "concurrent-queue", + "libc", + "log", + "pin-project-lite", + "windows-sys 0.48.0", +] + +[[package]] +name = "polling" +version = "3.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645493cf344456ef24219d02a768cf1fb92ddf8c92161679ae3d91b91a637be3" +dependencies = [ + "cfg-if", + "concurrent-queue", + "hermit-abi", + "pin-project-lite", + "rustix 0.38.34", + "tracing", + "windows-sys 0.52.0", +] + [[package]] name = "ppv-lite86" version = "0.2.17" @@ -2287,6 +2502,20 @@ dependencies = [ "semver 1.0.22", ] +[[package]] +name = "rustix" +version = "0.37.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fea8ca367a3a01fe35e6943c400addf443c0f57670e6ec51196f71a4b8762dd2" +dependencies = [ + "bitflags 1.3.2", + "errno", + "io-lifetimes", + "libc", + "linux-raw-sys 0.3.8", + "windows-sys 0.48.0", +] + [[package]] name = "rustix" version = "0.38.34" @@ -2296,7 +2525,7 @@ dependencies = [ "bitflags 2.5.0", "errno", "libc", - "linux-raw-sys", + "linux-raw-sys 0.4.13", "windows-sys 0.52.0", ] @@ -2419,16 +2648,6 @@ dependencies = [ "serde_derive", ] -[[package]] -name = "serde-value" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3a1a3341211875ef120e117ea7fd5228530ae7e7036a779fdc9117be6b3282c" -dependencies = [ - "ordered-float", - "serde", -] - [[package]] name = "serde_derive" version = "1.0.200" @@ -2463,19 +2682,6 @@ dependencies = [ "serde", ] -[[package]] -name = "serde_yaml" -version = "0.9.34+deprecated" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47" -dependencies = [ - "indexmap", - "itoa", - "ryu", - "serde", - "unsafe-libyaml", -] - [[package]] name = "sha2" version = "0.10.8" @@ -2529,7 +2735,7 @@ dependencies = [ "fxhash", "libc", "log", - "parking_lot 0.11.2", + "parking_lot", ] [[package]] @@ -2538,6 +2744,16 @@ version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" +[[package]] +name = "socket2" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7916fc008ca5542385b89a3d3ce689953c143e9304a9bf8beec1de48994c0d" +dependencies = [ + "libc", + "winapi", +] + [[package]] name = "socket2" version = "0.5.7" @@ -2644,8 +2860,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" dependencies = [ "cfg-if", - "fastrand", - "rustix", + "fastrand 2.1.0", + "rustix 0.38.34", "windows-sys 0.52.0", ] @@ -2669,16 +2885,6 @@ dependencies = [ "syn 2.0.60", ] -[[package]] -name = "thread-id" -version = "4.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0ec81c46e9eb50deaa257be2f148adf052d1fb7701cfd55ccfab2525280b70b" -dependencies = [ - "libc", - "winapi", -] - [[package]] name = "threadpool" version = "1.8.1" @@ -2723,7 +2929,7 @@ dependencies = [ "libc", "mio", "pin-project-lite", - "socket2", + "socket2 0.5.7", "tokio-macros", "windows-sys 0.48.0", ] @@ -2858,15 +3064,6 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" -[[package]] -name = "typemap-ors" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a68c24b707f02dd18f1e4ccceb9d49f2058c2fb86384ef9972592904d7a28867" -dependencies = [ - "unsafe-any-ors", -] - [[package]] name = "typenum" version = "1.17.0" @@ -2918,21 +3115,6 @@ dependencies = [ "tinyvec", ] -[[package]] -name = "unsafe-any-ors" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0a303d30665362d9680d7d91d78b23f5f899504d4f08b3c4cf08d055d87c0ad" -dependencies = [ - "destructure_traitobject", -] - -[[package]] -name = "unsafe-libyaml" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861" - [[package]] name = "url" version = "2.5.0" @@ -2959,6 +3141,12 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" +[[package]] +name = "value-bag" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a84c137d37ab0142f0f2ddfe332651fdbf252e7b7dbb4e67b6c1f1b2e925101" + [[package]] name = "vcpkg" version = "0.2.15" @@ -2980,6 +3168,12 @@ dependencies = [ "libc", ] +[[package]] +name = "waker-fn" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "317211a0dc0ceedd78fb2ca9a44aed3d7b9b26f81870d485c07122b4350673b7" + [[package]] name = "want" version = "0.3.1" @@ -3093,15 +3287,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -[[package]] -name = "windows-core" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" -dependencies = [ - "windows-targets 0.52.5", -] - [[package]] name = "windows-sys" version = "0.48.0" diff --git a/Cargo.toml b/Cargo.toml index 0992895..647881e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,6 +15,6 @@ sha2 = "0.10.8" tokio = "1.37.0" uuid = {version="1.8.0",features=["v4"]} reqwest = "0.12.4" -log4rs = "1.3.0" log = "0.4.21" zeroize = {version="1.7.0",features=["zeroize_derive"]} +async-std = "1.12.0" diff --git a/src/db/mod.rs b/src/db/mod.rs index ef5f2f6..68ee3c7 100644 --- a/src/db/mod.rs +++ b/src/db/mod.rs @@ -1,5 +1,4 @@ -use crate::common::DatabaseError; -use crate::types::Serializable; +use crate::{common::DatabaseError, types::Invoice}; use sled::Tree; /// Retrieve a value by key from a tree. @@ -24,11 +23,10 @@ async fn get_last_from_tree(db: &Tree) -> Result<(Vec, Vec), DatabaseErr db.last()? .map(|(key, value)| (key.to_vec(), value.to_vec())) .ok_or(DatabaseError::NotFound) - } /// Wrapper for retrieving the last added item to the tree -pub async fn get_last(tree: &sled::Tree) -> Result<(String, T), DatabaseError> { +pub async fn get_last(tree: &sled::Tree) -> Result<(String, Invoice), DatabaseError> { let binary_data = get_last_from_tree(tree).await?; // Convert binary key to String let key = String::from_utf8(binary_data.0).map_err(|error| { @@ -37,7 +35,7 @@ pub async fn get_last(tree: &sled::Tree) -> Result<(String, T), })?; // Deserialize binary value to T - let value = T::from_bin(binary_data.1).map_err(|error| { + let value = bincode::deserialize::(&binary_data.1).map_err(|error| { log::error!("Db Interaction Error: {}", error); DatabaseError::Deserialize })?; @@ -45,9 +43,7 @@ pub async fn get_last(tree: &sled::Tree) -> Result<(String, T), } /// Wrapper for retrieving all key value pairs from a tree -pub async fn get_all( - tree: &sled::Tree, -) -> Result, DatabaseError> { +pub async fn get_all(tree: &sled::Tree) -> Result, DatabaseError> { let binary_data = get_all_from_tree(tree).await?; let mut all = Vec::with_capacity(binary_data.len()); for (binary_key, binary_value) in binary_data { @@ -57,8 +53,8 @@ pub async fn get_all( DatabaseError::Deserialize })?; - // Deserialize binary value to T - let value = T::from_bin(binary_value).map_err(|error| { + // Deserialize binary value to invoice + let value = bincode::deserialize::(&binary_value).map_err(|error| { log::error!("Db Interaction Error: {}", error); DatabaseError::Deserialize })?; @@ -69,9 +65,9 @@ pub async fn get_all( } /// Wrapper for retrieving a value from a tree -pub async fn get(tree: &Tree, key: &str) -> Result { +pub async fn get(tree: &Tree, key: &str) -> Result { let binary_data = get_from_tree(tree, key).await?; - T::from_bin(binary_data).map_err(|error| { + bincode::deserialize::(&binary_data).map_err(|error| { log::error!("Db Interaction Error: {}", error); DatabaseError::Deserialize }) @@ -89,8 +85,8 @@ async fn set_to_tree(db: &Tree, key: &str, bin: Vec) -> Result<(), DatabaseE } /// Wrapper for setting a value to a tree -pub async fn set(tree: &Tree, key: &str, data: &T) -> Result<(), DatabaseError> { - let binary_data = T::to_bin(data).map_err(|error| { +pub async fn set(tree: &Tree, key: &str, data: &Invoice) -> Result<(), DatabaseError> { + let binary_data = bincode::serialize::(data).map_err(|error| { log::error!("Db Interaction Error: {}", error); DatabaseError::Serialize })?; diff --git a/src/gateway/mod.rs b/src/gateway/mod.rs index 975c518..a5020ef 100644 --- a/src/gateway/mod.rs +++ b/src/gateway/mod.rs @@ -7,13 +7,8 @@ use alloy::{ signers::wallet::LocalWallet, transports::http::Http, }; -use log::LevelFilter; -use log4rs::{ - append::file::FileAppender, - config::{Appender, Root}, - encode::pattern::PatternEncoder, - Config, -}; + +use async_std::channel::Sender; use reqwest::{Client, Url}; use sled::Tree; @@ -44,10 +39,32 @@ pub struct PaymentGatewayConfiguration { pub provider: RootProvider>, pub treasury_address: Address, pub invoice_delay_millis: u64, - pub callback: AsyncCallback, + pub reflector: Reflector, pub transfer_gas_limit: Option, } +/// ## Reflector +/// The reflector allows your payment gateway to be used in a more flexible way. +/// +/// In its current state you can pass a Sender from an unbound async-std channel +/// which you can create by doing: +/// ```rust +/// use async_std::channel::unbounded; +/// use acceptevm::gateway::Reflector; +/// +/// let (sender, receiver) = unbounded(); +/// +/// let reflector=Reflector::Sender(sender); +/// ``` +/// +/// You may clone the receiver as many times as you want but do not use the sender +/// for anything other than passing it to the try_new() method. +#[derive(Clone)] +pub enum Reflector { + /// A sender from async-std + Sender(Sender), +} + // Type alias for the underlying Web3 type. pub type Wei = U256; @@ -62,7 +79,9 @@ impl PaymentGateway { /// - `treasury_address`: the address of the treasury for all paid invoices, on this EVM network. /// - `invoice_delay_millis`: how long to wait before checking the next invoice in milliseconds. /// This is used to prevent potential rate limits from the node. - /// - `callback`: an async function that is called when an invoice is paid. + /// - `reflector`: The reflector is an enum that allows you to receive the paid invoices. + /// At the moment, the only reflector available is the `Sender` from the async-std channel. + /// This means that you will need to create a channel and pass the sender as the reflector. /// - `sled_path`: The path of the sled database where the pending invoices will /// be stored. In the event of a crash the invoices are saved and will be /// checked on reboot. @@ -70,49 +89,39 @@ impl PaymentGateway { /// - `transfer_gas_limit`: An optional gas limit used when transferring gas from paid invoices to /// the treasury. Useful in case your treasury address is a contract address /// that implements custom functionality for handling incoming gas. - pub fn new( + /// + /// Example: + /// ```rust + /// use acceptevm::gateway::{PaymentGateway, Reflector}; + /// use async_std::channel::unbounded; + /// let (sender, _receiver) = unbounded(); + /// let reflector = Reflector::Sender(sender); + /// + /// PaymentGateway::new( + /// "https://123.com", + /// "0xdac17f958d2ee523a2206206994597c13d831ec7".to_string(), + /// 10, + /// reflector, + /// "./your-wanted-db-path", + /// "test".to_string(), + /// Some(21000), + /// ); + /// ``` + + + pub fn new( rpc_url: &str, treasury_address: String, invoice_delay_millis: u64, - callback: F, + reflector: Reflector, sled_path: &str, name: String, transfer_gas_limit: Option, - ) -> PaymentGateway - where - F: Fn(Invoice) -> Fut + 'static + Send + Sync, - Fut: Future + 'static + Send, - { - // Send allows ownership to be transferred across threads - // Sync allows references to be shared - + ) -> PaymentGateway { let db = sled::open(sled_path).unwrap(); let tree = db.open_tree("invoices").unwrap(); let provider = ProviderBuilder::new().on_http(Url::from_str(rpc_url).unwrap()); - // Wrap the callback in Arc> to allow sharing across threads and state mutation - // We have to create a pinned box to prevent the future from being moved around in heap memory. - let callback = Arc::new(move |invoice: Invoice| { - Box::pin(callback(invoice)) as Pin + Send>> - }); - - // Setup logging - let logfile = FileAppender::builder() - .encoder(Box::new(PatternEncoder::new("{l} - {m}\n"))) - .build("./acceptevm.log") - .unwrap(); - - let config = Config::builder() - .appender(Appender::builder().build("logfile", Box::new(logfile))) - .build(Root::builder().appender("logfile").build(LevelFilter::Info)) - .unwrap(); - - // Try to initialize and catch error silently if already initialized - // during tests this make this function throw error - if log4rs::init_config(config).is_err() { - println!("Logger already initialized."); - } - // TODO: When implementing token transfers allow the user to add their gas wallet here. PaymentGateway { @@ -122,7 +131,7 @@ impl PaymentGateway { .parse() .unwrap_or_else(|_| panic!("Invalid treasury address")), invoice_delay_millis, - callback, + reflector, transfer_gas_limit, }, tree, @@ -132,7 +141,7 @@ impl PaymentGateway { /// Retrieves the last invoice pub async fn get_last_invoice(&self) -> Result<(String, Invoice), DatabaseError> { - get_last::(&self.tree).await + get_last(&self.tree).await } /// Retrieves all invoices in the form of a tuple: String,Invoice @@ -140,12 +149,12 @@ impl PaymentGateway { /// and the second part is the invoice. The key is a SHA256 hash of the /// creation timestamp and the recipient address. pub async fn get_all_invoices(&self) -> Result, DatabaseError> { - get_all::(&self.tree).await + get_all(&self.tree).await } /// Retrieve an invoice from the payment gateway pub async fn get_invoice(&self, key: String) -> Result { - get::(&self.tree, &key).await + get(&self.tree, &key).await } /// Spawns an asynchronous task that checks all the pending invoices @@ -189,7 +198,7 @@ impl PaymentGateway { let seed = format!("{}{}", signer.address(), get_unix_time_millis()); let invoice_id = hash_now(seed); // Save the invoice in db. - set::(&self.tree, &invoice_id, &invoice).await?; + set(&self.tree, &invoice_id, &invoice).await?; Ok(invoice) } } diff --git a/src/lib.rs b/src/lib.rs index 6efb617..8c55ff7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,37 +11,23 @@ mod tests { use std::{fs, path::Path, str::FromStr}; use alloy::primitives::U256; + use async_std::channel::unbounded; use crate::{ common::DatabaseError, - gateway::PaymentGateway, + gateway::{PaymentGateway, Reflector}, types::{Invoice, PaymentMethod}, }; - struct Foo { - bar: std::sync::Mutex, - } - - impl Foo { - async fn increase(&self) { - *self.bar.lock().unwrap() += 1; - } - } - fn setup_test_gateway(db_path: &str) -> PaymentGateway { - let foo = std::sync::Arc::new(Foo { - bar: Default::default(), - }); - let foo_clone = foo.clone(); - let callback = move |_| { - let foo = foo_clone.clone(); - async move { foo.increase().await } - }; + let (sender, _receiver) = unbounded(); + let reflector = Reflector::Sender(sender); + PaymentGateway::new( "https://123.com", "0xdac17f958d2ee523a2206206994597c13d831ec7".to_string(), 10, - callback, + reflector, db_path, "test".to_string(), Some(21000), @@ -86,4 +72,5 @@ mod tests { assert_eq!(address_length, 42); remove_test_db("./test-assert-valid-address-length"); } + } diff --git a/src/poller/mod.rs b/src/poller/mod.rs index 609aeec..5895ffb 100644 --- a/src/poller/mod.rs +++ b/src/poller/mod.rs @@ -12,6 +12,7 @@ use alloy::{ rpc::types::eth::TransactionReceipt, transports::http::Http, }; +use crate::gateway::Reflector::Sender; use reqwest::Client; use sled::Tree; @@ -70,11 +71,8 @@ async fn check_and_process(provider: RootProvider>, invoice: &Invoi async fn delete_invoice(tree: &Tree, key: String) { // Optimistically delete the old invoice. - match delete(tree, &key).await { - Ok(()) => {} - Err(error) => { - log::error!("Could not remove invoice, did not callback: {}", error); - } + if let Err(delete_error) = delete(tree, &key).await { + log::error!("Could not remove invoice: {}", delete_error); } } @@ -89,7 +87,7 @@ async fn transfer_to_treasury( /// to the specified polling interval. pub async fn poll_payments(gateway: PaymentGateway) { loop { - match get_all::(&gateway.tree).await { + match get_all(&gateway.tree).await { Ok(all) => { // Loop through all invoices for (key, mut invoice) in all { @@ -121,7 +119,14 @@ pub async fn poll_payments(gateway: PaymentGateway) { // lock to the callback function. delete_invoice(&gateway.tree, key).await; invoice.paid_at_timestamp = get_unix_time_seconds(); - (gateway.config.callback)(invoice).await;// Execute callback function + match gateway.config.reflector { + Sender(ref sender) => { + // Attempt to send the PriceData through the channel. + if let Err(error) = sender.send(invoice).await { + log::error!("Failed sending data: {}", error); + } + } + } } // To prevent rate limitations on certain Web3 RPC's we sleep here for the specified amount. tokio::time::sleep(std::time::Duration::from_millis( diff --git a/src/types/errors.rs b/src/types/errors.rs deleted file mode 100644 index 3d1cc97..0000000 --- a/src/types/errors.rs +++ /dev/null @@ -1,7 +0,0 @@ -use thiserror::Error; - -#[derive(Error, Debug)] -pub enum SerializableError { - #[error("Could not deserialize binary")] - Deserialize, -} diff --git a/src/types/mod.rs b/src/types/mod.rs index 1455e76..62bf293 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -1,19 +1,11 @@ -mod errors; use std::ops::{Deref, DerefMut}; -use self::errors::SerializableError; use alloy::{ primitives::{B256, U256}, rpc::types::eth::TransactionReceipt, }; use serde::{Deserialize, Serialize}; use zeroize::ZeroizeOnDrop; -pub trait Serializable { - fn to_bin(&self) -> Result, Box>; - fn from_bin(data: Vec) -> Result - where - Self: Sized; -} /// Describes the structure of a payment method in /// a gateway @@ -62,14 +54,3 @@ pub struct Invoice { pub receipt: Option, } -impl Serializable for Invoice { - /// Serializes invoice to bytes - fn to_bin(&self) -> Result, Box> { - bincode::serialize(&self) - } - - /// Deserializes invoice from bytes - fn from_bin(data: Vec) -> Result { - bincode::deserialize(&data).map_err(|_| SerializableError::Deserialize) - } -}