Preparing for blockchain fork code upgrade

This commit is contained in:
Rick Falkvinge
2017-12-04 12:52:14 +01:00
parent bda7e5b764
commit 962d1ac8fa
11 changed files with 275 additions and 0 deletions
+1
View File
@@ -57,6 +57,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Types\Common\BlockchainHash.cs" />
<Compile Include="Types\Financial\BasicHotBitcoinAddress.cs" />
<Compile Include="Types\Financial\BasicHotBitcoinAddressUnspent.cs" />
<Compile Include="Types\Financial\BasicVatReport.cs" />
+48
View File
@@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Swarmops.Common.Enums;
namespace Swarmops.Basic.Types.Common
{
[Serializable]
public class BlockchainHash
{
[Obsolete("Do not call the parameterless ctor", true)]
public BlockchainHash()
{
// do not call the parameterless ctor; it is there for serialization to work
}
public BlockchainHash(BitcoinChain chain, string hash)
{
this.Chain = chain;
this.Hash = hash;
}
public BitcoinChain Chain { get; private set; }
public string Hash { get; private set; }
public static BlockchainHash Parse(string input)
{
int indexOfDash = input.IndexOf('-');
if (indexOfDash < 0)
{
throw new ArgumentException("Invalid chain hash");
}
string chainPart = input.Substring(0, indexOfDash);
string hashPart = input.Substring(indexOfDash + 1);
BitcoinChain chain = (BitcoinChain) Enum.Parse(typeof (BitcoinChain), chainPart);
return new BlockchainHash(chain, hashPart);
}
public new string ToString()
{
return this.Chain.ToString() + "-" + this.Hash;
}
}
}
+97
View File
@@ -0,0 +1,97 @@
using System;
using Swarmops.Common.Enums;
using Swarmops.Common.Interfaces;
namespace Swarmops.Basic.Types.Structure
{
public class BasicDocument : IHasIdentity
{
private readonly string clientFileName;
private readonly int documentId;
private readonly DocumentType documentType;
private readonly Int64 fileSize;
private readonly int foreignId;
private readonly int uploadedByPersonId;
private readonly DateTime uploadedDateTime;
private string description;
private string serverFileName;
#region IHasIdentity Members
public int Identity
{
get { return this.DocumentId; }
}
#endregion
public BasicDocument (int documentId, string serverFileName, string clientFileName, string description,
DocumentType documentType, int foreignId, Int64 fileSize, int uploadedByPersonId, DateTime uploadedDateTime)
{
this.documentId = documentId;
this.serverFileName = serverFileName;
this.clientFileName = clientFileName;
this.description = description;
this.documentType = documentType;
this.foreignId = foreignId;
this.fileSize = fileSize;
this.uploadedByPersonId = uploadedByPersonId;
this.uploadedDateTime = uploadedDateTime;
}
public BasicDocument (BasicDocument original) :
this (original.documentId, original.serverFileName, original.clientFileName, original.description,
original.documentType, original.foreignId, original.fileSize, original.uploadedByPersonId,
original.uploadedDateTime)
{
// empty ctor apart from calling the other one
}
public int DocumentId
{
get { return this.documentId; }
}
public string ServerFileName
{
get { return this.serverFileName; }
protected set { this.serverFileName = value; }
}
public string ClientFileName
{
get { return this.clientFileName; }
}
public string Description
{
get { return this.description; }
protected set { this.description = value; }
}
public DocumentType DocumentType
{
get { return this.documentType; }
}
public int ForeignId
{
get { return this.foreignId; }
}
public Int64 FileSize
{
get { return this.fileSize; }
}
public int UploadedByPersonId
{
get { return this.uploadedByPersonId; }
}
public DateTime UploadedDateTime
{
get { return this.uploadedDateTime; }
}
}
}
@@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Swarmops.Logic.Support;
namespace Swarmops.Logic.Financial
{
internal class BitcoinBlockchainUpgrade
{
static internal void Upgrade(int fromVersion)
{
fromVersion -= fromVersion%2;
int toVersion = BitcoinUtility.ExpectedBlockchainCodeVersion;
while (fromVersion < toVersion)
{
SystemSettings.BlockchainCodeVersion = fromVersion + 1; // Indicates upgrade in progress
switch (fromVersion)
{
case 0:
SplitCashFromCore();
break;
default:
throw new NotImplementedException("Unimplemented upgrade path");
}
fromVersion += 2;
}
SystemSettings.BlockchainCodeVersion = fromVersion;
}
static internal void SplitCashFromCore()
{
}
}
}
+17
View File
@@ -37,6 +37,23 @@ namespace Swarmops.Logic.Financial
}
/// <summary>
/// Always an even number. If an odd number, the upgrade to the next even number
/// is currently in progress, and all blockchain operations are halted.
/// </summary>
public static int ExpectedBlockchainCodeVersion => 2;
public static bool CurrentlyUpgrading
{
get { return SystemSettings.BlockchainCodeVersion%2 == 1 ? true : false; }
}
public static void Upgrade(int fromVersion)
{
BitcoinBlockchainUpgrade.Upgrade(fromVersion);
}
public static void VerifyBitcoinHotWallet()
{
// This must only be run from the backend
+1
View File
@@ -131,6 +131,7 @@
<Compile Include="Communications\IHasGeography.cs" />
<Compile Include="Communications\Resolution\ParticipantResolver.cs" />
<Compile Include="Communications\Resolution\ResolverEnvelope.cs" />
<Compile Include="Financial\BitcoinBlockchainUpgrade.cs" />
<Compile Include="Financial\BitcoinTransactionInput.cs" />
<Compile Include="Financial\BitcoinUtility.cs" />
<Compile Include="Financial\HotBitcoinAddress.cs" />
+23
View File
@@ -282,6 +282,29 @@ namespace Swarmops.Logic.Support
}
public static int BlockchainCodeVersion
{
get
{
string result = Persistence.Key["BlockchainCodeVersion"];
if (!string.IsNullOrEmpty(result))
{
try
{
return Int32.Parse(result);
}
catch (Exception)
{
return 0;
}
}
return 0;
}
set { Persistence.Key["BlockchainCodeVersion"] = value.ToString(CultureInfo.InvariantCulture); }
}
public static bool DatabaseInitialized
{
get { return !String.IsNullOrEmpty(InstallationId); }
@@ -0,0 +1,13 @@
<%@ Page Title="" Language="C#" MasterPageFile="~/Master-v5.master" AutoEventWireup="true" Inherits="Pages_v5_Finance_BlockchainCodeUpgrading" Codebehind="BlockchainCodeUpgrading.aspx.cs" %>
<asp:Content ID="Content1" ContentPlaceHolderID="PlaceHolderHead" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="PlaceHolderMain" Runat="Server">
<h2>A blockchain upgrade is in progress</h2>
<img alt="Fail symbol" src="/Images/Icons/iconshock-wrench-128x96px-centered.png" align="left" />A blockchain upgrade is currently in progress, either within Swarmops or on the blockchain itself. Financial operations are suspended until the upgrade is completed. This could be in minutes or in hours; check the appropriate bulletins.
<div style="clear:both"></div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="PlaceHolderSide" Runat="Server">
</asp:Content>
@@ -0,0 +1,12 @@
using System;
using Swarmops.Frontend;
public partial class Pages_v5_Finance_BlockchainCodeUpgrading : PageV5Base
{
protected void Page_Load (object sender, EventArgs e)
{
PageTitle = "Upgrade in progress";
PageIcon = "iconshock-coins-cross";
InfoBoxLiteral = "An upgrade of the blockchain is in progress. Until the upgrade has verifiably completed, all financial operations are suspended.";
}
}
@@ -0,0 +1,13 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
public partial class Pages_v5_Finance_BlockchainCodeUpgrading {
}
+8
View File
@@ -216,6 +216,13 @@
<Compile Include="Pages\v5\Comms\SendMassMessage.aspx.designer.cs">
<DependentUpon>SendMassMessage.aspx</DependentUpon>
</Compile>
<Compile Include="Pages\v5\Financial\BlockchainCodeUpgrading.aspx.cs">
<DependentUpon>BlockchainCodeUpgrading.aspx</DependentUpon>
<SubType>ASPXCodeBehind</SubType>
</Compile>
<Compile Include="Pages\v5\Financial\BlockchainCodeUpgrading.aspx.designer.cs">
<DependentUpon>BlockchainCodeUpgrading.aspx</DependentUpon>
</Compile>
<Compile Include="Pages\v5\Financial\Json-ListInvoicesOutbound.aspx.cs">
<DependentUpon>Json-ListInvoicesOutbound.aspx</DependentUpon>
<SubType>ASPXCodeBehind</SubType>
@@ -1110,6 +1117,7 @@
<Content Include="Pages\v5\Admin\OrgStaffing.aspx" />
<Content Include="Pages\v5\Admin\SystemSettings.aspx" />
<Content Include="Pages\v5\Comms\SendMassMessage.aspx" />
<Content Include="Pages\v5\Financial\BlockchainCodeUpgrading.aspx" />
<Content Include="Pages\v5\Financial\Json-ListInvoicesOutbound.aspx" />
<Content Include="Pages\v5\Financial\Json-ListInvoicesInbound.aspx" />
<Content Include="Pages\v5\Financial\ListInvoicesOutbound.aspx" />