Example #1
0
        public async Task <SendBulsData> PrepareSendBuls(string fromPubkey, string toPubkey, double amountBuls, bool disableConvertor = false)
        {
            var request = PrepareRequest(apiVersion + "/prepare_send_buls", Method.POST);

            var amount = amountBuls;

            if (!disableConvertor)
            {
                amount = StellarConverter.ConvertBULToStroops(amountBuls);
            }

            if (StellarConverter.IsValidBUL(amount) == false)
            {
                throw new ServiceException(400, "You can't specify more then 7 fractional digits");
            }

            var myBalance = await App.Locator.BridgeServiceClient.Balance(App.Locator.Profile.Pubkey);

            if (myBalance == null || myBalance.Account.BalanceBUL < amount)
            {
                throw new ServiceException(420, AppResources.InsufficientBULs);
            }

            request.AddParameter("from_pubkey", fromPubkey);
            request.AddParameter("to_pubkey", toPubkey);
            request.AddParameter("amount_buls", amount);

            return(await SendRequest <SendBulsData>(request));
        }
Example #2
0
        public async Task <PackageData> CreatePackage(string escrowPubkey, string recipientPubkey, string launcherPhone, string recipientPhone, long deadlineTimestamp, double paymentBuls, double collateralBuls,
                                                      string description, string fromAddress, string toAddress, string fromLocation, string toLocation, string eventLocation, byte[] packagePhoto, SignHandler customSign)
        {
            var request = PrepareRequest(apiVersion + "/create_package", Method.POST);

            var payment = StellarConverter.ConvertBULToStroops(paymentBuls);

            if (StellarConverter.IsValidBUL(payment) == false)
            {
                throw new ServiceException(400, "You can't specify more then 7 fractional digits");
            }

            var collateral = StellarConverter.ConvertBULToStroops(collateralBuls);

            if (StellarConverter.IsValidBUL(collateral) == false)
            {
                throw new ServiceException(400, "You can't specify more then 7 fractional digits");
            }

            request.AddParameter("escrow_pubkey", escrowPubkey);
            request.AddParameter("recipient_pubkey", recipientPubkey);
            request.AddParameter("launcher_phone_number", launcherPhone);
            request.AddParameter("recipient_phone_number", recipientPhone);
            request.AddParameter("deadline_timestamp", deadlineTimestamp);
            request.AddParameter("payment_buls", payment);
            request.AddParameter("collateral_buls", collateral);
            request.AddParameter("description", description);
            request.AddParameter("to_address", toAddress);
            request.AddParameter("from_address", fromAddress);
            request.AddParameter("from_location", fromLocation);
            request.AddParameter("to_location", toLocation);
            request.AddParameter("event_location", eventLocation);
            if (packagePhoto != null)
            {
                request.AddFile("photo", packagePhoto, "photo.jpg");
            }

            return(await SendRequest <PackageData>(request, customSign : customSign));
        }
Example #3
0
        public static async Task <StellarOperationResult> CreatePackage(KeyPair escrowKP, string recipientPubkey, string launcherPhone, string recipientPhone, string description,
                                                                        string fromAddress, string toAddress, long deadlineTimestamp, double paymentBuls, double collateralBuls,
                                                                        string eventLocation, string fromLocation, string toLocation, byte[] packagePhoto, LaunchPackageEventHandler eventHandler)
        {
            if (toLocation.Length > 24)
            {
                toLocation = toLocation.Substring(0, 24);
            }

            if (fromLocation.Length > 24)
            {
                fromLocation = fromLocation.Substring(0, 24);
            }

            double steps       = 3;
            double currentStep = 1;

            var payment = StellarConverter.ConvertBULToStroops(paymentBuls);

            if (StellarConverter.IsValidBUL(payment) == false)
            {
                throw new ServiceException(400, AppResources.FractionalDigitsError);
            }

            var collateral = StellarConverter.ConvertBULToStroops(collateralBuls);

            if (StellarConverter.IsValidBUL(collateral) == false)
            {
                throw new ServiceException(400, AppResources.FractionalDigitsError);
            }

            //Check launcher's balance
            eventHandler("", new LaunchPackageEventArgs(AppResources.LaunchPackageStep1, currentStep / steps));
            currentStep++;

            var launcherBalance = await App.Locator.BridgeServiceClient.Balance(App.Locator.Profile.Pubkey);

            if (launcherBalance == null || launcherBalance.Account.BalanceBUL < payment)
            {
                return(StellarOperationResult.LowBULsLauncher);
            }

            eventHandler("", new LaunchPackageEventArgs(AppResources.CreatePackage, currentStep / steps));
            currentStep++;

            var createResult = await App.Locator.RouteServiceClient.CreatePackage(escrowKP.Address, recipientPubkey, launcherPhone, recipientPhone, deadlineTimestamp, paymentBuls, collateralBuls,
                                                                                  description, fromAddress, toAddress, fromLocation, toLocation, eventLocation, packagePhoto, (d) => {
                return(App.Locator.Profile.SignData(d, escrowKP));
            });

            if (createResult != null)
            {
                var packedId = createResult.Package.PaketId;

                App.Locator.Profile.AddPackageKeyPair(packedId, escrowKP.SecretSeed);

                return(StellarOperationResult.Success);
            }


            return(StellarOperationResult.FailedLaunchPackage);
        }