-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add SchemaType and method for constructing parameters using JSON
- Loading branch information
Showing
9 changed files
with
171 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
namespace Concordium.Sdk.Types; | ||
|
||
/// <summary> | ||
/// Smart contract schema type. | ||
/// This represents a single type as part of a smart contract module schema, and allows for | ||
/// converting structure data, such as JSON, from and to the binary representation used by a | ||
/// smart contract. | ||
/// </summary> | ||
public sealed record SchemaType(byte[] Type) : IEquatable<SchemaType> | ||
{ | ||
/// <summary>Construct SchemaType from a HEX encoding.</summary> | ||
public static SchemaType FromHexString(string hexString) | ||
{ | ||
var value = Convert.FromHexString(hexString); | ||
return new(value); | ||
} | ||
|
||
/// <summary>Construct SchemaType from a base64 encoding.</summary> | ||
public static SchemaType FromBase64String(string base64) | ||
{ | ||
var value = Convert.FromBase64String(base64); | ||
return new(value); | ||
} | ||
|
||
/// <summary>Check for equality.</summary> | ||
public bool Equals(SchemaType? other) => other != null && this.Type.SequenceEqual(other.Type); | ||
|
||
/// <summary>Gets hash code.</summary> | ||
public override int GetHashCode() | ||
{ | ||
var paramHash = Helpers.HashCode.GetHashCodeByteArray(this.Type); | ||
return paramHash; | ||
} | ||
|
||
/// <summary> | ||
/// Convert schema type to hex string. | ||
/// </summary> | ||
public string ToHexString() => Convert.ToHexString(this.Type).ToLowerInvariant(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
tests/UnitTests/Interop/__snapshots__/wCCD-wrap-param-hex-from-json.verified.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
00FFFA722D840687699743E5F1A1AD86113D0404115661AB09A3611BFFC1BDAABE0000 |