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

Abstract Method Dependency on #2371

Open
coderabbitai bot opened this issue Mar 27, 2024 · 1 comment
Open

Abstract Method Dependency on #2371

coderabbitai bot opened this issue Mar 27, 2024 · 1 comment

Comments

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 27, 2024

The addition of the method in introduces a tight coupling to , which may not be appropriate for all signers. This issue was raised during the review of PR #2234 (#2234 (comment)). Consider abstracting this functionality into a more generic interface or providing a mechanism to access private keys that doesn't tightly couple to .

@trajan0x trajan0x added the small label Jun 24, 2024
@trajan0x trajan0x reopened this Jun 24, 2024
@trajan0x trajan0x removed the small label Jun 24, 2024
Copy link

greptile-apps bot commented Jun 24, 2024

To address the tight coupling introduced by the method in PR #2234, follow these steps:

  1. Define a Generic Interface: Create a new interface in /ethergo/signer/signer that abstracts the signing functionality.
// signer.go
package signer

type Signer interface {
    SignTransaction(tx *Transaction) ([]byte, error)
    GetPublicKey() ([]byte, error)
}
  1. Implement the Interface in Existing Signers: Modify AwsSigner, GcpSigner, and LocalSigner to implement the new Signer interface.
// awssigner.go
package awssigner

import "path/to/signer"

type AwsSigner struct {
    // existing fields
}

func (a *AwsSigner) SignTransaction(tx *Transaction) ([]byte, error) {
    // existing implementation
}

func (a *AwsSigner) GetPublicKey() ([]byte, error) {
    // existing implementation
}
  1. Refactor Dependency Injection: Update the codebase to use the new Signer interface instead of concrete implementations.
// usage_example.go
package main

import "path/to/signer"

func ProcessTransaction(s signer.Signer, tx *Transaction) error {
    signedTx, err := s.SignTransaction(tx)
    if err != nil {
        return err
    }
    // further processing
    return nil
}

This approach abstracts the signing functionality and reduces tight coupling to specific signer implementations.

References

/ethergo/signer/signer/README.md
/ethergo/signer/signer/awssigner
/ethergo/signer/wallet

Ask Greptile

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

No branches or pull requests

1 participant