forked from ava-labs/avalanchego
-
Notifications
You must be signed in to change notification settings - Fork 4
/
pubsub_filterer.go
44 lines (37 loc) · 974 Bytes
/
pubsub_filterer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package avm
import (
"github.com/MetalBlockchain/metalgo/api"
"github.com/MetalBlockchain/metalgo/pubsub"
"github.com/MetalBlockchain/metalgo/vms/avm/txs"
"github.com/MetalBlockchain/metalgo/vms/components/avax"
)
var _ pubsub.Filterer = (*connector)(nil)
type connector struct {
tx *txs.Tx
}
func NewPubSubFilterer(tx *txs.Tx) pubsub.Filterer {
return &connector{tx: tx}
}
// Apply the filter on the addresses.
func (f *connector) Filter(filters []pubsub.Filter) ([]bool, interface{}) {
resp := make([]bool, len(filters))
for _, utxo := range f.tx.UTXOs() {
addressable, ok := utxo.Out.(avax.Addressable)
if !ok {
continue
}
for _, address := range addressable.Addresses() {
for i, c := range filters {
if resp[i] {
continue
}
resp[i] = c.Check(address)
}
}
}
return resp, api.JSONTxID{
TxID: f.tx.ID(),
}
}