Skip to content
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

Merged
merged 4 commits into from
Jul 4, 2024
Merged

Conversation

iulianpascalau
Copy link
Contributor

  • added SC module implementation

@iulianpascalau iulianpascalau marked this pull request as ready for review July 3, 2024 17:44
@iulianpascalau iulianpascalau self-assigned this Jul 3, 2024
@iulianpascalau iulianpascalau marked this pull request as draft July 3, 2024 17:44
@iulianpascalau iulianpascalau changed the title [WIP]Added SC module implementation Added SC module implementation Jul 3, 2024
@iulianpascalau iulianpascalau marked this pull request as ready for review July 3, 2024 18:14
ODY5Yzk4ZGYwYjExZmRhMDgwNGQ3ODM1NGVjYTQzMWY4N2E2ZTkxMGZhZTE0MDgx
ZjczOGMzMTZhMjVlYTQwOTFlOGE4YjZiNDlkZTViN2JlMTBhYWExNThhNWE2YTRh
YmI0YjU2Y2MwOGY1MjRiYjVlNmNkNWYyMTFhZDNlMTM=
-----END PRIVATE KEY for erd1r69gk66fmedhhcg24g2c5kn2f2a5k4kvpr6jfw67dn2lyydd8cfswy6ede-----
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing new line

Copy link
Contributor Author

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()
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very good point, changed

Comment on lines 123 to 174
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
}
Copy link
Contributor

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
}

Copy link
Contributor Author

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

@dragos-rebegea dragos-rebegea merged commit 09d92ea into feat/v3 Jul 4, 2024
4 checks passed
@dragos-rebegea dragos-rebegea deleted the sc-calls-executor-module branch July 4, 2024 07:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants