diff --git a/internal/server/ship_processor.go b/internal/server/ship_processor.go index 38ef73f..7106f4f 100644 --- a/internal/server/ship_processor.go +++ b/internal/server/ship_processor.go @@ -153,7 +153,7 @@ func (processor *ShipProcessor) proccessActionTrace(logger *log.Entry, trace *sh } // Check blacklist if we should skip this action - if processor.blacklist.Lookup(trace.Act.Account.String(), trace.Act.Name.String()) { + if !processor.blacklist.IsAllowed(trace.Act.Account.String(), trace.Act.Name.String()) { logger.WithFields(log.Fields{ "contract": trace.Act.Account, "action": trace.Act.Name, diff --git a/internal/types/blacklist.go b/internal/types/blacklist.go index cbe28b5..2b0812f 100644 --- a/internal/types/blacklist.go +++ b/internal/types/blacklist.go @@ -9,13 +9,17 @@ func (bl Blacklist) Add(contract string, action string) { bl[contract] = append(bl[contract], action) } -func (bl Blacklist) Lookup(contract string, action string) bool { +func (bl Blacklist) IsAllowed(contract string, action string) bool { if v, ok := bl[contract]; ok { for _, act := range v { if act == action || act == "*" { - return true + return false } } } - return false + return true +} + +func (bl Blacklist) IsDenied(contract string, action string) bool { + return bl.IsAllowed(contract, action) } diff --git a/internal/types/blacklist_test.go b/internal/types/blacklist_test.go index a897802..f156e78 100644 --- a/internal/types/blacklist_test.go +++ b/internal/types/blacklist_test.go @@ -20,24 +20,24 @@ func TestBlacklist_Add(t *testing.T) { require.Equal(t, expected, bl) } -func TestBlacklist_Lookup(t *testing.T) { +func TestBlacklist_IsAllowed(t *testing.T) { bl := Blacklist{ "mycontract": {"myaction", "noop"}, } - require.True(t, bl.Lookup("mycontract", "myaction")) - require.True(t, bl.Lookup("mycontract", "noop")) - require.False(t, bl.Lookup("mycontract", "xxx")) - require.False(t, bl.Lookup("xxx", "yyy")) + require.False(t, bl.IsAllowed("mycontract", "myaction")) + require.False(t, bl.IsAllowed("mycontract", "noop")) + require.True(t, bl.IsAllowed("mycontract", "xxx")) + require.True(t, bl.IsAllowed("xxx", "yyy")) } -func TestBlacklist_LookupWildcard(t *testing.T) { +func TestBlacklist_IsAllowedWildcard(t *testing.T) { bl := Blacklist{ "mycontract": {"*"}, } - require.True(t, bl.Lookup("mycontract", "myaction")) - require.True(t, bl.Lookup("mycontract", "noop")) - require.True(t, bl.Lookup("mycontract", "xxx")) - require.False(t, bl.Lookup("xxx", "yyy")) + require.False(t, bl.IsAllowed("mycontract", "myaction")) + require.False(t, bl.IsAllowed("mycontract", "noop")) + require.False(t, bl.IsAllowed("mycontract", "xxx")) + require.True(t, bl.IsAllowed("xxx", "yyy")) }