Skip to content

Commit

Permalink
rename InboundProcessability as InboundCategory
Browse files Browse the repository at this point in the history
  • Loading branch information
ws4charlie committed Nov 20, 2024
1 parent 5e4e6d7 commit 426547b
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 56 deletions.
23 changes: 11 additions & 12 deletions zetaclient/chains/bitcoin/observer/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ type BTCInboundEvent struct {
TxHash string
}

// Processability returns the processability of the inbound event
func (event *BTCInboundEvent) Processability() clienttypes.InboundProcessability {
// Category returns the category of the inbound event
func (event *BTCInboundEvent) Category() clienttypes.InboundCategory {
// compliance check on sender and receiver addresses
if config.ContainRestrictedAddress(event.FromAddress, event.ToAddress) {
return clienttypes.InboundProcessabilityComplianceViolation
return clienttypes.InboundCategoryRestricted
}

// compliance check on receiver, revert/abort addresses in standard memo
Expand All @@ -63,16 +63,16 @@ func (event *BTCInboundEvent) Processability() clienttypes.InboundProcessability
event.MemoStd.RevertOptions.RevertAddress,
event.MemoStd.RevertOptions.AbortAddress,
) {
return clienttypes.InboundProcessabilityComplianceViolation
return clienttypes.InboundCategoryRestricted
}
}

// donation check
if bytes.Equal(event.MemoBytes, []byte(constant.DonationMessage)) {
return clienttypes.InboundProcessabilityDonation
return clienttypes.InboundCategoryDonation
}

return clienttypes.InboundProcessabilityGood
return clienttypes.InboundCategoryGood
}

