当前位置: 首页>>代码示例>>C#>>正文


C# UInt256类代码示例

本文整理汇总了C#中UInt256的典型用法代码示例。如果您正苦于以下问题:C# UInt256类的具体用法?C# UInt256怎么用?C# UInt256使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


UInt256类属于命名空间,在下文中一共展示了UInt256类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: LevelDBBlockchain

 public LevelDBBlockchain()
 {
     Slice value;
     db = DB.Open(Settings.Default.DataDirectoryPath);
     if (db.TryGet(ReadOptions.Default, SliceBuilder.Begin(DataEntryPrefix.CFG_Initialized), out value) && value.ToBoolean())
     {
         value = db.Get(ReadOptions.Default, SliceBuilder.Begin(DataEntryPrefix.SYS_CurrentBlock));
         this.current_block = new UInt256(value.ToArray().Take(32).ToArray());
         this.current_height = BitConverter.ToUInt32(value.ToArray(), 32);
     }
     else
     {
         WriteBatch batch = new WriteBatch();
         ReadOptions options = new ReadOptions { FillCache = false };
         using (Iterator it = db.NewIterator(options))
         {
             for (it.SeekToFirst(); it.Valid(); it.Next())
             {
                 batch.Delete(it.Key());
             }
         }
         batch.Put(SliceBuilder.Begin(DataEntryPrefix.CFG_Version), 0);
         db.Write(WriteOptions.Default, batch);
         AddBlockToChain(GenesisBlock);
         db.Put(WriteOptions.Default, SliceBuilder.Begin(DataEntryPrefix.CFG_Initialized), true);
     }
     thread_persistence = new Thread(PersistBlocks);
     thread_persistence.Name = "LevelDBBlockchain.PersistBlocks";
     thread_persistence.Start();
     AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit;
 }
开发者ID:4T-Shirt,项目名称:AntShares,代码行数:31,代码来源:LevelDBBlockchain.cs

示例2: TxOutputKey

        public TxOutputKey(UInt256 txHash, UInt32 txOutputIndex)
        {
            TxHash = txHash;
            TxOutputIndex = txOutputIndex;

            this.hashCode = txHash.GetHashCode() ^ txOutputIndex.GetHashCode();
        }
开发者ID:ArsenShnurkov,项目名称:BitSharp,代码行数:7,代码来源:TxOutputKey.cs

示例3: TryReadValue

        public bool TryReadValue(UInt256 blockHash, out ImmutableArray<Transaction> blockTransactions)
        {
            using (var conn = this.OpenConnection())
            using (var cmd = conn.CreateCommand())
            {
                cmd.CommandText = @"
                    SELECT MinTxIndex, MaxTxIndex, TxChunkBytes
                    FROM BlockTransactionsChunked
                    WHERE BlockHash = @blockHash
                    ORDER BY MinTxIndex ASC";

                cmd.Parameters.SetValue("@blockHash", SqlDbType.Binary, 32).Value = blockHash.ToDbByteArray();

                using (var reader = cmd.ExecuteReader())
                {
                    var blockTransactionsBuilder = ImmutableArray.CreateBuilder<Transaction>();

                    while (reader.Read())
                    {
                        var minTxIndex = reader.GetInt32(0);
                        var maxTxIndex = reader.GetInt32(1);
                        var txChunkBytes = reader.GetBytes(2);

                        var txChunkStream = txChunkBytes.ToMemoryStream();
                        for (var i = minTxIndex; i <= maxTxIndex; i++)
                        {
                            blockTransactionsBuilder.Add(StorageEncoder.DecodeTransaction(txChunkStream));
                        }
                    }

                    blockTransactions = blockTransactionsBuilder.ToImmutable();
                    return blockTransactions.Length > 0;
                }
            }
        }
开发者ID:knocte,项目名称:BitSharp,代码行数:35,代码来源:BlockTransactionsStorage.cs

