1- use std:: time:: Duration ;
2-
31use alloy:: { network:: Ethereum , providers:: ProviderBuilder , sol, sol_types:: SolEvent } ;
42use alloy_node_bindings:: Anvil ;
53
64use event_scanner:: { EventFilter , EventScanner , Message } ;
7- use tokio:: time:: sleep;
85use tokio_stream:: StreamExt ;
96use tracing:: { error, info} ;
107use tracing_subscriber:: EnvFilter ;
118
129sol ! {
1310 // Built directly with solc 0.8.30+commit.73712a01.Darwin.appleclang
14- #[ sol( rpc,
15- bytecode="608080604052346015576101b0908161001a8239f35b5f80fdfe6080806040526004361015610012575f80fd5b5f3560e01c90816306661abd1461016157508063a87d942c14610145578063d732d955146100ad5763e8927fbc14610048575f80fd5b346100a9575f3660031901126100a9575f5460018101809111610095576020817f7ca2ca9527391044455246730762df008a6b47bbdb5d37a890ef78394535c040925f55604051908152a1005b634e487b7160e01b5f52601160045260245ffd5b5f80fd5b346100a9575f3660031901126100a9575f548015610100575f198101908111610095576020817f53a71f16f53e57416424d0d18ccbd98504d42a6f98fe47b09772d8f357c620ce925f55604051908152a1005b60405162461bcd60e51b815260206004820152601860248201527f436f756e742063616e6e6f74206265206e6567617469766500000000000000006044820152606490fd5b346100a9575f3660031901126100a95760205f54604051908152f35b346100a9575f3660031901126100a9576020905f548152f3fea2646970667358221220471585b420a1ad0093820ff10129ec863f6df4bec186546249391fbc3cdbaa7c64736f6c634300081e0033"
16- ) ] contract Counter {
17- uint256 public count;
11+ #[ sol( rpc, bytecode="608080604052346015576101b0908161001a8239f35b5f80fdfe6080806040526004361015610012575f80fd5b5f3560e01c90816306661abd1461016157508063a87d942c14610145578063d732d955146100ad5763e8927fbc14610048575f80fd5b346100a9575f3660031901126100a9575f5460018101809111610095576020817f7ca2ca9527391044455246730762df008a6b47bbdb5d37a890ef78394535c040925f55604051908152a1005b634e487b7160e01b5f52601160045260245ffd5b5f80fd5b346100a9575f3660031901126100a9575f548015610100575f198101908111610095576020817f53a71f16f53e57416424d0d18ccbd98504d42a6f98fe47b09772d8f357c620ce925f55604051908152a1005b60405162461bcd60e51b815260206004820152601860248201527f436f756e742063616e6e6f74206265206e6567617469766500000000000000006044820152606490fd5b346100a9575f3660031901126100a95760205f54604051908152f35b346100a9575f3660031901126100a9576020905f548152f3fea2646970667358221220471585b420a1ad0093820ff10129ec863f6df4bec186546249391fbc3cdbaa7c64736f6c634300081e0033" ) ]
12+ contract Counter {
13+ uint256 public count;
1814
19- event CountIncreased ( uint256 newCount) ;
20- event CountDecreased ( uint256 newCount) ;
15+ event CountIncreased ( uint256 newCount) ;
16+ event CountDecreased ( uint256 newCount) ;
2117
22- function increase( ) public {
23- count += 1 ;
24- emit CountIncreased ( count) ;
25- }
18+ function increase( ) public {
19+ count += 1 ;
20+ emit CountIncreased ( count) ;
21+ }
2622
27- function decrease( ) public {
28- require( count > 0 , "Count cannot be negative" ) ;
29- count -= 1 ;
30- emit CountDecreased ( count) ;
31- }
23+ function decrease( ) public {
24+ require( count > 0 , "Count cannot be negative" ) ;
25+ count -= 1 ;
26+ emit CountDecreased ( count) ;
27+ }
3228
33- function getCount( ) public view returns ( uint256) {
34- return count;
29+ function getCount( ) public view returns ( uint256) {
30+ return count;
31+ }
3532 }
3633}
37- }
3834
3935#[ tokio:: main]
4036async fn main ( ) -> anyhow:: Result < ( ) > {
4137 let _ = tracing_subscriber:: fmt ( ) . with_env_filter ( EnvFilter :: from_default_env ( ) ) . try_init ( ) ;
4238
43- let anvil = Anvil :: new ( ) . block_time ( 1 ) . try_spawn ( ) ?;
39+ let anvil = Anvil :: new ( ) . block_time_f64 ( 0. 1) . try_spawn ( ) ?;
4440 let wallet = anvil. wallet ( ) ;
4541 let provider =
4642 ProviderBuilder :: new ( ) . wallet ( wallet. unwrap ( ) ) . connect ( anvil. endpoint ( ) . as_str ( ) ) . await ?;
@@ -59,7 +55,6 @@ async fn main() -> anyhow::Result<()> {
5955
6056 let mut stream = scanner. subscribe ( increase_filter) ;
6157
62- sleep ( Duration :: from_secs ( 10 ) ) . await ;
6358 scanner. start ( ) . await . expect ( "failed to start scanner" ) ;
6459
6560 while let Some ( message) = stream. next ( ) . await {
0 commit comments