mirror of
https://github.com/uqbar-dao/nectar.git
synced 2024-11-23 03:44:04 +03:00
Merge pull request #447 from kinode-dao/dr/fix-no-from-block-in-subscribe
fix: don't use from_block in eth subscribe filters
This commit is contained in:
commit
f8598d15ee
@ -76,7 +76,6 @@ pub fn fetch_state(our: Address, provider: eth::Provider) -> State {
|
||||
pub fn app_store_filter(state: &State) -> eth::Filter {
|
||||
eth::Filter::new()
|
||||
.address(eth::Address::from_str(&state.contract_address).unwrap())
|
||||
.from_block(state.last_saved_block)
|
||||
.events(EVENTS)
|
||||
}
|
||||
|
||||
@ -84,7 +83,10 @@ pub fn app_store_filter(state: &State) -> eth::Filter {
|
||||
pub fn fetch_and_subscribe_logs(state: &mut State) {
|
||||
let filter = app_store_filter(state);
|
||||
// get past logs, subscribe to new ones.
|
||||
for log in fetch_logs(&state.provider, &filter) {
|
||||
for log in fetch_logs(
|
||||
&state.provider,
|
||||
&filter.clone().from_block(state.last_saved_block),
|
||||
) {
|
||||
if let Err(e) = state.ingest_contract_event(log, false) {
|
||||
println!("error ingesting log: {e:?}");
|
||||
};
|
||||
|
@ -6,8 +6,8 @@ wit_bindgen::generate!({
|
||||
world: "process-v0",
|
||||
});
|
||||
|
||||
/// 20 minutes
|
||||
const REFRESH_INTERVAL: u64 = 20 * 60 * 1000;
|
||||
/// 2 hours
|
||||
const REFRESH_INTERVAL: u64 = 120 * 60 * 1000;
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct KinodeBlogPost {
|
||||
|
@ -59,9 +59,9 @@ sol! {
|
||||
event RoutingUpdate(bytes32 indexed node, bytes32[] routers);
|
||||
}
|
||||
|
||||
fn subscribe_to_logs(eth_provider: ð::Provider, from_block: u64, filter: eth::Filter) {
|
||||
fn subscribe_to_logs(eth_provider: ð::Provider, filter: eth::Filter) {
|
||||
loop {
|
||||
match eth_provider.subscribe(1, filter.clone().from_block(from_block)) {
|
||||
match eth_provider.subscribe(1, filter.clone()) {
|
||||
Ok(()) => break,
|
||||
Err(_) => {
|
||||
println!("failed to subscribe to chain! trying again in 5s...");
|
||||
@ -126,7 +126,6 @@ fn init(our: Address) {
|
||||
fn main(our: Address, mut state: State) -> anyhow::Result<()> {
|
||||
let filter = eth::Filter::new()
|
||||
.address(state.contract_address.parse::<eth::Address>().unwrap())
|
||||
.from_block(state.block - 1)
|
||||
.to_block(eth::BlockNumberOrTag::Latest)
|
||||
.events(vec![
|
||||
"NodeRegistered(bytes32,bytes)",
|
||||
@ -147,11 +146,11 @@ fn main(our: Address, mut state: State) -> anyhow::Result<()> {
|
||||
state.chain_id
|
||||
);
|
||||
|
||||
subscribe_to_logs(ð_provider, state.block - 1, filter.clone());
|
||||
subscribe_to_logs(ð_provider, filter.clone());
|
||||
|
||||
// if block in state is < current_block, get logs from that part.
|
||||
loop {
|
||||
match eth_provider.get_logs(&filter) {
|
||||
match eth_provider.get_logs(&filter.clone().from_block(state.block - 1)) {
|
||||
Ok(logs) => {
|
||||
for log in logs {
|
||||
match handle_log(&our, &mut state, &log) {
|
||||
@ -277,7 +276,7 @@ fn handle_eth_message(
|
||||
}
|
||||
Err(_e) => {
|
||||
println!("got eth subscription error");
|
||||
subscribe_to_logs(ð_provider, state.block - 1, filter.clone());
|
||||
subscribe_to_logs(ð_provider, filter.clone());
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user