@@ -23,12 +23,12 @@ import (
23
23
)
24
24
25
25
type ChainSync struct {
26
- errorChan chan error
27
- inputChan chan event.Event
28
- outputChan chan event.Event
29
- filterAddress string
30
- filterPolicyId string
31
- filterAssetFingerprint string
26
+ errorChan chan error
27
+ inputChan chan event.Event
28
+ outputChan chan event.Event
29
+ filterAddresses [] string
30
+ filterPolicyIds [] string
31
+ filterAssetFingerprints [] string
32
32
}
33
33
34
34
// New returns a new ChainSync object with the specified options applied
@@ -57,74 +57,95 @@ func (c *ChainSync) Start() error {
57
57
switch v := evt .Payload .(type ) {
58
58
case chainsync.TransactionEvent :
59
59
// Check address filter
60
- if c .filterAddress != "" {
61
- isStakeAddress := false
62
- if strings .HasPrefix (c .filterAddress , "stake" ) {
63
- isStakeAddress = true
64
- }
65
- foundMatch := false
66
- for _ , output := range v .Outputs {
67
- if output .Address ().String () == c .filterAddress {
68
- foundMatch = true
69
- break
70
- }
71
- if isStakeAddress {
72
- stakeAddr := output .Address ().StakeAddress ()
73
- if stakeAddr == nil {
74
- continue
75
- }
76
- if stakeAddr .String () == c .filterAddress {
60
+ if len (c .filterAddresses ) > 0 {
61
+ filterMatched := false
62
+ for _ , filterAddress := range c .filterAddresses {
63
+ isStakeAddress := strings .HasPrefix (filterAddress , "stake" )
64
+ foundMatch := false
65
+ for _ , output := range v .Outputs {
66
+ if output .Address ().String () == filterAddress {
77
67
foundMatch = true
78
68
break
79
69
}
70
+ if isStakeAddress {
71
+ stakeAddr := output .Address ().StakeAddress ()
72
+ if stakeAddr == nil {
73
+ continue
74
+ }
75
+ if stakeAddr .String () == filterAddress {
76
+ foundMatch = true
77
+ break
78
+ }
79
+ }
80
+ }
81
+ if foundMatch {
82
+ filterMatched = true
83
+ break
80
84
}
81
85
}
82
- if ! foundMatch {
86
+ // Skip the event if none of the filter values matched
87
+ if ! filterMatched {
83
88
continue
84
89
}
85
90
}
86
91
// Check policy ID filter
87
- if c .filterPolicyId != "" {
88
- foundMatch := false
89
- for _ , output := range v .Outputs {
90
- if output .Assets () != nil {
91
- for _ , policyId := range output .Assets ().Policies () {
92
- if policyId .String () == c .filterPolicyId {
93
- foundMatch = true
94
- break
92
+ if len (c .filterPolicyIds ) > 0 {
93
+ filterMatched := false
94
+ for _ , filterPolicyId := range c .filterPolicyIds {
95
+ foundMatch := false
96
+ for _ , output := range v .Outputs {
97
+ if output .Assets () != nil {
98
+ for _ , policyId := range output .Assets ().Policies () {
99
+ if policyId .String () == filterPolicyId {
100
+ foundMatch = true
101
+ break
102
+ }
95
103
}
96
104
}
105
+ if foundMatch {
106
+ break
107
+ }
97
108
}
98
109
if foundMatch {
110
+ filterMatched = true
99
111
break
100
112
}
101
113
}
102
- if ! foundMatch {
114
+ // Skip the event if none of the filter values matched
115
+ if ! filterMatched {
103
116
continue
104
117
}
105
118
}
106
119
// Check asset fingerprint filter
107
- if c .filterAssetFingerprint != "" {
108
- foundMatch := false
109
- for _ , output := range v .Outputs {
110
- if output .Assets () != nil {
111
- for _ , policyId := range output .Assets ().Policies () {
112
- for _ , assetName := range output .Assets ().Assets (policyId ) {
113
- assetFp := ledger .NewAssetFingerprint (policyId .Bytes (), assetName )
114
- if assetFp .String () == c .filterAssetFingerprint {
115
- foundMatch = true
120
+ if len (c .filterAssetFingerprints ) > 0 {
121
+ filterMatched := false
122
+ for _ , filterAssetFingerprint := range c .filterAssetFingerprints {
123
+ foundMatch := false
124
+ for _ , output := range v .Outputs {
125
+ if output .Assets () != nil {
126
+ for _ , policyId := range output .Assets ().Policies () {
127
+ for _ , assetName := range output .Assets ().Assets (policyId ) {
128
+ assetFp := ledger .NewAssetFingerprint (policyId .Bytes (), assetName )
129
+ if assetFp .String () == filterAssetFingerprint {
130
+ foundMatch = true
131
+ }
132
+ }
133
+ if foundMatch {
134
+ break
116
135
}
117
136
}
118
137
if foundMatch {
119
138
break
120
139
}
121
140
}
122
- if foundMatch {
123
- break
124
- }
141
+ }
142
+ if foundMatch {
143
+ filterMatched = true
144
+ break
125
145
}
126
146
}
127
- if ! foundMatch {
147
+ // Skip the event if none of the filter values matched
148
+ if ! filterMatched {
128
149
continue
129
150
}
130
151
}
0 commit comments