Esempio n. 1
0
        public void Put(
            TransactionContext transactionContext,
            byte[] BkHash,
            Types.Block block,
            LocationEnum location,
            double totalWork)
        {
            var txs = block.transactions.Select(t =>
            {
                return(new KeyValuePair <byte[], Types.Transaction>(Merkle.transactionHasher.Invoke(t), t));
            });

            Put(transactionContext, BkHash, new Block
            {
                BlockHeader = block.header,
                TxHashes    = txs.Select(t => t.Key).ToList()
            });

            //children
            var children = new HashSet <byte[]>();

            children.Add(BkHash);

            transactionContext.Transaction.InsertHashSet <byte[], byte[]>(
                CHILDREN,
                block.header.parent,
                children,
                0,
                false
                );

            //location
            transactionContext.Transaction.Insert <byte[], int>(LOCATIONS, BkHash, (int)location);

            //total work
            transactionContext.Transaction.Insert <byte[], double>(TOTAL_WORK, BkHash, totalWork);

            //transactions
            var isFirstTx = true;

            foreach (var tx in txs)
            {
                if (!TxStore.ContainsKey(transactionContext, tx.Key))
                {
                    TxStore.Put(transactionContext, tx.Key,
                                new Transaction {
                        Tx          = tx.Value,
                        InMainChain = false
                    });

                    if (isFirstTx)
                    {
                        transactionContext.Transaction.Insert <byte[], byte[]>(COINBASETX_BLOCK, tx.Key, BkHash);
                        isFirstTx = false;
                    }
                }
            }
        }