Created
May 5, 2020 22:16
-
-
Save Garoth/81a5dc5d5fdf16accac639a09dfa6f1c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
ETHER_PAYMENT_EVENT_ID = "0xb66556f6cabf16c4a3460f3164c6fe631dc20e73625d505042244a586761c346" | |
VENDING_MACHINE_ADDR = "0xa9d00e3a19a4ddebde3cb96d883658a721f4df38" | |
VENDING_MACHINE_CHECKPOINT = 9927996 | |
fromBlock = big.NewInt(VENDING_MACHINE_CHECKPOINT) | |
query := ethereum.FilterQuery{ | |
FromBlock: fromBlock, | |
ToBlock: nil, | |
Addresses: []common.Address{common.HexToAddress(VENDING_MACHINE_ADDR)}, | |
Topics: [][]common.Hash{ | |
[]common.Hash{ | |
// Only listening for EtherPurchase Events | |
common.HexToHash(ETHER_PAYMENT_EVENT_ID), | |
}, | |
}, | |
} | |
// Then later, called by an hourly loop: | |
func checkHistory(client *ethclient.Client, | |
query ethereum.FilterQuery, processorInput chan types.Log) { | |
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) | |
defer cancel() | |
logs, err := client.FilterLogs(ctx, query) | |
if err != nil { | |
log.Println("Error Querying Historic Logs:", err) | |
} | |
for _, log := range logs { | |
processorInput <- log | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment