Exemple #1
0
        public void Run()
        {
            try
            {
                var lastStatus = Status;

                if (Status == State.Queued)
                {
                    Process.Invoke(this);
                }
                else if (Status >= State.RevealOK || Status < State.DBlockConfirmed)
                {
                    var ack = new Ack(Chain.FactomD);
                    switch (ack.CheckReveal(Chain.ChainID, EntryHash))
                    {
                    case Ack.Status.DBlockConfirmed:
                        Status = State.DBlockConfirmed;
                        break;

                    case Ack.Status.TransactionACK:
                        Status = State.TransactionACK;
                        break;

                    case Ack.Status.NotConfirmed:
                    case Ack.Status.RequestFailed:
                    case Ack.Status.Unknown:
                        break;
                    }
                }
                else
                {
                    //retry?
                }
            }catch (Exception ex)
            {
                ApiError = new APIError(ex);
                Status   = State.Exception;
            }
        }
        /// <summary>
        /// Create a new chain, with the first entry.
        /// </summary>
        /// <returns>The create.</returns>
        /// <param name="data">Data.</param>
        /// <param name="extIDs">Ext identifier.</param>
        /// <param name="chainIdString">Optional ChainID (a random ID will be created if not supplied).</param>

        public async Task <bool> Create(byte[] data, byte[][] extIDs = null, string chainIdString = null)
        {
            if (EcAddress == null)
            {
                throw new Exception("No EcAddress provided - read only");
            }

            var task = Task.Run(() =>
            {
                try
                {
                    Commit           = new CommitChain(FactomD);
                    var commitStatus = Commit.Run(data, EcAddress, extIDs, chainIdString);
                    ChainID          = Commit.Entry.ChainIdString;

                    if (commitStatus)
                    {
                        Status = State.CommitOK;
                        TxId   = Commit?.Result?.result?.Txid ?? null;
                        Reveal = new RevealChain(FactomD);
                        if (Reveal.Run(Commit.Entry))
                        {
                            Status    = State.RevealOK;
                            EntryHash = Reveal?.Result?.result?.Entryhash;

                            var sleep   = PollACKms;
                            var timeout = DateTime.UtcNow.AddMinutes(10);
                            do
                            {
                                Thread.Sleep(sleep);

                                var ack = new Ack(FactomD);
                                switch (ack.CheckReveal(ChainID, EntryHash))
                                {
                                case Ack.Status.DBlockConfirmed:
                                    Status = State.DBlockConfirmed;
                                    return;  //Complete, so quit

                                case Ack.Status.TransactionACK:
                                    Status = State.TransactionACK;
                                    sleep  = PollDBACKms;
                                    if (Blocking != BlockingMode.DBlockConfirmed)
                                    {
                                        return;                                           //Complete if we are not looking for DBlockConfirmed
                                    }
                                    break;

                                case Ack.Status.NotConfirmed:
                                case Ack.Status.RequestFailed:
                                case Ack.Status.Unknown:
                                    break;
                                }
                            } while (timeout < DateTime.UtcNow);
                        }
                        else
                        {
                            Status = State.RevealFail;
                        }
                    }
                    else
                    {
                        Status = State.CommitFail;
                    }
                }
                catch (Exception ex)
                {
                    var error = new APIError(ex);
                    Status    = State.Exception;
                }
            });

            return(false);
        }