diff --git a/go/rpc/encrypted_client.go b/go/rpc/encrypted_client.go index b9f6392b22..7045376d2b 100644 --- a/go/rpc/encrypted_client.go +++ b/go/rpc/encrypted_client.go @@ -120,7 +120,7 @@ func (c *EncRPCClient) Subscribe(ctx context.Context, result interface{}, namesp return nil, fmt.Errorf("expected a channel of type `chan types.Log`, got %T", ch) } clientChannel := make(chan common.IDAndEncLog) - subscription, err := c.obscuroClient.Subscribe(ctx, nil, namespace, clientChannel, subscriptionType, encryptedParams) + subscriptionToObscuro, err := c.obscuroClient.Subscribe(ctx, nil, namespace, clientChannel, subscriptionType, encryptedParams) if err != nil { return nil, err } @@ -128,15 +128,15 @@ func (c *EncRPCClient) Subscribe(ctx context.Context, result interface{}, namesp // We need to return the subscription ID, to allow unsubscribing. However, the client API has already converted // from a subscription ID to a subscription object under the hood, so we can't retrieve the subscription ID. // To hack around this, we always return the subscription ID as the first message on the newly-created subscription. - err = c.setResultToSubID(clientChannel, result, subscription) + err = c.setResultToSubID(clientChannel, result, subscriptionToObscuro) if err != nil { - subscription.Unsubscribe() + subscriptionToObscuro.Unsubscribe() return nil, err } - go c.forwardLogs(clientChannel, logCh, subscription) + go c.forwardLogs(clientChannel, logCh, subscriptionToObscuro) - return subscription, nil + return subscriptionToObscuro, nil } func (c *EncRPCClient) forwardLogs(clientChannel chan common.IDAndEncLog, logCh chan common.IDAndLog, subscription *rpc.ClientSubscription) { @@ -165,18 +165,11 @@ func (c *EncRPCClient) forwardLogs(clientChannel chan common.IDAndEncLog, logCh } case err := <-subscription.Err(): - if c == nil { - panic("c is nill") - } - if c.logger == nil { - panic("c.logger is nill") - } - if subscription == nil { - panic("subscription is nil") + if err != nil { + c.logger.Info("subscription to obscuro node closed with error", log.ErrKey, err) + } else { + c.logger.Info("subscription to obscuro node closed") } - - c.logger.Info("subscription closed", log.ErrKey, err) - return } } diff --git a/tools/walletextension/common/common.go b/tools/walletextension/common/common.go index 8b84a2c4c4..e1055d41df 100644 --- a/tools/walletextension/common/common.go +++ b/tools/walletextension/common/common.go @@ -5,6 +5,7 @@ import ( "encoding/hex" "errors" "fmt" + gethlog "github.com/ethereum/go-ethereum/log" "regexp" gethcommon "github.com/ethereum/go-ethereum/common" @@ -63,7 +64,12 @@ func GetUserIDbyte(userID string) ([]byte, error) { return hex.DecodeString(userID) } -func CreateEncClient(hostRPCBindAddr string, addressBytes []byte, privateKeyBytes []byte, signature []byte) (*rpc.EncRPCClient, error) { +func CreateEncClient( + hostRPCBindAddr string, + addressBytes []byte, + privateKeyBytes []byte, + signature []byte, + logger gethlog.Logger) (*rpc.EncRPCClient, error) { privateKey, err := BytesToPrivateKey(privateKeyBytes) if err != nil { return nil, fmt.Errorf("unable to convert bytes to ecies private key: %w", err) @@ -77,7 +83,7 @@ func CreateEncClient(hostRPCBindAddr string, addressBytes []byte, privateKeyByte PublicKey: PrivateKeyToCompressedPubKey(privateKey), Signature: signature, } - encClient, err := rpc.NewEncNetworkClient(hostRPCBindAddr, vk, nil) + encClient, err := rpc.NewEncNetworkClient(hostRPCBindAddr, vk, logger) if err != nil { return nil, fmt.Errorf("unable to create EncRPCClient: %w", err) } diff --git a/tools/walletextension/container/walletextension_container.go b/tools/walletextension/container/walletextension_container.go index 4c4cdd80b9..335fabcec4 100644 --- a/tools/walletextension/container/walletextension_container.go +++ b/tools/walletextension/container/walletextension_container.go @@ -68,7 +68,7 @@ func NewWalletExtensionContainerFromConfig(config config.Config, logger gethlog. logger.Error(fmt.Errorf("error getting accounts for user: %s, %w", hex.EncodeToString(user.UserID), err).Error()) } for _, account := range accounts { - encClient, err := wecommon.CreateEncClient(hostRPCBindAddr, account.AccountAddress, user.PrivateKey, account.Signature) + encClient, err := wecommon.CreateEncClient(hostRPCBindAddr, account.AccountAddress, user.PrivateKey, account.Signature, logger) if err != nil { logger.Error(fmt.Errorf("error creating new client, %w", err).Error()) } diff --git a/tools/walletextension/storage/database/mariadb.go b/tools/walletextension/storage/database/mariadb.go index 5d33b9a4ee..bc36da789f 100644 --- a/tools/walletextension/storage/database/mariadb.go +++ b/tools/walletextension/storage/database/mariadb.go @@ -74,11 +74,10 @@ func (m *MariaDB) AddAccount(userID []byte, accountAddress []byte, signature []b } defer stmt.Close() - res, err := stmt.Exec(userID, accountAddress, signature) + _, err = stmt.Exec(userID, accountAddress, signature) if err != nil { return err } - fmt.Println(res) return nil } diff --git a/tools/walletextension/wallet_extension.go b/tools/walletextension/wallet_extension.go index 08d1d612ac..87b30635a3 100644 --- a/tools/walletextension/wallet_extension.go +++ b/tools/walletextension/wallet_extension.go @@ -244,7 +244,7 @@ func (w *WalletExtension) AddAddressToUser(hexUserID string, message string, sig accManager := w.userAccountManager.AddAndReturnAccountManager(hexUserID) - encClient, err := common.CreateEncClient(w.hostAddr, addressFromMessage.Bytes(), privateKeyBytes, signature) + encClient, err := common.CreateEncClient(w.hostAddr, addressFromMessage.Bytes(), privateKeyBytes, signature, w.Logger()) if err != nil { w.Logger().Error(fmt.Errorf("error creating encrypted client for user: (%s), %w", hexUserID, err).Error()) }