Beispiel #1
0
        /// <summary>
        /// Backup Sub Account data as serialized AcountExportDto
        /// </summary>
        /// <returns>true and serialized AcountExportDto</returns>
        public async Task <(bool, string)> BackupAddressToString()
        {
            if (string.IsNullOrEmpty(Address) || (string.IsNullOrEmpty(EKey) && string.IsNullOrEmpty(ESKey)))
            {
                return(false, "Account is not loaded.");
            }

            try
            {
                var dto = new AccountExportDto()
                {
                    Address = Address,
                    EKey    = EKey,
                    ESKey   = ESKey,
                    Name    = Name
                };
                var res = JsonConvert.SerializeObject(dto);
                return(true, res);
            }
            catch (Exception ex)
            {
                return(false, "Cannot backup address from SubAccount. " + ex.Message);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Backup Sub Account to AcountExportDto
        /// </summary>
        /// <returns>true and AcountExportDto</returns>
        public (bool, AccountExportDto) BackupAddressToDto()
        {
            if (string.IsNullOrEmpty(Address) || (string.IsNullOrEmpty(EKey) && string.IsNullOrEmpty(ESKey)))
            {
                return(false, null);
            }

            try
            {
                var dto = new AccountExportDto()
                {
                    Address = Address,
                    EKey    = EKey,
                    ESKey   = ESKey,
                    Name    = Name
                };
                return(true, dto);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Canont backup address data dto. " + ex.Message);
                return(false, null);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Load Sub Account from AcountExportDto
        /// </summary>
        /// <param name="mainSecret"></param>
        /// <param name="dto">account export data</param>
        /// <returns></returns>
        public async Task <(bool, string)> LoadFromBackupDto(BitcoinSecret mainSecret, AccountExportDto dto)
        {
            try
            {
                if (dto == null)
                {
                    return(false, "Cannot load SubAccount from backup. Wrong input data.");
                }

                Address = dto.Address;
                EKey    = dto.EKey;
                ESKey   = dto.ESKey;
                Name    = dto.Name;
                var key = DecryptEncryptedKey(mainSecret);
                AccountKey           = new EncryptionKey(key);
                AccountKey.PublicKey = Address;
                Secret = new BitcoinSecret(key, NeblioTransactionHelpers.Network);
                return(true, Address);
            }
            catch (Exception ex)
            {
                //todo
                return(false, ex.Message);
            }
        }