예제 #1
0
        public IRaumRecord CreateRaumRecord(IBlockInfo acadBlockInfo)
        {
            var raumRecord = new RaumRecord();

            raumRecord.UpdateValuesFrom(acadBlockInfo);
            return(raumRecord);
        }
예제 #2
0
 private void FixBegrundungValue(IBlockInfo blockInfo)
 {
     if (blockInfo.Begrundung == null || string.IsNullOrEmpty(blockInfo.Begrundung.Trim()) || blockInfo.Begrundung.ToUpper().Contains("PKW"))
     {
         blockInfo.Begrundung = "als Wohnungseigentumsobjekt";
     }
 }
예제 #3
0
파일: ClientBase.cs 프로젝트: wyk125/AElf
        /// <summary>
        /// Try Take element from cached queue.
        /// </summary>
        /// <param name="millisecondsTimeout"></param>
        /// <param name="height">the height of block info needed</param>
        /// <param name="blockInfo"></param>
        /// <param name="cachingThreshold">Use <see cref="_cachedBoundedCapacity"/> as cache count threshold if true.</param>
        /// <returns></returns>
        public bool TryTake(int millisecondsTimeout, ulong height, out IBlockInfo blockInfo, bool cachingThreshold = false)
        {
            var first = First();

            if (first != null && first.Height == height && (!cachingThreshold || ToBeIndexedInfoQueue.Count >= _cachedBoundedCapacity))
            {
                var res = ToBeIndexedInfoQueue.TryTake(out blockInfo, millisecondsTimeout);
                if (res)
                {
                    CacheBlockInfo(blockInfo);
                }
                else
                {
                    _logger?.Trace($"Timeout to get cached data from chain {_targetChainId}");
                }
                return(res);
            }

            blockInfo = CachedInfoQueue.FirstOrDefault(c => c.Height == height);
            if (blockInfo != null)
            {
                return(!cachingThreshold ||
                       ToBeIndexedInfoQueue.Count + CachedInfoQueue.Count(ci => ci.Height >= height) >=
                       _cachedBoundedCapacity);
            }

            //_logger?.Trace($"Not found cached data from chain {_targetChainId} at height {height}");
            return(false);
        }
예제 #4
0
        /// <summary>
        /// Try Take element from cached queue.
        /// </summary>
        /// <param name="height">Height of block info needed</param>
        /// <param name="blockInfo"></param>
        /// <param name="isCacheSizeLimited">Use <see cref="_cachedBoundedCapacity"/> as cache count threshold if true.</param>
        /// <returns></returns>
        public bool TryTake(long height, out IBlockInfo blockInfo, bool isCacheSizeLimited)
        {
            // clear outdated data
            var cachedInQueue = CacheBlockInfoBeforeHeight(height);
            // isCacheSizeLimited means minimal caching size limit, so that most nodes have this block.
            var lastQueuedHeight = ToBeIndexedBlockInfoQueue.LastOrDefault()?.Height ?? 0;

            if (cachedInQueue && !(isCacheSizeLimited && lastQueuedHeight < height + CrossChainConstants.MinimalBlockInfoCacheThreshold))
            {
                var res = ToBeIndexedBlockInfoQueue.TryTake(out blockInfo,
                                                            CrossChainConstants.WaitingIntervalInMillisecond);
                if (res)
                {
                    CacheBlockInfo(blockInfo);
                }
                return(res);
            }

            blockInfo = LastBlockInfoInCache(height);
            if (blockInfo != null)
            {
                return(!isCacheSizeLimited ||
                       ToBeIndexedBlockInfoQueue.Count + CachedIndexedBlockInfoQueue.Count(ci => ci.Height >= height)
                       >= CrossChainConstants.MinimalBlockInfoCacheThreshold);
            }

            return(false);
        }
예제 #5
0
 /// <summary>
 /// Cache block info lately removed.
 /// Dequeue one element if the cached count reaches <see cref="_cachedBoundedCapacity"/>
 /// </summary>
 /// <param name="blockInfo"></param>
 private void CacheBlockInfo(IBlockInfo blockInfo)
 {
     CachedIndexedBlockInfoQueue.Enqueue(blockInfo);
     if (CachedIndexedBlockInfoQueue.Count <= _cachedBoundedCapacity)
     {
         return;
     }
     CachedIndexedBlockInfoQueue.Dequeue();
 }