// DecodeMemoBytes decodes the contained memo bytes as either standard or legacy memo
Expand Down Expand Up @@ -153,23 +153,22 @@ func ValidateStandardMemo(memoStd memo.InboundMemo, chainID int64) error {

// IsEventProcessable checks if the inbound event is processable
func (ob *Observer) IsEventProcessable(event BTCInboundEvent) bool {
// check if the event is processable
switch result := event.Processability(); result {
case clienttypes.InboundProcessabilityGood:
switch category := event.Category(); category {
case clienttypes.InboundCategoryGood:
return true
case clienttypes.InboundProcessabilityDonation:
case clienttypes.InboundCategoryDonation:
logFields := map[string]any{
logs.FieldChain: ob.Chain().ChainId,
logs.FieldTx: event.TxHash,
}
ob.Logger().Inbound.Info().Fields(logFields).Msgf("thank you rich folk for your donation!")
return false
case clienttypes.InboundProcessabilityComplianceViolation:
case clienttypes.InboundCategoryRestricted:
compliance.PrintComplianceLog(ob.logger.Inbound, ob.logger.Compliance,
false, ob.Chain().ChainId, event.TxHash, event.FromAddress, event.ToAddress, "BTC")
return false
default:
ob.Logger().Inbound.Error().Msgf("unreachable code got InboundProcessability: %v", result)
ob.Logger().Inbound.Error().Msgf("unreachable code got InboundProcessability: %v", category)
return false
}
}
Expand Down
26 changes: 13 additions & 13 deletions zetaclient/chains/bitcoin/observer/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func createTestBtcEvent(
}
}

func Test_Processability(t *testing.T) {
func Test_Category(t *testing.T) {
// setup compliance config
cfg := config.Config{
ComplianceConfig: sample.ComplianceConfig(),
Expand All @@ -53,26 +53,26 @@ func Test_Processability(t *testing.T) {
tests := []struct {
name string
event *observer.BTCInboundEvent
expected clienttypes.InboundProcessability
expected clienttypes.InboundCategory
}{
{
name: "should return InboundProcessabilityGood for a processable inbound event",
name: "should return InboundCategoryGood for a processable inbound event",
event: &observer.BTCInboundEvent{
FromAddress: "tb1quhassyrlj43qar0mn0k5sufyp6mazmh2q85lr6ex8ehqfhxpzsksllwrsu",
ToAddress: testutils.TSSAddressBTCAthens3,
},
expected: clienttypes.InboundProcessabilityGood,
expected: clienttypes.InboundCategoryGood,
},
{
name: "should return InboundProcessabilityComplianceViolation for a restricted sender address",
name: "should return InboundCategoryRestricted for a restricted sender address",
event: &observer.BTCInboundEvent{
FromAddress: sample.RestrictedBtcAddressTest,
ToAddress: testutils.TSSAddressBTCAthens3,
},
expected: clienttypes.InboundProcessabilityComplianceViolation,
expected: clienttypes.InboundCategoryRestricted,
},
{
name: "should return InboundProcessabilityComplianceViolation for a restricted receiver address in standard memo",
name: "should return InboundCategoryRestricted for a restricted receiver address in standard memo",
event: &observer.BTCInboundEvent{
FromAddress: "tb1quhassyrlj43qar0mn0k5sufyp6mazmh2q85lr6ex8ehqfhxpzsksllwrsu",
ToAddress: testutils.TSSAddressBTCAthens3,
Expand All @@ -82,10 +82,10 @@ func Test_Processability(t *testing.T) {
},
},
},
expected: clienttypes.InboundProcessabilityComplianceViolation,
expected: clienttypes.InboundCategoryRestricted,
},
{
name: "should return InboundProcessabilityComplianceViolation for a restricted revert address in standard memo",
name: "should return InboundCategoryRestricted for a restricted revert address in standard memo",
event: &observer.BTCInboundEvent{
FromAddress: "tb1quhassyrlj43qar0mn0k5sufyp6mazmh2q85lr6ex8ehqfhxpzsksllwrsu",
ToAddress: testutils.TSSAddressBTCAthens3,
Expand All @@ -97,22 +97,22 @@ func Test_Processability(t *testing.T) {
},
},
},
expected: clienttypes.InboundProcessabilityComplianceViolation,
expected: clienttypes.InboundCategoryRestricted,
},
{
name: "should return InboundProcessabilityDonation for a donation inbound event",
name: "should return InboundCategoryDonation for a donation inbound event",
event: &observer.BTCInboundEvent{
FromAddress: "tb1quhassyrlj43qar0mn0k5sufyp6mazmh2q85lr6ex8ehqfhxpzsksllwrsu",
ToAddress: testutils.TSSAddressBTCAthens3,
MemoBytes: []byte(constant.DonationMessage),
},
expected: clienttypes.InboundProcessabilityDonation,
expected: clienttypes.InboundCategoryDonation,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := tt.event.Processability()
result := tt.event.Category()
require.Equal(t, tt.expected, result)
})
}
Expand Down
10 changes: 5 additions & 5 deletions zetaclient/chains/solana/observer/inbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,22 +307,22 @@ func (ob *Observer) BuildInboundVoteMsgFromEvent(event *clienttypes.InboundEvent

// IsEventProcessable checks if the inbound event is processable
func (ob *Observer) IsEventProcessable(event clienttypes.InboundEvent) bool {
switch result := event.Processability(); result {
case clienttypes.InboundProcessabilityGood:
switch category := event.Category(); category {
case clienttypes.InboundCategoryGood:
return true
case clienttypes.InboundProcessabilityDonation:
case clienttypes.InboundCategoryDonation:
logFields := map[string]any{
logs.FieldChain: ob.Chain().ChainId,
logs.FieldTx: event.TxHash,
}
ob.Logger().Inbound.Info().Fields(logFields).Msgf("thank you rich folk for your donation!")
return false
case clienttypes.InboundProcessabilityComplianceViolation:
case clienttypes.InboundCategoryRestricted:
compliance.PrintComplianceLog(ob.Logger().Inbound, ob.Logger().Compliance,
false, ob.Chain().ChainId, event.TxHash, event.Sender, event.Receiver, event.CoinType.String())
return false
default:
ob.Logger().Inbound.Error().Msgf("unreachable code got InboundProcessability: %v", result)
ob.Logger().Inbound.Error().Msgf("unreachable code got InboundProcessability: %v", category)
return false
}
}
26 changes: 13 additions & 13 deletions zetaclient/types/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ import (
"github.com/zeta-chain/node/zetaclient/config"
)

// InboundProcessability is an enum representing the processability of an inbound
type InboundProcessability int
// InboundCategory is an enum representing the category of an inbound event
type InboundCategory int

const (
// InboundProcessabilityGood represents a processable inbound
InboundProcessabilityGood InboundProcessability = iota
// InboundCategoryGood represents a processable inbound
InboundCategoryGood InboundCategory = iota

// InboundProcessabilityDonation represents a donation inbound
InboundProcessabilityDonation
// InboundCategoryDonation represents a donation inbound
InboundCategoryDonation

// InboundProcessabilityComplianceViolation represents a compliance violation
InboundProcessabilityComplianceViolation
// InboundCategoryRestricted represents a restricted inbound
InboundCategoryRestricted
)

// InboundEvent represents an inbound event
Expand Down Expand Up @@ -88,8 +88,8 @@ func (event *InboundEvent) DecodeMemo() error {
return nil
}

// Processability returns the processability of the inbound event
func (event *InboundEvent) Processability() InboundProcessability {
// Category returns the category of the inbound event
func (event *InboundEvent) Category() InboundCategory {
// parse memo-specified receiver
receiver := ""
parsedAddress, _, err := memo.DecodeLegacyMemoHex(hex.EncodeToString(event.Memo))
Expand All @@ -99,13 +99,13 @@ func (event *InboundEvent) Processability() InboundProcessability {

// check restricted addresses
if config.ContainRestrictedAddress(event.Sender, event.Receiver, event.TxOrigin, receiver) {
return InboundProcessabilityComplianceViolation
return InboundCategoryRestricted
}

// donation check
if bytes.Equal(event.Memo, []byte(constant.DonationMessage)) {
return InboundProcessabilityDonation
return InboundCategoryDonation
}

return InboundProcessabilityGood
return InboundCategoryGood
}
26 changes: 13 additions & 13 deletions zetaclient/types/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func Test_DecodeMemo(t *testing.T) {
}
}

func Test_Processability(t *testing.T) {
func Test_Catetory(t *testing.T) {
// setup compliance config
cfg := config.Config{
ComplianceConfig: sample.ComplianceConfig(),
Expand All @@ -69,55 +69,55 @@ func Test_Processability(t *testing.T) {
tests := []struct {
name string
event *types.InboundEvent
expected types.InboundProcessability
expected types.InboundCategory
}{
{
name: "should return InboundProcessabilityGood for a processable inbound event",
name: "should return InboundCategoryGood for a processable inbound event",
event: &types.InboundEvent{
Sender: sample.SolanaAddress(t),
Receiver: sample.EthAddress().Hex(),
},
expected: types.InboundProcessabilityGood,
expected: types.InboundCategoryGood,
},
{
name: "should return InboundProcessabilityComplianceViolation for a restricted sender address",
name: "should return InboundCategoryRestricted for a restricted sender address",
event: &types.InboundEvent{
Sender: sample.RestrictedSolAddressTest,
Receiver: sample.EthAddress().Hex(),
},
expected: types.InboundProcessabilityComplianceViolation,
expected: types.InboundCategoryRestricted,
},
{
name: "should return InboundProcessabilityComplianceViolation for a restricted receiver address",
name: "should return InboundCategoryRestricted for a restricted receiver address",
event: &types.InboundEvent{
Sender: sample.SolanaAddress(t),
Receiver: sample.RestrictedSolAddressTest,
},
expected: types.InboundProcessabilityComplianceViolation,
expected: types.InboundCategoryRestricted,
},
{
name: "should return InboundProcessabilityComplianceViolation for a restricted receiver address in memo",
name: "should return InboundCategoryRestricted for a restricted receiver address in memo",
event: &types.InboundEvent{
Sender: sample.SolanaAddress(t),
Receiver: sample.EthAddress().Hex(),
Memo: ethcommon.HexToAddress(sample.RestrictedEVMAddressTest).Bytes(),
},
expected: types.InboundProcessabilityComplianceViolation,
expected: types.InboundCategoryRestricted,
},
{
name: "should return InboundProcessabilityDonation for a donation inbound event",
name: "should return InboundCategoryDonation for a donation inbound event",
event: &types.InboundEvent{
Sender: sample.SolanaAddress(t),
Receiver: sample.EthAddress().Hex(),
Memo: []byte(constant.DonationMessage),
},
expected: types.InboundProcessabilityDonation,
expected: types.InboundCategoryDonation,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := tt.event.Processability()
result := tt.event.Category()
require.Equal(t, tt.expected, result)
})
}
Expand Down

0 comments on commit 426547b

Please sign in to comment.