Skip to content

Commit

Permalink
Add API endpoints to check operation status
Browse files Browse the repository at this point in the history
  • Loading branch information
MS committed Aug 5, 2022
1 parent 7ffae69 commit bf4c4dc
Show file tree
Hide file tree
Showing 18 changed files with 488 additions and 5 deletions.
4 changes: 3 additions & 1 deletion Tzkt.Api/Controllers/AccountsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,9 @@ public async Task<ActionResult<IEnumerable<Delegator>>> GetDelegators(
/// Note: for better flexibility this endpoint accumulates query parameters (filters) of each `/operations/{type}` endpoint,
/// so a particular filter may affect several operation types containing this filter.
/// For example, if you specify an `initiator` it will affect all transactions, delegations and originations,
/// because all these types have an `initiator` field.
/// because all these types have an `initiator` field.
/// **NOTE: if you know in advance what operation type you want to get (e.g. transactions), prefer using `/v1/operations/{type}`
/// (e.g. [/v1/operations/transactions](#operation/Operations_GetTransactions)) instead, because it's much more efficient and way more flexible.**
/// </remarks>
/// <param name="address">Account address (starting with tz or KT)</param>
/// <param name="type">Comma separated list of operation types to return (`endorsement`, `preendorsement`, `ballot`, `proposal`, `activation`, `double_baking`, `double_endorsing`, `double_preendorsing`, `nonce_revelation`, `delegation`, `origination`, `transaction`, `reveal`, `register_constant`, `set_deposits_limit`, `migration`, `revelation_penalty`, `baking`, `endorsing_reward`). If not specified then the default set will be returned.</param>
Expand Down
351 changes: 347 additions & 4 deletions Tzkt.Api/Controllers/OperationsController.cs

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions Tzkt.Api/Repositories/OperationRepository.Delegations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@
using System.Threading.Tasks;
using Dapper;
using Tzkt.Api.Models;
using Tzkt.Data;

namespace Tzkt.Api.Repositories
{
public partial class OperationRepository : DbConnection
{
public async Task<bool?> GetDelegationStatus(string hash)
{
using var db = GetConnection();
return await GetStatus(db, nameof(TzktContext.DelegationOps), hash);
}

public async Task<int> GetDelegationsCount(
Int32Parameter level,
DateTimeParameter timestamp)
Expand Down
7 changes: 7 additions & 0 deletions Tzkt.Api/Repositories/OperationRepository.Originations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,18 @@
using Netezos.Encoding;
using Tzkt.Api.Models;
using Tzkt.Api.Services.Cache;
using Tzkt.Data;

namespace Tzkt.Api.Repositories
{
public partial class OperationRepository : DbConnection
{
public async Task<bool?> GetOriginationStatus(string hash)
{
using var db = GetConnection();
return await GetStatus(db, nameof(TzktContext.OriginationOps), hash);
}

public async Task<int> GetOriginationsCount(
Int32Parameter level,
DateTimeParameter timestamp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@
using Dapper;
using Netezos.Encoding;
using Tzkt.Api.Models;
using Tzkt.Data;

namespace Tzkt.Api.Repositories
{
public partial class OperationRepository : DbConnection
{
public async Task<bool?> GetRegisterConstantStatus(string hash)
{
using var db = GetConnection();
return await GetStatus(db, nameof(TzktContext.RegisterConstantOps), hash);
}

public async Task<int> GetRegisterConstantsCount(
Int32Parameter level,
DateTimeParameter timestamp)
Expand Down
7 changes: 7 additions & 0 deletions Tzkt.Api/Repositories/OperationRepository.Reveals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@
using System.Threading.Tasks;
using Dapper;
using Tzkt.Api.Models;
using Tzkt.Data;

namespace Tzkt.Api.Repositories
{
public partial class OperationRepository : DbConnection
{
public async Task<bool?> GetRevealStatus(string hash)
{
using var db = GetConnection();
return await GetStatus(db, nameof(TzktContext.RevealOps), hash);
}

public async Task<int> GetRevealsCount(
Int32Parameter level,
DateTimeParameter timestamp)
Expand Down
7 changes: 7 additions & 0 deletions Tzkt.Api/Repositories/OperationRepository.SetDepositsLimit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@
using System.Threading.Tasks;
using Dapper;
using Tzkt.Api.Models;
using Tzkt.Data;

namespace Tzkt.Api.Repositories
{
public partial class OperationRepository : DbConnection
{
public async Task<bool?> GetSetDepositsLimitStatus(string hash)
{
using var db = GetConnection();
return await GetStatus(db, nameof(TzktContext.SetDepositsLimitOps), hash);
}

public async Task<int> GetSetDepositsLimitsCount(
Int32Parameter level,
DateTimeParameter timestamp)
Expand Down
7 changes: 7 additions & 0 deletions Tzkt.Api/Repositories/OperationRepository.Transactions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@
using Dapper;
using Netezos.Encoding;
using Tzkt.Api.Models;
using Tzkt.Data;

namespace Tzkt.Api.Repositories
{
public partial class OperationRepository : DbConnection
{
public async Task<bool?> GetTransactionStatus(string hash)
{
using var db = GetConnection();
return await GetStatus(db, nameof(TzktContext.TransactionOps), hash);
}

public async Task<int> GetTransactionsCount(
AnyOfParameter anyof,
AccountParameter initiator,
Expand Down
7 changes: 7 additions & 0 deletions Tzkt.Api/Repositories/OperationRepository.TransferTicket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@
using Dapper;
using Netezos.Encoding;
using Tzkt.Api.Models;
using Tzkt.Data;

namespace Tzkt.Api.Repositories
{
public partial class OperationRepository : DbConnection
{
public async Task<bool?> GetTransferTicketStatus(string hash)
{
using var db = GetConnection();
return await GetStatus(db, nameof(TzktContext.TransferTicketOps), hash);
}

public async Task<int> GetTransferTicketOpsCount(
Int32Parameter level,
DateTimeParameter timestamp)
Expand Down
7 changes: 7 additions & 0 deletions Tzkt.Api/Repositories/OperationRepository.TxRollupCommit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@
using System.Threading.Tasks;
using Dapper;
using Tzkt.Api.Models;
using Tzkt.Data;

namespace Tzkt.Api.Repositories
{
public partial class OperationRepository : DbConnection
{
public async Task<bool?> GetTxRollupCommitStatus(string hash)
{
using var db = GetConnection();
return await GetStatus(db, nameof(TzktContext.TxRollupCommitOps), hash);
}

public async Task<int> GetTxRollupCommitOpsCount(
Int32Parameter level,
DateTimeParameter timestamp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@
using System.Threading.Tasks;
using Dapper;
using Tzkt.Api.Models;
using Tzkt.Data;

namespace Tzkt.Api.Repositories
{
public partial class OperationRepository : DbConnection
{
public async Task<bool?> GetTxRollupDispatchTicketsStatus(string hash)
{
using var db = GetConnection();
return await GetStatus(db, nameof(TzktContext.TxRollupDispatchTicketsOps), hash);
}

public async Task<int> GetTxRollupDispatchTicketsOpsCount(
Int32Parameter level,
DateTimeParameter timestamp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@
using System.Threading.Tasks;
using Dapper;
using Tzkt.Api.Models;
using Tzkt.Data;

namespace Tzkt.Api.Repositories
{
public partial class OperationRepository : DbConnection
{
public async Task<bool?> GetTxRollupFinalizeCommitmentStatus(string hash)
{
using var db = GetConnection();
return await GetStatus(db, nameof(TzktContext.TxRollupFinalizeCommitmentOps), hash);
}

public async Task<int> GetTxRollupFinalizeCommitmentOpsCount(
Int32Parameter level,
DateTimeParameter timestamp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@
using System.Threading.Tasks;
using Dapper;
using Tzkt.Api.Models;
using Tzkt.Data;

namespace Tzkt.Api.Repositories
{
public partial class OperationRepository : DbConnection
{
public async Task<bool?> GetTxRollupOriginationStatus(string hash)
{
using var db = GetConnection();
return await GetStatus(db, nameof(TzktContext.TxRollupOriginationOps), hash);
}

public async Task<int> GetTxRollupOriginationOpsCount(
Int32Parameter level,
DateTimeParameter timestamp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@
using System.Threading.Tasks;
using Dapper;
using Tzkt.Api.Models;
using Tzkt.Data;

namespace Tzkt.Api.Repositories
{
public partial class OperationRepository : DbConnection
{
public async Task<bool?> GetTxRollupRejectionStatus(string hash)
{
using var db = GetConnection();
return await GetStatus(db, nameof(TzktContext.TxRollupRejectionOps), hash);
}

public async Task<int> GetTxRollupRejectionOpsCount(
Int32Parameter level,
DateTimeParameter timestamp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@
using System.Threading.Tasks;
using Dapper;
using Tzkt.Api.Models;
using Tzkt.Data;

namespace Tzkt.Api.Repositories
{
public partial class OperationRepository : DbConnection
{
public async Task<bool?> GetTxRollupRemoveCommitmentStatus(string hash)
{
using var db = GetConnection();
return await GetStatus(db, nameof(TzktContext.TxRollupRemoveCommitmentOps), hash);
}

public async Task<int> GetTxRollupRemoveCommitmentOpsCount(
Int32Parameter level,
DateTimeParameter timestamp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@
using System.Threading.Tasks;
using Dapper;
using Tzkt.Api.Models;
using Tzkt.Data;

namespace Tzkt.Api.Repositories
{
public partial class OperationRepository : DbConnection
{
public async Task<bool?> GetTxRollupReturnBondStatus(string hash)
{
using var db = GetConnection();
return await GetStatus(db, nameof(TzktContext.TxRollupReturnBondOps), hash);
}

public async Task<int> GetTxRollupReturnBondOpsCount(
Int32Parameter level,
DateTimeParameter timestamp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@
using System.Threading.Tasks;
using Dapper;
using Tzkt.Api.Models;
using Tzkt.Data;

namespace Tzkt.Api.Repositories
{
public partial class OperationRepository : DbConnection
{
public async Task<bool?> GetTxRollupSubmitBatchStatus(string hash)
{
using var db = GetConnection();
return await GetStatus(db, nameof(TzktContext.TxRollupSubmitBatchOps), hash);
}

public async Task<int> GetTxRollupSubmitBatchOpsCount(
Int32Parameter level,
DateTimeParameter timestamp)
Expand Down
33 changes: 33 additions & 0 deletions Tzkt.Api/Repositories/OperationRepository.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using Dapper;
using Tzkt.Api.Models;
using Tzkt.Api.Services.Cache;
using Tzkt.Data;

namespace Tzkt.Api.Repositories
{
Expand All @@ -18,6 +21,36 @@ public OperationRepository(AccountsCache accounts, QuotesCache quotes, IConfigur
Quotes = quotes;
}

static async Task<bool?> GetStatus(IDbConnection db, string table, string hash)
{
return await db.QueryFirstOrDefaultAsync<bool?>($@"
SELECT ""Status"" = 1
FROM ""{table}""
WHERE ""OpHash"" = @hash::character(51)
LIMIT 1",
new { hash });
}

public async Task<bool?> GetStatus(string hash)
{
using var db = GetConnection();
return await GetStatus(db, nameof(TzktContext.TransactionOps), hash)
?? await GetStatus(db, nameof(TzktContext.OriginationOps), hash)
?? await GetStatus(db, nameof(TzktContext.DelegationOps), hash)
?? await GetStatus(db, nameof(TzktContext.RevealOps), hash)
?? await GetStatus(db, nameof(TzktContext.RegisterConstantOps), hash)
?? await GetStatus(db, nameof(TzktContext.SetDepositsLimitOps), hash)
?? await GetStatus(db, nameof(TzktContext.TransferTicketOps), hash)
?? await GetStatus(db, nameof(TzktContext.TxRollupCommitOps), hash)
?? await GetStatus(db, nameof(TzktContext.TxRollupDispatchTicketsOps), hash)
?? await GetStatus(db, nameof(TzktContext.TxRollupFinalizeCommitmentOps), hash)
?? await GetStatus(db, nameof(TzktContext.TxRollupOriginationOps), hash)
?? await GetStatus(db, nameof(TzktContext.TxRollupRejectionOps), hash)
?? await GetStatus(db, nameof(TzktContext.TxRollupRemoveCommitmentOps), hash)
?? await GetStatus(db, nameof(TzktContext.TxRollupReturnBondOps), hash)
?? await GetStatus(db, nameof(TzktContext.TxRollupSubmitBatchOps), hash);
}

public async Task<IEnumerable<Operation>> Get(string hash, MichelineFormat format, Symbols quote)
{
#region test manager operations
Expand Down

0 comments on commit bf4c4dc

Please sign in to comment.