Пример #1
0
        WalletTx AddOutgoingTx(string from, TransferTransaction signedTx, WalletTag tagFor)
        {
            var date    = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
            var address = db.AddrGet(from);
            var amount  = asset.AmountToLong(signedTx.Amount);
            var fee     = asset.AmountToLong(signedTx.Fee);

            logger.LogDebug("outgoing tx: amount: {0}, fee: {1}", amount, fee);
            // create chain tx
            var ctx = new ChainTx(signedTx.GenerateId(), date, fee, -1, 0);

            ctx.NetworkStatus = new ChainTxNetworkStatus(ctx, ChainTxStatus.Unconfirmed, date, signedTx.GetBytes());
            db.ChainTxs.Add(ctx);
            db.ChainTxNetworkStatus.Add(ctx.NetworkStatus);
            // create tx inputs
            var i = new TxInput(signedTx.GenerateId(), from /*signedTx.Sender is null*/, 0, amount);

            i.ChainTx    = ctx;
            i.WalletAddr = address;
            db.TxInputs.Add(i);
            i            = new TxInput(signedTx.GenerateId(), from /*signedTx.Sender is null*/, 1, fee);
            i.ChainTx    = ctx;
            i.WalletAddr = address;
            db.TxInputs.Add(i);
            // create tx output
            var o = new TxOutput(signedTx.GenerateId(), signedTx.Recipient, 0, amount);

            o.ChainTx = ctx;
            db.TxOutputs.Add(o);
            if (tagFor != null)
            {
                db.TxOutputsForTag.Add(new TxOutputForTag {
                    TxOutput = o, Tag = tagFor
                });
            }
            // create wallet tx
            var wtx = new WalletTx {
                ChainTx = ctx, Address = address, Direction = WalletDirection.Outgoing
            };

            db.WalletTxs.Add(wtx);
            return(wtx);
        }