コード例 #1
0
        public static async Task UpdateCoinTable(Page parentPage)
        {
            _parentPage = parentPage;
            _waitHandle.Reset();
            var deviceCommPage = new DeviceCommPage(CommFunction.UpdateCoinTable);
            await _parentPage.Navigation.PushModalAsync(deviceCommPage);

            await Task.Run(() => _waitHandle.WaitOne());
        }
コード例 #2
0
        public static async Task ResetDevice(Page parentPage, string deviceLabel)
        {
            _parentPage  = parentPage;
            _deviceLabel = deviceLabel;
            _waitHandle.Reset();
            var deviceCommPage = new DeviceCommPage(CommFunction.ResetDevice);
            await _parentPage.Navigation.PushModalAsync(deviceCommPage);

            await Task.Run(() => _waitHandle.WaitOne());
        }
コード例 #3
0
        public static async Task <BitcoinTransaction> SignBitcoinTransaction(Page parentPage, BitcoinTransaction bitcoinTX)
        {
            _parentPage = parentPage;
            _bitcoinTX  = bitcoinTX;
            _waitHandle.Reset();
            var deviceCommPage = new DeviceCommPage(CommFunction.SignBitcoinTx);
            await _parentPage.Navigation.PushModalAsync(deviceCommPage);

            await Task.Run(() => _waitHandle.WaitOne());

            return(_bitcoinTX);
        }
コード例 #4
0
        async void Handle_Clicked(object sender, System.EventArgs e)
        {
            await DeviceCommPage.ResetDevice(this, deviceLabelEntry.Text);

            Application.Current.MainPage = new NavigationPage(new MainTabbedPage());
        }
コード例 #5
0
 async void DeviceNameLabel_Tapped(object sender, System.EventArgs e)
 {
     await DeviceCommPage.UpdateCoinTable(this);
 }
コード例 #6
0
        protected override async void OnAppearing()
        {
            base.OnAppearing();
            Device.StartTimer(TimeSpan.FromSeconds(0.3), () =>
            {
                canvasView.InvalidateSurface();
                lock (drawStageLock)
                {
                    if (drawStage < 0)
                    {
                        return(false);
                    }
                    drawStage++;
                    if (drawStage > MAX_DRAW_STAGE)
                    {
                        drawStage = 0;
                    }
                }
                return(true); // True = Repeat again, False = Stop the timer
            });

            if (Device.RuntimePlatform == Device.Android)
            {
                var status = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Location);

                if (status != PermissionStatus.Granted)
                {
                    if (await CrossPermissions.Current.ShouldShowRequestPermissionRationaleAsync(Permission.Location))
                    {
                        await DisplayAlert("Need Location Permission", "Soter Wallet needs Location Permission in order to search for the device.", "OK");
                    }

                    var results = await CrossPermissions.Current.RequestPermissionsAsync(Permission.Location);

                    //Best practice to always check that the key exists
                    if (results.ContainsKey(Permission.Location))
                    {
                        status = results[Permission.Location];
                    }
                }
                if (status != PermissionStatus.Granted)
                {
                    await DisplayAlert("Location Permission Denied", "Can not continue, try again.", "OK");
                }
            }

            ISoterDevice device = null;
            await SoterDeviceFactoryBle.Instance.StartDeviceSearchAsync();

            Log.Information("Wait for search results");
            await Task.Delay(500);

            Log.Information("Wait finished");
            await SoterDeviceFactoryBle.Instance.StopDeviceSearchAsync();

            Log.Information("Search stopped");
            if (SoterDeviceFactoryBle.Instance.Devices.Count == 0)
            {
                await DisplayAlert("Error", "Can't find any Soter Wallet device!", "OK");
            }
            else if (SoterDeviceFactoryBle.Instance.Devices.Count == 1)
            {
                device = SoterDeviceFactoryBle.Instance.Devices.First();
            }
            else
            {
                var action = await DisplayActionSheet("Select the device", "Cancel", null, SoterDeviceFactoryBle.Instance.Devices.Select(d => d.Name).ToArray());

                device = SoterDeviceFactoryBle.Instance.Devices.FirstOrDefault(d => d.Name.Equals(action));
            }
            if (device != null)
            {
                try
                {
                    await SoterDeviceFactoryBle.Instance.ConnectByIdAsync(device.Id);

                    await device.InitializeAsync();

                    lock (drawStageLock)
                    {
                        drawStage = -1;
                    }
                    if (device.Features.Initialized)
                    {
                        await DeviceCommPage.UpdateCoinTable(this);

                        Application.Current.MainPage = new NavigationPage(new MainTabbedPage());
                        return;
                    }
                    else
                    {
                        Application.Current.MainPage = new NavigationPage(new DeviceLabelPage());
                        return;
                    }
                }
                catch (Exception ex)
                {
                    Log.Error(ex.ToString());
                    await DisplayAlert("Error", "Can't connect to the Soter Wallet!", "OK");
                }
            }
            Application.Current.MainPage = new StartPairingPage();
        }
