Skip to content

Commit

Permalink
Merge pull request #45 from RemarkableTools/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
axenteoctavian authored Jul 27, 2023
2 parents 5e82dfb + 46ae0de commit 64c3060
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/Mx.NET.SDK.Core/Domain/Abi/Abi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class Input
public string Name { get; set; }
public string Type { get; set; }

[JsonProperty("multi_arg")]
[JsonProperty("multi_arg")]
public bool MultiArg { get; set; }
}

Expand Down Expand Up @@ -40,11 +40,17 @@ public class Endpoint
public string[] PayableInTokens { get; set; }
}

public class Event
{
public string Identifier { get; set; }
public Input[] Inputs { get; set; }
}

public class Output
{
public string Type { get; set; }

[JsonProperty("multi_result")]
[JsonProperty("multi_result")]
public bool MultiResult { get; set; }
}
}
Expand Down
12 changes: 12 additions & 0 deletions src/Mx.NET.SDK.Core/Domain/Abi/AbiDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class AbiDefinition
{
public string Name { get; set; }
public Abi.Endpoint[] Endpoints { get; set; }
public Abi.Event[] Events { get; set; }
public Dictionary<string, Abi.CustomTypes> Types { get; set; }

public EndpointDefinition GetEndpointDefinition(string endpoint)
Expand All @@ -28,6 +29,17 @@ public EndpointDefinition GetEndpointDefinition(string endpoint)
return new EndpointDefinition(endpoint, inputs.ToArray(), outputs.ToArray());
}

public EventDefinition GetEventDefinition(string identifier)
{
var data = Events.ToList().SingleOrDefault(s => s.Identifier == identifier) ?? throw new Exception("Event is not defined in ABI");

var inputs = data.Inputs is null ?
new List<FieldDefinition>() :
data.Inputs.Select(i => new FieldDefinition(i.Name, "", GetTypeValue(i.Type))).ToList();

return new EventDefinition(identifier, inputs.ToArray());
}

private TypeValue GetTypeValue(string rustType)
{
var optional = new Regex("^optional<(.*)>$");
Expand Down
16 changes: 16 additions & 0 deletions src/Mx.NET.SDK.Core/Domain/Abi/EventDefinition.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Mx.NET.SDK.Core.Domain.Values;

namespace Mx.NET.SDK.Core.Domain.Abi
{
public class EventDefinition
{
public string Identifier { get; }
public FieldDefinition[] Input { get; }

public EventDefinition(string identifier, FieldDefinition[] input)
{
Identifier = identifier;
Input = input;
}
}
}
2 changes: 1 addition & 1 deletion src/Mx.NET.SDK.Core/Domain/Codec/NumericBinaryCodec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class NumericBinaryCodec : IBinaryCodec
var payload = data.Slice(BytesSizeOfU32, BytesSizeOfU32 + sizeInBytes);
var bigNumber = Converter.ToBigInteger(payload, !type.HasSign(), isBigEndian: true);

return (new NumericValue(type, bigNumber), sizeInBytes + payload.Length);
return (new NumericValue(type, bigNumber), BytesSizeOfU32 + payload.Length);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Mx.NET.SDK/Mx.NET.SDK.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<RepositoryUrl>https://github.com/RemarkableTools/Mx.NET.SDK</RepositoryUrl>
<RepositoryType>GitHub</RepositoryType>
<Company>Remarkable Tools</Company>
<Version>2.0.1</Version>
<Version>2.0.2</Version>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Title>RemarkableTools.Mx</Title>
<PackageReadmeFile>README.md</PackageReadmeFile>
Expand Down

0 comments on commit 64c3060

Please sign in to comment.