예제 #1
0
 public void AddNewUtxoToSet(UtxoMsg utxo)
 {
     if (UtxoSet.Instance != null)
     {
         UtxoSet.Instance.AddUtxoRecord(utxo);
     }
 }
예제 #2
0
        public void RefreshUtxoSet(string accountId)
        {
            var outputDac  = new OutputDac();
            var accountDac = new AccountDac();
            var txDac      = new TransactionDac();

            var account = accountDac.SelectById(accountId);

            if (account != null && UtxoSet.Instance != null)
            {
                var set = UtxoSet.Instance.GetUtxoSetByAccountId(accountId);

                if (set != null)
                {
                    set.Clear();

                    //load from database
                    var outputsInDB = outputDac.SelectUnspentByReceiverId(accountId);

                    foreach (var output in outputsInDB)
                    {
                        var msg = new UtxoMsg();
                        msg.AccountId       = output.ReceiverId;
                        msg.TransactionHash = output.TransactionHash;
                        msg.OutputIndex     = output.Index;
                        msg.Amount          = output.Amount;
                        msg.IsConfirmed     = true;
                        msg.IsWatchedOnly   = account.WatchedOnly;

                        var txEntity = txDac.SelectByHash(output.TransactionHash);
                        msg.BlockHash = txEntity != null ? txEntity.BlockHash : null;

                        set.Add(msg);
                    }

                    //load from transaction pool
                    var outputsInTxPool = TransactionPool.Instance.GetTransactionOutputsByAccountId(accountId);

                    foreach (var txHash in outputsInTxPool.Keys)
                    {
                        foreach (var output in outputsInTxPool[txHash])
                        {
                            var msg = new UtxoMsg();
                            msg.AccountId       = accountId;
                            msg.TransactionHash = txHash;
                            msg.OutputIndex     = output.Index;
                            msg.Amount          = output.Amount;
                            msg.IsConfirmed     = false;
                            msg.IsWatchedOnly   = account.WatchedOnly;

                            set.Add(msg);
                        }
                    }
                }
            }
        }
예제 #3
0
        public void AddUtxoRecord(UtxoMsg utxo)
        {
            if (this.MainSet.ContainsKey(utxo.AccountId))
            {
                var item = this.MainSet[utxo.AccountId].Where(u => u.TransactionHash == utxo.TransactionHash &&
                                                              u.OutputIndex == utxo.OutputIndex).FirstOrDefault();

                if (item == null)
                {
                    this.MainSet[utxo.AccountId].Add(utxo);
                }
                else
                {
                    item.BlockHash   = utxo.BlockHash;
                    item.IsConfirmed = utxo.IsConfirmed;
                }
            }
        }
예제 #4
0
        //public List<UtxoMsg> GetAllConfirmedOutputs()
        //{
        //    return UtxoSet.Instance.GetAllUnspentOutputs();
        //}


        public List <UtxoMsg> GetAllConfirmedOutputs()
        {
            List <UtxoMsg> utxoMsgs = new List <UtxoMsg>();

            var outputDac  = new OutputDac();
            var txDac      = new TransactionDac();
            var blockDac   = new BlockDac();
            var accountDac = new AccountDac();

            var lastHeight = -1L;
            var lastBlock  = blockDac.SelectLast();

            if (lastBlock != null)
            {
                lastHeight = lastBlock.Height;
            }
            var outputs = outputDac.SelectAllUnspentOutputs();

            foreach (var output in outputs)
            {
                var msg = new UtxoMsg();
                msg.AccountId       = output.ReceiverId;
                msg.TransactionHash = output.TransactionHash;
                msg.OutputIndex     = output.Index;
                msg.Amount          = output.Amount;
                msg.IsConfirmed     = true;
                var account = accountDac.SelectById(msg.AccountId);
                msg.IsWatchedOnly = account.WatchedOnly;

                var txEntity = txDac.SelectByHash(output.TransactionHash);
                msg.BlockHash = txEntity != null ? txEntity.BlockHash : null;
                utxoMsgs.Add(msg);
            }

            return(utxoMsgs);
        }