public XMRTaskTransferResponse XMR_Sign(string ToAddress, string Amount, string BaseData, string FromAddress) { XMRTaskTransferResponse taskTransferResponse = new XMRTaskTransferResponse(); try { constructionAttempt = 0; var step2Response = TryReconstructTransaction(ToAddress, Amount, BaseData, FromAddress); constructionAttempt = 1; while (bool.Parse(step2Response.tx_must_be_reconstructed) || string.IsNullOrEmpty(step2Response.serialized_signed_tx)) { if (constructionAttempt > kRECONSTRUCT_LIMIT) { taskTransferResponse.Error = "Unable to construct a transaction with sufficient fee for unknown reason."; return(taskTransferResponse); } step2Response = TryReconstructTransaction(ToAddress, Amount, BaseData, FromAddress, step2Response.fee_actually_needed); constructionAttempt++; } if (!string.IsNullOrEmpty(step2Response.serialized_signed_tx) && step2Response.tx_key_images != null && step2Response.tx_key_images.Length > 0) { taskTransferResponse.TxnHex = step2Response.serialized_signed_tx; taskTransferResponse.SpendKeyImages = step2Response.tx_key_images; } else { taskTransferResponse.Error = "Tx construction completed with error. Something went wrong"; } } catch (Exception exc) { taskTransferResponse.Error = exc.Message; } return(taskTransferResponse); }
private Step2Response TryReconstructTransaction(string ToAddress, string Amount, string BaseData, string FromAddress, string feeNeeded = null) { string s1jData = ""; string s2jData = ""; var res = Double.Parse(Amount) * 1e12; Amount = res.ToString(); XMRTaskTransferResponse taskTransferResponse = new XMRTaskTransferResponse(); MoneroWalletInput data = ConvertFromString(BaseData); data.PassedInAttemptAtFee = null; if (feeNeeded != null) data.PassedInAttemptAtFee = feeNeeded; Step1Prepare step1Prepare = ConvertFromWSObject(data, Amount); byte[] s1compdata = System.Text.Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(step1Prepare, ser)); int s1len = XMRNative.s1compute(s1compdata, s1compdata.Length); s1compdata = new byte[s1len]; XMRNative.s1getdata(s1compdata, s1len); s1jData = System.Text.Encoding.UTF8.GetString(s1compdata); Step1Response step1Response = JsonConvert.DeserializeObject\\(s1jData, ser); if (!string.IsNullOrEmpty(step1Response.err_msg)) throw new Exception(step1Response.err_msg); if (!string.IsNullOrEmpty(step1Response.using_fee) && !string.IsNullOrEmpty(data.MaxAllowedFee)) { BigInteger UsingFee = BigInteger.Parse(step1Response.using_fee); BigInteger MaxFee = BigInteger.Parse(data.MaxAllowedFee); if (UsingFee \>\ MaxFee) throw new Exception("Max fee exceeded by " + NDReverse((UsingFee - MaxFee).ToString(), 12)); } string[] amounts = new string[step1Response.using_outs.Length]; for (int i = 0; i \ string mix = WS.XMRGetRandom(step1Response.mixin, amounts); MixOutput[] mixOuts = JsonConvert.DeserializeObject\\(mix); Step2Prepare step2Prepare = ConcertFromWSObjectAndMergeStep1(step1Response, data, Amount, MoneroWallet.Converters.ByteArrayToHex(wallet.Keys.SpendSecret), MoneroWallet.Converters.ByteArrayToHex(wallet.Keys.ViewSecret), FromAddress, ToAddress, mixOuts); var s2 = JsonConvert.SerializeObject(step2Prepare, ser); byte[] s2compdata = System.Text.Encoding.UTF8.GetBytes(s2); int s2len = XMRNative.s2compute(s2compdata, s2compdata.Length); s2compdata = new byte[s2len]; XMRNative.s2getdata(s2compdata, s2len); s2jData = System.Text.Encoding.UTF8.GetString(s2compdata); Step2Response step2Response = JsonConvert.DeserializeObject\\(s2jData, ser); return step2Response; }