コード例 #1
0
        /// <summary>
        /// backup an account which can be restored later
        /// </summary>
        /// <param name="kinClient"></param>
        /// <param name="onComplete"></param>
        /// <returns></returns>
        public void BackupAccount(KinClient kinClient, Action <KinException, BackupRestoreResult> onComplete)
        {
            if (KinManager.onBackup.ContainsKey(_accountId))
            {
                throw new KinException("KinBackupAndRestoreManager request already in flight for this method. Wait for it to complete before requesting it again.");
            }
            KinManager.onBackup[_accountId] = onComplete;

            NativeBridge.Get().BackupAccount(_accountId, kinClient._clientId);
        }
コード例 #2
0
        protected override void OnLeftColumnGUI()
        {
            GUILayout.Label("Connecting to a service provider");
            if (GUILayout.Button("Create Kin Client"))
            {
                _client = new KinClient(Environment.Test, "test");
            }


            if (_client != null && GUILayout.Button("Free Kin Client"))
            {
                _client  = null;
                _account = null;
            }


            if (_client == null)
            {
                return;
            }

            GUILayout.Space(40);
            GUILayout.Label("Kin Client Operations");
            if (GUILayout.Button("Clear All Accounts"))
            {
                _client.ClearAllAccounts();
                removeListeners();
            }


            if (GUILayout.Button("Get Account Count"))
            {
                Debug.Log("account count: " + _client.GetAccountCount());
            }


            if (GUILayout.Button("Get Minimum Fee"))
            {
                ShowProgressWindow("GetMinimumFee");
                _client.GetMinimumFee((ex, fee) =>
                {
                    HideProgressWindow();
                    if (ex == null)
                    {
                        Debug.Log("Fee: " + fee);
                        _feeAmount = fee;
                    }
                    else
                    {
                        Debug.LogError("Get Minimum Fee Failed. " + ex);
                    }
                });
            }


            GUILayout.Space(40);
            GUILayout.Label("Creating and retrieving a Kin account");
            if (GUILayout.Button("Get or Create Kin Account"))
            {
                _isAccountCreated = false;
                _transaction      = null;

                if (_client.HasAccount())
                {
                    _account = _client.GetAccount();
                }
                else
                {
                    try
                    {
                        _account = _client.AddAccount();
                    }
                    catch (KinException e)
                    {
                        Debug.LogError("error adding account: " + e);
                        return;
                    }
                }

                // if we found an account add blockchain listeners that will log the events as they happen
                if (_account != null)
                {
                    addListeners();
                    _account.GetStatus((KinException error, AccountStatus status) =>
                    {
                        _isAccountCreated = status == AccountStatus.Created;
                    });
                }
            }


            GUILayout.Space(40);
            GUILayout.Label("Exported Account JSON:");
            _exportedAccountJson = GUILayout.TextField(_exportedAccountJson);

            if (!string.IsNullOrEmpty(_exportedAccountJson) && GUILayout.Button("Import Account"))
            {
                try
                {
                    _account = _client.ImportAccount(_exportedAccountJson, _importExportPassphrase);
                }
                catch (KinException e)
                {
                    Debug.LogError(e);
                }

                // if we imported an account add blockchain listeners that will log the events as they happen
                if (_account != null)
                {
                    addListeners();
                }
            }

            if (GUILayout.Button("Restore Account"))
            {
                _client.RestoreAccount(
                    (KinException ex, BackupRestoreResult result, KinAccount account) => {
                    switch (result)
                    {
                    case BackupRestoreResult.Success:
                        Debug.Log("Account successfully restored");
                        // Remove listeners from the currnet account
                        removeListeners();

                        _account = account;
                        // Add listeners to the new account
                        addListeners();
                        _account.GetStatus((KinException error, AccountStatus status) =>
                        {
                            _isAccountCreated = status == AccountStatus.Created;
                        });
                        break;

                    case BackupRestoreResult.Cancel:
                        Debug.Log("Account restoration canceled");
                        break;

                    case BackupRestoreResult.Failed:
                        Debug.Log("Account restoration failed");
                        Debug.LogError(ex);
                        break;
                    }
                });
            }

            if (_account == null)
            {
                return;
            }


            if (GUILayout.Button("Delete Account"))
            {
                try
                {
                    _client.DeleteAccount();
                    removeListeners();
                }
                catch (KinException e)
                {
                    Debug.LogError("error deleting account: " + e);
                    return;
                }
            }
        }
コード例 #3
0
		protected override void OnLeftColumnGUI()
		{
			GUILayout.Label( "Connecting to a service provider" );
			if( GUILayout.Button( "Create Kin Client" ) )
			{
				_client = new KinClient( Environment.Test, "test" );
			}


			if( _client != null && GUILayout.Button( "Free Kin Client" ) )
			{
				_client = null;
				_account = null;
			}


			if( _client == null )
				return;

			GUILayout.Space( 40 );
			GUILayout.Label( "Kin Client Operations" );
			if( GUILayout.Button( "Clear All Accounts" ) )
			{
				_client.ClearAllAccounts();
				removeListeners();
			}


			if( GUILayout.Button( "Get Account Count" ) )
			{
				Debug.Log( "account count: " + _client.GetAccountCount() );
			}


			if( GUILayout.Button( "Get Minimum Fee" ) )
			{
				ShowProgressWindow( "GetMinimumFee" );
				_client.GetMinimumFee( ( ex, fee ) =>
				{
					HideProgressWindow();
					if( ex == null )
					{
						Debug.Log( "Fee: " + fee );
						_feeAmount = fee;
					}
					else
					{
						Debug.LogError( "Get Minimum Fee Failed. " + ex );
					}
				});
			}


			GUILayout.Space( 40 );
			GUILayout.Label( "Creating and retrieving a Kin account" );
			if( GUILayout.Button( "Get or Create Kin Account" ) )
			{
				_isAccountCreated = false;
				_transaction = null;

				if( _client.HasAccount() )
				{
					_account = _client.GetAccount();
				}
				else
				{
					try
					{
						_account = _client.AddAccount();
					}
					catch( KinException e )
					{
						Debug.LogError( "error adding account: " + e );
						return;
					}
				}

				// if we found an account add blockchain listeners that will log the events as they happen
				if( _account != null )
					addListeners();
			}


			GUILayout.Space( 40 );
			GUILayout.Label( "Exported Account JSON:" );
			_exportedAccountJson = GUILayout.TextField( _exportedAccountJson );

			if( !string.IsNullOrEmpty( _exportedAccountJson ) && GUILayout.Button( "Import Account" ) )
			{
				try
				{
					_account = _client.ImportAccount( _exportedAccountJson, _importExportPassphrase );
				}
				catch( KinException e )
				{
					Debug.LogError( e );
				}

				// if we imported an account add blockchain listeners that will log the events as they happen
				if( _account != null )
					addListeners();
			}


			if( _account == null )
				return;


			if( GUILayout.Button( "Delete Account" ) )
			{
				try
				{
					_client.DeleteAccount();
					removeListeners();
				}
				catch( KinException e )
				{
					Debug.LogError( "error deleting account: " + e );
					return;
				}
			}
		}