Пример #1
0
        static Task <string> GetAddressAsync(uint coinNumber, bool isChange, uint index, bool display, bool isPublicKey = false, bool isLegacy = true)
        {
            var coinInfo    = _soterDevice.CoinUtility.GetCoinInfo(coinNumber);
            var addressPath = new BIP44AddressPath(!isLegacy && coinInfo.IsSegwit, coinNumber, 0, isChange, index);

            return(_soterDevice.GetAddressAsync((IAddressPath)addressPath, isPublicKey, display));
        }
Пример #2
0
        public static async Task LoadCoinTableFromDeviceAsync(ISoterDevice device)
        {
            using (var db = new DatabaseContext())
            {
                db.Database.EnsureCreated();
                db.Transactions.Clear();
                db.Addresses.Clear();
                db.Coins.Clear();
                var coinTable = await device.GetCoinTableAsync(48);

                device.CoinUtility = new CoinUtility(coinTable);
                foreach (var coinType in coinTable)
                {
                    if (SupportedCoins.Any(c => c.Equals(coinType.CoinShortcut)))
                    {
                        db.Coins.Add(new Coin(coinType)
                        {
                            WalletDeviceId = _currentDevice.Id
                        });
                    }
                }
                db.SaveChanges();
                foreach (var coin in db.Coins)
                {
                    var addressPath = new BIP44AddressPath(coin.Segwit, AddressUtilities.UnhardenNumber(coin.Bip44AccountPath), 0, false, 0);
                    var addressStr  = await device.GetAddressAsync((IAddressPath)addressPath, false, false);

                    var address = new Address()
                    {
                        CoinId        = coin.Id,
                        Account       = addressPath.Account,
                        Change        = addressPath.Change,
                        AddressIndex  = addressPath.AddressIndex,
                        AddressString = addressStr,
                        CoinType      = addressPath.CoinType,
                        Purpose       = addressPath.Purpose,
                    };
                    db.Addresses.Add(address);
                }
                db.SaveChanges();
            }
        }