Example #1
0
        /// <summary>
        /// Set the period of time where the network will suspend will stop creating events
        /// and accepting transactions. This can be used to safely shut down
        /// the platform for maintenance and for upgrades if the file information is included.
        /// </summary>
        /// <param name="suspendParameters">
        /// The details of the suspend request, includes the time to wait before suspension,
        /// the duration of the suspension and optionally to include an update file.
        /// </param>
        /// <param name="configure">
        /// Optional callback method providing an opportunity to modify
        /// the execution configuration for just this method call.
        /// It is executed prior to submitting the request to the network.
        /// </param>
        /// <returns>
        /// A Submit Message Receipt indicating success.
        /// </returns>
        /// <exception cref="ArgumentOutOfRangeException">If required arguments are missing.</exception>
        /// <exception cref="InvalidOperationException">If required context configuration is missing.</exception>
        /// <exception cref="PrecheckException">If the gateway node create rejected the request upon submission.</exception>
        /// <exception cref="ConsensusException">If the network was unable to come to consensus before the duration of the transaction expired.</exception>
        /// <exception cref="TransactionException">If the network rejected the create request as invalid or had missing data.</exception>
        public async Task <TransactionReceipt> SuspendNetworkAsync(SuspendNetworkParams suspendParameters, Action <IContext>?configure = null)
        {
            suspendParameters       = RequireInputParameter.SuspendNetworkParams(suspendParameters);
            await using var context = CreateChildContext(configure);
            var gateway         = RequireInContext.Gateway(context);
            var payer           = RequireInContext.Payer(context);
            var signatories     = Transactions.GatherSignatories(context);
            var transactionId   = Transactions.GetOrCreateTransactionID(context);
            var transactionBody = new TransactionBody(context, transactionId);
            var startDate       = DateTime.UtcNow.Add(suspendParameters.Starting);
            var endDate         = startDate.Add(suspendParameters.Duration);

            transactionBody.Freeze = new FreezeTransactionBody
            {
                StartHour = startDate.Hour,
                StartMin  = startDate.Minute,
                EndHour   = endDate.Hour,
                EndMin    = endDate.Minute,
            };
            if (!suspendParameters.UpdateFile.IsNullOrNone())
            {
                transactionBody.Freeze.UpdateFile = new FileID(suspendParameters.UpdateFile);
                transactionBody.Freeze.FileHash   = ByteString.CopyFrom(suspendParameters.UpdateFileHash.Span);
            }
            var receipt = await transactionBody.SignAndExecuteWithRetryAsync(signatories, context);

            if (receipt.Status != ResponseCodeEnum.Success)
            {
                throw new TransactionException($"Failed to submit suspend/freeze command, status: {receipt.Status}", transactionId.ToTxId(), (ResponseCode)receipt.Status);
            }
            return(receipt.FillProperties(transactionId, new TransactionReceipt()));
        }
Example #2
0
        internal FreezeTransactionBody(Hashgraph.SuspendNetworkParams suspendParameters) : this()
        {
            if (suspendParameters is null)
            {
                throw new ArgumentNullException("Suspend Network Parameters can not be null.", nameof(suspendParameters));
            }
            if (suspendParameters.Duration.Ticks < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(suspendParameters.Duration), "The duration of the suspension must be greater than zero.");
            }
            if (suspendParameters.Duration.TotalHours > 24)
            {
                throw new ArgumentOutOfRangeException(nameof(suspendParameters.Duration), "The duration of suspension must not exceed 24 hours.");
            }
            if (suspendParameters.Starting.TotalHours > 24)
            {
                throw new ArgumentOutOfRangeException(nameof(suspendParameters.Starting), "The starting wait must not exceed 24 hours.");
            }
            var now  = DateTime.UtcNow;
            var then = now.Add(suspendParameters.Starting).Add(suspendParameters.Duration);

            if (then < now)
            {
                throw new ArgumentOutOfRangeException(nameof(suspendParameters.Starting), "The combination of Starting wait and Duration has already passed.");
            }
            if (suspendParameters.UpdateFile.IsNullOrNone())
            {
                if (!suspendParameters.UpdateFileHash.IsEmpty)
                {
                    throw new ArgumentOutOfRangeException(nameof(suspendParameters.UpdateFile), "The the the hash of the file contents is specified, an address for the update file must be included.");
                }
            }
            else if (suspendParameters.UpdateFileHash.IsEmpty)
            {
                throw new ArgumentOutOfRangeException(nameof(suspendParameters.UpdateFileHash), "The an update file address is specified, the hash of the file contents must be included.");
            }
            var startDate = DateTime.UtcNow.Add(suspendParameters.Starting);
            var endDate   = startDate.Add(suspendParameters.Duration);

            StartHour = startDate.Hour;
            StartMin  = startDate.Minute;
            EndHour   = endDate.Hour;
            EndMin    = endDate.Minute;
            if (!suspendParameters.UpdateFile.IsNullOrNone())
            {
                UpdateFile = new FileID(suspendParameters.UpdateFile);
                FileHash   = ByteString.CopyFrom(suspendParameters.UpdateFileHash.Span);
            }
        }
Example #3
0
 /// <summary>
 /// Set the period of time where the network will suspend will stop creating events
 /// and accepting transactions. This can be used to safely shut down
 /// the platform for maintenance and for upgrades if the file information is included.
 /// </summary>
 /// <param name="suspendParameters">
 /// The details of the suspend request, includes the time to wait before suspension,
 /// the duration of the suspension and optionally to include an update file.
 /// </param>
 /// <param name="configure">
 /// Optional callback method providing an opportunity to modify
 /// the execution configuration for just this method call.
 /// It is executed prior to submitting the request to the network.
 /// </param>
 /// <returns>
 /// A Submit Message Receipt indicating success.
 /// </returns>
 /// <exception cref="ArgumentOutOfRangeException">If required arguments are missing.</exception>
 /// <exception cref="InvalidOperationException">If required context configuration is missing.</exception>
 /// <exception cref="PrecheckException">If the gateway node create rejected the request upon submission.</exception>
 /// <exception cref="ConsensusException">If the network was unable to come to consensus before the duration of the transaction expired.</exception>
 /// <exception cref="TransactionException">If the network rejected the create request as invalid or had missing data.</exception>
 public async Task <TransactionReceipt> SuspendNetworkAsync(SuspendNetworkParams suspendParameters, Action <IContext>?configure = null)
 {
     return(new TransactionReceipt(await ExecuteTransactionAsync(new FreezeTransactionBody(suspendParameters), configure, false).ConfigureAwait(false)));
 }