async Task <UInt256> SubmitTransactionAsync(Transaction tx) { if (disposedValue) { throw new ObjectDisposedException(nameof(OfflineNode)); } var transactions = new[] { tx }; // Verify the provided transactions. When running, Blockchain class does verification in two steps: VerifyStateIndependent and VerifyStateDependent. // However, Verify does both parts and there's no point in verifying dependent/independent in separate steps here var verificationContext = new TransactionVerificationContext(); for (int i = 0; i < transactions.Length; i++) { if (transactions[i].Verify(neoSystem.Settings, neoSystem.StoreView, verificationContext) != VerifyResult.Succeed) { throw new Exception("Verification failed"); } } var prevHash = NativeContract.Ledger.CurrentHash(neoSystem.StoreView); var prevHeader = NativeContract.Ledger.GetHeader(neoSystem.StoreView, prevHash); var block = ExpressOracle.CreateSignedBlock(prevHeader, consensusNodesKeys.Value, neoSystem.Settings.Network, transactions); await RelayBlockAsync(block).ConfigureAwait(false); return(block.Hash); }
public static async Task FastForwardAsync(Header prevHeader, uint blockCount, TimeSpan timestampDelta, KeyPair[] keyPairs, uint network, Func <Block, Task> submitBlockAsync) { if (timestampDelta.TotalSeconds < 0) { throw new ArgumentException($"Negative {nameof(timestampDelta)} not supported"); } if (blockCount == 0) { return; } var timestamp = Math.Max(Neo.Helper.ToTimestampMS(DateTime.UtcNow), prevHeader.Timestamp + 1); var delta = (ulong)timestampDelta.TotalMilliseconds; if (blockCount == 1) { var block = ExpressOracle.CreateSignedBlock( prevHeader, keyPairs, network, timestamp: timestamp + delta); await submitBlockAsync(block).ConfigureAwait(false); } else { var period = delta / (blockCount - 1); for (int i = 0; i < blockCount; i++) { var block = ExpressOracle.CreateSignedBlock( prevHeader, keyPairs, network, timestamp: timestamp); await submitBlockAsync(block).ConfigureAwait(false); prevHeader = block.Header; timestamp += period; } } }