private bool CheckValidators(ApplicationEngine engine) { UInt256 prev_hash = engine.Snapshot.PersistingBlock.PrevHash; TrimmedBlock prev_block = engine.Snapshot.Blocks[prev_hash]; return(InteropService.CheckWitness(engine, prev_block.NextConsensus)); }
private TrimmedBlock GetBlock(ApplicationEngine engine, byte[] indexOrHash) { UInt256 hash; if (indexOrHash.Length < UInt256.Length) { hash = GetBlockHash(engine.Snapshot, (uint)new BigInteger(indexOrHash)); } else if (indexOrHash.Length == UInt256.Length) { hash = new UInt256(indexOrHash); } else { throw new ArgumentException(null, nameof(indexOrHash)); } if (hash is null) { return(null); } TrimmedBlock block = GetTrimmedBlock(engine.Snapshot, hash); if (block is null || !IsTraceableBlock(engine.Snapshot, block.Index, engine.ProtocolSettings.MaxTraceableBlocks)) { return(null); } return(block); }
private Transaction GetTransactionFromBlock(ApplicationEngine engine, byte[] blockIndexOrHash, int txIndex) { UInt256 hash; if (blockIndexOrHash.Length < UInt256.Length) { hash = GetBlockHash(engine.Snapshot, (uint)new BigInteger(blockIndexOrHash)); } else if (blockIndexOrHash.Length == UInt256.Length) { hash = new UInt256(blockIndexOrHash); } else { throw new ArgumentException(null, nameof(blockIndexOrHash)); } if (hash is null) { return(null); } TrimmedBlock block = GetTrimmedBlock(engine.Snapshot, hash); if (block is null || !IsTraceableBlock(engine.Snapshot, block.Index, engine.ProtocolSettings.MaxTraceableBlocks)) { return(null); } if (txIndex < 0 || txIndex >= block.Hashes.Length) { throw new ArgumentOutOfRangeException(nameof(txIndex)); } return(GetTransaction(engine.Snapshot, block.Hashes[txIndex])); }
void IInteroperable.FromReplica(IInteroperable replica) { TrimmedBlock from = (TrimmedBlock)replica; Header = from.Header; Hashes = from.Hashes; }
private TrimmedBlock GetBlock(DataCache snapshot, byte[] indexOrHash) { UInt256 hash; if (indexOrHash.Length < UInt256.Length) { hash = GetBlockHash(snapshot, (uint)new BigInteger(indexOrHash)); } else if (indexOrHash.Length == UInt256.Length) { hash = new UInt256(indexOrHash); } else { throw new ArgumentException(null, nameof(indexOrHash)); } if (hash is null) { return(null); } TrimmedBlock block = GetTrimmedBlock(snapshot, hash); if (block is null || !IsTraceableBlock(snapshot, block.Index)) { return(null); } return(block); }
private Transaction GetTransactionFromBlock(DataCache snapshot, byte[] blockIndexOrHash, int txIndex) { UInt256 hash; if (blockIndexOrHash.Length < UInt256.Length) { hash = GetBlockHash(snapshot, (uint)new BigInteger(blockIndexOrHash)); } else if (blockIndexOrHash.Length == UInt256.Length) { hash = new UInt256(blockIndexOrHash); } else { throw new ArgumentException(null, nameof(blockIndexOrHash)); } if (hash is null) { return(null); } TrimmedBlock block = GetTrimmedBlock(snapshot, hash); if (block is null || !IsTraceableBlock(snapshot, block.Index)) { return(null); } if (txIndex < 0 || txIndex >= block.Hashes.Length - 1) { throw new ArgumentOutOfRangeException(nameof(txIndex)); } return(GetTransaction(snapshot, block.Hashes[txIndex + 1])); }
public Block GetBlock(DataCache snapshot, UInt256 hash) { TrimmedBlock state = GetTrimmedBlock(snapshot, hash); if (state is null) { return(null); } return(new Block { Header = state.Header, Transactions = state.Hashes.Select(p => GetTransaction(snapshot, p)).ToArray() }); }
public Block GetBlock(DataCache snapshot, UInt256 hash) { TrimmedBlock state = GetTrimmedBlock(snapshot, hash); if (state is null) { return(null); } return(new Block { Version = state.Version, PrevHash = state.PrevHash, MerkleRoot = state.MerkleRoot, Timestamp = state.Timestamp, Index = state.Index, NextConsensus = state.NextConsensus, Witness = state.Witness, ConsensusData = state.ConsensusData, Transactions = state.Hashes.Skip(1).Select(p => GetTransaction(snapshot, p)).ToArray() }); }