Пример #1
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();
            }
        }
Пример #2
0
        static async Task ResetDevice()
        {
            IEnumerable <CoinType> coinTable;
            await SoterDeviceFactoryHid.Instance.StartDeviceSearchAsync();

            await Task.Delay(1000);

            await SoterDeviceFactoryHid.Instance.StopDeviceSearchAsync();

            if (SoterDeviceFactoryHid.Instance.Devices.Count == 0)
            {
                throw new Exception("Do Soter Wallet device detected!");
            }
            _soterDevice = (SoterDeviceHid)SoterDeviceFactoryHid.Instance.Devices.FirstOrDefault();
            _soterDevice.EnterPinCallback = _soterDevice_EnterPinCallback;;
            await _soterDevice.InitializeAsync();

            await _soterDevice.CancelAsync();

            if (_soterDevice.Features.Initialized)
            {
                coinTable = await _soterDevice.GetCoinTableAsync(24);

                _soterDevice.CoinUtility = new CoinUtility(coinTable);
                //Get Bitcoin Testnet Address
                Log.Information(await GetAddressAsync(1, false, 0, false, false, false));
                await _soterDevice.WipeDeviceAsync();
            }
            await _soterDevice.ResetDeviceAsync("Digbig Wallet");

            await _soterDevice.InitializeAsync();

            if (!_soterDevice.Features.Initialized)
            {
                Log.Error("Reset Device Failed!!!");
                return;
            }
            await _soterDevice.ChangePinAsync();

            await _soterDevice.ChangeAutoLockDelayAsync(1200000);

            await _soterDevice.ChangeDeviceNameAsync("Test Wallet");

            coinTable = await _soterDevice.GetCoinTableAsync();

            _soterDevice.CoinUtility = new CoinUtility(coinTable);

            //Get Bitcoin Address
            Log.Information(await GetAddressAsync(0, false, 0, false));
            Log.Information(await GetAddressAsync(0, false, 0, false, true, false));
            Log.Information(await GetAddressAsync(0, false, 0, false, true, true));
            Log.Information(await GetAddressAsync(0, false, 0, true));

            //Get Litecoin Address
            Log.Information(await GetAddressAsync(2, false, 0, false));

            //Get Dodge Address
            Log.Information(await GetAddressAsync(3, false, 0, false));

            //Get Dash Address
            Log.Information(await GetAddressAsync(5, false, 0, false));

            //Get Ethereum Address
            Log.Information(await GetAddressAsync(60, false, 0, false));

            //Get BitcoinCash Address
            Log.Information(await GetAddressAsync(145, false, 0, false));

            //await SignBitcoinTransactionAsync();

            Log.Information("All Done!");
        }