-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added SC module implementation #306
Conversation
iulianpascalau
commented
Jul 3, 2024
- added SC module implementation
ODY5Yzk4ZGYwYjExZmRhMDgwNGQ3ODM1NGVjYTQzMWY4N2E2ZTkxMGZhZTE0MDgx | ||
ZjczOGMzMTZhMjVlYTQwOTFlOGE4YjZiNDlkZTViN2JlMTBhYWExNThhNWE2YTRh | ||
YmI0YjU2Y2MwOGY1MjRiYjVlNmNkNWYyMTFhZDNlMTM= | ||
-----END PRIVATE KEY for erd1r69gk66fmedhhcg24g2c5kn2f2a5k4kvpr6jfw67dn2lyydd8cfswy6ede----- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing new line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
// Close closes any components started | ||
func (module *scCallsModule) Close() error { | ||
errNonceTxsHandler := module.nonceTxsHandler.Close() | ||
errPollingHandler := module.pollingHandler.Close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably not a big issue, but shouldn't we close first the pollingHandler, as it uses the nonceTxHandler on Execute?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very good point, changed
func (filter *pendingOperationFilter) checkLists() error { | ||
err := filter.checkEthList(filter.allowedEthAddresses) | ||
if err != nil { | ||
return fmt.Errorf("%w in list AllowedEthAddresses", err) | ||
} | ||
|
||
err = filter.checkEthList(filter.deniedEthAddresses) | ||
if err != nil { | ||
return fmt.Errorf("%w in list DeniedEthAddresses", err) | ||
} | ||
|
||
err = filter.checkMvxList(filter.allowedMvxAddresses) | ||
if err != nil { | ||
return fmt.Errorf("%w in list AllowedMvxAddresses", err) | ||
} | ||
|
||
err = filter.checkMvxList(filter.deniedMvxAddresses) | ||
if err != nil { | ||
return fmt.Errorf("%w in list DeniedMvxAddresses", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (filter *pendingOperationFilter) checkEthList(list []string) error { | ||
for index, item := range list { | ||
if item == wildcardString { | ||
continue | ||
} | ||
|
||
if !strings.HasPrefix(item, ethAddressPrefix) { | ||
return fmt.Errorf("%w (%s) on item at index %d", errMissingEthPrefix, ethAddressPrefix, index) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (filter *pendingOperationFilter) checkMvxList(list []string) error { | ||
for index, item := range list { | ||
if item == wildcardString { | ||
continue | ||
} | ||
|
||
_, err := data.NewAddressFromBech32String(item) | ||
if err != nil { | ||
return fmt.Errorf("%w on item at index %d", err, index) | ||
} | ||
} | ||
|
||
return nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
optional, not a strong opinion, could be reduced to:
func (filter *pendingOperationFilter) checkLists() error {
err := filter.checkList(filter.allowedEthAddresses, isEthItemValid)
if err != nil {
return fmt.Errorf("%w in list AllowedEthAddresses", err)
}
err = filter.checkList(filter.deniedEthAddresses, isEthItemValid)
if err != nil {
return fmt.Errorf("%w in list DeniedEthAddresses", err)
}
err = filter.checkList(filter.allowedMvxAddresses, isMvxItemValid)
if err != nil {
return fmt.Errorf("%w in list AllowedMvxAddresses", err)
}
err = filter.checkList(filter.deniedMvxAddresses, isMvxItemValid)
if err != nil {
return fmt.Errorf("%w in list DeniedMvxAddresses", err)
}
return nil
}
func isMvxItemValid(item string) bool {
_, errNewAddr := data.NewAddressFromBech32String(item)
return errNewAddr == nil
}
func isEthItemValid(item string) bool {
return !strings.HasPrefix(item, ethAddressPrefix)
}
func (filter *pendingOperationFilter) checkList(list []string, isItemValid func(item string) bool) error {
for index, item := range list {
if item == wildcardString {
continue
}
if !isItemValid(item) {
return fmt.Errorf("%w on item at index %d", errInvalidItem, index)
}
}
return nil
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a little bit reticent on using function pointers, but agree with this solution. Changed