Work on bitcoin hotwallet
This commit is contained in:
@@ -191,3 +191,5 @@ External Dependencies/*
|
||||
#Except the batch file to rebuild them
|
||||
!External Dependencies/rebuild-all.cmd
|
||||
|
||||
#The hotwallet keyfiles should obviously never be checked in
|
||||
Site5/hotwallet*
|
||||
|
||||
@@ -168,6 +168,12 @@ namespace Swarmops.Backend
|
||||
Persistence.Key["SwarmopsInstallationId"] = Guid.NewGuid().ToString();
|
||||
}
|
||||
|
||||
// Check for existence of bitcoin hotwallet root
|
||||
|
||||
FinancialAccounts.VerifyBitcoinHotWallet();
|
||||
|
||||
// Begin maintenance loop
|
||||
|
||||
DateTime cycleStartTime = DateTime.UtcNow;
|
||||
DateTime cycleEndTime;
|
||||
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using NBitcoin;
|
||||
using Swarmops.Basic.Types.Financial;
|
||||
using Swarmops.Common.Enums;
|
||||
using Swarmops.Database;
|
||||
@@ -212,5 +215,41 @@ namespace Swarmops.Logic.Financial
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public static void VerifyBitcoinHotWallet()
|
||||
{
|
||||
// Make sure there's always a private hotwallet root, regardless of whether it's used or not
|
||||
|
||||
if (!File.Exists (SystemSettings.EtcFolder + Path.DirectorySeparatorChar + "hotwallet"))
|
||||
{
|
||||
ExtKey privateRoot = new ExtKey();
|
||||
File.WriteAllText(SystemSettings.EtcFolder + Path.DirectorySeparatorChar + "hotwallet", privateRoot.GetWif(Network.Main).ToWif(), Encoding.ASCII);
|
||||
File.WriteAllText(SystemSettings.EtcFolder + Path.DirectorySeparatorChar + "hotwallet-created-" + DateTime.UtcNow.ToString("yyyy-MM-dd--HH-mm-ss--fff.backup"), privateRoot.GetWif(Network.Main).ToWif(), Encoding.ASCII); // an extra backup
|
||||
Persistence.Key["BitcoinHotPublicRoot"] = privateRoot.Neuter().GetWif(Network.Main).ToWif();
|
||||
}
|
||||
}
|
||||
|
||||
public static ExtKey BitcoinHotPrivateRoot
|
||||
{
|
||||
get
|
||||
{
|
||||
VerifyBitcoinHotWallet();
|
||||
|
||||
return
|
||||
ExtKey.Parse (File.ReadAllText (SystemSettings.EtcFolder + Path.DirectorySeparatorChar + "hotwallet"));
|
||||
}
|
||||
}
|
||||
|
||||
public static ExtPubKey BitcoinHotPublicRoot
|
||||
{
|
||||
get
|
||||
{
|
||||
return ExtPubKey.Parse ((string) Persistence.Key["BitcoinHotPublicRoot"]);
|
||||
}
|
||||
}
|
||||
|
||||
public const int RootWalletIndex = 1;
|
||||
public const int RootDonationsIndex = 2;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -105,7 +105,7 @@ namespace Swarmops.Logic.Resources {
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to You have set a bitcoin payout address: [BitcoinAddress]. As a security precaution, all payouts are quarantined for the next 48 hours, and will proceed to be paid out to the new address after that.
|
||||
///
|
||||
///If you did not set your payout address, contact [OrganizationName] immediately..
|
||||
///If you did not set this payout address (it may be worth double checking the address above for added security), contact [OrganizationName] immediately..
|
||||
/// </summary>
|
||||
internal static string BitcoinPayoutAddress_Set_Body {
|
||||
get {
|
||||
|
||||
@@ -138,7 +138,7 @@ Please log on to [InstallationName] at [InstallationUrl] and follow the link to
|
||||
<data name="BitcoinPayoutAddress_Set_Body" xml:space="preserve">
|
||||
<value>You have set a bitcoin payout address: [BitcoinAddress]. As a security precaution, all payouts are quarantined for the next 48 hours, and will proceed to be paid out to the new address after that.
|
||||
|
||||
If you did not set your payout address, contact [OrganizationName] immediately.</value>
|
||||
If you did not set this payout address (it may be worth double checking the address above for added security), contact [OrganizationName] immediately.</value>
|
||||
</data>
|
||||
<data name="BitcoinPayoutAddress_Set_OfficerNotify_Body" xml:space="preserve">
|
||||
<value>A bitcoin payout address was set by [ConcernedPersonName]. Payouts will begin after 48 hours when the quarantine period has elapsed.</value>
|
||||
|
||||
+1
-1
@@ -106,7 +106,7 @@ namespace Swarmops.Logic.Resources {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Please set your bitcoin address for payouts from [InstallationName]:.
|
||||
/// Looks up a localized string similar to Please set your bitcoin address for payouts from [InstallationName] (spaces in the address are ok but not required):.
|
||||
/// </summary>
|
||||
internal static string Bitcoin_SetPayoutAddress_Prompt {
|
||||
get {
|
||||
|
||||
@@ -133,7 +133,7 @@
|
||||
<value>Set bitcoin payout address</value>
|
||||
</data>
|
||||
<data name="Bitcoin_SetPayoutAddress_Prompt" xml:space="preserve">
|
||||
<value>Please set your bitcoin address for payouts from [InstallationName]:</value>
|
||||
<value>Please set your bitcoin address for payouts from [InstallationName] (spaces in the address are ok but not required):</value>
|
||||
</data>
|
||||
<data name="Payout_Many" xml:space="preserve">
|
||||
<value>Settle {0} payouts</value>
|
||||
|
||||
@@ -4,10 +4,12 @@ using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.Remoting.Channels;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
// This class is just for readability of other code. Doesn't add any logic at all, really - just readability, like SystemSettings.SmtpHost instead of Persistence.blahblah.
|
||||
using System.Web;
|
||||
using NBitcoin;
|
||||
using Swarmops.Logic.Security;
|
||||
|
||||
@@ -212,5 +214,32 @@ namespace Swarmops.Logic.Support
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public static string EtcFolder
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Debugger.IsAttached && Path.DirectorySeparatorChar == '\\')
|
||||
{
|
||||
// Windows environment - dev environment
|
||||
|
||||
if (HttpContext.Current != null)
|
||||
{
|
||||
// If in HTTP context, return the root frontend folder
|
||||
|
||||
return HttpContext.Current.Server.MapPath ("~");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Not in HTTP context - debugging backend or something not considered at time of writing this
|
||||
|
||||
return "."; // current directory (execution directory)
|
||||
}
|
||||
}
|
||||
|
||||
return "/etc/swarmops"; // live etc folder
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -325,6 +325,16 @@
|
||||
<data name="CreateInboundInvoice_ValidationError_Account" xml:space="preserve">
|
||||
<value>Please enter the supplier's bank account or equivalent.</value>
|
||||
</data>
|
||||
<data name="Donate_Explain" xml:space="preserve">
|
||||
<value>This is a QR code for donations to {0}. Read it from your phone's bitcoin wallet to make a donation, or donate from your computer directly to [{1}] (that's a bitcoin address).</value>
|
||||
<comment>The {0} is the organization name. {1} is the bitcoin address for donations.</comment>
|
||||
</data>
|
||||
<data name="Donate_Info" xml:space="preserve">
|
||||
<value>If you want to donate to the organization, your can do so here.</value>
|
||||
</data>
|
||||
<data name="Donate_PageTitle" xml:space="preserve">
|
||||
<value>Donate</value>
|
||||
</data>
|
||||
<data name="FileExpenseClaim_Amount" xml:space="preserve">
|
||||
<value>Expense claim amount (in {0})</value>
|
||||
<comment>{0} is the currency.</comment>
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
<%@ Page Title="" Language="C#" MasterPageFile="~/Master-v5.master" AutoEventWireup="true" CodeFile="Donate.aspx.cs" Inherits="Swarmops.Frontend.Pages.v5.Financial.Donate" %>
|
||||
|
||||
<asp:Content ID="Content1" ContentPlaceHolderID="PlaceHolderHead" Runat="Server">
|
||||
</asp:Content>
|
||||
|
||||
<asp:Content ID="Content2" ContentPlaceHolderID="PlaceHolderMain" Runat="Server">
|
||||
<h2><asp:Label runat="server" ID="BoxTitle" /></h2>
|
||||
<p><asp:Label runat="server" ID="LabelExplainBitcoinDonation" /></p>
|
||||
<div align="center"><asp:Image ID="ImageBitcoinQr" runat="server"/></div>
|
||||
|
||||
</asp:Content>
|
||||
|
||||
<asp:Content ID="Content3" ContentPlaceHolderID="PlaceHolderSide" Runat="Server">
|
||||
</asp:Content>
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using NBitcoin;
|
||||
using Swarmops.Logic.Financial;
|
||||
using Swarmops.Logic.Security;
|
||||
|
||||
namespace Swarmops.Frontend.Pages.v5.Financial
|
||||
{
|
||||
public partial class Donate : PageV5Base
|
||||
{
|
||||
protected void Page_Load (object sender, EventArgs e)
|
||||
{
|
||||
this.PageAccessRequired = new Access (this.CurrentOrganization, AccessAspect.Null);
|
||||
|
||||
this.PageTitle = Resources.Pages.Financial.Donate_PageTitle;
|
||||
this.InfoBoxLiteral = Resources.Pages.Financial.FileExpenseClaim_Info;
|
||||
string bitcoinAddress =
|
||||
FinancialAccounts.BitcoinHotPublicRoot
|
||||
.Derive ((uint) this.CurrentOrganization.Identity)
|
||||
.Derive (FinancialAccounts.RootDonationsIndex)
|
||||
.PubKey.GetAddress (Network.Main)
|
||||
.ToString();
|
||||
|
||||
this.BoxTitle.Text = Resources.Pages.Financial.Donate_PageTitle;
|
||||
this.LabelExplainBitcoinDonation.Text = String.Format(Resources.Pages.Financial.Donate_Explain, CurrentOrganization.Name, bitcoinAddress);
|
||||
|
||||
this.ImageBitcoinQr.ImageUrl =
|
||||
"https://chart.googleapis.com/chart?cht=qr&chs=400x400&chl=bitcoin:" + bitcoinAddress + "&label=" + CurrentOrganization.Name.Replace ("&","et").Replace ("=", string.Empty); // URI scheme doesn't like &, =
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user