diff --git a/SharedBuildProperties.props b/SharedBuildProperties.props index e7db907..fd4d072 100644 --- a/SharedBuildProperties.props +++ b/SharedBuildProperties.props @@ -2,7 +2,7 @@ xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> Solnet - 0.2.7 + 0.2.8 Copyright 2022 © Solnet blockmountain blockmountain diff --git a/Solnet.Anchor/Converters/IIdlAccountItemConverter.cs b/Solnet.Anchor/Converters/IIdlAccountItemConverter.cs index 1eb6171..83cbd7a 100644 --- a/Solnet.Anchor/Converters/IIdlAccountItemConverter.cs +++ b/Solnet.Anchor/Converters/IIdlAccountItemConverter.cs @@ -1,97 +1,79 @@ -using Solnet.Anchor.Models.Accounts; -using Solnet.Anchor.Models.Types; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Text.Json; -using System.Text.Json.Serialization; -using System.Threading.Tasks; - -namespace Solnet.Anchor.Converters -{ - public class IIdlAccountItemConverter : JsonConverter - { - public override IIdlAccountItem[] Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) - { - if (reader.TokenType != JsonTokenType.StartArray) return null; - - List accountItems = new List(); - - while (reader.Read() && reader.TokenType == JsonTokenType.StartObject) - { - //IIdlAccountItem acc = - - reader.Read(); - if (reader.TokenType != JsonTokenType.PropertyName) throw new JsonException("Unexpected error value."); - - string propertyName = reader.GetString(); - if ("name" != propertyName) throw new JsonException("Unexpected error value."); - - reader.Read(); - if (reader.TokenType != JsonTokenType.String) throw new JsonException("Unexpected error value."); - - string name = reader.GetString(); - - reader.Read(); - if (reader.TokenType != JsonTokenType.PropertyName) throw new JsonException("Unexpected error value."); - - propertyName = reader.GetString(); - reader.Read(); - - if ("accounts" == propertyName) - { - IdlAccounts accounts = new(); - accounts.Name = name; - - accounts.Accounts = Read(ref reader, typeToConvert, options); - accountItems.Add(accounts); - } - else - { - IdlAccount account = new(); - account.Name = name; - - if ("isMut" != propertyName) throw new JsonException("Unexpected error value."); - account.IsMut = reader.GetBoolean(); - - reader.Read(); - - if (reader.TokenType != JsonTokenType.PropertyName) throw new JsonException("Unexpected error value."); - - propertyName = reader.GetString(); - reader.Read(); - if ("isSigner" != propertyName) throw new JsonException("Unexpected error value."); - account.IsSigner = reader.GetBoolean(); - accountItems.Add(account); - - reader.Read(); - - if(reader.TokenType == JsonTokenType.PropertyName) - { - var prop = reader.GetString(); - - if ("pda" != prop) throw new JsonException("Unexpected property."); - - reader.Read(); - - account.Pda = JsonSerializer.Deserialize(ref reader, options); - reader.Read(); - } - } - - // object end - if(reader.TokenType != JsonTokenType.EndObject) - reader.Read(); - } - //array end - //reader.Read(); - return accountItems.ToArray(); - } - - public override void Write(Utf8JsonWriter writer, IIdlAccountItem[] value, JsonSerializerOptions options) - { - throw new NotImplementedException(); - } - } +using Solnet.Anchor.Models.Accounts; +using Solnet.Anchor.Models.Types; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.Json; +using System.Text.Json.Serialization; +using System.Threading.Tasks; + +namespace Solnet.Anchor.Converters +{ + public class IIdlAccountItemConverter : JsonConverter + { + public override IIdlAccountItem[] Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + if (reader.TokenType != JsonTokenType.StartArray) return null; + + List accountItems = new List(); + + reader.Read(); + + + while (reader.TokenType == JsonTokenType.StartObject) + { + Utf8JsonReader readerCopy = reader; + //IIdlAccountItem acc = + + reader.Read(); + if (reader.TokenType != JsonTokenType.PropertyName) throw new JsonException("Unexpected error value."); + + string propertyName = reader.GetString(); + if ("name" != propertyName) throw new JsonException("Unexpected error value."); + + reader.Read(); + if (reader.TokenType != JsonTokenType.String) throw new JsonException("Unexpected error value."); + + string name = reader.GetString(); + + reader.Read(); + if (reader.TokenType != JsonTokenType.PropertyName) throw new JsonException("Unexpected error value."); + + propertyName = reader.GetString(); + reader.Read(); + + if ("accounts" == propertyName) + { + IdlAccounts accounts = new(); + accounts.Name = name; + + accounts.Accounts = Read(ref reader, typeToConvert, options); + accountItems.Add(accounts); + } + else + { + IdlAccount account = JsonSerializer.Deserialize(ref readerCopy, options); + + accountItems.Add(account); + + reader = readerCopy; + } + + // object end + if(reader.TokenType != JsonTokenType.EndObject) + reader.Read(); + reader.Read(); + + } + //array end + //reader.Read(); + return accountItems.ToArray(); + } + + public override void Write(Utf8JsonWriter writer, IIdlAccountItem[] value, JsonSerializerOptions options) + { + throw new NotImplementedException(); + } + } } \ No newline at end of file diff --git a/Solnet.Anchor/Models/Accounts/IdlAccount.cs b/Solnet.Anchor/Models/Accounts/IdlAccount.cs index a95f15f..946d1ff 100644 --- a/Solnet.Anchor/Models/Accounts/IdlAccount.cs +++ b/Solnet.Anchor/Models/Accounts/IdlAccount.cs @@ -1,23 +1,25 @@ -using Solnet.Anchor.CodeGen; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Solnet.Anchor.Models.Accounts -{ - public class IdlAccount : IIdlAccountItem - { - public string Name { get; set; } - - public string NamePascalCase => Name.ToPascalCase(); - - public bool IsMut { get; set; } - - public bool IsSigner { get; set; } - - public IdlPda Pda { get; set; } - - } +using Solnet.Anchor.CodeGen; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Solnet.Anchor.Models.Accounts +{ + public class IdlAccount : IIdlAccountItem + { + public string Name { get; set; } + + public string Description { get; set; } + + public string NamePascalCase => Name.ToPascalCase(); + + public bool IsMut { get; set; } + + public bool IsSigner { get; set; } + + public IdlPda Pda { get; set; } + + } } \ No newline at end of file