public MerkleTreeNode ReadNode()
        {
            var blockIndexColumn = new Int32ColumnValue { Columnid = cursor.blockIndexColumnId };
            var txIndexColumn = new Int32ColumnValue { Columnid = cursor.txIndexColumnId };
            var depthColumn = new Int32ColumnValue { Columnid = cursor.blockDepthColumnId };
            var txHashColumn = new BytesColumnValue { Columnid = cursor.blockTxHashColumnId };
            Api.RetrieveColumns(cursor.jetSession, cursor.blocksTableId, blockIndexColumn, txIndexColumn, depthColumn, txHashColumn);

            if (this.blockIndex != blockIndexColumn.Value.Value)
                throw new InvalidOperationException();

            var txIndex = txIndexColumn.Value.Value;
            var depth = depthColumn.Value.Value;
            var txHash = DbEncoder.DecodeUInt256(txHashColumn.Value);

            var pruned = depth >= 0;
            depth = Math.Max(0, depth);

            return new MerkleTreeNode(txIndex, depth, txHash, pruned);
        }
        private void InitColumns()
        {

            _colIdShapeLabel = Api.GetTableColumnid(sesid, table, colNameShapeLabel);
            _colIdIfcShapeLabel = Api.GetTableColumnid(sesid, table, colNameIfcShapeLabel);
            _colIdGeometryHash = Api.GetTableColumnid(sesid, table, colNameGeometryHash);
            _colIdCost = Api.GetTableColumnid(sesid, table, colNameCost);
            _colIdReferenceCount = Api.GetTableColumnid(sesid, table, colNameReferenceCount);
            _colIdLOD = Api.GetTableColumnid(sesid, table, colNameLOD);
            _colIdFormat = Api.GetTableColumnid(sesid, table, colNameFormat);
            _colIdBoundingBox = Api.GetTableColumnid(sesid, table, colNameBoundingBox);
            _colIdShapeData = Api.GetTableColumnid(sesid, table, colNameShapeData);

            _colValShapeLabel = new Int32ColumnValue { Columnid = _colIdShapeLabel };
            _colValIfcShapeLabel = new Int32ColumnValue { Columnid = _colIdIfcShapeLabel };
            _colValGeometryHash = new Int32ColumnValue { Columnid = _colIdGeometryHash };
            _colValCost = new Int32ColumnValue { Columnid = _colIdCost };
            _colValReferenceCount = new Int32ColumnValue { Columnid = _colIdReferenceCount };
            _colValLOD = new ByteColumnValue { Columnid = _colIdLOD };
            _colValFormat = new ByteColumnValue { Columnid = _colIdFormat };
            _colValBoundingBox = new BytesColumnValue { Columnid = _colIdBoundingBox };
            _colValShapeData = new BytesColumnValue { Columnid = _colIdShapeData }; 


            _colValues = new ColumnValue[] { _colValIfcShapeLabel, _colValGeometryHash, _colValCost, _colValReferenceCount, _colValLOD, _colValFormat,_colValBoundingBox,_colValShapeData };



        }
