Skip to content

Commit

Permalink
Merge pull request #41 from IOTA-NET/8-feat-computestoragedeposit
Browse files Browse the repository at this point in the history
8 feat computestoragedeposit
  • Loading branch information
wireless90 authored Dec 6, 2023
2 parents 4ac68df + d3e7641 commit b51313b
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 0 deletions.
55 changes: 55 additions & 0 deletions IotaSDK.NET/Domain/Outputs/Output.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using JsonSubTypes;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;

namespace IotaSDK.NET.Domain.Outputs
{
[JsonConverter(typeof(JsonSubtypes), "Type")]
//[JsonSubtypes.KnownSubType(typeof(AliasOutput), 4)]
//[JsonSubtypes.KnownSubType(typeof(BasicOutput), 3)]
//[JsonSubtypes.KnownSubType(typeof(FoundryOutput), 5)]
//[JsonSubtypes.KnownSubType(typeof(NftOutput), 6)]
//[JsonSubtypes.KnownSubType(typeof(TreasuryOutput), 2)]
public abstract class Output
{
public Output(string amount, int type)
{
Amount = amount;
Type = type;
}

public string Amount { get; }
public int Type { get; }

public OutputType GetOutputType()
{
if (Enum.IsDefined(typeof(OutputType), this.Type))
{
return (OutputType)this.Type;
}
else
{
// Handle the case where the input value doesn't match any enum value
throw new ArgumentOutOfRangeException(nameof(this.Type), "Invalid OutputType value");
}
}

public ulong GetAmount()
{
if(ulong.TryParse(this.Amount, out var value))
{
return value;
}
throw new ArgumentOutOfRangeException(nameof(this.Amount), $"Invalid Amount of {Amount}");

}
}

public abstract class CommonOutput : Output
{
protected CommonOutput(string amount, int type) : base(amount, type)
{
}
}
}
27 changes: 27 additions & 0 deletions IotaSDK.NET/Domain/UnlockConditions/UnlockCondition.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;

namespace IotaSDK.NET.Domain.UnlockConditions
{
public abstract class UnlockCondition
{
public UnlockCondition(int type)
{
Type = type;
}

public int Type { get; }

public UnlockConditionType GetUnlockConditionType()
{
if (Enum.IsDefined(typeof(UnlockConditionType), this.Type))
{
return (UnlockConditionType)this.Type;
}
else
{
// Handle the case where the input value doesn't match any enum value
throw new ArgumentOutOfRangeException(nameof(this.Type), "Invalid UnlockConditionType value");
}
}
}
}
35 changes: 35 additions & 0 deletions IotaSDK.NET/Domain/UnlockConditions/UnlockConditionType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using IotaSDK.NET.Domain.Outputs;
using System.Runtime.InteropServices;

namespace IotaSDK.NET.Domain.UnlockConditions
{
/**
* All of the unlock condition types.
*/
public enum UnlockConditionType
{
/** An address unlock condition. */
Address = 0,
/** A storage deposit return unlock condition. */
StorageDepositReturn = 1,
/** A timelock unlock condition. */
Timelock = 2,
/** An expiration unlock condition. */
Expiration = 3,
/** A state controller address unlock condition. */
StateControllerAddress = 4,
/** A governor address unlock condition. */
GovernorAddress = 5,
/** An immutable alias address unlock condition. */
ImmutableAliasAddress = 6,
}

public class AddressUnlockCondition : UnlockCondition
{
public AddressUnlockCondition(int type) : base(type)
{
}


}
}
1 change: 1 addition & 0 deletions IotaSDK.NET/IotaSDK.NET.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="JsonSubTypes" Version="2.0.1" />
<PackageReference Include="MediatR" Version="12.2.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>
Expand Down

0 comments on commit b51313b

Please sign in to comment.