public static ExecutionOutcomeWithId FromDynamicJsonObject(dynamic jsonObject)
        {
            var result = new ExecutionOutcomeWithId()
            {
                Id      = jsonObject.id,
                Outcome = ExecutionOutcome.FromDynamicJsonObject(jsonObject.outcome)
            };

            return(result);
        }
Beispiel #2
0
        private async Task <FinalExecutionOutcome> SignAndSendTransactionAsync(string receiverId, Action[] actions)
        {
            if (!await GetReadyStatusAsync())
            {
                throw new Exception($"Can not sign transactions, no matching key pair found in Signer.");
            }
            var status = await _connection.Provider.GetStatusAsync();

            var signTransaction = await SignedTransaction.SignTransactionAsync(receiverId, (ulong)++_accessKey.Nonce, actions,
                                                                               new ByteArray32()
            {
                Buffer = Base58.Decode(status.SyncInfo.LatestBlockHash)
            }, _connection.Signer, _accountId, _connection.NetworkId);

            FinalExecutionOutcome result;

            try
            {
                result = await _connection.Provider.SendTransactionAsync(signTransaction.Item2);
            }
            catch (Exception e)
            {
                var parts = e.Message.Split(':');
                if (parts.Length > 1 && parts[1] == " Request timed out.")
                {
                    result = await RetryTxResultAsync(signTransaction.Item1, _accountId);
                }
                else
                {
                    throw e;
                }
            }

            var tempFlatLogs = new ExecutionOutcomeWithId[1 + result.Receipts.Length];

            tempFlatLogs[0] = result.Transaction;
            Array.Copy(result.Receipts, 0, tempFlatLogs, 1, result.Receipts.Length);

            var flatLogs = new List <string>();

            foreach (var t in tempFlatLogs)
            {
                flatLogs.AddRange(t.Outcome.Logs);
            }

            PrintLogs(signTransaction.Item2.Transaction.ReceiverId, flatLogs.ToArray());

            if (result.Status != null && result.Status.Failure != null)
            {
                throw new Exception($"Transaction {result.Transaction.Id} failed. {result.Status.Failure.ErrorMessage ?? ""}");
            }

            // ToDo: Add typed error handling
            return(result);
        }
Beispiel #3
0
        public void ShouldHaveCorrectFinalResult()
        {
            var excStatus = new ExecutionStatus()
            {
                SuccessReceiptId = "11112"
            };
            var excOutcome = new ExecutionOutcome()
            {
                Status     = excStatus,
                Logs       = new string[0],
                ReceiptIds = new string[] { "11112" },
                GasBurnt   = 1
            };
            var transaction = new ExecutionOutcomeWithId()
            {
                Id      = "11111",
                Outcome = excOutcome
            };
            var firstExcStatus = new ExecutionStatus()
            {
                SuccessValue = "e30="
            };
            var firstExcOutcome = new ExecutionOutcome()
            {
                Status     = firstExcStatus,
                Logs       = new string[0],
                ReceiptIds = new string[] { "11112" },
                GasBurnt   = 9001
            };
            var secondExcStatus = new ExecutionStatus()
            {
                SuccessValue = ""
            };
            var secondExcOutcome = new ExecutionOutcome()
            {
                Status     = secondExcStatus,
                Logs       = new string[0],
                ReceiptIds = new string[0],
                GasBurnt   = 0
            };
            var receipts = new ExecutionOutcomeWithId[] {
                new ExecutionOutcomeWithId {
                    Id = "11112", Outcome = firstExcOutcome
                },
                new ExecutionOutcomeWithId {
                    Id = "11113", Outcome = secondExcOutcome
                }
            };
            var result = new FinalExecutionOutcome()
            {
                Status = new FinalExecutionStatus()
                {
                    SuccessValue = "e30="
                },
                Transaction = transaction,
                Receipts    = receipts
            };
            dynamic lastResult = Provider.GetTransactionLastResult(result);

            Assert.IsFalse(lastResult is null);
        }