plugin_api.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. package core
  2. import (
  3. "context"
  4. "errors"
  5. "github.com/ethereum/go-ethereum/accounts"
  6. "github.com/ethereum/go-ethereum/plugin/account"
  7. )
  8. // <Quorum>
  9. type approvalCreatorService struct {
  10. creator account.CreatorService
  11. ui UIClientAPI
  12. }
  13. // NewApprovalCreatorService adds a wrapper to the provided creator service which requires UI approval before executing the service's methods
  14. func NewApprovalCreatorService(creator account.CreatorService, ui UIClientAPI) account.CreatorService {
  15. return &approvalCreatorService{
  16. creator: creator,
  17. ui: ui,
  18. }
  19. }
  20. func (s *approvalCreatorService) NewAccount(ctx context.Context, newAccountConfig interface{}) (accounts.Account, error) {
  21. if resp, err := s.ui.ApproveNewAccount(&NewAccountRequest{MetadataFromContext(ctx)}); err != nil {
  22. return accounts.Account{}, err
  23. } else if !resp.Approved {
  24. return accounts.Account{}, ErrRequestDenied
  25. }
  26. return s.creator.NewAccount(ctx, newAccountConfig)
  27. }
  28. // ImportRawKey is unsupported in the clef external API for parity with the available keystore account functionality
  29. func (s *approvalCreatorService) ImportRawKey(_ context.Context, _ string, _ interface{}) (accounts.Account, error) {
  30. return accounts.Account{}, errors.New("not supported")
  31. }