示例4: ScanHash_CryptoPP

        protected override List<uint> ScanHash_CryptoPP(MinerData md, UInt256 target)
        {
            uint nonce = (uint)md.nHashesDone;
            List<uint> results = new List<uint>(1);

            UInt256 hashResult = new UInt256();

            byte[] tmp = new byte[16 * 4];

            DateTime endLhutc = DateTime.UtcNow + new TimeSpan(0, 0, 1);
            long count = 0;
            while (true)
            {
                count++;
                Single(md, hashResult, nonce, tmp);

                var lastInt = BitConverter.ToInt32(hashResult.bytes, 7*4);
                if (lastInt == 0 && hashResult.CompareTo(target) < 0)
                    results.Add(nonce);

                nonce++;

                if (DateTime.UtcNow >= endLhutc || nonce == 0)
                    break;
            }

            md.nHashesDone += count;
            HashedSome(count);

            return results;
        }
开发者ID:pointgaming,项目名称:point-gaming-desktop,代码行数:31,代码来源:CPUThreadMiner.cs

示例5: PublicKeyHashAddress

        public PublicKeyHashAddress(ImmutableArray<byte> publicKeyHashBytes)
        {
            this.publicKeyHashBytes = publicKeyHashBytes;

            var outputScript = new PayToPublicKeyHashBuilder().CreateOutputFromPublicKeyHash(publicKeyHashBytes.ToArray());
            this.outputScriptHash = new UInt256(SHA256Static.ComputeHash(outputScript));
        }
开发者ID:cole2295,项目名称:BitSharp,代码行数:7,代码来源:PublicKeyHashAddress.cs

示例6: VerifyScript

        public bool VerifyScript(UInt256 blockHash, int txIndex, byte[] scriptPubKey, Transaction tx, int inputIndex, byte[] script)
        {
            if (logger.IsTraceEnabled)
                logger.Trace(
@"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Verifying script for block {0}, transaction {1}, input {2}
{3}
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
                    , blockHash, txIndex, inputIndex, script.ToArray().ToHexDataString());

            Stack stack, altStack;
            if (
                ExecuteOps(scriptPubKey, tx, inputIndex, script, out stack, out altStack)
                && stack.Count == 1 && altStack.Count == 0)
            {
                var success = stack.PeekBool(); //TODO Pop? does it matter?

                // Additional validation for spend-to-script-hash transactions:
                //TODO

                return success;
            }
            else
            {
                return false;
            }
        }
开发者ID:cole2295,项目名称:BitSharp,代码行数:27,代码来源:ScriptEngine.cs

示例7: MerkleTreePruningCursor

 public MerkleTreePruningCursor(UInt256 blockHash, LightningTransaction txn, LightningDatabase db, LightningCursor cursor)
 {
     this.blockHash = blockHash;
     this.db = db;
     this.txn = txn;
     this.cursor = cursor;
 }
开发者ID:ArsenShnurkov,项目名称:BitSharp,代码行数:7,代码来源:MerkleTreePruningCursor.cs

示例8: TryReadValue

        public bool TryReadValue(UInt256 txHash, out Transaction transaction)
        {
            using (var conn = this.OpenConnection())
            using (var cmd = conn.CreateCommand())
            {
                cmd.CommandText = @"
                    SELECT TxBytes
                    FROM BlockTransactions
                    WHERE TxHash = @txHash";

                cmd.Parameters.SetValue("@txHash", FbDbType.Char, FbCharset.Octets, 32).Value = txHash.ToDbByteArray();

                using (var reader = cmd.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        var txBytes = reader.GetBytes(0);

                        transaction = StorageEncoder.DecodeTransaction(txBytes.ToMemoryStream(), txHash);
                        return true;
                    }
                    else
                    {
                        transaction = default(Transaction);
                        return false;
                    }
                }
            }
        }
开发者ID:holinov,项目名称:BitSharp,代码行数:29,代码来源:TransactionStorage.cs

示例9: TryAddBlockTransactions

 public bool TryAddBlockTransactions(UInt256 blockHash, IEnumerable<EncodedTx> blockTxes)
 {
     return this.allBlockTxNodes.TryAdd(blockHash,
         ImmutableSortedDictionary.CreateRange<int, BlockTxNode>(
             blockTxes.Select((tx, txIndex) =>
                 new KeyValuePair<int, BlockTxNode>(txIndex, new BlockTx(txIndex, tx)))));
 }
开发者ID:cole2295,项目名称:BitSharp,代码行数:7,代码来源:MemoryBlockTxesStorage.cs

