示例#1
0
        public UTXO(NBXplorer.Models.UTXO utxo)
        {
            Confirmations = utxo.Confirmations;
            KeyPath       = utxo.KeyPath;
            Timestamp     = utxo.Timestamp;

            Index        = utxo.Index;
            ScriptPubKey = utxo.ScriptPubKey;
            if (utxo.Value is Money m)
            {
                ValueInSatoshi = m.Satoshi;
            }
            TransactionHash = utxo.TransactionHash;
            Outpoint        = utxo.Outpoint;
        }
示例#2
0
        private void processUtxo(NBXplorer.Models.UTXO utxo, int currentHeight)
        {
            //TODO - add attachment
            // - read OP_RETURN ?

            //var addr = AddressOf(pubkey.Root, utxo.KeyPath);
            var to     = utxo.ScriptPubKey.GetDestinationAddress(GetNetwork());
            var id     = utxo.Outpoint.Hash.ToString();
            var date   = utxo.Timestamp.ToUnixTimeSeconds();
            var height = utxo.Confirmations > 0 ? currentHeight - (utxo.Confirmations - 1) : -1;

            logger.LogInformation($"processing UTXO - txid {id} - destination addr {to} - value {utxo.Value}");

            var address = db.AddrGet(to.ToString());

            if (address == null)
            {
                logger.LogError($"Address not found for {to}");
                return;
            }

            // add/update chain tx
            var ctx = db.ChainTxGet(id);

            if (ctx == null)
            {
                ctx = new ChainTx(id, date, -1, height, utxo.Confirmations);
                db.ChainTxs.Add(ctx);
            }
            else
            {
                ctx.Height        = height;
                ctx.Confirmations = utxo.Confirmations;
                db.ChainTxs.Update(ctx);
            }
            var status = utxo.Confirmations > 0 ? ChainTxStatus.Confirmed : ChainTxStatus.Unconfirmed;

            if (ctx.NetworkStatus == null)
            {
                var txResult      = GetClient().GetTransaction(utxo.Outpoint.Hash);
                var networkStatus = new ChainTxNetworkStatus(ctx, status, 0, txResult.Transaction.ToBytes());
                db.ChainTxNetworkStatus.Add(networkStatus);
            }
            else
            {
                // transaction update comes from our trusted node so we will override any status we have set manually
                ctx.NetworkStatus.Status = status;
                db.ChainTxNetworkStatus.Update(ctx.NetworkStatus);
            }
            // add output
            var o = db.TxOutputGet(id, utxo.Outpoint.N);

            if (o == null)
            {
                o            = new TxOutput(id, address.Address, utxo.Outpoint.N, utxo.Value.Satoshi);
                o.ChainTx    = ctx;
                o.WalletAddr = address;
                db.TxOutputs.Add(o);
            }
            else if (o.WalletAddr == null)
            {
                logger.LogInformation($"Updating output with no address: {id}, {o.N}, {address.Address}");
                o.WalletAddr = address;
                db.TxOutputs.Update(o);
            }
            // add/update wallet tx
            var wtx = db.TxGet(address, ctx, WalletDirection.Incomming);

            if (wtx == null)
            {
                wtx = new WalletTx {
                    ChainTx = ctx, Address = address, Direction = WalletDirection.Incomming, State = WalletTxState.None
                };
                db.WalletTxs.Add(wtx);
            }
        }