コード例 #1
0
        /// <summary>
        /// Init ethereum transaction.
        /// </summary>
        /// <param name="trx">Transaction data model.</param>
        /// <param name="model">Transaction view model.</param>
        private async Task InitializationEthereum(Transaction trx, TransactionViewModel model)
        {
            var merchant = await _merchantRepository.GetByUser(trx.UserId);

            if (string.IsNullOrWhiteSpace(trx.Address) && !string.IsNullOrWhiteSpace(trx.XPubKey))
            {
                var account = await this._ethereumService.CreateAddress(trx.EtherId);

                trx.Address    = account.Item1;
                trx.PassPhrase = account.Item2;

                var foundsWithdraw = MAD.Withdraw(trx.Amount);
                var foundsDeposit  = MAD.Deposit(trx.Amount);

                var estimateGasSize = await _ethereumService.EstimateGasSize(trx.EtherId, merchant.EthereumAddress, trx.XPubKey, foundsWithdraw.Item1, foundsWithdraw.Item2, foundsDeposit.Item1,
                                                                             trx.Address, trx.PassPhrase);

                trx.Fee = CurrencyConverter.WeiToEther(estimateGasSize.Value);

                await this._transactionRepository.Update(trx);
            }

            if (!string.IsNullOrWhiteSpace(trx.Address))
            {
                model.ABI     = this._ethereumService.GetABI();
                model.Balance = CurrencyConverter.WeiToEther((await this._ethereumService.GetBalance(trx.Address)).Value).ToString();
            }

            model.BuyerAddress = trx.XPubKey;
            model.FeeAddress   = trx.Address;
            model.FeeValue     = trx.Fee.ToString();
        }
コード例 #2
0
        public async Task <IActionResult> Merchant()
        {
            MerchantViewModel model = null;

            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
            }

            var userMerchant = await _merchantRepository.GetByUser(user.Id);

            if (userMerchant == null)
            {
                return(View("Merchant/Create"));
            }

            var subscriptions = await _subscriptionsRepository.GetByUserId(user.Id);

            if (subscriptions == null ||
                subscriptions.Paid && subscriptions.Expired < DateTime.Now)
            {
                await _subscriptionsRepository.CreatePaymentAddress(user.Id);
            }

            decimal price = Convert.ToDecimal(_configuration["Subscription:" + subscriptions?.WalletType + ":Price"]);

            await Subscriptions(price);

            subscriptions = await _subscriptionsRepository.GetByUserId(user.Id);

            model = new MerchantViewModel
            {
                MerchantId     = userMerchant.MerchantId,
                MerchantSecret = Crypto.GetSha256Hash(userMerchant.MerchantSecret),
                RedirectUri    = userMerchant.RedirectUri,

                XPubKey         = userMerchant.XPubKey,
                EthereumAddress = userMerchant.EthereumAddress,

                Status     = subscriptions.Expired > DateTime.Now && subscriptions.Paid,
                Address    = subscriptions.Address,
                Expired    = subscriptions.Expired,
                WalletType = subscriptions.WalletType,
                Price      = price,

                StatusMessage = StatusMessage
            };

            return(View("Merchant/Index", model));
        }