Пример #3
0
        private void InitColumns()
        {
           // IDictionary<string, JET_COLUMNID> columnids = Api.GetColumnDictionary(_jetSession, _jetCursor);
            _colIdHeaderId = Api.GetTableColumnid(_jetSession, _jetCursor, _colNameHeaderId);
            _colIdEntityCount = Api.GetTableColumnid(_jetSession, _jetCursor, _colNameEntityCount);
            _colIdFileVersion = Api.GetTableColumnid(_jetSession, _jetCursor, _colNameFileVersion);
            _colIdHeaderData = Api.GetTableColumnid(_jetSession, _jetCursor, _colNameHeaderData);
            
            _colValHeaderId = new Int32ColumnValue { Columnid = _colIdHeaderId };
            _colValEntityCount = new Int64ColumnValue { Columnid = _colIdEntityCount };
            _colValFileVersion = new StringColumnValue { Columnid = _colIdFileVersion };
            _colValHeaderData = new BytesColumnValue { Columnid = _colIdHeaderData };
           

        }
        private void InitColumns()
        {
            _colIdInstanceLabel = Api.GetTableColumnid(sesid, table, colNameInstanceLabel);
            _colIdIfcTypeId = Api.GetTableColumnid(sesid, table, colNameIfcTypeId);
            _colIdIfcProductLabel = Api.GetTableColumnid(sesid, table, colNameIfcProductLabel);
            _colIdStyleLabel = Api.GetTableColumnid(sesid, table, colNameStyleLabel);
            _colIdShapeLabel = Api.GetTableColumnid(sesid, table, colNameShapeLabel);
            _colIdRepresentationContext = Api.GetTableColumnid(sesid, table, colNameRepresentationContext);
            _colIdRepType = Api.GetTableColumnid(sesid, table, colNameRepType);
            _colIdTransformation = Api.GetTableColumnid(sesid, table, colNameTransformation);
            _colIdBoundingBox = Api.GetTableColumnid(sesid, table, colNameBoundingBox);

            _colValInstanceLabel = new Int32ColumnValue { Columnid = _colIdInstanceLabel };
            _colValIfcTypeId = new Int16ColumnValue { Columnid = _colIdIfcTypeId };
            _colValIfcProductLabel = new Int32ColumnValue { Columnid = _colIdIfcProductLabel };
            _colValStyleLabel = new Int32ColumnValue { Columnid = _colIdStyleLabel };
            _colValShapeLabel = new Int32ColumnValue { Columnid = _colIdShapeLabel };
            _colValRepresentationContext = new Int32ColumnValue { Columnid = _colIdRepresentationContext };
            _colValRepType = new ByteColumnValue { Columnid = _colIdRepType };
            _colValTransformation = new BytesColumnValue { Columnid = _colIdTransformation };
            _colValBoundingBox = new BytesColumnValue { Columnid = _colIdBoundingBox };

            _colValues = new ColumnValue[] { _colValIfcTypeId, _colValIfcProductLabel, _colValStyleLabel, _colValShapeLabel, _colValRepresentationContext, _colValRepType, _colValTransformation,_colValBoundingBox, };
        }
Пример #5
0
        public bool TryGetTransaction(UInt256 blockHash, int txIndex, out BlockTx transaction)
        {
            using (var handle = this.cursorCache.TakeItem())
            {
                var cursor = handle.Item;

                using (var jetTx = cursor.jetSession.BeginTransaction())
                {
                    int blockIndex;
                    if (!TryGetBlockIndex(cursor, blockHash, out blockIndex))
                    {
                        transaction = null;
                        return false;
                    }

                    Api.JetSetCurrentIndex(cursor.jetSession, cursor.blocksTableId, "IX_BlockIndexTxIndex");
                    Api.MakeKey(cursor.jetSession, cursor.blocksTableId, blockIndex, MakeKeyGrbit.NewKey);
                    Api.MakeKey(cursor.jetSession, cursor.blocksTableId, txIndex, MakeKeyGrbit.None);
                    if (Api.TrySeek(cursor.jetSession, cursor.blocksTableId, SeekGrbit.SeekEQ))
                    {
                        var blockTxHashColumn = new BytesColumnValue { Columnid = cursor.blockTxHashColumnId };
                        var blockTxBytesColumn = new BytesColumnValue { Columnid = cursor.blockTxBytesColumnId };
                        Api.RetrieveColumns(cursor.jetSession, cursor.blocksTableId, blockTxHashColumn, blockTxBytesColumn);

                        if (blockTxBytesColumn.Value != null)
                        {
                            var txHash = DbEncoder.DecodeUInt256(blockTxHashColumn.Value);
                            transaction = new BlockTx(txIndex, txHash, blockTxBytesColumn.Value.ToImmutableArray());
                            return true;
                        }
                        else
                        {
                            transaction = null;
                            return false;
                        }
                    }
                    else
                    {
                        transaction = null;
                        return false;
                    }
                }
            }
        }