예제 #6
0
 public BlockSummaryModel(IBlockInfo blockInfo)
 {
     Height   = blockInfo.Height;
     Hash     = blockInfo.Hash;
     Header   = blockInfo.Block.Header;
     TxCount  = blockInfo.Block.Transactions.Count;
     TxTotal  = blockInfo.Block.Transactions.Sum(tx => tx.TotalOut);
     Size     = blockInfo.Block.GetSerializedSize();
     Time     = Utils.UnixTimeToDateTime(blockInfo.Block.Header.Time);
     PosBlock = blockInfo.Block.Transactions.Any(tx => tx.IsCoinStake);
 }
예제 #7
0
 public BlockSummaryEntity(string partitionKey, IBlockInfo block)
     : base(partitionKey)
 {
     Height   = block.Height;
     Hash     = block.BlockId;
     TxCount  = block.Block.Transactions.Count;
     TxTotal  = block.Block.Transactions.Sum(tx => tx.TotalOut);
     Size     = block.Block.GetSerializedSize();
     Time     = NBitcoin.Utils.UnixTimeToDateTime(block.Block.Header.Time);
     PosBlock = block.Block.Transactions.Any(tx => tx.IsCoinStake);
 }
예제 #8
0
        private static string GetM2(IBlockInfo bi)
        {
            var m2S = bi.Flaeche.Trim().Replace(".", "").Replace(',', '.');
            int iom = m2S.IndexOf('m');

            if (iom >= 0)
            {
                m2S = m2S.Substring(0, iom);
            }
            m2S = m2S.Trim();
            return(m2S);
        }
예제 #9
0
        private async Task <List <AddressTransactionModel> > GetTransferAsync(IBlockInfo blockInfo, Transaction tx)
        {
            var results = new List <AddressTransactionModel>();

            foreach (var txInput in tx.Inputs)
            {
                var txIn = await _blockRepository.GetTrxAsync(txInput.PrevOut.Hash).ConfigureAwait(false);

                var txInValue   = txIn.Outputs[txInput.PrevOut.N].Value;
                var txInAddress = txIn.Outputs[txInput.PrevOut.N].ScriptPubKey.GetDestinationAddress(_network);
                if (txInAddress == null)
                {
                    var txInKeys = txIn.Outputs[txInput.PrevOut.N].ScriptPubKey.GetDestinationPublicKeys();
                    txInAddress = txInKeys.Single().GetAddress(_network);
                }

                results.Add(new AddressTransactionModel
                {
                    Address     = txInAddress.ToString(),
                    TxId        = tx.GetHash(),
                    BlockId     = blockInfo.Hash,
                    BlockHeight = blockInfo.Height,
                    Time        = NBitcoin.Utils.UnixTimeToDateTime(tx.Time),
                    Value       = -txInValue,
                    TxType      = TransactionType.Normal
                });
            }
            ;

            foreach (var txOutput in tx.Outputs)
            {
                var txOutAddress = txOutput.ScriptPubKey.GetDestinationAddress(_network);
                if (txOutAddress == null)
                {
                    var txOutKeys = txOutput.ScriptPubKey.GetDestinationPublicKeys();
                    txOutAddress = txOutKeys.Single().GetAddress(_network);
                }

                results.Add(new AddressTransactionModel
                {
                    Address     = txOutAddress.ToString(),
                    TxId        = tx.GetHash(),
                    BlockId     = blockInfo.Hash,
                    BlockHeight = blockInfo.Height,
                    Time        = NBitcoin.Utils.UnixTimeToDateTime(tx.Time),
                    Value       = txOutput.Value,
                    TxType      = TransactionType.Normal
                });
            }
            ;

            return(results);
        }
예제 #10
0
        private bool IsChangeToWohnungseigentumsobjektBegrundung(IBlockInfo blockInfo)
        {
            if (blockInfo.Begrundung == null ||
                string.IsNullOrEmpty(blockInfo.Begrundung.Trim()) ||
                blockInfo.Begrundung.ToUpper().Contains("PKW") ||
                (string.IsNullOrEmpty(blockInfo.Top) && blockInfo.Top.ToUpper().Contains("ALLG"))
                )
            {
                return(true);
            }

            return(false);
        }
예제 #11
0
        public bool TryAdd(IBlockInfo blockInfo)
        {
            if (ToBeIndexedBlockInfoQueue.Count() >= _cachedBoundedCapacity)
            {
                return(false);
            }
            // thread unsafe in some extreme cases, but it can be covered with caching mechanism.
            if (blockInfo.Height != TargetChainHeight())
            {
                return(false);
            }
            var res = ToBeIndexedBlockInfoQueue.TryAdd(blockInfo);

            return(res);
        }
