[ctr/lua] to able filter event arguments for objects and arrays
@@ -571,26 +571,31 @@ func (ev *Event) SetMemoryInfo(receipt *Receipt, blkHash []byte, blkNo BlockNo,
ev.BlockNo = blkNo
}
-func (ev *Event) Filter(filter *FilterInfo, argFilter []ArgFilter) bool {
- if filter.ContractAddress != nil && !bytes.Equal(ev.ContractAddress, filter.ContractAddress) {
+func checkSameArray(value []interface{}, check []interface{}) bool {
+ if len(value) != len(check) {
return false
}
- if len(filter.EventName) != 0 && ev.EventName != filter.EventName {
+ for i, v := range value {
+ if checkValue(v, check[i]) == false {
return false
}
- if argFilter != nil {
- var args []interface{}
- err := json.Unmarshal([]byte(ev.JsonArgs), &args)
- if err != nil {
+ }
+ return true
+}
+
+func checkSameMap(value map[string]interface{}, check map[string]interface{}) bool {
+ if len(value) != len(check) {
return false
}
- argLen := len(args)
- for _, filter := range argFilter {
- if filter.argNo >= argLen {
- continue
+ for k, v := range value {
+ if checkValue(v, check[k]) == false {
+ return false
}
- value := args[filter.argNo]
- check := filter.value
+ }
+ return true
+}
+
+func checkValue(value interface{}, check interface{}) bool {
if reflect.TypeOf(value) != reflect.TypeOf(check) {
return false
}
@@ -612,9 +617,41 @@ func (ev *Event) Filter(filter *FilterInfo, argFilter []ArgFilter) bool {
return false
}
case nil:
+ return false
+ case []interface{}:
+ return checkSameArray(value.([]interface{}), check.([]interface{}))
+ case map[string]interface{}:
+ return checkSameMap(value.(map[string]interface{}), check.(map[string]interface{}))
default:
return false
}
+
+ return true
+}
+
+func (ev *Event) Filter(filter *FilterInfo, argFilter []ArgFilter) bool {
+ if filter.ContractAddress != nil && !bytes.Equal(ev.ContractAddress, filter.ContractAddress) {
+ return false
+ }
+ if len(filter.EventName) != 0 && ev.EventName != filter.EventName {
+ return false
+ }
+ if argFilter != nil {
+ var args []interface{}
+ err := json.Unmarshal([]byte(ev.JsonArgs), &args)
+ if err != nil {
+ return false
+ }
+ argLen := len(args)
+ for _, filter := range argFilter {
+ if filter.argNo >= argLen {
+ return false
+ }
+ value := args[filter.argNo]
+ check := filter.value
+ if checkValue(value, check) == false {
+ return false
+ }
}
}
ev.ContractAddress = AddressOrigin(ev.ContractAddress)
