Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

programmatic json with property names from schema #370

Merged
merged 6 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ _WORK IN PROGRESS_
- Added package details to `/satus/entity/details` endpoint.
- New endpoint `/statistics/validators/uptime` returns validator uptime data.
- New endpoint `/state/key-value/data` returns entries of requested KeyValueStore.
- Return programmatic json with type names for:
- key-value key and data in `/state/key-value/data` endpoint
- non fungible data in `/state/non-fungible/data` endpoint
- events in `/transaction/committed-details` and `/stream/transactions` endpoints.

-------

Expand Down
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@
<PackageVersion Include="xunit" Version="2.5.0" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.0" />
</ItemGroup>
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
*/

using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;

namespace RadixDlt.CoreApiSdk.Model;
Expand All @@ -78,4 +79,30 @@ public IEnumerable<string> GetEntityAddresses()

return Enumerable.Empty<string>();
}

public bool TryGetObjectInstanceSchema([NotNullWhen(true)] out InstanceSchema instanceSchema)
{
instanceSchema = null;

if (Value.Details is ObjectTypeInfoDetails objectTypeInfoDetails && objectTypeInfoDetails.InstanceSchema != null)
{
instanceSchema = objectTypeInfoDetails.InstanceSchema;
return true;
}

return false;
}

public bool TryGetKeyValueStoreSchema([NotNullWhen(true)] out KeyValueStoreSchema keyValueStoreSchema)
{
keyValueStoreSchema = null;

if (Value.Details is KeyValueStoreTypeInfoDetails keyValueStoreTypeInfoDetails && keyValueStoreTypeInfoDetails.KeyValueStoreInfo.KvStoreSchema != null)
{
keyValueStoreSchema = keyValueStoreTypeInfoDetails.KeyValueStoreInfo.KvStoreSchema;
return true;
}

return false;
}
}
10 changes: 10 additions & 0 deletions src/RadixDlt.NetworkGateway.Abstractions/Model/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,14 @@ public static ObjectModuleId ToInternalModel(this CoreModel.ObjectModuleId objec
_ => throw new UnreachableException($"Didn't expect {objectModuleId} value"),
};
}

public static SborTypeKind ToInternalModel(this CoreModel.LocalTypeIndex.KindEnum indexKind)
{
return indexKind switch
{
CoreModel.LocalTypeIndex.KindEnum.SchemaLocal => SborTypeKind.SchemaLocal,
CoreModel.LocalTypeIndex.KindEnum.WellKnown => SborTypeKind.WellKnown,
_ => throw new UnreachableException($"Didn't expect {indexKind} value"),
};
}
}
71 changes: 71 additions & 0 deletions src/RadixDlt.NetworkGateway.Abstractions/Model/SborTypeKind.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/* Copyright 2021 Radix Publishing Ltd incorporated in Jersey (Channel Islands).
*
* Licensed under the Radix License, Version 1.0 (the "License"); you may not use this
* file except in compliance with the License. You may obtain a copy of the License at:
*
* radixfoundation.org/licenses/LICENSE-v1
*
* The Licensor hereby grants permission for the Canonical version of the Work to be
* published, distributed and used under or by reference to the Licensor’s trademark
* Radix ® and use of any unregistered trade names, logos or get-up.
*
* The Licensor provides the Work (and each Contributor provides its Contributions) on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
* including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT,
* MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE.
*
* Whilst the Work is capable of being deployed, used and adopted (instantiated) to create
* a distributed ledger it is your responsibility to test and validate the code, together
* with all logic and performance of that code under all foreseeable scenarios.
*
* The Licensor does not make or purport to make and hereby excludes liability for all
* and any representation, warranty or undertaking in any form whatsoever, whether express
* or implied, to any entity or person, including any representation, warranty or
* undertaking, as to the functionality security use, value or other characteristics of
* any distributed ledger nor in respect the functioning or value of any tokens which may
* be created stored or transferred using the Work. The Licensor does not warrant that the
* Work or any use of the Work complies with any law or regulation in any territory where
* it may be implemented or used or that it will be appropriate for any specific purpose.
*
* Neither the licensor nor any current or former employees, officers, directors, partners,
* trustees, representatives, agents, advisors, contractors, or volunteers of the Licensor
* shall be liable for any direct or indirect, special, incidental, consequential or other
* losses of any kind, in tort, contract or otherwise (including but not limited to loss
* of revenue, income or profits, or loss of use or data, or loss of reputation, or loss
* of any economic or other opportunity of whatsoever nature or howsoever arising), arising
* out of or in connection with (without limitation of any use, misuse, of any ledger system
* or use made or its functionality or any performance or operation of any code or protocol
* caused by bugs or programming or logic errors or otherwise);
*
* A. any offer, purchase, holding, use, sale, exchange or transmission of any
* cryptographic keys, tokens or assets created, exchanged, stored or arising from any
* interaction with the Work;
*
* B. any failure in a transmission or loss of any token or assets keys or other digital
* artefacts due to errors in transmission;
*
* C. bugs, hacks, logic errors or faults in the Work or any communication;
*
* D. system software or apparatus including but not limited to losses caused by errors
* in holding or transmitting tokens by any third-party;
*
* E. breaches or failure of security including hacker attacks, loss or disclosure of
* password, loss of private key, unauthorised use or misuse of such passwords or keys;
*
* F. any losses including loss of anticipated savings or other benefits resulting from
* use of the Work or any changes to the Work (however implemented).
*
* You are solely responsible for; testing, validating and evaluation of all operation
* logic, functionality, security and appropriateness of using the Work for any commercial
* or non-commercial purpose and for any reproduction or redistribution by You of the
* Work. You assume all risks associated with Your use of the Work and the exercise of
* permissions under this License.
*/

