コード例 #1
0
        public IActionResult CreateTransaction([FromBody] byte[] sendPayment)
        {
            var payment = Util.DeserializeProto <SendPayment>(sendPayment);
            var session = _walletService.SessionAddOrUpdate(new Session(payment.Credentials.Identifier.ToSecureString(), payment.Credentials.Passphrase.ToSecureString())
            {
                SessionType       = payment.SessionType,
                WalletTransaction = new WalletTransaction
                {
                    Fee              = payment.SessionType == SessionType.Coin ? payment.Fee : 0,
                    Payment          = payment.Amount,
                    Reward           = payment.SessionType == SessionType.Coinstake ? payment.Fee : 0,
                    Memo             = payment.Memo,
                    RecipientAddress = payment.Address
                }
            });

            _walletService.CreatePayment(session.SessionId);

            var transaction = _walletService.Transaction(session.SessionId);
            var txByteArray = Util.SerializeProto(transaction);

            return(new ObjectResult(new { protobuf = txByteArray }));
        }
コード例 #2
0
ファイル: WalletTransferCommand.cs プロジェクト: meany/bamboo
        public override async Task Execute()
        {
            using var identifier = Prompt.GetPasswordAsSecureString("Identifier:", ConsoleColor.Yellow);
            using var passphrase = Prompt.GetPasswordAsSecureString("Passphrase:", ConsoleColor.Yellow);

            var address = Prompt.GetString("Address:", null, ConsoleColor.Red);
            var amount  = Prompt.GetString("Amount:", null, ConsoleColor.Red);
            var memo    = Prompt.GetString("Memo:", null, ConsoleColor.Green);

            if (double.TryParse(amount, out double t))
            {
                await Spinner.StartAsync("Processing payment ...", async spinner =>
                {
                    this.spinner = spinner;

                    try
                    {
                        var session = _walletService.SessionAddOrUpdate(new Session(identifier, passphrase)
                        {
                            SessionType       = SessionType.Coin,
                            WalletTransaction = new WalletTransaction
                            {
                                Memo             = memo,
                                Payment          = t.ConvertToUInt64(),
                                RecipientAddress = address,
                                WalletType       = WalletType.Send
                            }
                        });

                        _walletService.CreatePayment(session.SessionId);

                        if (session.LastError != null)
                        {
                            spinner.Fail(JsonConvert.SerializeObject(session.LastError.GetValue("message")));
                            return;
                        }

                        await _walletService.Send(session.SessionId);

                        if (session.LastError != null)
                        {
                            spinner.Fail(JsonConvert.SerializeObject(session.LastError.GetValue("message")));
                            return;
                        }

                        var balance = _walletService.AvailableBalance(session.SessionId);
                        var message = $"Available Balance: {balance.Result.DivWithNaT():F9}";

                        var walletTx = _walletService.LastWalletTransaction(session.SessionId, WalletType.Send);
                        if (walletTx != null)
                        {
                            message += $"PaymentID: {walletTx.TxId.ByteToHex()}";
                        }

                        spinner.Succeed(message);
                    }
                    catch (Exception ex)
                    {
                        _logger.LogError(ex.StackTrace);
                        throw;
                    }
                }, Patterns.Toggle3);
            }
        }