forked from cerc-io/ipld-eth-server
Backfill/listen for contract logs (#113)
This commit is contained in:
@@ -11,5 +11,5 @@ type Blockchain interface {
|
||||
StopListening()
|
||||
GetAttributes(contract Contract) (ContractAttributes, error)
|
||||
GetAttribute(contract Contract, attributeName string, blockNumber *big.Int) (interface{}, error)
|
||||
GetLogs(contract Contract, blockNumber *big.Int) ([]Log, error)
|
||||
GetLogs(contract Contract, startingBlockNumber *big.Int, endingBlockNumber *big.Int) ([]Log, error)
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ func (blockchain *Blockchain) LastBlock() *big.Int {
|
||||
return big.NewInt(max)
|
||||
}
|
||||
|
||||
func (blockchain *Blockchain) GetLogs(contract core.Contract, blockNumber *big.Int) ([]core.Log, error) {
|
||||
func (blockchain *Blockchain) GetLogs(contract core.Contract, startingBlock *big.Int, endingBlock *big.Int) ([]core.Log, error) {
|
||||
return blockchain.logs[contract.Hash], nil
|
||||
}
|
||||
|
||||
|
||||
@@ -23,14 +23,14 @@ type GethBlockchain struct {
|
||||
node core.Node
|
||||
}
|
||||
|
||||
func (blockchain *GethBlockchain) GetLogs(contract core.Contract, blockNumber *big.Int) ([]core.Log, error) {
|
||||
if blockNumber == nil {
|
||||
blockNumber = blockchain.LastBlock()
|
||||
func (blockchain *GethBlockchain) GetLogs(contract core.Contract, startingBlockNumber *big.Int, endingBlockNumber *big.Int) ([]core.Log, error) {
|
||||
if endingBlockNumber == nil {
|
||||
endingBlockNumber = startingBlockNumber
|
||||
}
|
||||
contractAddress := common.HexToAddress(contract.Hash)
|
||||
fc := ethereum.FilterQuery{
|
||||
FromBlock: blockNumber,
|
||||
ToBlock: blockNumber,
|
||||
FromBlock: startingBlockNumber,
|
||||
ToBlock: endingBlockNumber,
|
||||
Addresses: []common.Address{contractAddress},
|
||||
}
|
||||
gethLogs, err := blockchain.client.FilterLogs(context.Background(), fc)
|
||||
|
||||
Reference in New Issue
Block a user