Пример #6
0
        private IEnumerator<BlockTxNode> ReadBlockTransactions(UInt256 blockHash, bool requireTx)
        {
            using (var handle = this.cursorCache.TakeItem())
            {
                var cursor = handle.Item;

                using (var jetTx = cursor.jetSession.BeginTransaction())
                {
                    int blockIndex;
                    if (!TryGetBlockIndex(cursor, blockHash, out blockIndex))
                        throw new MissingDataException(blockHash);

                    Api.JetSetCurrentIndex(cursor.jetSession, cursor.blocksTableId, "IX_BlockIndexTxIndex");

                    Api.MakeKey(cursor.jetSession, cursor.blocksTableId, blockIndex, MakeKeyGrbit.NewKey);
                    Api.MakeKey(cursor.jetSession, cursor.blocksTableId, 0, MakeKeyGrbit.None);
                    if (!Api.TrySeek(cursor.jetSession, cursor.blocksTableId, SeekGrbit.SeekGE))
                        throw new MissingDataException(blockHash);

                    Api.MakeKey(cursor.jetSession, cursor.blocksTableId, blockIndex, MakeKeyGrbit.NewKey);
                    Api.MakeKey(cursor.jetSession, cursor.blocksTableId, int.MaxValue, MakeKeyGrbit.None);
                    if (!Api.TrySetIndexRange(cursor.jetSession, cursor.blocksTableId, SetIndexRangeGrbit.RangeUpperLimit))
                        throw new MissingDataException(blockHash);

                    do
                    {
                        var txIndexColumn = new Int32ColumnValue { Columnid = cursor.txIndexColumnId };
                        var blockDepthColumn = new Int32ColumnValue { Columnid = cursor.blockDepthColumnId };
                        var blockTxHashColumn = new BytesColumnValue { Columnid = cursor.blockTxHashColumnId };
                        var blockTxBytesColumn = new BytesColumnValue { Columnid = cursor.blockTxBytesColumnId };
                        Api.RetrieveColumns(cursor.jetSession, cursor.blocksTableId, txIndexColumn, blockDepthColumn, blockTxHashColumn, blockTxBytesColumn);

                        var txIndex = txIndexColumn.Value.Value;
                        var depth = blockDepthColumn.Value.Value;
                        var txHash = DbEncoder.DecodeUInt256(blockTxHashColumn.Value);
                        var txBytes = blockTxBytesColumn.Value;

                        // determine if transaction is pruned by its depth
                        var pruned = depth >= 0;
                        depth = Math.Max(0, depth);

                        if (pruned && requireTx)
                            throw new MissingDataException(blockHash);

                        var blockTxNode = new BlockTxNode(txIndex, depth, txHash, pruned, txBytes?.ToImmutableArray());

                        yield return blockTxNode;
                    }
                    while (Api.TryMoveNext(cursor.jetSession, cursor.blocksTableId));
                }
            }
        }
Пример #7
0
        public bool TryGetUnspentTxOutput(TxOutputKey txOutputKey, out TxOutput txOutput)
        {
            CheckTransaction();

            using (SetSessionContext())
            {
                Api.JetSetCurrentIndex(this.jetSession, this.unspentTxOutputTableId, "IX_TxOutputKey");
                Api.MakeKey(this.jetSession, this.unspentTxOutputTableId, DbEncoder.EncodeTxOutputKey(txOutputKey), MakeKeyGrbit.NewKey);
                if (Api.TrySeek(this.jetSession, this.unspentTxOutputTableId, SeekGrbit.SeekEQ))
                {
                    var txOutputBytesColumn = new BytesColumnValue { Columnid = this.txOutputBytesColumnId };
                    Api.RetrieveColumns(this.jetSession, this.unspentTxOutputTableId, txOutputBytesColumn);

                    txOutput = DataDecoder.DecodeTxOutput(txOutputBytesColumn.Value);
                    return true;
                }

                txOutput = default(TxOutput);
                return false;
            }
        }
Пример #8
0
        private IEnumerable<UnspentTx> ReadUnspentTransactionsInner()
        {
            using (SetSessionContext())
            {
                Api.JetSetCurrentIndex(this.jetSession, this.unspentTxTableId, "IX_TxHash");

                if (Api.TryMoveFirst(this.jetSession, this.unspentTxTableId))
                {
                    do
                    {
                        var txHashColumn = new BytesColumnValue { Columnid = this.txHashColumnId };
                        var blockIndexColumn = new Int32ColumnValue { Columnid = this.blockIndexColumnId };
                        var txIndexColumn = new Int32ColumnValue { Columnid = this.txIndexColumnId };
                        var txVersionColumn = new UInt32ColumnValue { Columnid = this.txVersionColumnId };
                        var isCoinbaseColumn = new BoolColumnValue { Columnid = this.isCoinbaseColumnId };
                        var outputStatesColumn = new BytesColumnValue { Columnid = this.outputStatesColumnId };
                        var txOutputBytesColumn = new BytesColumnValue { Columnid = this.txOutputBytesColumnId };
                        Api.RetrieveColumns(this.jetSession, this.unspentTxTableId, txHashColumn, blockIndexColumn, txIndexColumn, txVersionColumn, isCoinbaseColumn, outputStatesColumn, txOutputBytesColumn);

                        var txHash = DbEncoder.DecodeUInt256(txHashColumn.Value);
                        var blockIndex = blockIndexColumn.Value.Value;
                        var txIndex = txIndexColumn.Value.Value;
                        var txVersion = txVersionColumn.Value.Value;
                        var isCoinbase = isCoinbaseColumn.Value.Value;
                        var outputStates = DataDecoder.DecodeOutputStates(outputStatesColumn.Value);

                        yield return new UnspentTx(txHash, blockIndex, txIndex, txVersion, isCoinbase, outputStates);
                    }
                    while (Api.TryMoveNext(this.jetSession, this.unspentTxTableId));
                }
            }
        }
