Beispiel #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;
                    }
                }
            }
        }
Beispiel #2
0
        public void SetLocation(TransactionContext transactionContext, byte[] item, LocationEnum location)
        {
            transactionContext.Transaction.Insert <byte[], int>(LOCATIONS, item, (int)location);

            var block = Get(transactionContext, item).Value;

            foreach (var txHash in block.TxHashes)
            {
                var tx = TxStore.Get(transactionContext, txHash);
                TxStore.Put(transactionContext, txHash, tx.Value.Tx, false);
            }
        }
Beispiel #3
0
        public Keyed <Types.Block> GetBlock(TransactionContext transactionContext, byte[] key)
        {
            var _block = Get(transactionContext, key);

            if (_block == null)
            {
                BlockChainTrace.Information("Block not found: " + Convert.ToBase64String(key));
                return(null);
            }
            else
            {
                var txs = _block.Value.TxHashes.Select(t => TxStore.Get(transactionContext, t).Value).ToList();

                var block = new Types.Block(_block.Value.BlockHeader, ListModule.OfSeq <Types.Transaction>(txs.Select(t => t.Tx)));

                return(new Keyed <Types.Block>(key, block));
            }
        }