示例10:

 void ISerializable.Deserialize(BinaryReader reader)
 {
     this.AssetId = reader.ReadSerializable<UInt256>();
     this.Value = reader.ReadSerializable<Fixed8>();
     if (Value <= Fixed8.Zero) throw new FormatException();
     this.ScriptHash = reader.ReadSerializable<UInt160>();
 }
开发者ID:zhengger,项目名称:AntShares,代码行数:7,代码来源:TransactionOutput.cs

示例11: TestCanSpend_Spent

        public void TestCanSpend_Spent()
        {
            // prepare utxo storage
            var chain = Chain.CreateForGenesisBlock(new FakeHeaders().GenesisChained());
            var unspentTransactions = ImmutableSortedDictionary.CreateBuilder<UInt256, UnspentTx>();

            // prepare spent output
            var txHash = new UInt256(0);
            unspentTransactions.Add(txHash, new UnspentTx(txHash, blockIndex: 0, txIndex: 0, txVersion: 0, isCoinbase: false, length: 1, state: OutputState.Spent));

            // prepare utxo
            var memoryStorage = new MemoryStorageManager(unspentTransactions: unspentTransactions.ToImmutable());
            var chainStateStorage = memoryStorage.OpenChainStateCursor().Item;
            chainStateStorage.BeginTransaction();
            chainStateStorage.ChainTip = chain.GenesisBlock;
            chainStateStorage.CommitTransaction();
            var utxo = new ChainState(chain, memoryStorage);

            // prepare output reference
            var prevTxOutput = new TxOutputKey(txHash, txOutputIndex: 0);

            // check if output can be spent
            var canSpend = utxo.CanSpend(prevTxOutput);

            // verify output cannot be spent
            Assert.IsFalse(canSpend);
        }
开发者ID:cole2295,项目名称:BitSharp,代码行数:27,代码来源:UtxoTest.cs

示例12: SpentTx

 public SpentTx(UInt256 txHash, int confirmedBlockIndex, int txIndex, int outputCount)
 {
     TxHash = txHash;
     ConfirmedBlockIndex = confirmedBlockIndex;
     TxIndex = txIndex;
     OutputCount = outputCount;
 }
开发者ID:cole2295,项目名称:BitSharp,代码行数:7,代码来源:SpentTx.cs

示例13: BlockchainKey

        public BlockchainKey(Guid guid, UInt256 rootBlockHash)
        {
            this._guid = guid;
            this._rootBlockHash = rootBlockHash;

            this.hashCode = guid.GetHashCode() ^ rootBlockHash.GetHashCode();
        }
开发者ID:holinov,项目名称:BitSharp,代码行数:7,代码来源:BlockchainKey.cs

示例14: ToCompact

        public static uint ToCompact(UInt256 value, bool negative = false)
        {
            var size = (HighBit(value) + 7) / 8;
            var compact = 0U;

            if (size <= 3)
            {
                compact = (uint)(value.Part4 << 8 * (3 - size));
            }
            else
            {
                value >>= 8 * (size - 3);
                compact = (uint)(value.Part4);
            }

            // The 0x00800000 bit denotes the sign.
            // Thus, if it is already set, divide the mantissa by 256 and increase the exponent.
            if ((compact & 0x00800000) != 0)
            {
                compact >>= 8;
                size++;
            }

            Debug.Assert((compact & ~0x007fffff) == 0);
            Debug.Assert(size < 256);

            compact |= (uint)(size << 24);
            if (negative && (compact & 0x007fffff) != 0)
                compact |= 0x00800000;

            return compact;
        }
开发者ID:pmlyon,项目名称:BitSharp,代码行数:32,代码来源:DataCalculator.cs

示例15: ContainsChainedHeader

 public bool ContainsChainedHeader(UInt256 blockHash)
 {
     using (var txn = this.jetInstance.BeginTransaction(TransactionBeginFlags.ReadOnly))
     {
         return txn.ContainsKey(blockHeadersTableId, DbEncoder.EncodeUInt256(blockHash));
     }
 }
开发者ID:ArsenShnurkov,项目名称:BitSharp,代码行数:7,代码来源:LmdbBlockStorage.cs


注:本文中的UInt256类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。