mirror of
https://github.com/Nathanwoodburn/FireWallet.git
synced 2024-11-24 08:08:14 +11:00
main: HIP-02 transfers for domains
This commit is contained in:
parent
5323a8ff0d
commit
14cb5453dc
29
FireWallet/TransferForm.Designer.cs
generated
29
FireWallet/TransferForm.Designer.cs
generated
@ -36,6 +36,8 @@
|
|||||||
label2 = new Label();
|
label2 = new Label();
|
||||||
textBoxAddress = new TextBox();
|
textBoxAddress = new TextBox();
|
||||||
labelError = new Label();
|
labelError = new Label();
|
||||||
|
labelSendingHIPAddress = new Label();
|
||||||
|
labelHIPArrow = new Label();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// buttonTransfer
|
// buttonTransfer
|
||||||
@ -105,18 +107,41 @@
|
|||||||
// labelError
|
// labelError
|
||||||
//
|
//
|
||||||
labelError.AutoSize = true;
|
labelError.AutoSize = true;
|
||||||
labelError.Location = new Point(46, 139);
|
labelError.Location = new Point(492, 139);
|
||||||
labelError.Name = "labelError";
|
labelError.Name = "labelError";
|
||||||
labelError.Size = new Size(98, 15);
|
labelError.Size = new Size(98, 15);
|
||||||
labelError.TabIndex = 6;
|
labelError.TabIndex = 6;
|
||||||
labelError.Text = "Address not valid";
|
labelError.Text = "Address not valid";
|
||||||
labelError.Visible = false;
|
labelError.Visible = false;
|
||||||
//
|
//
|
||||||
|
// labelSendingHIPAddress
|
||||||
|
//
|
||||||
|
labelSendingHIPAddress.AutoSize = true;
|
||||||
|
labelSendingHIPAddress.Location = new Point(75, 150);
|
||||||
|
labelSendingHIPAddress.Name = "labelSendingHIPAddress";
|
||||||
|
labelSendingHIPAddress.Size = new Size(64, 15);
|
||||||
|
labelSendingHIPAddress.TabIndex = 19;
|
||||||
|
labelSendingHIPAddress.Text = "To Address";
|
||||||
|
labelSendingHIPAddress.Visible = false;
|
||||||
|
//
|
||||||
|
// labelHIPArrow
|
||||||
|
//
|
||||||
|
labelHIPArrow.AutoSize = true;
|
||||||
|
labelHIPArrow.Font = new Font("Segoe UI", 18F, FontStyle.Bold, GraphicsUnit.Point);
|
||||||
|
labelHIPArrow.Location = new Point(46, 139);
|
||||||
|
labelHIPArrow.Name = "labelHIPArrow";
|
||||||
|
labelHIPArrow.Size = new Size(32, 32);
|
||||||
|
labelHIPArrow.TabIndex = 20;
|
||||||
|
labelHIPArrow.Text = "⮡ ";
|
||||||
|
labelHIPArrow.Visible = false;
|
||||||
|
//
|
||||||
// TransferForm
|
// TransferForm
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(602, 340);
|
ClientSize = new Size(602, 340);
|
||||||
|
Controls.Add(labelSendingHIPAddress);
|
||||||
|
Controls.Add(labelHIPArrow);
|
||||||
Controls.Add(labelError);
|
Controls.Add(labelError);
|
||||||
Controls.Add(textBoxAddress);
|
Controls.Add(textBoxAddress);
|
||||||
Controls.Add(label2);
|
Controls.Add(label2);
|
||||||
@ -143,5 +168,7 @@
|
|||||||
private Label label2;
|
private Label label2;
|
||||||
private TextBox textBoxAddress;
|
private TextBox textBoxAddress;
|
||||||
private Label labelError;
|
private Label labelError;
|
||||||
|
private Label labelSendingHIPAddress;
|
||||||
|
private Label labelHIPArrow;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -8,6 +8,8 @@ using System.Net;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
using DnsClient.Protocol;
|
||||||
|
using DnsClient;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
namespace FireWallet
|
namespace FireWallet
|
||||||
@ -46,16 +48,19 @@ namespace FireWallet
|
|||||||
this.Close();
|
this.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string address = "";
|
||||||
private async void buttonTransfer_Click(object sender, EventArgs e)
|
private async void buttonTransfer_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (!await MainForm.ValidAddress(textBoxAddress.Text))
|
updateAddress();
|
||||||
|
|
||||||
|
if (!await MainForm.ValidAddress(address))
|
||||||
{
|
{
|
||||||
labelError.Show();
|
labelError.Show();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
string content = "{\"method\": \"sendtransfer\",\"params\": [ \"" + Domain + "\", \"" +
|
string content = "{\"method\": \"sendtransfer\",\"params\": [ \"" + Domain + "\", \"" +
|
||||||
textBoxAddress.Text + "\"]}";
|
address + "\"]}";
|
||||||
string output = await MainForm.APIPost("", true, content);
|
string output = await MainForm.APIPost("", true, content);
|
||||||
JObject APIresp = JObject.Parse(output);
|
JObject APIresp = JObject.Parse(output);
|
||||||
if (APIresp["error"].ToString() != "")
|
if (APIresp["error"].ToString() != "")
|
||||||
@ -78,14 +83,113 @@ namespace FireWallet
|
|||||||
|
|
||||||
private async void buttonBatch_Click(object sender, EventArgs e)
|
private async void buttonBatch_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (!await MainForm.ValidAddress(textBoxAddress.Text))
|
updateAddress();
|
||||||
|
|
||||||
|
if (!await MainForm.ValidAddress(address))
|
||||||
{
|
{
|
||||||
labelError.Show();
|
labelError.Show();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
MainForm.AddBatch(Domain, "TRANSFER", textBoxAddress.Text);
|
MainForm.AddBatch(Domain, "TRANSFER", address);
|
||||||
this.Close();
|
this.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateAddress()
|
||||||
|
{
|
||||||
|
labelError.Hide();
|
||||||
|
|
||||||
|
if (textBoxAddress.Text.Length < 1)
|
||||||
|
{
|
||||||
|
address = "";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (textBoxAddress.Text.Substring(0, 1) == "@")
|
||||||
|
{
|
||||||
|
string domain = textBoxAddress.Text.Substring(1);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
IPAddress iPAddress = null;
|
||||||
|
|
||||||
|
|
||||||
|
// Create an instance of LookupClient using the custom options
|
||||||
|
NameServer nameServer = new NameServer(IPAddress.Parse("127.0.0.1"), 5350);
|
||||||
|
var options = new LookupClientOptions(nameServer);
|
||||||
|
options.EnableAuditTrail = true;
|
||||||
|
options.UseTcpOnly = true;
|
||||||
|
options.Recursion = true;
|
||||||
|
options.UseCache = false;
|
||||||
|
options.RequestDnsSecRecords = true;
|
||||||
|
options.Timeout = TimeSpan.FromSeconds(5);
|
||||||
|
|
||||||
|
|
||||||
|
var client = new LookupClient(options);
|
||||||
|
|
||||||
|
|
||||||
|
// Perform the DNS lookup for the specified domain using DNSSec
|
||||||
|
|
||||||
|
var result = client.Query(domain, QueryType.A);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Display the DNS lookup results
|
||||||
|
foreach (var record in result.Answers.OfType<ARecord>())
|
||||||
|
{
|
||||||
|
iPAddress = record.Address;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (iPAddress == null)
|
||||||
|
{
|
||||||
|
labelError.Show();
|
||||||
|
labelError.Text = "HIP-02 lookup failed";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get TLSA record
|
||||||
|
var resultTLSA = client.Query("_443._tcp." + domain, QueryType.TLSA);
|
||||||
|
foreach (var record in resultTLSA.Answers.OfType<TlsaRecord>())
|
||||||
|
{
|
||||||
|
MainForm.TLSA = record.CertificateAssociationDataAsString;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
string url = "https://" + iPAddress.ToString() + "/.well-known/wallets/HNS";
|
||||||
|
var handler = new HttpClientHandler();
|
||||||
|
|
||||||
|
handler.ServerCertificateCustomValidationCallback = MainForm.ValidateServerCertificate;
|
||||||
|
|
||||||
|
// Create an instance of HttpClient with the custom handler
|
||||||
|
using (var httpclient = new HttpClient(handler))
|
||||||
|
{
|
||||||
|
httpclient.DefaultRequestHeaders.Add("Host", domain);
|
||||||
|
// Send a GET request to the specified URL
|
||||||
|
HttpResponseMessage response = httpclient.GetAsync(url).Result;
|
||||||
|
|
||||||
|
// Response
|
||||||
|
string address = response.Content.ReadAsStringAsync().Result;
|
||||||
|
|
||||||
|
labelSendingHIPAddress.Text = address;
|
||||||
|
this.address = address;
|
||||||
|
labelSendingHIPAddress.Show();
|
||||||
|
labelHIPArrow.Show();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MainForm.AddLog(ex.Message);
|
||||||
|
labelError.Show();
|
||||||
|
labelError.Text = "HIP-02 lookup failed";
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
address = textBoxAddress.Text;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user