Esempio n. 1
0
        /// *** This is ported from Dart Future to C# Task<TResult>
        /// *** The usage of the class should be mantained - to be checked
        public static async Task <TransactionResult> broadcastStdTx(Wallet wallet, StdTx stdTx, String mode = "sync")
        {
            // Get the endpoint
            String apiUrl = $"{wallet.networkInfo.lcdUrl}/txs";

            // Build the request body
            Dictionary <String, Object> requestBody = new Dictionary <String, Object>
            {
                { "tx", stdTx.toJson() },
                { "mode", mode }
            };
            String payload = JsonConvert.SerializeObject(requestBody);

            Debug.WriteLine($"****** Payload: {payload}");

            HttpContent content = new StringContent(payload, Encoding.UTF8, "application/json");
            // Get the server response
            HttpResponseMessage response = await client.PostAsync(apiUrl, content);

            if (response.StatusCode != System.Net.HttpStatusCode.OK)
            {
                System.ArgumentException argEx = new System.ArgumentException($"Expected status code OK (200) but got ${response.StatusCode} - ${response.ReasonPhrase} - ${response.Content}");
                throw argEx;
            }

            // Convert the response
            String encodedJson = await response.Content.ReadAsStringAsync();

            Debug.WriteLine($"******+++++++ encodedJson: {encodedJson}");
            Dictionary <String, Object> json = JsonConvert.DeserializeObject <Dictionary <String, Object> >(encodedJson);

            return(_convertJson(json));
        }
Esempio n. 2
0
        /// Reads the account endpoint and retrieves data from it.
        /// *** This is ported from Dart Future to C# Task<TResult>
        /// *** The usage of the class should be mantained - to be checked
        public static async Task <StdTx> signStdTx(Wallet wallet, StdTx stdTx)
        {
            // Get the account data and node info from the network
            AccountData account = await AccountDataRetrieval.getAccountData(wallet);

            NodeInfo nodeInfo = await NodeInfoRetrieval.getNodeInfo(wallet);

            // Sign each message
            List <StdSignature> signatures = new List <StdSignature>();

            // This was corrected in Dart version 25/11/2019
            //foreach (StdMsg msg in stdTx.messages)
            //{
            //    signatures.Add(_getStdSignature(wallet, account, nodeInfo, msg, stdTx.fee, stdTx.memo));
            //}
            signatures.Add(_getStdSignature(wallet, account, nodeInfo, stdTx.messages, stdTx.fee, stdTx.memo));


            // Assemble the transaction
            return(new StdTx(
                       fee: stdTx.fee,
                       memo: stdTx.memo,
                       messages: stdTx.messages,
                       signatures: signatures
                       ));
        }
Esempio n. 3
0
        // This is different from Dart implementation, as we are not initialising the optional parameters
        public static StdTx buildStdTx(List <StdMsg> stdMsgs, [Optional] String memo, [Optional] StdFee fee)
        {
            // Arrange optional parameters here
            if (memo == null)
            {
                memo = "";
            }
            if (fee == null)
            {
                fee = new StdFee(gas: "200000", amount: new List <StdCoin> {
                });
            }
            StdTx txMsg = new StdTx(messages: stdMsgs,
                                    memo: memo,
                                    fee: fee,
                                    signatures: null);


            return(txMsg);
        }