示例#1
0
        /// <summary>
        /// Commits a transaction to the DAppChain.
        /// </summary>
        /// <param name="tx">Transaction to commit.</param>
        /// <returns>Commit metadata.</returns>
        /// <exception cref="InvalidTxNonceException">Thrown if transaction is rejected due to a bad nonce after <see cref="NonceRetries"/> attempts.</exception>
        internal async Task <BroadcastTxResult> CommitTxAsync(IMessage tx)
        {
            BroadcastTxResult result = null;
            int badNonceCount        = 0;

            do
            {
                try
                {
                    return(await this.TryCommitTxAsync(tx));
                }
                catch (InvalidTxNonceException)
                {
                    ++badNonceCount;
                }

                // WaitForSecondsRealtime can throw a "get_realtimeSinceStartup can only be called from the main thread." error.
                // WebGL doesn't have threads, so use WaitForSecondsRealtime for WebGL anyway
                const float delay = 0.5f;
#if UNITY_WEBGL && !UNITY_EDITOR
                await new WaitForSecondsRealtime(delay);
#else
                await Task.Delay(TimeSpan.FromSeconds(delay));
#endif
            } while ((this.NonceRetries != 0) && (badNonceCount <= this.NonceRetries));

            if (badNonceCount > 0)
            {
                throw new InvalidTxNonceException();
            }
            return(result);
        }
示例#2
0
        /// <summary>
        /// Commits a transaction to the DAppChain.
        /// </summary>
        /// <param name="tx">Transaction to commit.</param>
        /// <returns>Commit metadata.</returns>
        /// <exception cref="InvalidTxNonceException">Thrown if the tx is rejected due to a bad nonce after <see cref="NonceRetries"/> attempts.</exception>
        public async Task <BroadcastTxResult> CommitTxAsync(IMessage tx)
        {
            BroadcastTxResult result = null;
            int badNonceCount        = 0;

            do
            {
                try
                {
                    return(await this.TryCommitTxAsync(tx));
                }
                catch (InvalidTxNonceException)
                {
                    ++badNonceCount;
                }
                await new WaitForSecondsRealtime(0.5f);
            } while ((this.NonceRetries != 0) && (badNonceCount <= this.NonceRetries));

            if (badNonceCount > 0)
            {
                throw new InvalidTxNonceException();
            }
            return(result);
        }