From 5b7627b48c6b8cd691562e9b0a1a2c8021fe41b7 Mon Sep 17 00:00:00 2001 From: Konstantin Karuna Date: Thu, 6 Jul 2023 13:41:17 +0300 Subject: [PATCH] Closing beacon.db connections before app exit; --- CHANGELOG.md | 4 ++++ Runtime/Scripts/Beacon/BeaconConnectorDotNet.cs | 9 +++++++-- Runtime/Scripts/Tezos/TezosSingleton.cs | 8 ++++++++ Runtime/Scripts/Tezos/Wallet/WalletProvider.cs | 13 +++++++++++-- 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index affe7757..3c75679a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [unreleased] +### Fixed +- [Bug](https://github.com/trilitech/tezos-unity-sdk/issues/103) with closing Beacon database connections before app exit + ## [1.5.1] - 2023-06-27 ### Fixed diff --git a/Runtime/Scripts/Beacon/BeaconConnectorDotNet.cs b/Runtime/Scripts/Beacon/BeaconConnectorDotNet.cs index 393d6d35..484361c3 100644 --- a/Runtime/Scripts/Beacon/BeaconConnectorDotNet.cs +++ b/Runtime/Scripts/Beacon/BeaconConnectorDotNet.cs @@ -23,7 +23,7 @@ namespace TezosSDK.Beacon { - public class BeaconConnectorDotNet : IBeaconConnector + public class BeaconConnectorDotNet : IBeaconConnector, IDisposable { private static WalletMessageReceiver _walletMessageReceiver; private DappBeaconClient BeaconDappClient { get; set; } @@ -269,9 +269,14 @@ private async void OnBeaconDappClientMessageReceived(object sender, BeaconMessag } #endregion + + public void Dispose() + { + BeaconDappClient.Disconnect(); + } } -// todo: this logger didn't work inside Beacon, improve this. + // todo: this logger didn't work inside Beacon, improve this. public class MyLoggerProvider : ILoggerProvider { public class MyLogger : ILogger diff --git a/Runtime/Scripts/Tezos/TezosSingleton.cs b/Runtime/Scripts/Tezos/TezosSingleton.cs index d235853c..cafe103f 100644 --- a/Runtime/Scripts/Tezos/TezosSingleton.cs +++ b/Runtime/Scripts/Tezos/TezosSingleton.cs @@ -29,6 +29,14 @@ protected override void Awake() TezosConfig.Instance.Network = NetworkType.ghostnet; _tezos = new Tezos(); } + + void OnApplicationQuit() + { + if (Wallet is IDisposable disposable) + { + disposable.Dispose(); + } + } public IEnumerator GetCurrentWalletBalance(Action callback) { diff --git a/Runtime/Scripts/Tezos/Wallet/WalletProvider.cs b/Runtime/Scripts/Tezos/Wallet/WalletProvider.cs index 0effb560..f9fff2d0 100644 --- a/Runtime/Scripts/Tezos/Wallet/WalletProvider.cs +++ b/Runtime/Scripts/Tezos/Wallet/WalletProvider.cs @@ -1,4 +1,5 @@ -using System.Text.Json; +using System; +using System.Text.Json; using Beacon.Sdk.Beacon.Sign; using TezosSDK.Beacon; using TezosSDK.Helpers; @@ -6,7 +7,7 @@ namespace TezosSDK.Tezos.Wallet { - public class WalletProvider : IWalletProvider + public class WalletProvider : IWalletProvider, IDisposable { public WalletMessageReceiver MessageReceiver { get; private set; } private IBeaconConnector _beaconConnector; @@ -119,5 +120,13 @@ public void CallContract( networkName: TezosConfig.Instance.Network.ToString(), networkRPC: TezosConfig.Instance.RpcBaseUrl); } + + public void Dispose() + { + if (_beaconConnector is IDisposable disposable) + { + disposable.Dispose(); + } + } } } \ No newline at end of file