예제 #12
0
        public bool AddNewBlockInfo(IBlockInfo blockInfo)
        {
            if (blockInfo == null)
            {
                return(false);
            }
            var blockInfoCache = _multiChainBlockInfoCacheProvider.GetBlockInfoCache(blockInfo.ChainId);

            if (blockInfoCache == null)
            {
                return(false);
            }
            var res = blockInfoCache.TryAdd(blockInfo);

            return(res);
        }
예제 #13
0
        /// <summary>
        /// generate a variable
        /// </summary>
        /// <param name="fromIndex">from index of source string</param>
        /// <param name="source">source string</param>
        /// <param name="blockInfo">block of variable</param>
        /// <param name="compiler">compile for new variable ids</param>
        /// <returns>new index of source to find next objects</returns>
        public static int GenerateVariable(int fromIndex, ref string source, IBlockInfo blockInfo, ICompiler compiler)
        {
            int           i             = fromIndex + 1;
            StringBuilder stringBuilder = new StringBuilder();

            //find end of variable
            for (; i < source.Length; i++)
            {
                char currentChar = source[i];
                if (currentChar == ';')
                {
                    break;
                }
                stringBuilder.Append(currentChar);
            }
            //create variable
            VariableLine variableLine = new VariableLine();
            string       result       = stringBuilder.ToString();
            //split if variable has = char
            int indexOfEqual = result.IndexOf('=');

            string leftSideOfEqual = "", rightSideOfEqual = "";

            if (indexOfEqual > 0)
            {
                //left side of '=' char
                leftSideOfEqual = result.Substring(0, indexOfEqual);
                //right side of '=' char
                rightSideOfEqual = result.Substring(indexOfEqual + 1);
            }
            else
            {
                leftSideOfEqual = result;
            }
            //set variable name
            variableLine.Name = leftSideOfEqual.Trim();
            //set variable value
            variableLine.Value = rightSideOfEqual;
            //add variable to block with new id
            blockInfo.Variables.Add(compiler.GetNewPointerId, variableLine);
            return(i);
        }
예제 #14
0
        public static IEnumerable <BlockEntity> GetBlockEntries(string partitionKey, IBlockInfo blockInfo)
        {
            var results = new List <BlockEntity>();

            var block = blockInfo.Block.ToBytes();
            var parts = 0;
            var index = 0;

            var b = new BlockEntity(partitionKey)
            {
                Hash  = blockInfo.BlockId,
                Index = index
            };

            results.Add(b);

            foreach (var part in block.Split(64))
            {
                b.Chunks.Add(part.ToArray());
                parts++;

                if (parts != 200)
                {
                    continue;
                }

                parts = 0;
                index++;
                b = new BlockEntity(partitionKey)
                {
                    Hash  = blockInfo.BlockId,
                    Index = index
                };
                results.Add(b);
            }

            return(results);
        }
예제 #15
0
        public void UpdateValuesFrom(IBlockInfo acadBlockInfo)
        {
            Top        = acadBlockInfo.Top;
            Lage       = acadBlockInfo.Geschoss;
            Raum       = acadBlockInfo.Raum;
            RNW        = acadBlockInfo.Nutzwert.Trim();
            Begrundung = acadBlockInfo.Begrundung;
            Widmung    = acadBlockInfo.Widmung;
            if (string.IsNullOrEmpty(RNW))
            {
                // todo: rnw darf nicht mehr leer sein. wenn rnw nicht vorhanden ist, dann kommt er aus dem top-block der wohnung
                // ALLG – Flächen haben keinen Wohnungsblock. Woher kommt der Nutzwert? Bisher wurde dieser immer auf 1.0 gesetzt.
                //throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "Kein Nutzwert {2} in {0}, Top {1}.", acadBlockInfo.Raum, acadBlockInfo.Top, acadBlockInfo.Nutzwert));
                Nutzwert = 1.0;
            }
            else
            {
                double nutzwert;
                var    rnw = RNW.Replace(',', '.');
                if (!double.TryParse(rnw, NumberStyles.Any, CultureInfo.CurrentCulture, out nutzwert))
                {
                    throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "Ungültiger Nutzwert {2} in {0}, Top {1}.", acadBlockInfo.Raum, acadBlockInfo.Top, acadBlockInfo.Nutzwert));
                }
                Nutzwert = nutzwert;
            }
            var    m2S = GetM2(acadBlockInfo);
            double m2;

            if (!double.TryParse(m2S, out m2))
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "Ungültige Fläche {2} in {0}, Top {1}.", acadBlockInfo.Raum, acadBlockInfo.Top, acadBlockInfo.Flaeche));
            }

            //WidmungAndBegrundungCorrection();

            Flaeche    = m2;
            AcadHandle = acadBlockInfo.Handle;
        }
