Exemplo n.º 1
0
        /// <summary>
        /// Asynchronously creates a request to the peer to create a transaction.
        /// </summary>
        ///
        /// <param name="transaction">A reference to a <see cref="TransactionApi"/> type.</param>
        ///
        /// <param name="peer">The peer to create the request to.</param>
        ///
        /// <returns>Returns an <see cref="Task{ArkTransactionPostResponse}"/> type.</returns>
        ///
        public async Task <ArkTransactionPostResponse> PostTransactionAsync(TransactionApi transaction, PeerApi peer = null)
        {
            try
            {
                string body = "{transactions: [" + transaction.ToObject(true) + "]} ";

                _logger.Info(string.Format("Send transaction <<{0}>>", body));

                var response = string.Empty;

                if (peer == null)
                {
                    response = await _networkApi.ActivePeer.MakeRequest(ArkStaticStrings.ArkHttpMethods.POST, ArkStaticStrings.ArkApiPaths.Transaction.POST, body).ConfigureAwait(false);
                }
                else
                {
                    response = await peer.MakeRequest(ArkStaticStrings.ArkHttpMethods.POST, ArkStaticStrings.ArkApiPaths.Transaction.POST, body).ConfigureAwait(false);
                }

                return(JsonConvert.DeserializeObject <ArkTransactionPostResponse>(response));
            }
            catch (Exception e)
            {
                _logger.Error(e.ToString());
                throw e;
            }
        }
Exemplo n.º 2
0
        public static (bool status, string data, string error) PostTransaction(TransactionApi transaction)
        {
            string body = "{transactions: [" + transaction.ToObject(true) + "]} ";

            var response = NetworkApi.Instance.ActivePeer.MakeRequest("POST", "/peer/transactions", body);

            var parsed = JObject.Parse(response);
            var status = Convert.ToBoolean(parsed["success"]);


            return(new ValueTuple <bool, string, string>(status,
                                                         parsed["message"]?.ToString() ?? parsed["transactionIds"]?.ToString() ?? "",
                                                         parsed["error"]?.ToString() ?? ""));
        }
Exemplo n.º 3
0
        public async static Task <ArkTransactionPostResponse> PostTransactionAsync(TransactionApi transaction, PeerApi peer = null)
        {
            string body = "{transactions: [" + transaction.ToObject(true) + "]} ";

            var response = string.Empty;

            if (peer == null)
            {
                response = await NetworkApi.Instance.ActivePeer.MakeRequest(ArkStaticStrings.ArkHttpMethods.POST, ArkStaticStrings.ArkApiPaths.Transaction.POST, body);
            }
            else
            {
                response = await peer.MakeRequest(ArkStaticStrings.ArkHttpMethods.POST, ArkStaticStrings.ArkApiPaths.Transaction.POST, body);
            }

            return(JsonConvert.DeserializeObject <ArkTransactionPostResponse>(response));
        }