2023-01-05 12:45:09 +01:00
|
|
|
package main
|
|
|
|
|
2023-01-06 12:32:20 +01:00
|
|
|
import (
|
2023-01-14 11:17:34 +01:00
|
|
|
"strings"
|
|
|
|
"sync"
|
|
|
|
|
2023-01-19 09:42:59 +01:00
|
|
|
"github.com/grassrootseconomics/cic-chain-events/internal/filter"
|
2023-03-08 15:30:40 +01:00
|
|
|
"github.com/grassrootseconomics/cic-chain-events/internal/pub"
|
2023-01-06 12:32:20 +01:00
|
|
|
)
|
|
|
|
|
2023-02-24 11:28:30 +01:00
|
|
|
var (
|
2023-03-11 10:39:26 +01:00
|
|
|
systemAddress string
|
2023-02-24 11:28:30 +01:00
|
|
|
)
|
|
|
|
|
2023-01-06 12:32:20 +01:00
|
|
|
func initAddressFilter() filter.Filter {
|
2023-03-11 10:39:26 +01:00
|
|
|
// TODO: Temporary shortcut
|
|
|
|
systemAddress = ko.MustString("chain.system_address")
|
|
|
|
|
2023-01-14 11:17:34 +01:00
|
|
|
// TODO: Bootstrap addresses from smart contract
|
|
|
|
// TODO: Add route to update cache
|
|
|
|
cache := &sync.Map{}
|
|
|
|
|
2023-03-11 10:29:51 +01:00
|
|
|
cache.Store(strings.ToLower(ko.MustString("chain.token_index_address")), "TokenIndex")
|
|
|
|
cache.Store(strings.ToLower(ko.MustString("chain.gas_faucet_address")), "GasFaucet")
|
|
|
|
cache.Store(strings.ToLower(ko.MustString("chain.user_index_address")), "UserIndex")
|
2023-01-14 11:17:34 +01:00
|
|
|
|
2023-01-06 12:32:20 +01:00
|
|
|
return filter.NewAddressFilter(filter.AddressFilterOpts{
|
2023-03-11 10:39:26 +01:00
|
|
|
Cache: cache,
|
|
|
|
Logg: lo,
|
2023-02-24 11:28:30 +01:00
|
|
|
SystemAddress: systemAddress,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-03-08 15:30:40 +01:00
|
|
|
func initTransferFilter(pub *pub.Pub) filter.Filter {
|
2023-02-24 11:28:30 +01:00
|
|
|
return filter.NewTransferFilter(filter.TransferFilterOpts{
|
2023-03-08 15:30:40 +01:00
|
|
|
Pub: pub,
|
|
|
|
Logg: lo,
|
2023-01-06 12:32:20 +01:00
|
|
|
})
|
2023-02-24 11:28:30 +01:00
|
|
|
|
2023-01-06 12:32:20 +01:00
|
|
|
}
|
|
|
|
|
2023-03-08 15:30:40 +01:00
|
|
|
func initGasGiftFilter(pub *pub.Pub) filter.Filter {
|
2023-02-24 11:28:30 +01:00
|
|
|
return filter.NewGasFilter(filter.GasFilterOpts{
|
2023-03-08 15:30:40 +01:00
|
|
|
Pub: pub,
|
2023-02-24 11:28:30 +01:00
|
|
|
Logg: lo,
|
|
|
|
SystemAddress: systemAddress,
|
|
|
|
})
|
|
|
|
}
|
2023-01-14 11:17:34 +01:00
|
|
|
|
2023-03-08 15:30:40 +01:00
|
|
|
func initRegisterFilter(pub *pub.Pub) filter.Filter {
|
2023-02-24 11:28:30 +01:00
|
|
|
return filter.NewRegisterFilter(filter.RegisterFilterOpts{
|
2023-03-08 15:30:40 +01:00
|
|
|
Pub: pub,
|
|
|
|
Logg: lo,
|
2023-01-06 12:32:20 +01:00
|
|
|
})
|
|
|
|
}
|