Пример #9
0
        public bool TryGetUnspentTx(UInt256 txHash, out UnspentTx unspentTx)
        {
            CheckTransaction();

            using (SetSessionContext())
            {
                Api.JetSetCurrentIndex(this.jetSession, this.unspentTxTableId, "IX_TxHash");
                Api.MakeKey(this.jetSession, this.unspentTxTableId, DbEncoder.EncodeUInt256(txHash), MakeKeyGrbit.NewKey);
                if (Api.TrySeek(this.jetSession, this.unspentTxTableId, SeekGrbit.SeekEQ))
                {
                    var blockIndexColumn = new Int32ColumnValue { Columnid = this.blockIndexColumnId };
                    var txIndexColumn = new Int32ColumnValue { Columnid = this.txIndexColumnId };
                    var txVersionColumn = new UInt32ColumnValue { Columnid = this.txVersionColumnId };
                    var isCoinbaseColumn = new BoolColumnValue { Columnid = this.isCoinbaseColumnId };
                    var outputStatesColumn = new BytesColumnValue { Columnid = this.outputStatesColumnId };
                    var txOutputBytesColumn = new BytesColumnValue { Columnid = this.txOutputBytesColumnId };
                    Api.RetrieveColumns(this.jetSession, this.unspentTxTableId, blockIndexColumn, txIndexColumn, txVersionColumn, isCoinbaseColumn, outputStatesColumn, txOutputBytesColumn);

                    var blockIndex = blockIndexColumn.Value.Value;
                    var txIndex = txIndexColumn.Value.Value;
                    var txVersion = txVersionColumn.Value.Value;
                    var isCoinbase = isCoinbaseColumn.Value.Value;
                    var outputStates = DataDecoder.DecodeOutputStates(outputStatesColumn.Value);

                    unspentTx = new UnspentTx(txHash, blockIndex, txIndex, txVersion, isCoinbase, outputStates);
                    return true;
                }

                unspentTx = default(UnspentTx);
                return false;
            }
        }
Пример #10
0
 public void TestBytesValueAsObject()
 {
     byte[] data = Any.Bytes;
     var instance = new BytesColumnValue { Value = data };
     Assert.AreEqual(data, instance.ValueAsObject);
 }
Пример #11
0
        private void InitColumns()
        {

            _colIdGeometryLabel = Api.GetTableColumnid(sesid, table, colNameGeometryLabel);
            _colIdGeomType = Api.GetTableColumnid(sesid, table, colNameGeomType);
            _colIdProductIfcTypeId = Api.GetTableColumnid(sesid, table, colNameProductIfcTypeId);
            _colIdProductLabel = Api.GetTableColumnid(sesid, table, colNameProductLabel);
            _colIdSubPart = Api.GetTableColumnid(sesid, table, colNameSubPart);
            _colIdTransformMatrix = Api.GetTableColumnid(sesid, table, colNameTransformMatrix);
            _colIdShapeData = Api.GetTableColumnid(sesid, table, colNameShapeData);
            _colIdGeometryHash = Api.GetTableColumnid(sesid, table, colNameGeometryHash);
            _colIdStyleLabel = Api.GetTableColumnid(sesid, table, colNameStyleLabel);

            _colValGeometryLabel = new Int32ColumnValue { Columnid = _colIdGeometryLabel };
            _colValGeomType = new ByteColumnValue { Columnid = _colIdGeomType };
            _colValProductIfcTypeId = new Int16ColumnValue { Columnid = _colIdProductIfcTypeId };
            _colValProductLabel = new Int32ColumnValue { Columnid = _colIdProductLabel };
            _colValSubPart = new Int16ColumnValue { Columnid = _colIdSubPart };
            _colValTransformMatrix = new BytesColumnValue { Columnid = _colIdTransformMatrix };
            _colValShapeData = new BytesColumnValue { Columnid = _colIdShapeData };
            _colValGeometryHash = new Int32ColumnValue { Columnid = _colIdGeometryHash };
            _colValStyleLabel = new Int32ColumnValue { Columnid = _colIdStyleLabel };
            _colValues = new ColumnValue[] { _colValGeomType, _colValProductLabel, _colValProductIfcTypeId, _colValSubPart, _colValTransformMatrix, _colValShapeData, _colValGeometryHash , _colValStyleLabel};

        }