diff --git a/example/dapp/lib/main.dart b/example/dapp/lib/main.dart index 3d3a7b1e..68c68cc3 100644 --- a/example/dapp/lib/main.dart +++ b/example/dapp/lib/main.dart @@ -61,7 +61,7 @@ class _MyHomePageState extends State { debugPrint('Project ID: ${DartDefines.projectId}'); _web3App = await Web3App.createInstance( projectId: DartDefines.projectId, - logLevel: LogLevel.info, + logLevel: LogLevel.debug, metadata: const PairingMetadata( name: 'Sample dApp Flutter', description: 'WalletConnect\'s sample dapp with Flutter', diff --git a/example/wallet/lib/dependencies/web3wallet_service.dart b/example/wallet/lib/dependencies/web3wallet_service.dart index 2a7c897a..9047c620 100644 --- a/example/wallet/lib/dependencies/web3wallet_service.dart +++ b/example/wallet/lib/dependencies/web3wallet_service.dart @@ -40,7 +40,7 @@ class Web3WalletService extends IWeb3WalletService { _web3Wallet = Web3Wallet( core: Core( projectId: DartDefines.projectId, - logLevel: LogLevel.error, + logLevel: LogLevel.debug, ), metadata: const PairingMetadata( name: 'Sample Wallet Flutter', diff --git a/lib/apis/auth_api/auth_engine.dart b/lib/apis/auth_api/auth_engine.dart index c9eba970..0d4cad38 100644 --- a/lib/apis/auth_api/auth_engine.dart +++ b/lib/apis/auth_api/auth_engine.dart @@ -431,7 +431,7 @@ class AuthEngine implements IAuthEngine { payload.id, topic, payload.method, - JsonRpcError.invalidParams( + JsonRpcError.invalidRequest( err.message, ), ); diff --git a/lib/apis/core/core.dart b/lib/apis/core/core.dart index 13766119..7b9dab92 100644 --- a/lib/apis/core/core.dart +++ b/lib/apis/core/core.dart @@ -1,3 +1,4 @@ +import 'package:flutter/foundation.dart'; import 'package:logger/logger.dart'; import 'package:walletconnect_flutter_v2/apis/core/crypto/crypto.dart'; import 'package:walletconnect_flutter_v2/apis/core/crypto/i_crypto.dart'; @@ -75,6 +76,8 @@ class Core implements ICore { @override late IStore> storage; + void _logListener(LogEvent event) => debugPrint('${event.message}'); + Core({ required this.projectId, this.relayUrl = WalletConnectConstants.DEFAULT_RELAY_URL, @@ -88,6 +91,12 @@ class Core implements ICore { level: logLevel.toLevel(), printer: PrettyPrinter(), ); + try { + Logger.removeLogListener(_logListener); + } catch (_) {} + if (kDebugMode && logLevel == LogLevel.debug) { + Logger.addLogListener(_logListener); + } heartbeat = HeartBeat(); storage = SharedPrefsStores( memoryStore: memoryStore, diff --git a/lib/apis/core/relay_client/json_rpc_2/error_code.dart b/lib/apis/core/relay_client/json_rpc_2/error_code.dart index 14e0543d..a3447d5e 100644 --- a/lib/apis/core/relay_client/json_rpc_2/error_code.dart +++ b/lib/apis/core/relay_client/json_rpc_2/error_code.dart @@ -12,7 +12,7 @@ /// /// [spec]: http://www.jsonrpc.org/specification#error_object /// An error code indicating that invalid JSON was received by the server. -const PARSE_ERROR = -32700; +// const PARSE_ERROR = -32700; /// An error code indicating that the request JSON was invalid according to the /// JSON-RPC 2.0 spec. @@ -24,7 +24,7 @@ const METHOD_NOT_FOUND = -32601; /// An error code indicating that the request parameters are invalid for the /// requested method. -const INVALID_PARAMS = -32602; +// const INVALID_PARAMS = -32602; /// An internal JSON-RPC error. const INTERNAL_ERROR = -32603; @@ -41,14 +41,14 @@ const SERVER_ERROR = -32000; /// If [errorCode] isn't defined in the JSON-RPC 2.0 spec, returns null. String? name(int errorCode) { switch (errorCode) { - case PARSE_ERROR: - return 'parse error'; + // case PARSE_ERROR: + // return 'parse error'; case INVALID_REQUEST: return 'invalid request'; case METHOD_NOT_FOUND: return 'method not found'; - case INVALID_PARAMS: - return 'invalid parameters'; + // case INVALID_PARAMS: + // return 'invalid parameters'; case INTERNAL_ERROR: return 'internal error'; default: diff --git a/lib/apis/core/relay_client/json_rpc_2/src/exception.dart b/lib/apis/core/relay_client/json_rpc_2/src/exception.dart index ad39ff23..952d214e 100644 --- a/lib/apis/core/relay_client/json_rpc_2/src/exception.dart +++ b/lib/apis/core/relay_client/json_rpc_2/src/exception.dart @@ -39,7 +39,7 @@ class RpcException implements Exception { /// /// Methods can use this to reject requests with invalid parameters. RpcException.invalidParams(String message) - : this(error_code.INVALID_PARAMS, message); + : this(error_code.INVALID_REQUEST, message); /// Converts this exception into a JSON-serializable object that's a valid /// JSON-RPC 2.0 error response. diff --git a/lib/apis/core/relay_client/json_rpc_2/src/utils.dart b/lib/apis/core/relay_client/json_rpc_2/src/utils.dart index 305945c4..207d8972 100644 --- a/lib/apis/core/relay_client/json_rpc_2/src/utils.dart +++ b/lib/apis/core/relay_client/json_rpc_2/src/utils.dart @@ -61,8 +61,8 @@ class _RespondToFormatExceptionsTransformer return channel.changeStream((stream) { return stream.handleError((dynamic error) { final formatException = error as FormatException; - var exception = RpcException( - error_code.PARSE_ERROR, 'Invalid JSON: ${formatException.message}'); + var exception = RpcException(error_code.INVALID_REQUEST, + 'Invalid JSON: ${formatException.message}'); channel.sink.add(exception.serialize(formatException.source)); }, test: (error) => error is FormatException); }); diff --git a/lib/apis/models/json_rpc_error.dart b/lib/apis/models/json_rpc_error.dart index af067cf0..3ed7e130 100644 --- a/lib/apis/models/json_rpc_error.dart +++ b/lib/apis/models/json_rpc_error.dart @@ -13,12 +13,12 @@ class JsonRpcError with _$JsonRpcError { factory JsonRpcError.serverError(String message) => JsonRpcError(code: -32000, message: message); - factory JsonRpcError.invalidParams(String message) => - JsonRpcError(code: -32602, message: message); +// factory JsonRpcError.invalidParams(String message) => +// JsonRpcError(code: -32602, message: message); factory JsonRpcError.invalidRequest(String message) => JsonRpcError(code: -32600, message: message); - factory JsonRpcError.parseError(String message) => - JsonRpcError(code: -32700, message: message); +// factory JsonRpcError.parseError(String message) => +// JsonRpcError(code: -32700, message: message); factory JsonRpcError.methodNotFound(String message) => JsonRpcError(code: -32601, message: message); diff --git a/lib/apis/sign_api/sign_engine.dart b/lib/apis/sign_api/sign_engine.dart index 417e2784..c4994d5f 100644 --- a/lib/apis/sign_api/sign_engine.dart +++ b/lib/apis/sign_api/sign_engine.dart @@ -268,7 +268,7 @@ class SignEngine implements ISignEngine { ); // print('approve session topic: $sessionTopic'); final relay = Relay( - relayProtocol ?? 'irn', + relayProtocol ?? WalletConnectConstants.RELAYER_DEFAULT_PROTOCOL, ); // Respond to the proposal @@ -1101,7 +1101,7 @@ class SignEngine implements ISignEngine { payload.id, topic, payload.method, - JsonRpcError.invalidParams( + JsonRpcError.invalidRequest( err.message, ), ); @@ -1139,7 +1139,7 @@ class SignEngine implements ISignEngine { payload.id, topic, payload.method, - JsonRpcError.invalidParams( + JsonRpcError.invalidRequest( err.message, ), ); @@ -1176,7 +1176,7 @@ class SignEngine implements ISignEngine { payload.id, topic, payload.method, - JsonRpcError.invalidParams( + JsonRpcError.invalidRequest( err.message, ), ); @@ -1207,7 +1207,7 @@ class SignEngine implements ISignEngine { payload.id, topic, payload.method, - JsonRpcError.invalidParams( + JsonRpcError.invalidRequest( err.message, ), ); @@ -1233,7 +1233,7 @@ class SignEngine implements ISignEngine { payload.id, topic, payload.method, - JsonRpcError.invalidParams( + JsonRpcError.invalidRequest( err.message, ), ); @@ -1308,7 +1308,7 @@ class SignEngine implements ISignEngine { payload.id, topic, payload.method, - JsonRpcError.invalidParams( + JsonRpcError.invalidRequest( err.toString(), ), ); @@ -1337,7 +1337,7 @@ class SignEngine implements ISignEngine { payload.id, topic, payload.method, - JsonRpcError.invalidParams( + JsonRpcError.invalidRequest( err.message, ), ); @@ -1375,7 +1375,7 @@ class SignEngine implements ISignEngine { payload.id, topic, payload.method, - JsonRpcError.invalidParams( + JsonRpcError.invalidRequest( err.toString(), ), ); @@ -1413,7 +1413,7 @@ class SignEngine implements ISignEngine { payload.id, topic, payload.method, - JsonRpcError.invalidParams( + JsonRpcError.invalidRequest( err.message, ), ); diff --git a/test/sign_api/tests/sign_request_and_handler.dart b/test/sign_api/tests/sign_request_and_handler.dart index 47ddf5ed..c98d7de0 100644 --- a/test/sign_api/tests/sign_request_and_handler.dart +++ b/test/sign_api/tests/sign_request_and_handler.dart @@ -214,7 +214,7 @@ void signRequestAndHandler({ } on JsonRpcError catch (e) { expect( e.code, - JsonRpcError.invalidParams('swag').code, + JsonRpcError.invalidRequest('swag').code, ); } @@ -276,7 +276,7 @@ void signRequestAndHandler({ topic: request.topic, response: JsonRpcResponse( id: request.id, - error: JsonRpcError.invalidParams(request.params.toString()), + error: JsonRpcError.invalidRequest(request.params.toString()), ), ); } @@ -308,7 +308,7 @@ void signRequestAndHandler({ // print(e); expect( e.code, - JsonRpcError.invalidParams('swag').code, + JsonRpcError.invalidRequest('swag').code, ); expect(e.message!.contains(TEST_MESSAGE_1.toString()), true); } @@ -328,7 +328,7 @@ void signRequestAndHandler({ topic: session.topic, response: JsonRpcResponse( id: session.id, - error: JsonRpcError.invalidParams('invalid'), + error: JsonRpcError.invalidRequest('invalid'), ), );