本文整理汇总了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;
}
示例2: TxOutputKey
public TxOutputKey(UInt256 txHash, UInt32 txOutputIndex)
{
TxHash = txHash;
TxOutputIndex = txOutputIndex;
this.hashCode = txHash.GetHashCode() ^ txOutputIndex.GetHashCode();
}
示例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;
}
}
}
示例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;
}
示例5: PublicKeyHashAddress
public PublicKeyHashAddress(ImmutableArray<byte> publicKeyHashBytes)
{
this.publicKeyHashBytes = publicKeyHashBytes;
var outputScript = new PayToPublicKeyHashBuilder().CreateOutputFromPublicKeyHash(publicKeyHashBytes.ToArray());
this.outputScriptHash = new UInt256(SHA256Static.ComputeHash(outputScript));
}
示例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;
}
}
示例7: MerkleTreePruningCursor
public MerkleTreePruningCursor(UInt256 blockHash, LightningTransaction txn, LightningDatabase db, LightningCursor cursor)
{
this.blockHash = blockHash;
this.db = db;
this.txn = txn;
this.cursor = cursor;
}
示例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;
}
}
}
}
示例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)))));
}
示例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>();
}
示例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);
}
示例12: SpentTx
public SpentTx(UInt256 txHash, int confirmedBlockIndex, int txIndex, int outputCount)
{
TxHash = txHash;
ConfirmedBlockIndex = confirmedBlockIndex;
TxIndex = txIndex;
OutputCount = outputCount;
}
示例13: BlockchainKey
public BlockchainKey(Guid guid, UInt256 rootBlockHash)
{
this._guid = guid;
this._rootBlockHash = rootBlockHash;
this.hashCode = guid.GetHashCode() ^ rootBlockHash.GetHashCode();
}
示例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;
}
示例15: ContainsChainedHeader
public bool ContainsChainedHeader(UInt256 blockHash)
{
using (var txn = this.jetInstance.BeginTransaction(TransactionBeginFlags.ReadOnly))
{
return txn.ContainsKey(blockHeadersTableId, DbEncoder.EncodeUInt256(blockHash));
}
}