Skip to content

Commit

Permalink
Merge pull request #110 from DiscreetNetwork/patch/testing-blockbuffer
Browse files Browse the repository at this point in the history
Patch/testing blockbuffer
  • Loading branch information
BrandonKoerner authored Feb 29, 2024
2 parents 805bf1f + de2256d commit b5a12ad
Show file tree
Hide file tree
Showing 17 changed files with 1,005 additions and 171 deletions.
4 changes: 2 additions & 2 deletions Discreet/Cipher/Native/DiscreetCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@ public static extern Triptych triptych_PROVE(
[MarshalAs(UnmanagedType.Struct)] Key message);

[DllImport("DiscreetCore")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool triptych_VERIFY(
[return: MarshalAs(UnmanagedType.U1)]
public static extern byte triptych_VERIFY(
[In, Out] Triptych bp,
[MarshalAs(UnmanagedType.LPArray, SizeConst = 64, ArraySubType = UnmanagedType.Struct)] Key[] M,
[MarshalAs(UnmanagedType.LPArray, SizeConst = 64, ArraySubType = UnmanagedType.Struct)] Key[] P,
Expand Down
4 changes: 2 additions & 2 deletions Discreet/Cipher/Native/Native.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ public delegate Triptych triptych_PROVEDelegate(
[MarshalAs(UnmanagedType.Struct)] Key r,
[MarshalAs(UnmanagedType.Struct)] Key s,
[MarshalAs(UnmanagedType.Struct)] Key message);
[return: MarshalAs(UnmanagedType.Bool)]
public delegate bool triptych_VERIFYDelegate(
[return: MarshalAs(UnmanagedType.U1)]
public delegate byte triptych_VERIFYDelegate(
[In, Out] Triptych bp,
[MarshalAs(UnmanagedType.LPArray, SizeConst = 64, ArraySubType = UnmanagedType.Struct)] Key[] M,
[MarshalAs(UnmanagedType.LPArray, SizeConst = 64, ArraySubType = UnmanagedType.Struct)] Key[] P,
Expand Down
2 changes: 1 addition & 1 deletion Discreet/Cipher/Triptych.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public static Triptych Prove(Key[] M, Key[] P, Key C_offset, uint l, Key r, Key
return proof;
}

public static bool triptych_VERIFY(Triptych bp, Key[] M, Key[] P, Key C_offset, Key message) => Native.Native.Instance.triptych_VERIFY(bp, M, P, C_offset, message);
public static bool triptych_VERIFY(Triptych bp, Key[] M, Key[] P, Key C_offset, Key message) => Native.Native.Instance.triptych_VERIFY(bp, M, P, C_offset, message) != 0;

public static bool Verify(Triptych bp, Key[] M, Key[] P, Key C_offset, Key message)
{
Expand Down
13 changes: 12 additions & 1 deletion Discreet/Coin/Converters/TransactionConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public override Models.FullTransaction Read(ref Utf8JsonReader reader, Type type
reader.Read();
version = reader.GetByte();
if (version >= (byte)Config.TransactionVersions.END) throw new JsonException("FullTransaction version exceeds defined range");
transaction.Version = version;

switch (version)
{
Expand All @@ -85,7 +86,7 @@ public override Models.FullTransaction Read(ref Utf8JsonReader reader, Type type

while (reader.Read())
{
if (reader.TokenType == JsonTokenType.EndObject) return transaction;
if (reader.TokenType == JsonTokenType.EndObject) break;

if (reader.TokenType == JsonTokenType.PropertyName)
{
Expand Down Expand Up @@ -206,6 +207,16 @@ public override Models.FullTransaction Read(ref Utf8JsonReader reader, Type type
}
}

if (transaction.Version == 3)
{
transaction.NumTInputs = transaction.NumInputs;
transaction.NumTOutputs = transaction.NumOutputs;
}
else if (transaction.Version == 2 || transaction.Version == 1 || transaction.Version == 0)
{
transaction.NumPInputs = transaction.NumInputs;
transaction.NumPOutputs = transaction.NumOutputs;
}
return transaction;
}

Expand Down
6 changes: 4 additions & 2 deletions Discreet/Coin/Models/Block.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Discreet.Common.Serialize;
using System.Text.Json;
using Discreet.Daemon;
using Discreet.DB;

namespace Discreet.Coin.Models
{
Expand Down Expand Up @@ -84,8 +85,9 @@ public static Block Build(List<FullTransaction> txs, StealthAddress miner, Key s
block.Header.BlockSize += txs[i].GetSize();
}

DB.DataView dataView = DB.DataView.GetView();

// because of block buffer, we need to use that instead
IView dataView = BlockBuffer.Instance;

block.Header.Height = dataView.GetChainHeight() + 1;

if (block.Header.Height > 0)
Expand Down
18 changes: 18 additions & 0 deletions Discreet/DB/AlreadyPresentException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Discreet.Common.Exceptions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Discreet.DB
{
public class AlreadyPresentException : VerifyException
{
public AlreadyPresentException(string msg) : base("Discreet.Coin.Verify: " + msg) { }

public AlreadyPresentException(string type, string msg) : base("Discreet.Coin." + type + ".Verify: " + msg) { }

public AlreadyPresentException(string type, string vertype, string msg) : base("Discreet.Coin." + type + "Verify" + vertype + ": " + msg) { }
}
}
Loading

0 comments on commit b5a12ad

Please sign in to comment.