• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# UInt256类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: TestUInt256Sha256

        public void TestUInt256Sha256()
        {
            var expected = SHA256Static.ComputeDoubleHash(UInt256.ParseHex(TestData.HEX_STRING_64).ToByteArray());
            var actual = new UInt256(expected).ToByteArray();

            CollectionAssert.AreEqual(expected, actual);
        }
开发者ID:cole2295,项目名称:BitSharp,代码行数:7,代码来源:UInt256Test.cs


示例17: SendGetBlocks

        public async Task SendGetBlocks(ImmutableArray<UInt256> blockLocatorHashes, UInt256 hashStop)
        {
            var getBlocksPayload = Messaging.ConstructGetBlocksPayload(blockLocatorHashes, hashStop);
            var getBlocksMessage = Messaging.ConstructMessage("getblocks", NetworkEncoder.EncodeGetBlocksPayload(getBlocksPayload));

            await SendMessageAsync(getBlocksMessage);
        }
开发者ID:holinov,项目名称:BitSharp,代码行数:7,代码来源:RemoteSender.cs


示例18: TargetToBits

        public static UInt32 TargetToBits(UInt256 target)
        {
            // to get the powerPart: take the log in base 2, round up to 8 to respect byte boundaries, and then remove 24 to represent 3 bytes of precision
            var log = Math.Ceiling(UInt256.Log(target, 2) / 8) * 8 - 24;
            var powerPart = (byte)(log / 8 + 3);

            // determine the multiplier based on the powerPart
            var multiplier = BigInteger.Pow(2, 8 * (powerPart - 3));

            // to get multiplicand: divide the target by the multiplier
            //TODO
            var multiplicandBytes = ((BigInteger)target / (BigInteger)multiplier).ToByteArray();
            Debug.Assert(multiplicandBytes.Length == 3 || multiplicandBytes.Length == 4);

            // this happens when multipicand would be greater than 0x7fffff
            // TODO need a better explanation comment
            if (multiplicandBytes.Last() == 0)
            {
                multiplicandBytes = multiplicandBytes.Skip(1).ToArray();
                powerPart++;
            }

            // construct the bits representing the powerPart and multiplicand
            var bits = Bits.ToUInt32(multiplicandBytes.Concat(powerPart).ToArray());
            return bits;
        }
开发者ID:cole2295,项目名称:BitSharp,代码行数:26,代码来源:DataCalculator.cs


示例19:

 void ISerializable.Deserialize(BinaryReader reader)
 {
     this.PrevHash = reader.ReadSerializable<UInt256>();
     this.PrevIndex = reader.ReadUInt32();
     this.Script = reader.ReadBytes((int)reader.ReadVarInt());
     this.Sequence = reader.ReadUInt32();
 }
开发者ID:erikzhang,项目名称:IceWallet,代码行数:7,代码来源:TransactionInput.cs


示例20: ContainsChainedHeader

        public bool ContainsChainedHeader(UInt256 blockHash)
        {
            var key = MakeHeaderKey(blockHash);

            Slice ignore;
            return db.TryGet(new ReadOptions(), key, out ignore);
        }
开发者ID:cole2295,项目名称:BitSharp,代码行数:7,代码来源:LevelDbBlockStorage.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# UInt32类代码示例发布时间:2022-05-24
下一篇:
C# UInt16类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap