-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from Jurshsmith/dispatch-event-handlers-dynami…
…cally Dispatch event handlers dynamically
- Loading branch information
Showing
12 changed files
with
128 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,18 @@ | ||
use chaindexing::{Chain, Contract}; | ||
|
||
use super::TestEventHandler; | ||
use super::{ApprovalForAllTestEventHandler, TestContractState, TransferTestEventHandler}; | ||
|
||
pub const TRANSFER_EVENT_ABI: &str = | ||
"event Transfer(address indexed from, address indexed to, uint256 indexed tokenId)"; | ||
|
||
pub const APPROCAL_EVENT_ABI: &str = | ||
"event ApprovalForAll(address indexed owner, address indexed operator, bool approved)"; | ||
|
||
pub const BAYC_CONTRACT_ADDRESS: &str = "0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D"; | ||
pub const BAYC_CONTRACT_START_BLOCK_NUMBER: u32 = 17773490; | ||
pub fn bayc_contract() -> Contract { | ||
pub fn bayc_contract() -> Contract<TestContractState> { | ||
Contract::new("BoredApeYachtClub") | ||
.add_event(TRANSFER_EVENT_ABI, TestEventHandler) | ||
.add_event(TRANSFER_EVENT_ABI, TransferTestEventHandler) | ||
.add_event(APPROCAL_EVENT_ABI, ApprovalForAllTestEventHandler) | ||
.add_address(BAYC_CONTRACT_ADDRESS, &Chain::Mainnet, 17773490) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,39 @@ | ||
use chaindexing::{Event, EventHandler}; | ||
use chaindexing::{ContractState, Event, EventHandler}; | ||
|
||
pub struct TestEventHandler; | ||
#[derive(Clone, Debug)] | ||
pub enum TestContractState { | ||
NftState(NftState), | ||
NftOperatorState(NftOperatorState), | ||
} | ||
|
||
impl ContractState for TestContractState {} | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct NftState; | ||
|
||
impl ContractState for NftState {} | ||
|
||
pub struct TransferTestEventHandler; | ||
|
||
#[async_trait::async_trait] | ||
impl EventHandler for TransferTestEventHandler { | ||
type State = TestContractState; | ||
async fn handle_event(&self, _event: Event) -> Option<Vec<Self::State>> { | ||
None | ||
} | ||
} | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct NftOperatorState; | ||
|
||
impl ContractState for NftOperatorState {} | ||
|
||
pub struct ApprovalForAllTestEventHandler; | ||
|
||
#[async_trait::async_trait] | ||
impl EventHandler for TestEventHandler { | ||
async fn handle_event(&self, _event: Event) {} | ||
impl EventHandler for ApprovalForAllTestEventHandler { | ||
type State = TestContractState; | ||
async fn handle_event(&self, event: Event) -> Option<Vec<Self::State>> { | ||
None | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.