Skip to content

Commit

Permalink
Add more API filters
Browse files Browse the repository at this point in the history
  • Loading branch information
Groxan committed Jun 6, 2024
1 parent 597d492 commit 064f573
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 42 deletions.
70 changes: 40 additions & 30 deletions Tzkt.Api/Controllers/OperationsController.cs

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions Tzkt.Api/Repositories/AccountRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2362,15 +2362,15 @@ public async Task<IEnumerable<Operation>> GetOperations(
: Task.FromResult(Enumerable.Empty<ActivationOperation>());

var doubleBaking = delegat.DoubleBakingCount > 0 && types.Contains(OpTypes.DoubleBaking)
? Operations.GetDoubleBakings(new AnyOfParameter { Fields = new[] { "accuser", "offender" }, Eq = delegat.Id }, accuser, offender, level, timestamp, sort, offset, limit, quote)
? Operations.GetDoubleBakings(new AnyOfParameter { Fields = new[] { "accuser", "offender" }, Eq = delegat.Id }, accuser, offender, null, level, timestamp, sort, offset, limit, quote)
: Task.FromResult(Enumerable.Empty<DoubleBakingOperation>());

var doubleEndorsing = delegat.DoubleEndorsingCount > 0 && types.Contains(OpTypes.DoubleEndorsing)
? Operations.GetDoubleEndorsings(new AnyOfParameter { Fields = new[] { "accuser", "offender" }, Eq = delegat.Id }, accuser, offender, level, timestamp, sort, offset, limit, quote)
? Operations.GetDoubleEndorsings(new AnyOfParameter { Fields = new[] { "accuser", "offender" }, Eq = delegat.Id }, accuser, offender, null, level, timestamp, sort, offset, limit, quote)
: Task.FromResult(Enumerable.Empty<DoubleEndorsingOperation>());

var doublePreendorsing = delegat.DoublePreendorsingCount > 0 && types.Contains(OpTypes.DoublePreendorsing)
? Operations.GetDoublePreendorsings(new AnyOfParameter { Fields = new[] { "accuser", "offender" }, Eq = delegat.Id }, accuser, offender, level, timestamp, sort, offset, limit, quote)
? Operations.GetDoublePreendorsings(new AnyOfParameter { Fields = new[] { "accuser", "offender" }, Eq = delegat.Id }, accuser, offender, null, level, timestamp, sort, offset, limit, quote)
: Task.FromResult(Enumerable.Empty<DoublePreendorsingOperation>());

var nonceRevelations = delegat.NonceRevelationsCount > 0 && types.Contains(OpTypes.NonceRevelation)
Expand All @@ -2382,7 +2382,7 @@ public async Task<IEnumerable<Operation>> GetOperations(
: Task.FromResult(Enumerable.Empty<VdfRevelationOperation>());

var delegations = delegat.DelegationsCount > 0 && types.Contains(OpTypes.Delegation)
? Operations.GetDelegations(new AnyOfParameter { Fields = new[] { "initiator", "sender", "prevDelegate", "newDelegate" }, Eq = delegat.Id }, initiator, sender, prevDelegate, newDelegate, level, timestamp, null, status, sort, offset, limit, quote)
? Operations.GetDelegations(new AnyOfParameter { Fields = new[] { "initiator", "sender", "prevDelegate", "newDelegate" }, Eq = delegat.Id }, initiator, sender, prevDelegate, newDelegate, null, level, timestamp, null, status, sort, offset, limit, quote)
: Task.FromResult(Enumerable.Empty<DelegationOperation>());

var originations = delegat.OriginationsCount > 0 && types.Contains(OpTypes.Origination)
Expand Down Expand Up @@ -2502,7 +2502,7 @@ public async Task<IEnumerable<Operation>> GetOperations(
: Task.FromResult(Enumerable.Empty<RevelationPenaltyOperation>());

var bakingOps = delegat.BlocksCount > 0 && types.Contains(OpTypes.Baking)
? Operations.GetBakings(new AnyOfParameter { Fields = new[] { "proposer", "producer" }, Eq = delegat.Id }, null, null, level, timestamp, sort, offset, limit, quote)
? Operations.GetBakings(new AnyOfParameter { Fields = new[] { "proposer", "producer" }, Eq = delegat.Id }, null, null, null, level, timestamp, sort, offset, limit, quote)
: Task.FromResult(Enumerable.Empty<BakingOperation>());

var endorsingRewards = delegat.EndorsingRewardsCount > 0 && types.Contains(OpTypes.EndorsingReward)
Expand Down Expand Up @@ -2611,7 +2611,7 @@ await Task.WhenAll(
: Task.FromResult(Enumerable.Empty<ActivationOperation>());

var userDelegations = user.DelegationsCount > 0 && types.Contains(OpTypes.Delegation)
? Operations.GetDelegations(new AnyOfParameter { Fields = new[] { "initiator", "sender", "prevDelegate", "newDelegate" }, Eq = user.Id }, initiator, sender, prevDelegate, newDelegate, level, timestamp, null, status, sort, offset, limit, quote)
? Operations.GetDelegations(new AnyOfParameter { Fields = new[] { "initiator", "sender", "prevDelegate", "newDelegate" }, Eq = user.Id }, initiator, sender, prevDelegate, newDelegate, null, level, timestamp, null, status, sort, offset, limit, quote)
: Task.FromResult(Enumerable.Empty<DelegationOperation>());

var userOriginations = user.OriginationsCount > 0 && types.Contains(OpTypes.Origination)
Expand Down Expand Up @@ -2788,7 +2788,7 @@ await Task.WhenAll(
var _contract = new AccountParameter { Eq = contract.Id };

var contractDelegations = contract.DelegationsCount > 0 && types.Contains(OpTypes.Delegation)
? Operations.GetDelegations(new AnyOfParameter { Fields = new[] { "initiator", "sender", "prevDelegate", "newDelegate" }, Eq = contract.Id }, initiator, sender, prevDelegate, newDelegate, level, timestamp, null, status, sort, offset, limit, quote)
? Operations.GetDelegations(new AnyOfParameter { Fields = new[] { "initiator", "sender", "prevDelegate", "newDelegate" }, Eq = contract.Id }, initiator, sender, prevDelegate, newDelegate, null, level, timestamp, null, status, sort, offset, limit, quote)
: Task.FromResult(Enumerable.Empty<DelegationOperation>());

var contractOriginations = contract.OriginationsCount > 0 && types.Contains(OpTypes.Origination)
Expand Down
6 changes: 6 additions & 0 deletions Tzkt.Api/Repositories/OperationRepository.Baking.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public async Task<IEnumerable<BakingOperation>> GetBakings(
AnyOfParameter anyof,
AccountParameter proposer,
AccountParameter producer,
Int64Parameter id,
Int32Parameter level,
DateTimeParameter timestamp,
SortParameter sort,
Expand All @@ -70,6 +71,7 @@ public async Task<IEnumerable<BakingOperation>> GetBakings(
.Filter("ProposerId", proposer)
.Filter("ProducerId", producer)
.Filter(@"""ProducerId"" IS NOT NULL")
.Filter("Id", id)
.Filter("Level", level)
.Filter("Timestamp", timestamp)
.Take(sort, offset, limit, x => x == "level" ? ("Id", "Level") : ("Id", "Id"));
Expand Down Expand Up @@ -105,6 +107,7 @@ public async Task<object[][]> GetBakings(
AnyOfParameter anyof,
AccountParameter proposer,
AccountParameter producer,
Int64Parameter id,
Int32Parameter level,
DateTimeParameter timestamp,
SortParameter sort,
Expand Down Expand Up @@ -164,6 +167,7 @@ public async Task<object[][]> GetBakings(
.Filter("ProposerId", proposer)
.Filter("ProducerId", producer)
.Filter(@"""ProducerId"" IS NOT NULL")
.Filter("Id", id)
.Filter("Level", level)
.Filter("Timestamp", timestamp)
.Take(sort, offset, limit, x => x == "level" ? ("Id", "Level") : ("Id", "Id"));
Expand Down Expand Up @@ -284,6 +288,7 @@ public async Task<object[]> GetBakings(
AnyOfParameter anyof,
AccountParameter proposer,
AccountParameter producer,
Int64Parameter id,
Int32Parameter level,
DateTimeParameter timestamp,
SortParameter sort,
Expand Down Expand Up @@ -340,6 +345,7 @@ public async Task<object[]> GetBakings(
.Filter("ProposerId", proposer)
.Filter("ProducerId", producer)
.Filter(@"""ProducerId"" IS NOT NULL")
.Filter("Id", id)
.Filter("Level", level)
.Filter("Timestamp", timestamp)
.Take(sort, offset, limit, x => x == "level" ? ("Id", "Level") : ("Id", "Id"));
Expand Down
6 changes: 6 additions & 0 deletions Tzkt.Api/Repositories/OperationRepository.Delegations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ public async Task<IEnumerable<DelegationOperation>> GetDelegations(
AccountParameter sender,
AccountParameter prevDelegate,
AccountParameter newDelegate,
Int64Parameter id,
Int32Parameter level,
DateTimeParameter timestamp,
Int32Parameter senderCodeHash,
Expand All @@ -205,6 +206,7 @@ public async Task<IEnumerable<DelegationOperation>> GetDelegations(
.Filter("SenderId", sender, x => x == "prevDelegate" ? "PrevDelegateId" : "DelegateId")
.Filter("PrevDelegateId", prevDelegate, x => x == "initiator" ? "InitiatorId" : x == "sender" ? "SenderId" : "DelegateId")
.Filter("DelegateId", newDelegate, x => x == "initiator" ? "InitiatorId" : x == "sender" ? "SenderId" : "PrevDelegateId")
.FilterA(@"o.""Id""", id)
.FilterA(@"o.""Level""", level)
.FilterA(@"o.""Timestamp""", timestamp)
.FilterA(@"o.""SenderCodeHash""", senderCodeHash)
Expand Down Expand Up @@ -252,6 +254,7 @@ public async Task<object[][]> GetDelegations(
AccountParameter sender,
AccountParameter prevDelegate,
AccountParameter newDelegate,
Int64Parameter id,
Int32Parameter level,
DateTimeParameter timestamp,
Int32Parameter senderCodeHash,
Expand Down Expand Up @@ -316,6 +319,7 @@ public async Task<object[][]> GetDelegations(
.Filter("SenderId", sender, x => x == "prevDelegate" ? "PrevDelegateId" : "DelegateId")
.Filter("PrevDelegateId", prevDelegate, x => x == "initiator" ? "InitiatorId" : x == "sender" ? "SenderId" : "DelegateId")
.Filter("DelegateId", newDelegate, x => x == "initiator" ? "InitiatorId" : x == "sender" ? "SenderId" : "PrevDelegateId")
.FilterA(@"o.""Id""", id)
.FilterA(@"o.""Level""", level)
.FilterA(@"o.""Timestamp""", timestamp)
.FilterA(@"o.""SenderCodeHash""", senderCodeHash)
Expand Down Expand Up @@ -449,6 +453,7 @@ public async Task<object[]> GetDelegations(
AccountParameter sender,
AccountParameter prevDelegate,
AccountParameter newDelegate,
Int64Parameter id,
Int32Parameter level,
DateTimeParameter timestamp,
Int32Parameter senderCodeHash,
Expand Down Expand Up @@ -510,6 +515,7 @@ public async Task<object[]> GetDelegations(
.Filter("SenderId", sender, x => x == "prevDelegate" ? "PrevDelegateId" : "DelegateId")
.Filter("PrevDelegateId", prevDelegate, x => x == "initiator" ? "InitiatorId" : x == "sender" ? "SenderId" : "DelegateId")
.Filter("DelegateId", newDelegate, x => x == "initiator" ? "InitiatorId" : x == "sender" ? "SenderId" : "PrevDelegateId")
.FilterA(@"o.""Id""", id)
.FilterA(@"o.""Level""", level)
.FilterA(@"o.""Timestamp""", timestamp)
.FilterA(@"o.""SenderCodeHash""", senderCodeHash)
Expand Down
6 changes: 6 additions & 0 deletions Tzkt.Api/Repositories/OperationRepository.DoubleBaking.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public async Task<IEnumerable<DoubleBakingOperation>> GetDoubleBakings(
AnyOfParameter anyof,
AccountParameter accuser,
AccountParameter offender,
Int64Parameter id,
Int32Parameter level,
DateTimeParameter timestamp,
SortParameter sort,
Expand All @@ -105,6 +106,7 @@ INNER JOIN "Blocks" as b
.Filter(anyof, x => x == "accuser" ? "AccuserId" : "OffenderId")
.Filter("AccuserId", accuser, x => "OffenderId")
.Filter("OffenderId", offender, x => "AccuserId")
.FilterA(@"o.""Id""", id)
.FilterA(@"o.""Level""", level)
.FilterA(@"o.""Timestamp""", timestamp)
.Take(sort, offset, limit, x => x switch
Expand Down Expand Up @@ -147,6 +149,7 @@ public async Task<object[][]> GetDoubleBakings(
AnyOfParameter anyof,
AccountParameter accuser,
AccountParameter offender,
Int64Parameter id,
Int32Parameter level,
DateTimeParameter timestamp,
SortParameter sort,
Expand Down Expand Up @@ -203,6 +206,7 @@ public async Task<object[][]> GetDoubleBakings(
.Filter(anyof, x => x == "accuser" ? "AccuserId" : "OffenderId")
.Filter("AccuserId", accuser, x => "OffenderId")
.Filter("OffenderId", offender, x => "AccuserId")
.FilterA(@"o.""Id""", id)
.FilterA(@"o.""Level""", level)
.FilterA(@"o.""Timestamp""", timestamp)
.Take(sort, offset, limit, x => x switch
Expand Down Expand Up @@ -316,6 +320,7 @@ public async Task<object[]> GetDoubleBakings(
AnyOfParameter anyof,
AccountParameter accuser,
AccountParameter offender,
Int64Parameter id,
Int32Parameter level,
DateTimeParameter timestamp,
SortParameter sort,
Expand Down Expand Up @@ -369,6 +374,7 @@ public async Task<object[]> GetDoubleBakings(
.Filter(anyof, x => x == "accuser" ? "AccuserId" : "OffenderId")
.Filter("AccuserId", accuser, x => "OffenderId")
.Filter("OffenderId", offender, x => "AccuserId")
.FilterA(@"o.""Id""", id)
.FilterA(@"o.""Level""", level)
.FilterA(@"o.""Timestamp""", timestamp)
.Take(sort, offset, limit, x => x switch
Expand Down
6 changes: 6 additions & 0 deletions Tzkt.Api/Repositories/OperationRepository.DoubleEndorsing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public async Task<IEnumerable<DoubleEndorsingOperation>> GetDoubleEndorsings(
AnyOfParameter anyof,
AccountParameter accuser,
AccountParameter offender,
Int64Parameter id,
Int32Parameter level,
DateTimeParameter timestamp,
SortParameter sort,
Expand All @@ -105,6 +106,7 @@ INNER JOIN "Blocks" as b
.Filter(anyof, x => x == "accuser" ? "AccuserId" : "OffenderId")
.Filter("AccuserId", accuser, x => "OffenderId")
.Filter("OffenderId", offender, x => "AccuserId")
.FilterA(@"o.""Id""", id)
.FilterA(@"o.""Level""", level)
.FilterA(@"o.""Timestamp""", timestamp)
.Take(sort, offset, limit, x => x switch
Expand Down Expand Up @@ -147,6 +149,7 @@ public async Task<object[][]> GetDoubleEndorsings(
AnyOfParameter anyof,
AccountParameter accuser,
AccountParameter offender,
Int64Parameter id,
Int32Parameter level,
DateTimeParameter timestamp,
SortParameter sort,
Expand Down Expand Up @@ -203,6 +206,7 @@ public async Task<object[][]> GetDoubleEndorsings(
.Filter(anyof, x => x == "accuser" ? "AccuserId" : "OffenderId")
.Filter("AccuserId", accuser, x => "OffenderId")
.Filter("OffenderId", offender, x => "AccuserId")
.FilterA(@"o.""Id""", id)
.FilterA(@"o.""Level""", level)
.FilterA(@"o.""Timestamp""", timestamp)
.Take(sort, offset, limit, x => x switch
Expand Down Expand Up @@ -316,6 +320,7 @@ public async Task<object[]> GetDoubleEndorsings(
AnyOfParameter anyof,
AccountParameter accuser,
AccountParameter offender,
Int64Parameter id,
Int32Parameter level,
DateTimeParameter timestamp,
SortParameter sort,
Expand Down Expand Up @@ -369,6 +374,7 @@ public async Task<object[]> GetDoubleEndorsings(
.Filter(anyof, x => x == "accuser" ? "AccuserId" : "OffenderId")
.Filter("AccuserId", accuser, x => "OffenderId")
.Filter("OffenderId", offender, x => "AccuserId")
.FilterA(@"o.""Id""", id)
.FilterA(@"o.""Level""", level)
.FilterA(@"o.""Timestamp""", timestamp)
.Take(sort, offset, limit, x => x switch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public async Task<IEnumerable<DoublePreendorsingOperation>> GetDoublePreendorsin
AnyOfParameter anyof,
AccountParameter accuser,
AccountParameter offender,
Int64Parameter id,
Int32Parameter level,
DateTimeParameter timestamp,
SortParameter sort,
Expand All @@ -105,6 +106,7 @@ INNER JOIN "Blocks" as b
.Filter(anyof, x => x == "accuser" ? "AccuserId" : "OffenderId")
.Filter("AccuserId", accuser, x => "OffenderId")
.Filter("OffenderId", offender, x => "AccuserId")
.FilterA(@"o.""Id""", id)
.FilterA(@"o.""Level""", level)
.FilterA(@"o.""Timestamp""", timestamp)
.Take(sort, offset, limit, x => x switch
Expand Down Expand Up @@ -147,6 +149,7 @@ public async Task<object[][]> GetDoublePreendorsings(
AnyOfParameter anyof,
AccountParameter accuser,
AccountParameter offender,
Int64Parameter id,
Int32Parameter level,
DateTimeParameter timestamp,
SortParameter sort,
Expand Down Expand Up @@ -203,6 +206,7 @@ public async Task<object[][]> GetDoublePreendorsings(
.Filter(anyof, x => x == "accuser" ? "AccuserId" : "OffenderId")
.Filter("AccuserId", accuser, x => "OffenderId")
.Filter("OffenderId", offender, x => "AccuserId")
.FilterA(@"o.""Id""", id)
.FilterA(@"o.""Level""", level)
.FilterA(@"o.""Timestamp""", timestamp)
.Take(sort, offset, limit, x => x switch
Expand Down Expand Up @@ -316,6 +320,7 @@ public async Task<object[]> GetDoublePreendorsings(
AnyOfParameter anyof,
AccountParameter accuser,
AccountParameter offender,
Int64Parameter id,
Int32Parameter level,
DateTimeParameter timestamp,
SortParameter sort,
Expand Down Expand Up @@ -369,6 +374,7 @@ public async Task<object[]> GetDoublePreendorsings(
.Filter(anyof, x => x == "accuser" ? "AccuserId" : "OffenderId")
.Filter("AccuserId", accuser, x => "OffenderId")
.Filter("OffenderId", offender, x => "AccuserId")
.FilterA(@"o.""Id""", id)
.FilterA(@"o.""Level""", level)
.FilterA(@"o.""Timestamp""", timestamp)
.Take(sort, offset, limit, x => x switch
Expand Down
Loading

0 comments on commit 064f573

Please sign in to comment.