diff --git a/packages/flutter_nekoton_bridge/lib/example_related/caller_wrapper.reflectable.dart b/packages/flutter_nekoton_bridge/lib/example_related/caller_wrapper.reflectable.dart index bb17e825..19992d82 100644 --- a/packages/flutter_nekoton_bridge/lib/example_related/caller_wrapper.reflectable.dart +++ b/packages/flutter_nekoton_bridge/lib/example_related/caller_wrapper.reflectable.dart @@ -141,6 +141,7 @@ final _data = { r'initializeMirror': 2, r'connection': 2, r'connection=': 1, + r'settings': 2, r'type': 2, r'name': 2, r'group': 2, @@ -177,6 +178,7 @@ final _data = { r'initializeMirror': 2, r'connection': 2, r'connection=': 1, + r'settings': 2, r'type': 2, r'name': 2, r'group': 2, @@ -213,6 +215,7 @@ final _data = { r'initializeMirror': 2, r'connection': 2, r'connection=': 1, + r'settings': 2, r'type': 2, r'name': 2, r'group': 2, @@ -538,6 +541,7 @@ final _data = { r'request': (dynamic instance) => instance.request, r'post': (dynamic instance) => instance.post, r'connection': (dynamic instance) => instance.connection, + r'settings': (dynamic instance) => instance.settings, r'type': (dynamic instance) => instance.type, r'name': (dynamic instance) => instance.name, r'group': (dynamic instance) => instance.group, diff --git a/packages/flutter_nekoton_bridge/lib/nekoton/core/generic_contract/generic_contract.reflectable.dart b/packages/flutter_nekoton_bridge/lib/nekoton/core/generic_contract/generic_contract.reflectable.dart index 374354b6..12649f45 100644 --- a/packages/flutter_nekoton_bridge/lib/nekoton/core/generic_contract/generic_contract.reflectable.dart +++ b/packages/flutter_nekoton_bridge/lib/nekoton/core/generic_contract/generic_contract.reflectable.dart @@ -198,6 +198,7 @@ final _data = { r'initializeMirror': 0, r'connection': 0, r'connection=': 4, + r'settings': 0, r'type': 0, r'name': 0, r'group': 0, @@ -234,6 +235,7 @@ final _data = { r'initializeMirror': 0, r'connection': 0, r'connection=': 4, + r'settings': 0, r'type': 0, r'name': 0, r'group': 0, @@ -270,6 +272,7 @@ final _data = { r'initializeMirror': 0, r'connection': 0, r'connection=': 4, + r'settings': 0, r'type': 0, r'name': 0, r'group': 0, @@ -574,6 +577,7 @@ final _data = { r'test1': (dynamic instance) => instance.test1, r'post': (dynamic instance) => instance.post, r'connection': (dynamic instance) => instance.connection, + r'settings': (dynamic instance) => instance.settings, r'type': (dynamic instance) => instance.type, r'name': (dynamic instance) => instance.name, r'group': (dynamic instance) => instance.group, diff --git a/packages/flutter_nekoton_bridge/lib/nekoton/core/token_wallet/token_wallet.reflectable.dart b/packages/flutter_nekoton_bridge/lib/nekoton/core/token_wallet/token_wallet.reflectable.dart index 470fdd5c..1e39758e 100644 --- a/packages/flutter_nekoton_bridge/lib/nekoton/core/token_wallet/token_wallet.reflectable.dart +++ b/packages/flutter_nekoton_bridge/lib/nekoton/core/token_wallet/token_wallet.reflectable.dart @@ -209,6 +209,7 @@ final _data = { r'initializeMirror': 0, r'connection': 0, r'connection=': 5, + r'settings': 0, r'type': 0, r'name': 0, r'group': 0, @@ -245,6 +246,7 @@ final _data = { r'initializeMirror': 0, r'connection': 0, r'connection=': 5, + r'settings': 0, r'type': 0, r'name': 0, r'group': 0, @@ -281,6 +283,7 @@ final _data = { r'initializeMirror': 0, r'connection': 0, r'connection=': 5, + r'settings': 0, r'type': 0, r'name': 0, r'group': 0, @@ -568,6 +571,7 @@ final _data = { r'test1': (dynamic instance) => instance.test1, r'post': (dynamic instance) => instance.post, r'connection': (dynamic instance) => instance.connection, + r'settings': (dynamic instance) => instance.settings, r'type': (dynamic instance) => instance.type, r'name': (dynamic instance) => instance.name, r'group': (dynamic instance) => instance.group, diff --git a/packages/flutter_nekoton_bridge/lib/nekoton/core/ton_wallet/ton_wallet.reflectable.dart b/packages/flutter_nekoton_bridge/lib/nekoton/core/ton_wallet/ton_wallet.reflectable.dart index 67c6586a..bce9e5d8 100644 --- a/packages/flutter_nekoton_bridge/lib/nekoton/core/ton_wallet/ton_wallet.reflectable.dart +++ b/packages/flutter_nekoton_bridge/lib/nekoton/core/ton_wallet/ton_wallet.reflectable.dart @@ -229,6 +229,7 @@ final _data = { r'initializeMirror': 0, r'connection': 0, r'connection=': 11, + r'settings': 0, r'type': 0, r'name': 0, r'group': 0, @@ -265,6 +266,7 @@ final _data = { r'initializeMirror': 0, r'connection': 0, r'connection=': 11, + r'settings': 0, r'type': 0, r'name': 0, r'group': 0, @@ -301,6 +303,7 @@ final _data = { r'initializeMirror': 0, r'connection': 0, r'connection=': 11, + r'settings': 0, r'type': 0, r'name': 0, r'group': 0, @@ -587,6 +590,7 @@ final _data = { r'test1': (dynamic instance) => instance.test1, r'post': (dynamic instance) => instance.post, r'connection': (dynamic instance) => instance.connection, + r'settings': (dynamic instance) => instance.settings, r'type': (dynamic instance) => instance.type, r'name': (dynamic instance) => instance.name, r'group': (dynamic instance) => instance.group, diff --git a/packages/flutter_nekoton_bridge/lib/nekoton/external/gql_connection.dart b/packages/flutter_nekoton_bridge/lib/nekoton/external/gql_connection.dart index 1a0102e7..898037df 100644 --- a/packages/flutter_nekoton_bridge/lib/nekoton/external/gql_connection.dart +++ b/packages/flutter_nekoton_bridge/lib/nekoton/external/gql_connection.dart @@ -24,7 +24,7 @@ class GqlConnection extends RustToDartMirrorInterface { final String _name; final String _group; - final GqlNetworkSettings _settings; + final GqlNetworkSettings settings; final type = TransportType.gql; @@ -33,7 +33,7 @@ class GqlConnection extends RustToDartMirrorInterface { GqlConnection._( this._post, this._get, - this._settings, + this.settings, this._name, this._group, ); @@ -65,8 +65,8 @@ class GqlConnection extends RustToDartMirrorInterface { try { String endpoint; - if (_settings.endpoints.length == 1) { - endpoint = _settings.endpoints.first; + if (settings.endpoints.length == 1) { + endpoint = settings.endpoints.first; } else { endpoint = await _getEndpoint(); } @@ -87,16 +87,16 @@ class GqlConnection extends RustToDartMirrorInterface { if (_cachedEndpoint != null) return _cachedEndpoint!; _cachedEndpoint = await _selectQueryingEndpoint().timeout( - Duration(milliseconds: _settings.latencyDetectionInterval), + Duration(milliseconds: settings.latencyDetectionInterval), onTimeout: () => throw ErrorCode.Network, ); return _cachedEndpoint!; } Future _selectQueryingEndpoint() async { - final maxLatency = _settings.maxLatency; - final retryCount = _settings.endpointSelectionRetryCount; - final endpointsCount = _settings.endpoints.length; + final maxLatency = settings.maxLatency; + final retryCount = settings.endpointSelectionRetryCount; + final endpointsCount = settings.endpoints.length; for (var i = 0; i < retryCount; i++) { try { @@ -104,7 +104,7 @@ class GqlConnection extends RustToDartMirrorInterface { var checkedEndpoints = 0; - for (final e in _settings.endpoints) { + for (final e in settings.endpoints) { _checkLatency(e).whenComplete(() { checkedEndpoints++; }).then((v) { diff --git a/packages/flutter_nekoton_bridge/lib/nekoton/external/gql_connection.reflectable.dart b/packages/flutter_nekoton_bridge/lib/nekoton/external/gql_connection.reflectable.dart index 2a820d67..5be132af 100644 --- a/packages/flutter_nekoton_bridge/lib/nekoton/external/gql_connection.reflectable.dart +++ b/packages/flutter_nekoton_bridge/lib/nekoton/external/gql_connection.reflectable.dart @@ -70,6 +70,7 @@ final _data = { r'initializeMirror': 0, r'connection': 0, r'connection=': 1, + r'settings': 0, r'type': 0, r'name': 0, r'group': 0, @@ -177,6 +178,7 @@ final _data = { r'initializeMirror': 0, r'connection': 0, r'connection=': 1, + r'settings': 0, r'type': 0, r'name': 0, r'group': 0, @@ -213,6 +215,7 @@ final _data = { r'initializeMirror': 0, r'connection': 0, r'connection=': 1, + r'settings': 0, r'type': 0, r'name': 0, r'group': 0, @@ -531,6 +534,7 @@ final _data = { r'post': (dynamic instance) => instance.post, r'initializeMirror': (dynamic instance) => instance.initializeMirror, r'connection': (dynamic instance) => instance.connection, + r'settings': (dynamic instance) => instance.settings, r'type': (dynamic instance) => instance.type, r'name': (dynamic instance) => instance.name, r'group': (dynamic instance) => instance.group, diff --git a/packages/flutter_nekoton_bridge/lib/nekoton/external/jrpc_connection.dart b/packages/flutter_nekoton_bridge/lib/nekoton/external/jrpc_connection.dart index 3105d875..bd9b564a 100644 --- a/packages/flutter_nekoton_bridge/lib/nekoton/external/jrpc_connection.dart +++ b/packages/flutter_nekoton_bridge/lib/nekoton/external/jrpc_connection.dart @@ -18,13 +18,13 @@ class JrpcConnection extends RustToDartMirrorInterface { final String _name; final String _group; - final JrpcNetworkSettings _settings; + final JrpcNetworkSettings settings; final type = TransportType.gql; JrpcConnection._( this._post, - this._settings, + this.settings, this._name, this._group, ); @@ -53,7 +53,7 @@ class JrpcConnection extends RustToDartMirrorInterface { Future post(String requestData) async { try { return await _post( - endpoint: _settings.endpoint, + endpoint: settings.endpoint, headers: { 'Content-Type': 'application/json', }, diff --git a/packages/flutter_nekoton_bridge/lib/nekoton/external/jrpc_connection.reflectable.dart b/packages/flutter_nekoton_bridge/lib/nekoton/external/jrpc_connection.reflectable.dart index 23a99c14..91da14e1 100644 --- a/packages/flutter_nekoton_bridge/lib/nekoton/external/jrpc_connection.reflectable.dart +++ b/packages/flutter_nekoton_bridge/lib/nekoton/external/jrpc_connection.reflectable.dart @@ -70,6 +70,7 @@ final _data = { r'initializeMirror': 0, r'connection': 0, r'connection=': 1, + r'settings': 0, r'type': 0, r'name': 0, r'group': 0, @@ -177,6 +178,7 @@ final _data = { r'initializeMirror': 0, r'connection': 0, r'connection=': 1, + r'settings': 0, r'type': 0, r'name': 0, r'group': 0, @@ -213,6 +215,7 @@ final _data = { r'initializeMirror': 0, r'connection': 0, r'connection=': 1, + r'settings': 0, r'type': 0, r'name': 0, r'group': 0, @@ -531,6 +534,7 @@ final _data = { r'post': (dynamic instance) => instance.post, r'initializeMirror': (dynamic instance) => instance.initializeMirror, r'connection': (dynamic instance) => instance.connection, + r'settings': (dynamic instance) => instance.settings, r'type': (dynamic instance) => instance.type, r'name': (dynamic instance) => instance.name, r'group': (dynamic instance) => instance.group, diff --git a/packages/flutter_nekoton_bridge/lib/nekoton/external/ledger_connection.reflectable.dart b/packages/flutter_nekoton_bridge/lib/nekoton/external/ledger_connection.reflectable.dart index 553c37a0..e6e35884 100644 --- a/packages/flutter_nekoton_bridge/lib/nekoton/external/ledger_connection.reflectable.dart +++ b/packages/flutter_nekoton_bridge/lib/nekoton/external/ledger_connection.reflectable.dart @@ -174,6 +174,7 @@ final _data = { r'initializeMirror': 0, r'connection': 0, r'connection=': 1, + r'settings': 0, r'type': 0, r'name': 0, r'group': 0, @@ -210,6 +211,7 @@ final _data = { r'initializeMirror': 0, r'connection': 0, r'connection=': 1, + r'settings': 0, r'type': 0, r'name': 0, r'group': 0, @@ -246,6 +248,7 @@ final _data = { r'initializeMirror': 0, r'connection': 0, r'connection=': 1, + r'settings': 0, r'type': 0, r'name': 0, r'group': 0, @@ -539,6 +542,7 @@ final _data = { r'test0': (dynamic instance) => instance.test0, r'test1': (dynamic instance) => instance.test1, r'post': (dynamic instance) => instance.post, + r'settings': (dynamic instance) => instance.settings, r'type': (dynamic instance) => instance.type, r'name': (dynamic instance) => instance.name, r'group': (dynamic instance) => instance.group, diff --git a/packages/flutter_nekoton_bridge/lib/nekoton/external/proto_connection.dart b/packages/flutter_nekoton_bridge/lib/nekoton/external/proto_connection.dart index 85dc55aa..de40a61b 100644 --- a/packages/flutter_nekoton_bridge/lib/nekoton/external/proto_connection.dart +++ b/packages/flutter_nekoton_bridge/lib/nekoton/external/proto_connection.dart @@ -21,13 +21,13 @@ class ProtoConnection extends RustToDartMirrorInterface { final String _name; final String _group; - final ProtoNetworkSettings _settings; + final ProtoNetworkSettings settings; final type = TransportType.proto; ProtoConnection._( this._post, - this._settings, + this.settings, this._name, this._group, ); @@ -56,7 +56,7 @@ class ProtoConnection extends RustToDartMirrorInterface { Future post(Uint8List requestData) async { try { return await _post( - endpoint: _settings.endpoint, + endpoint: settings.endpoint, headers: { 'Content-Type': 'x-protobuf', }, diff --git a/packages/flutter_nekoton_bridge/lib/nekoton/external/proto_connection.reflectable.dart b/packages/flutter_nekoton_bridge/lib/nekoton/external/proto_connection.reflectable.dart index 264af2ee..9e913915 100644 --- a/packages/flutter_nekoton_bridge/lib/nekoton/external/proto_connection.reflectable.dart +++ b/packages/flutter_nekoton_bridge/lib/nekoton/external/proto_connection.reflectable.dart @@ -70,6 +70,7 @@ final _data = { r'initializeMirror': 0, r'connection': 0, r'connection=': 1, + r'settings': 0, r'type': 0, r'name': 0, r'group': 0, @@ -177,6 +178,7 @@ final _data = { r'initializeMirror': 0, r'connection': 0, r'connection=': 1, + r'settings': 0, r'type': 0, r'name': 0, r'group': 0, @@ -213,6 +215,7 @@ final _data = { r'initializeMirror': 0, r'connection': 0, r'connection=': 1, + r'settings': 0, r'type': 0, r'name': 0, r'group': 0, @@ -531,6 +534,7 @@ final _data = { r'post': (dynamic instance) => instance.post, r'initializeMirror': (dynamic instance) => instance.initializeMirror, r'connection': (dynamic instance) => instance.connection, + r'settings': (dynamic instance) => instance.settings, r'type': (dynamic instance) => instance.type, r'name': (dynamic instance) => instance.name, r'group': (dynamic instance) => instance.group, diff --git a/packages/flutter_nekoton_bridge/lib/nekoton/external/storage.reflectable.dart b/packages/flutter_nekoton_bridge/lib/nekoton/external/storage.reflectable.dart index 8d0c8cdc..4bb120b2 100644 --- a/packages/flutter_nekoton_bridge/lib/nekoton/external/storage.reflectable.dart +++ b/packages/flutter_nekoton_bridge/lib/nekoton/external/storage.reflectable.dart @@ -178,6 +178,7 @@ final _data = { r'initializeMirror': 0, r'connection': 0, r'connection=': 1, + r'settings': 0, r'type': 0, r'name': 0, r'group': 0, @@ -214,6 +215,7 @@ final _data = { r'initializeMirror': 0, r'connection': 0, r'connection=': 1, + r'settings': 0, r'type': 0, r'name': 0, r'group': 0, @@ -250,6 +252,7 @@ final _data = { r'initializeMirror': 0, r'connection': 0, r'connection=': 1, + r'settings': 0, r'type': 0, r'name': 0, r'group': 0, @@ -544,6 +547,7 @@ final _data = { r'test1': (dynamic instance) => instance.test1, r'post': (dynamic instance) => instance.post, r'connection': (dynamic instance) => instance.connection, + r'settings': (dynamic instance) => instance.settings, r'type': (dynamic instance) => instance.type, r'name': (dynamic instance) => instance.name, r'group': (dynamic instance) => instance.group, diff --git a/packages/flutter_nekoton_bridge/lib/nekoton/transport/gql_transport.dart b/packages/flutter_nekoton_bridge/lib/nekoton/transport/gql_transport.dart index 91b758e3..46863447 100644 --- a/packages/flutter_nekoton_bridge/lib/nekoton/transport/gql_transport.dart +++ b/packages/flutter_nekoton_bridge/lib/nekoton/transport/gql_transport.dart @@ -21,6 +21,9 @@ class GqlTransport extends Transport { instance.networkId = await instance.getNetworkId(); + instance.connectionParamsHash = + getHash('gql:${gqlConnection.settings.endpoints.join(',')}'); + return instance; } diff --git a/packages/flutter_nekoton_bridge/lib/nekoton/transport/jrpc_transport.dart b/packages/flutter_nekoton_bridge/lib/nekoton/transport/jrpc_transport.dart index bdeb984e..3b93a3ef 100644 --- a/packages/flutter_nekoton_bridge/lib/nekoton/transport/jrpc_transport.dart +++ b/packages/flutter_nekoton_bridge/lib/nekoton/transport/jrpc_transport.dart @@ -21,6 +21,9 @@ class JrpcTransport extends Transport { instance.networkId = await instance.getNetworkId(); + instance.connectionParamsHash = + getHash('jrpc:${jrpcConnection.settings.endpoint}'); + return instance; } diff --git a/packages/flutter_nekoton_bridge/lib/nekoton/transport/proto_transport.dart b/packages/flutter_nekoton_bridge/lib/nekoton/transport/proto_transport.dart index d0a138ac..1edb76dc 100644 --- a/packages/flutter_nekoton_bridge/lib/nekoton/transport/proto_transport.dart +++ b/packages/flutter_nekoton_bridge/lib/nekoton/transport/proto_transport.dart @@ -21,6 +21,9 @@ class ProtoTransport extends Transport { instance.networkId = await instance.getNetworkId(); + instance.connectionParamsHash = + getHash('proto:${protoConnection.settings.endpoint}'); + return instance; } diff --git a/packages/flutter_nekoton_bridge/lib/nekoton/transport/transport.dart b/packages/flutter_nekoton_bridge/lib/nekoton/transport/transport.dart index 8fd563d1..7b22f1c8 100644 --- a/packages/flutter_nekoton_bridge/lib/nekoton/transport/transport.dart +++ b/packages/flutter_nekoton_bridge/lib/nekoton/transport/transport.dart @@ -10,6 +10,9 @@ abstract class Transport { TransportType get type; + /// Get uniquer identifier of transport based on type and endpoints + late final String connectionParamsHash; + /// Get contract state of address and return RawContractState or throw error Future getContractState(Address address); diff --git a/packages/flutter_nekoton_bridge/lib/nekoton/utils.dart b/packages/flutter_nekoton_bridge/lib/nekoton/utils.dart index c48123c6..fce01c54 100644 --- a/packages/flutter_nekoton_bridge/lib/nekoton/utils.dart +++ b/packages/flutter_nekoton_bridge/lib/nekoton/utils.dart @@ -1,3 +1,4 @@ +import 'package:crypto/crypto.dart'; import 'package:flutter_nekoton_bridge/flutter_nekoton_bridge.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; @@ -56,3 +57,6 @@ extension KeySignerName on KeySigner { ); } } + +/// Get hash of String +String getHash(String string) => sha256.convert(string.codeUnits).toString(); diff --git a/packages/flutter_nekoton_bridge/pubspec.yaml b/packages/flutter_nekoton_bridge/pubspec.yaml index 4432dda1..856606e7 100644 --- a/packages/flutter_nekoton_bridge/pubspec.yaml +++ b/packages/flutter_nekoton_bridge/pubspec.yaml @@ -22,6 +22,7 @@ dependencies: # for generating mirror hash uuid: ^3.0.7 tuple: ^2.0.1 + crypto: ^3.0.3 dev_dependencies: ffi: ^2.0.2 ffigen: ^8.0.2