コード例 #7
0
        async void NextButton_Clicked(object sender, EventArgs e)
        {
            var bitcoinTransaction = new BitcoinTransaction(selectedCoin.Name);

            var bitcoinService = BitcoinService.GetBitcoinService(selectedCoin.Shortcut);
            var tx             = await bitcoinService.CreateTransactionAsync(new BitcoinTX()
            {
                Inputs = new List <BitcoinTXInput> {
                    new BitcoinTXInput {
                        Addresses = new List <string> {
                            selectedCoin.DefaultAddress
                        }
                    }
                },
                Outputs = new List <BitcoinTXOutput> {
                    new BitcoinTXOutput {
                        Addresses = new List <string> {
                            toAddressEntry.Text
                        }, Value = 100000
                    }
                }
            });

            foreach (var input in tx.Tx.Inputs)
            {
                var newInput = new BitcoinTransactionInput
                {
                    AddressNs = Repository.GetAddress(input.Addresses[0]).GetAddressPath(),
                    Amount    = (ulong)input.OutputValue,
                    PrevHash  = input.PrevHash.ToBytes(),
                    PrevIndex = (uint)input.OutputIndex,
                    Sequence  = (uint)input.Sequence
                };
                var inputTx = await bitcoinService.GetTransactionAsync(input.PrevHash);

                newInput.PrevTransaction = new BitcoinTransaction(selectedCoin.Shortcut, (uint)inputTx.Ver, (uint)inputTx.LockTime);

                foreach (var prevInput in inputTx.Inputs)
                {
                    newInput.PrevTransaction.Inputs.Add(new BitcoinTransactionInput
                    {
                        PrevHash   = prevInput.PrevHash.ToBytes(),
                        ScriptSig  = prevInput.Script.ToBytes(),
                        PrevIndex  = (uint)prevInput.OutputIndex,
                        Sequence   = (uint)prevInput.Sequence,
                        ScriptType = InputScriptType.Spendaddress
                    });
                }
                foreach (var prevOutput in inputTx.Outputs)
                {
                    newInput.PrevTransaction.Outputs.Add(new BitcoinTransactionOutput
                    {
                        Amount = (ulong)prevOutput.Value,
                        Script = prevOutput.Script.ToBytes()
                    });
                }

                bitcoinTransaction.Inputs.Add(newInput);
            }

            foreach (var output in tx.Tx.Outputs)
            {
                bitcoinTransaction.Outputs.Add(new BitcoinTransactionOutput
                {
                    Address     = output.Addresses[0],
                    Script      = output.Script.ToBytes(),
                    Amount      = (ulong)output.Value,
                    AddressType = OutputAddressType.Spend,
                    ScriptType  = OutputScriptType.Paytoscripthash,
                });
            }

            var signedTx = await DeviceCommPage.SignBitcoinTransaction(this, bitcoinTransaction);

            Log.Debug(JsonConvert.SerializeObject(signedTx));
            var txPushResult = await bitcoinService.PushRawTransactionAsync(new BitcoinTXRaw { Tx = signedTx.SerializedTx.ToHex().ToLower() });

            Log.Debug(JsonConvert.SerializeObject(txPushResult));
        }