예제 #16
0
        private Task <List <AddressTransactionModel> > GetCoinBaseAsync(IBlockInfo blockInfo, Transaction tx)
        {
            var vout    = tx.Outputs.Single();
            var address = vout.ScriptPubKey.GetDestinationAddress(_network);

            if (address == null)
            {
                return(Task.FromResult(new List <AddressTransactionModel>()));
            }

            return(Task.FromResult(new List <AddressTransactionModel>
            {
                new AddressTransactionModel
                {
                    Address = address.ToString(),
                    TxId = tx.GetHash(),
                    BlockId = blockInfo.Hash,
                    BlockHeight = blockInfo.Height,
                    Time = NBitcoin.Utils.UnixTimeToDateTime(tx.Time),
                    Value = vout.Value,
                    TxType = TransactionType.CoinBase
                }
            }));
        }
 public BlockInfoModel(IBlockInfo blockInfo)
 {
     Hash   = blockInfo.Hash;
     Height = blockInfo.Height;
     Block  = blockInfo.Block;
 }
예제 #18
0
 public AbstractBlock(ChunkEntity chunk, IntVector3 position)
 {
     Chunk = chunk;
     Position = position;
     Info = new BlockInfo();
 }
예제 #19
0
 /// <summary>
 /// Update side chain information
 /// </summary>
 /// <param name="blockInfo"></param>
 /// <returns></returns>
 private async Task UpdateCrossChainInfo(IBlockInfo blockInfo)
 {
     await _chainManagerBasic.UpdateCurrentBlockHeightAsync(blockInfo.ChainId, blockInfo.Height);
 }
예제 #20
0
        private async Task <List <AddressTransactionModel> > GetCoinStakeAsync(IBlockInfo blockInfo, Transaction tx)
        {
            var prevOut = tx.Inputs.Single().PrevOut;

            var txIn = await _blockRepository.GetTrxAsync(prevOut.Hash).ConfigureAwait(false);

            var txInAddress = txIn.Outputs[prevOut.N].ScriptPubKey.GetDestinationAddress(_network);

            if (txInAddress == null)
            {
                var txInKeys = txIn.Outputs[prevOut.N].ScriptPubKey.GetDestinationPublicKeys();
                txInAddress = txInKeys.Single().GetAddress(_network);
            }

            var txOutAddress1 = tx.Outputs[1].ScriptPubKey.GetDestinationAddress(_network);

            if (txOutAddress1 == null)
            {
                var txOutKeys = tx.Outputs[1].ScriptPubKey.GetDestinationPublicKeys();
                txOutAddress1 = txOutKeys.Single().GetAddress(_network);
            }

            var   txInValue = txIn.Outputs[prevOut.N].Value;
            Money change    = 0;

            if (tx.Outputs.Count == 2)
            {
                if (!txInAddress.Equals(txOutAddress1))
                {
                    throw new InvalidOperationException("coinstake invalid");
                }

                change = tx.Outputs[1].Value - txInValue;
            }
            else
            {
                var txOutAddress2 = tx.Outputs[2].ScriptPubKey.GetDestinationAddress(_network);
                if (txOutAddress2 == null)
                {
                    var txOutKeys = tx.Outputs[2].ScriptPubKey.GetDestinationPublicKeys();
                    txOutAddress2 = txOutKeys.Single().GetAddress(_network);
                }

                if (!txInAddress.Equals(txOutAddress1) || !txInAddress.Equals(txOutAddress2))
                {
                    throw new InvalidOperationException("coinstake invalid");
                }

                var txOutValue = tx.Outputs[1].Value + tx.Outputs[2].Value;
                change = txOutValue - txInValue;
            }

            return(new List <AddressTransactionModel>
            {
                new AddressTransactionModel
                {
                    Kind = AddressKind.Transaction,
                    Address = txInAddress.ToString(),
                    TxId = tx.GetHash(),
                    BlockId = blockInfo.Hash,
                    BlockHeight = blockInfo.Height,
                    Time = NBitcoin.Utils.UnixTimeToDateTime(tx.Time),
                    Value = change,
                    TxType = TransactionType.CoinStake
                }
            });
        }
예제 #21
0
 public BlockHeightModel(IBlockInfo blockInfo)
 {
     Hash   = blockInfo.Hash;
     Height = blockInfo.Height;
 }