namespace RadixDlt.NetworkGateway.Abstractions.Model;

public enum SborTypeKind
{
WellKnown,
SchemaLocal,
}
16 changes: 8 additions & 8 deletions src/RadixDlt.NetworkGateway.GatewayApi/gateway-api-schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -897,11 +897,11 @@ components:
type: object
required:
- raw_hex
- raw_json
krzlabrdx marked this conversation as resolved.
Show resolved Hide resolved
- programmatic_json
properties:
raw_hex:
type: string
raw_json:
programmatic_json:
type: object

EntityMetadataCollection:
Expand Down Expand Up @@ -2317,15 +2317,15 @@ components:
StateKeyValueStoreDataResponseItem:
type: object
required:
- key_hex
- value_hex
- key
- value
- last_updated_at_state_version
- is_locked
properties:
key_hex:
$ref: "#/components/schemas/HexString"
value_hex:
$ref: "#/components/schemas/HexString"
key:
$ref: "#/components/schemas/ScryptoSborValue"
value:
$ref: "#/components/schemas/ScryptoSborValue"
last_updated_at_state_version:
$ref: "#/components/schemas/LastUpdatedAtStateVersion"
is_locked:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,22 +104,22 @@ protected EntityMetadataItemValue() { }
/// Initializes a new instance of the <see cref="EntityMetadataItemValue" /> class.
/// </summary>
/// <param name="rawHex">rawHex (required).</param>
/// <param name="rawJson">rawJson (required).</param>
/// <param name="json">json (required).</param>
/// <param name="typed">typed (required).</param>
public EntityMetadataItemValue(string rawHex = default(string), Object rawJson = default(Object), MetadataTypedValue typed = default(MetadataTypedValue))
public EntityMetadataItemValue(string rawHex = default(string), Object json = default(Object), MetadataTypedValue typed = default(MetadataTypedValue))
{
// to ensure "rawHex" is required (not null)
if (rawHex == null)
{
throw new ArgumentNullException("rawHex is a required property for EntityMetadataItemValue and cannot be null");
}
this.RawHex = rawHex;
// to ensure "rawJson" is required (not null)
if (rawJson == null)
// to ensure "json" is required (not null)
if (json == null)
{
throw new ArgumentNullException("rawJson is a required property for EntityMetadataItemValue and cannot be null");
throw new ArgumentNullException("json is a required property for EntityMetadataItemValue and cannot be null");
}
this.RawJson = rawJson;
this.Json = json;
// to ensure "typed" is required (not null)
if (typed == null)
{
Expand All @@ -135,10 +135,10 @@ protected EntityMetadataItemValue() { }
public string RawHex { get; set; }

/// <summary>
/// Gets or Sets RawJson
/// Gets or Sets Json
/// </summary>
[DataMember(Name = "raw_json", IsRequired = true, EmitDefaultValue = true)]
public Object RawJson { get; set; }
[DataMember(Name = "json", IsRequired = true, EmitDefaultValue = true)]
public Object Json { get; set; }

/// <summary>
/// Gets or Sets Typed
Expand All @@ -155,7 +155,7 @@ public override string ToString()
StringBuilder sb = new StringBuilder();
sb.Append("class EntityMetadataItemValue {\n");
sb.Append(" RawHex: ").Append(RawHex).Append("\n");
sb.Append(" RawJson: ").Append(RawJson).Append("\n");
sb.Append(" Json: ").Append(Json).Append("\n");
sb.Append(" Typed: ").Append(Typed).Append("\n");
sb.Append("}\n");
return sb.ToString();
Expand Down Expand Up @@ -198,9 +198,9 @@ public bool Equals(EntityMetadataItemValue input)
this.RawHex.Equals(input.RawHex))
) &&
(
this.RawJson == input.RawJson ||
(this.RawJson != null &&
this.RawJson.Equals(input.RawJson))
this.Json == input.Json ||
(this.Json != null &&
this.Json.Equals(input.Json))
) &&
(
this.Typed == input.Typed ||
Expand All @@ -222,9 +222,9 @@ public override int GetHashCode()
{
hashCode = (hashCode * 59) + this.RawHex.GetHashCode();
}
if (this.RawJson != null)
if (this.Json != null)
{
hashCode = (hashCode * 59) + this.RawJson.GetHashCode();
hashCode = (hashCode * 59) + this.Json.GetHashCode();
}
if (this.Typed != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,21 +104,21 @@ protected ScryptoSborValue() { }
/// Initializes a new instance of the <see cref="ScryptoSborValue" /> class.
/// </summary>
/// <param name="rawHex">rawHex (required).</param>
/// <param name="rawJson">rawJson (required).</param>
public ScryptoSborValue(string rawHex = default(string), Object rawJson = default(Object))
/// <param name="json">json (required).</param>
public ScryptoSborValue(string rawHex = default(string), Object json = default(Object))
{
// to ensure "rawHex" is required (not null)
if (rawHex == null)
{
throw new ArgumentNullException("rawHex is a required property for ScryptoSborValue and cannot be null");
}
this.RawHex = rawHex;
// to ensure "rawJson" is required (not null)
if (rawJson == null)
// to ensure "json" is required (not null)
if (json == null)
{
throw new ArgumentNullException("rawJson is a required property for ScryptoSborValue and cannot be null");
throw new ArgumentNullException("json is a required property for ScryptoSborValue and cannot be null");
}
this.RawJson = rawJson;
this.Json = json;
}

/// <summary>
Expand All @@ -128,10 +128,10 @@ protected ScryptoSborValue() { }
public string RawHex { get; set; }

/// <summary>
/// Gets or Sets RawJson
/// Gets or Sets Json
/// </summary>
[DataMember(Name = "raw_json", IsRequired = true, EmitDefaultValue = true)]
public Object RawJson { get; set; }
[DataMember(Name = "json", IsRequired = true, EmitDefaultValue = true)]
public Object Json { get; set; }

/// <summary>
/// Returns the string presentation of the object
Expand All @@ -142,7 +142,7 @@ public override string ToString()
StringBuilder sb = new StringBuilder();
sb.Append("class ScryptoSborValue {\n");
sb.Append(" RawHex: ").Append(RawHex).Append("\n");
sb.Append(" RawJson: ").Append(RawJson).Append("\n");
sb.Append(" Json: ").Append(Json).Append("\n");
sb.Append("}\n");
return sb.ToString();
}
Expand Down Expand Up @@ -184,9 +184,9 @@ public bool Equals(ScryptoSborValue input)
this.RawHex.Equals(input.RawHex))
) &&
(
this.RawJson == input.RawJson ||
(this.RawJson != null &&
this.RawJson.Equals(input.RawJson))
this.Json == input.Json ||
(this.Json != null &&
this.Json.Equals(input.Json))
);
}

Expand All @@ -203,9 +203,9 @@ public override int GetHashCode()
{
hashCode = (hashCode * 59) + this.RawHex.GetHashCode();
}
if (this.RawJson != null)
if (this.Json != null)
{
hashCode = (hashCode * 59) + this.RawJson.GetHashCode();
hashCode = (hashCode * 59) + this.Json.GetHashCode();
}
return hashCode;
}
Expand Down
Loading
Loading