Skip to content

Commit

Permalink
Add .gt, .ge, .lt, .le modes to JsonParameter and minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Groxan committed Feb 25, 2021
1 parent 794775a commit d04bfd5
Show file tree
Hide file tree
Showing 15 changed files with 358 additions and 265 deletions.
10 changes: 5 additions & 5 deletions Tzkt.Api/Controllers/AccountsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,9 @@ public async Task<ActionResult<IEnumerable<Delegator>>> GetDelegators(
/// <param name="level">Filters operations by level.</param>
/// <param name="timestamp">Filters operations by timestamp.</param>
/// <param name="entrypoint">Filters transactions by entrypoint called on the target contract.</param>
/// <param name="params">Filters transactions by parameters. Note, this query parameter supports the following format: `?params{.path?}{.mode?}=...`,
/// so you can specify a path to a particular field to filter by, for example: `?params.token_id=...` or `?params.sigs.0.ne=...`.</param>
/// <param name="parameters">**DEPRECATED**. Use `entrypoint` and `params` instead.</param>
/// <param name="parameter">Filters transactions by parameter value. Note, this query parameter supports the following format: `?parameter{.path?}{.mode?}=...`,
/// so you can specify a path to a particular field to filter by, for example: `?parameter.token_id=...` or `?parameter.sigs.0.ne=...`.</param>
/// <param name="parameters">**DEPRECATED**. Use `entrypoint` and `parameter` instead.</param>
/// <param name="hasInternals">Filters transactions by presence of internal operations.</param>
/// <param name="status">Filters transactions, delegations, originations and reveals by operation status (`applied`, `failed`, `backtracked`, `skipped`).</param>
/// <param name="sort">Sort mode (0 - ascending, 1 - descending)</param>
Expand Down Expand Up @@ -251,7 +251,7 @@ public async Task<ActionResult<IEnumerable<Operation>>> GetOperations(
Int32Parameter level,
DateTimeParameter timestamp,
StringParameter entrypoint,
JsonParameter @params,
JsonParameter parameter,
StringParameter parameters,
BoolParameter hasInternals,
OperationStatusParameter status,
Expand Down Expand Up @@ -382,7 +382,7 @@ public async Task<ActionResult<IEnumerable<Operation>>> GetOperations(
if (to != null) timestamp.Lt = to.Value.DateTime;
#endregion

return Ok(await Accounts.GetOperations(address, types, initiator, sender, target, prevDelegate, newDelegate, contractManager, contractDelegate, originatedContract, accuser, offender, baker, level, timestamp, entrypoint, @params, parameters, hasInternals, status, _sort, _offset, limit, micheline, quote));
return Ok(await Accounts.GetOperations(address, types, initiator, sender, target, prevDelegate, newDelegate, contractManager, contractDelegate, originatedContract, accuser, offender, baker, level, timestamp, entrypoint, parameter, parameters, hasInternals, status, _sort, _offset, limit, micheline, quote));
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions Tzkt.Api/Controllers/ContractsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ public async Task<ActionResult> GetStorageSchema([Address] string address, [Min(
/// <param name="limit">Maximum number of items to return</param>
/// <returns></returns>
[HttpGet("{address}/storage/history")]
public Task<IEnumerable<StorageRecord>> GetStorageHistory([Address] string address, [Min(0)] int lastId = 0, [Range(0, 1000)] int limit = 10)
public Task<IEnumerable<StorageRecord<JsonString>>> GetStorageHistory([Address] string address, [Min(0)] int lastId = 0, [Range(0, 1000)] int limit = 10)
{
return Accounts.GetStorageHistory(address, lastId, limit);
}
Expand Down Expand Up @@ -319,7 +319,7 @@ public Task<IMicheline> GetRawStorageSchema([Address] string address, [Min(0)] i
/// <param name="limit">Maximum number of items to return</param>
/// <returns></returns>
[HttpGet("{address}/storage/raw/history")]
public Task<IEnumerable<RawStorageRecord>> GetRawStorageHistory([Address] string address, [Min(0)] int lastId = 0, [Range(0, 1000)] int limit = 10)
public Task<IEnumerable<StorageRecord<IMicheline>>> GetRawStorageHistory([Address] string address, [Min(0)] int lastId = 0, [Range(0, 1000)] int limit = 10)
{
return Accounts.GetRawStorageHistory(address, lastId, limit);
}
Expand Down
18 changes: 9 additions & 9 deletions Tzkt.Api/Controllers/OperationsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1269,9 +1269,9 @@ public Task<int> GetOriginationsCount(
/// <param name="timestamp">Filters transactions by timestamp.</param>
/// <param name="hasInternals">Filters transactions by presence of internal operations.</param>
/// <param name="entrypoint">Filters transactions by entrypoint called on the target contract.</param>
/// <param name="params">Filters transactions by parameters. Note, this query parameter supports the following format: `?params{.path?}{.mode?}=...`,
/// so you can specify a path to a particular field to filter by, for example: `?params.token_id=...` or `?params.sigs.0.ne=...`.</param>
/// <param name="parameters">**DEPRECATED**. Use `entrypoint` and `params` instead.</param>
/// <param name="parameter">Filters transactions by parameter value. Note, this query parameter supports the following format: `?parameter{.path?}{.mode?}=...`,
/// so you can specify a path to a particular field to filter by, for example: `?parameter.token_id=...` or `?parameter.sigs.0.ne=...`.</param>
/// <param name="parameters">**DEPRECATED**. Use `entrypoint` and `parameter` instead.</param>
/// <param name="status">Filters transactions by operation status (`applied`, `failed`, `backtracked`, `skipped`).</param>
/// <param name="select">Specify comma-separated list of fields to include into response or leave it undefined to return full object. If you select single field, response will be an array of values in both `.fields` and `.values` modes.</param>
/// <param name="sort">Sorts transactions by specified field. Supported fields: `id` (default), `level`, `gasUsed`, `storageUsed`, `bakerFee`, `storageFee`, `allocationFee`, `amount`.</param>
Expand All @@ -1290,7 +1290,7 @@ public async Task<ActionResult<IEnumerable<TransactionOperation>>> GetTransactio
Int32Parameter level,
DateTimeParameter timestamp,
StringParameter entrypoint,
JsonParameter @params,
JsonParameter parameter,
StringParameter parameters,
BoolParameter hasInternals,
OperationStatusParameter status,
Expand Down Expand Up @@ -1352,25 +1352,25 @@ public async Task<ActionResult<IEnumerable<TransactionOperation>>> GetTransactio
#endregion

if (select == null)
return Ok(await Operations.GetTransactions(anyof, initiator, sender, target, amount, level, timestamp, entrypoint, @params, parameters, hasInternals, status, sort, offset, limit, micheline, quote));
return Ok(await Operations.GetTransactions(anyof, initiator, sender, target, amount, level, timestamp, entrypoint, parameter, parameters, hasInternals, status, sort, offset, limit, micheline, quote));

if (select.Values != null)
{
if (select.Values.Length == 1)
return Ok(await Operations.GetTransactions(anyof, initiator, sender, target, amount, level, timestamp, entrypoint, @params, hasInternals, status, sort, offset, limit, select.Values[0], micheline, quote));
return Ok(await Operations.GetTransactions(anyof, initiator, sender, target, amount, level, timestamp, entrypoint, parameter, hasInternals, status, sort, offset, limit, select.Values[0], micheline, quote));
else
return Ok(await Operations.GetTransactions(anyof, initiator, sender, target, amount, level, timestamp, entrypoint, @params, hasInternals, status, sort, offset, limit, select.Values, micheline, quote));
return Ok(await Operations.GetTransactions(anyof, initiator, sender, target, amount, level, timestamp, entrypoint, parameter, hasInternals, status, sort, offset, limit, select.Values, micheline, quote));
}
else
{
if (select.Fields.Length == 1)
return Ok(await Operations.GetTransactions(anyof, initiator, sender, target, amount, level, timestamp, entrypoint, @params, hasInternals, status, sort, offset, limit, select.Fields[0], micheline, quote));
return Ok(await Operations.GetTransactions(anyof, initiator, sender, target, amount, level, timestamp, entrypoint, parameter, hasInternals, status, sort, offset, limit, select.Fields[0], micheline, quote));
else
{
return Ok(new SelectionResponse
{
Cols = select.Fields,
Rows = await Operations.GetTransactions(anyof, initiator, sender, target, amount, level, timestamp, entrypoint, @params, hasInternals, status, sort, offset, limit, select.Fields, micheline, quote)
Rows = await Operations.GetTransactions(anyof, initiator, sender, target, amount, level, timestamp, entrypoint, parameter, hasInternals, status, sort, offset, limit, select.Fields, micheline, quote)
});
}
}
Expand Down
3 changes: 1 addition & 2 deletions Tzkt.Api/Models/Entrypoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ public class Entrypoint
/// <summary>
/// A kind of JSON schema, describing how parameters will look like in a human-readable JSON format
/// </summary>
[JsonConverter(typeof(RawJsonConverter))]
[JsonSchemaType(typeof(object))]
public string JsonParameters { get; set; }
public JsonString JsonParameters { get; set; }

/// <summary>
/// Parameters schema in micheline format
Expand Down
24 changes: 16 additions & 8 deletions Tzkt.Api/Models/Operations/TransactionOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,9 @@ public class TransactionOperation : Operation
public long Amount { get; set; }

/// <summary>
/// Entrypoint called on the target contract
/// </summary>
public string Entrypoint { get; set; }

/// <summary>
/// Parameters passed to the called entrypoint converted to human-readable JSON. Note: you can configure parameters format by setting `micheline` query parameter.
/// Transaction parameter, including called entrypoint and value passed to the entrypoint.
/// </summary>
public object Params { get; set; }
public TxParameter Parameter { get; set; }

/// <summary>
/// Contract storage after executing the transaction converted to human-readable JSON. Note: you can configure storage format by setting `micheline` query parameter.
Expand Down Expand Up @@ -143,8 +138,21 @@ public class TransactionOperation : Operation
#endregion

/// <summary>
/// **DEPRECATED**. Use `entrypoint` and `params` instead.
/// **DEPRECATED**. Use `entrypoint` and `parameter` instead.
/// </summary>
public string Parameters { get; set; }
}

public class TxParameter
{
/// <summary>
/// Entrypoint called on the target contract
/// </summary>
public string Entrypoint { get; set; }

/// <summary>
/// Value passed to the called entrypoint converted to human-readable JSON. Note: you can configure parameters format by setting `micheline` query parameter.
/// </summary>
public object Value { get; set; }
}
}
81 changes: 12 additions & 69 deletions Tzkt.Api/Models/StorageRecord.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using System;
using System.Text.Json.Serialization;
using NJsonSchema.Annotations;
using Netezos.Encoding;

namespace Tzkt.Api.Models
{
public class StorageRecord
public class StorageRecord<T>
{
/// <summary>
/// Id of the record that can be used for pagination
Expand All @@ -25,17 +23,16 @@ public class StorageRecord
/// <summary>
/// Operation that caused the storage change
/// </summary>
public SourceOperation Operation { get; set; }
public SourceOperation<T> Operation { get; set; }

/// <summary>
/// New value of the storage
/// New storage value
/// </summary>
[JsonConverter(typeof(RawJsonConverter))]
[JsonSchemaType(typeof(object))]
public string Value { get; set; }
public T Value { get; set; }
}

public class SourceOperation
public class SourceOperation<T>
{
/// <summary>
/// Operation type
Expand All @@ -58,76 +55,22 @@ public class SourceOperation
public int? Nonce { get; set; }

/// <summary>
/// Called contract entrypoint
/// Transaction parameter, including called entrypoint and value passed to the entrypoint.
/// </summary>
public string Entrypoint { get; set; }

/// <summary>
/// Parameters passed
/// </summary>
[JsonConverter(typeof(RawJsonConverter))]
[JsonSchemaType(typeof(object))]
public string Params { get; set; }
}

public class RawStorageRecord
{
/// <summary>
/// Id of the record that can be used for pagination
/// </summary>
public int Id { get; set; }

/// <summary>
/// Level at which the storage value was taken
/// </summary>
public int Level { get; set; }

/// <summary>
/// Timestamp at which the storage value was taken
/// </summary>
public DateTime Timestamp { get; set; }

/// <summary>
/// Operation that caused the storage change
/// </summary>
public SourceOperationRaw Operation { get; set; }

/// <summary>
/// New value of the storage
/// </summary>
public IMicheline Value { get; set; }
public SourceOperationParameter<T> Parameter { get; set; }
}

public class SourceOperationRaw
public class SourceOperationParameter<T>
{
/// <summary>
/// Operation type
/// </summary>
public string Type { get; set; }

/// <summary>
/// Operation hash
/// </summary>
public string Hash { get; set; }

/// <summary>
/// Operation counter (null in case of synthetic operations)
/// </summary>
public int? Counter { get; set; }

/// <summary>
/// Operation nonce (null in case of non-internal or synthetic operations)
/// </summary>
public int? Nonce { get; set; }

/// <summary>
/// Called contract entrypoint
/// Called entrypoint
/// </summary>
public string Entrypoint { get; set; }

/// <summary>
/// Parameters passed
/// Value passed to the entrypoint
/// </summary>
public IMicheline Params { get; set; }
[JsonSchemaType(typeof(object))]
public T Value { get; set; }
}
}
44 changes: 44 additions & 0 deletions Tzkt.Api/Parameters/Binders/JsonBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,50 @@ public Task BindModelAsync(ModelBindingContext bindingContext)
res.Ne.Add((string.Join(',', arr[1..^1]), ne));
}
break;
case "gt":
hasValue = false;
if (!bindingContext.TryGetString(key, ref hasValue, out var gt))
return Task.CompletedTask;
if (hasValue)
{
res ??= new JsonParameter();
res.Gt ??= new List<(string, string)>();
res.Gt.Add((string.Join(',', arr[1..^1]), gt));
}
break;
case "ge":
hasValue = false;
if (!bindingContext.TryGetString(key, ref hasValue, out var ge))
return Task.CompletedTask;
if (hasValue)
{
res ??= new JsonParameter();
res.Ge ??= new List<(string, string)>();
res.Ge.Add((string.Join(',', arr[1..^1]), ge));
}
break;
case "lt":
hasValue = false;
if (!bindingContext.TryGetString(key, ref hasValue, out var lt))
return Task.CompletedTask;
if (hasValue)
{
res ??= new JsonParameter();
res.Lt ??= new List<(string, string)>();
res.Lt.Add((string.Join(',', arr[1..^1]), lt));
}
break;
case "le":
hasValue = false;
if (!bindingContext.TryGetString(key, ref hasValue, out var le))
return Task.CompletedTask;
if (hasValue)
{
res ??= new JsonParameter();
res.Le ??= new List<(string, string)>();
res.Le.Add((string.Join(',', arr[1..^1]), le));
}
break;
case "as":
hasValue = false;
if (!bindingContext.TryGetString(key, ref hasValue, out var @as))
Expand Down
Loading

0 comments on commit d04bfd5

Please sign in to comment.