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

v1.14 #171

Merged
merged 17 commits into from
May 31, 2024
Merged

v1.14 #171

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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
42 changes: 21 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ init:
docker-compose exec -T db createdb -U tzkt -T template0 tzkt_db
docker-compose exec -T db apt update
docker-compose exec -T db apt install -y wget
docker-compose exec -T db wget "https://snapshots.tzkt.io/tzkt_v1.13_mainnet.backup" -O tzkt_db.backup
docker-compose exec -T db wget "https://snapshots.tzkt.io/tzkt_v1.14_mainnet.backup" -O tzkt_db.backup
docker-compose exec -T db pg_restore -U tzkt -O -x -v -d tzkt_db -e -j 4 tzkt_db.backup
docker-compose exec -T db rm tzkt_db.backup
docker-compose exec -T db apt autoremove --purge -y wget
Expand Down Expand Up @@ -52,7 +52,7 @@ ghost-init:
docker-compose -f docker-compose.ghost.yml exec -T ghost-db createdb -U tzkt -T template0 tzkt_db
docker-compose -f docker-compose.ghost.yml exec -T ghost-db apt update
docker-compose -f docker-compose.ghost.yml exec -T ghost-db apt install -y wget
docker-compose -f docker-compose.ghost.yml exec -T ghost-db wget "https://snapshots.tzkt.io/tzkt_v1.13_ghostnet.backup" -O tzkt_db.backup
docker-compose -f docker-compose.ghost.yml exec -T ghost-db wget "https://snapshots.tzkt.io/tzkt_v1.14_ghostnet.backup" -O tzkt_db.backup
docker-compose -f docker-compose.ghost.yml exec -T ghost-db pg_restore -U tzkt -O -x -v -d tzkt_db -e -j 4 tzkt_db.backup
docker-compose -f docker-compose.ghost.yml exec -T ghost-db rm tzkt_db.backup
docker-compose -f docker-compose.ghost.yml exec -T ghost-db apt autoremove --purge -y wget
Expand All @@ -67,27 +67,27 @@ ghost-stop:
ghost-db-start:
docker-compose -f docker-compose.ghost.yml up -d ghost-db

oxford-init:
docker-compose -f docker-compose.oxford.yml up -d oxford-db
docker-compose -f docker-compose.oxford.yml exec -T oxford-db psql -U tzkt postgres -c '\l'
docker-compose -f docker-compose.oxford.yml exec -T oxford-db dropdb -U tzkt --if-exists tzkt_db
docker-compose -f docker-compose.oxford.yml exec -T oxford-db createdb -U tzkt -T template0 tzkt_db
docker-compose -f docker-compose.oxford.yml exec -T oxford-db apt update
docker-compose -f docker-compose.oxford.yml exec -T oxford-db apt install -y wget
docker-compose -f docker-compose.oxford.yml exec -T oxford-db wget "https://snapshots.tzkt.io/tzkt_v1.13_oxfordnet.backup" -O tzkt_db.backup
docker-compose -f docker-compose.oxford.yml exec -T oxford-db pg_restore -U tzkt -O -x -v -d tzkt_db -e -j 4 tzkt_db.backup
docker-compose -f docker-compose.oxford.yml exec -T oxford-db rm tzkt_db.backup
docker-compose -f docker-compose.oxford.yml exec -T oxford-db apt autoremove --purge -y wget
paris-init:
docker-compose -f docker-compose.paris.yml up -d paris-db
docker-compose -f docker-compose.paris.yml exec -T paris-db psql -U tzkt postgres -c '\l'
docker-compose -f docker-compose.paris.yml exec -T paris-db dropdb -U tzkt --if-exists tzkt_db
docker-compose -f docker-compose.paris.yml exec -T paris-db createdb -U tzkt -T template0 tzkt_db
docker-compose -f docker-compose.paris.yml exec -T paris-db apt update
docker-compose -f docker-compose.paris.yml exec -T paris-db apt install -y wget
docker-compose -f docker-compose.paris.yml exec -T paris-db wget "https://snapshots.tzkt.io/tzkt_v1.14_parisnet.backup" -O tzkt_db.backup
docker-compose -f docker-compose.paris.yml exec -T paris-db pg_restore -U tzkt -O -x -v -d tzkt_db -e -j 4 tzkt_db.backup
docker-compose -f docker-compose.paris.yml exec -T paris-db rm tzkt_db.backup
docker-compose -f docker-compose.paris.yml exec -T paris-db apt autoremove --purge -y wget
docker-compose pull

oxford-start:
docker-compose -f docker-compose.oxford.yml up -d
paris-start:
docker-compose -f docker-compose.paris.yml up -d

oxford-stop:
docker-compose -f docker-compose.oxford.yml down
paris-stop:
docker-compose -f docker-compose.paris.yml down

oxford-db-start:
docker-compose -f docker-compose.oxford.yml up -d oxford-db
paris-db-start:
docker-compose -f docker-compose.paris.yml up -d paris-db
reset:
docker-compose -f docker-compose.oxford.yml down --volumes
docker-compose -f docker-compose.oxford.yml up -d oxford-db
docker-compose -f docker-compose.paris.yml down --volumes
docker-compose -f docker-compose.paris.yml up -d paris-db
3 changes: 2 additions & 1 deletion Tzkt.Api.Tests/Auth/AuthServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public void PubKeyAuthTest()

var auth = new PubKeyAuth(configuration);
var config = configuration.GetAuthConfig();
var key = Key.FromBase58(configuration.GetSection("PrivKey").Value);
var key = Key.FromBase58(configuration.GetSection("PrivKey").Value
?? throw new Exception("PubKeyAuthSample.json seems to be corrupted"));

foreach (var credentials in config.Users)
{
Expand Down
8 changes: 4 additions & 4 deletions Tzkt.Api.Tests/Tzkt.Api.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.2" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="xunit" Version="2.8.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.0">
<PackageReference Include="coverlet.collector" Version="6.0.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
23 changes: 0 additions & 23 deletions Tzkt.Api/Base/DbConnection.cs

This file was deleted.

46 changes: 29 additions & 17 deletions Tzkt.Api/Controllers/AccountsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public AccountsController(AccountRepository accounts, BalanceHistoryRepository h
/// <param name="type">Filters accounts by type (`user`, `delegate`, `contract`, `rollup`, `smart_rollup`, `ghost`).</param>
/// <param name="kind">Filters accounts by contract kind (`delegator_contract` or `smart_contract`)</param>
/// <param name="delegate">Filters accounts by delegate. Allowed fields for `.eqx` mode: none.</param>
/// <param name="stakedPseudotokens">Filters accounts by amount of staked pseudotokens.</param>
/// <param name="balance">Filters accounts by balance</param>
/// <param name="staked">Filters accounts by participation in staking</param>
/// <param name="lastActivity">Filters accounts by last activity level (where the account was updated)</param>
Expand All @@ -53,6 +54,7 @@ public async Task<ActionResult<IEnumerable<Account>>> Get(
AccountTypeParameter type,
ContractKindParameter kind,
AccountParameter @delegate,
BigIntegerNullableParameter stakedPseudotokens,
Int64Parameter balance,
BoolParameter staked,
Int32Parameter lastActivity,
Expand All @@ -74,7 +76,7 @@ public async Task<ActionResult<IEnumerable<Account>>> Get(
return Ok(Enumerable.Empty<Account>());
}

if (sort != null && !sort.Validate("id", "balance", "rollupBonds", "firstActivity", "lastActivity", "numTransactions", "numContracts"))
if (sort != null && !sort.Validate("id", "balance", "rollupBonds", "firstActivity", "lastActivity", "numTransactions", "numContracts", "stakedPseudotokens"))
return new BadRequest($"{nameof(sort)}", "Sorting by the specified field is not allowed.");
#endregion

Expand All @@ -84,34 +86,35 @@ public async Task<ActionResult<IEnumerable<Account>>> Get(
#endregion

var query = ResponseCacheService.BuildKey(Request.Path.Value,
("id", id), ("address", address), ("type", type), ("kind", kind), ("delegate", @delegate), ("balance", balance), ("staked", staked),
("lastActivity", lastActivity), ("select", select), ("sort", sort), ("offset", offset), ("limit", limit));
("id", id), ("address", address), ("type", type), ("kind", kind), ("delegate", @delegate),
("stakedPseudotokens", stakedPseudotokens), ("balance", balance), ("staked", staked), ("lastActivity", lastActivity),
("select", select), ("sort", sort), ("offset", offset), ("limit", limit));

if (ResponseCache.TryGet(query, out var cached))
return this.Bytes(cached);

object res;
if (select == null)
{
res = await Accounts.Get(id, address, type, kind, @delegate, balance, staked, lastActivity, sort, offset, limit);
res = await Accounts.Get(id, address, type, kind, @delegate, stakedPseudotokens, balance, staked, lastActivity, sort, offset, limit);
}
else if (select.Values != null)
{
if (select.Values.Length == 1)
res = await Accounts.Get(id, address, type, kind, @delegate, balance, staked, lastActivity, sort, offset, limit, select.Values[0]);
res = await Accounts.Get(id, address, type, kind, @delegate, stakedPseudotokens, balance, staked, lastActivity, sort, offset, limit, select.Values[0]);
else
res = await Accounts.Get(id, address, type, kind, @delegate, balance, staked, lastActivity, sort, offset, limit, select.Values);
res = await Accounts.Get(id, address, type, kind, @delegate, stakedPseudotokens, balance, staked, lastActivity, sort, offset, limit, select.Values);
}
else
{
if (select.Fields.Length == 1)
res = await Accounts.Get(id, address, type, kind, @delegate, balance, staked, lastActivity, sort, offset, limit, select.Fields[0]);
res = await Accounts.Get(id, address, type, kind, @delegate, stakedPseudotokens, balance, staked, lastActivity, sort, offset, limit, select.Fields[0]);
else
{
res = new SelectionResponse
{
Cols = select.Fields,
Rows = await Accounts.Get(id, address, type, kind, @delegate, balance, staked, lastActivity, sort, offset, limit, select.Fields)
Rows = await Accounts.Get(id, address, type, kind, @delegate, stakedPseudotokens, balance, staked, lastActivity, sort, offset, limit, select.Fields)
};
}
}
Expand Down Expand Up @@ -141,7 +144,7 @@ public async Task<ActionResult<int>> GetCount(
{
#region optimize
if (type == null && kind == null && balance == null && staked == null && firstActivity == null)
return Ok(State.Current.AccountsCount);
return Ok(State.Current.AccountCounter);

if (kind?.Eq != null && type == null)
type = new AccountTypeParameter { Eq = 2 };
Expand Down Expand Up @@ -484,10 +487,7 @@ public async Task<ActionResult<int>> GetCounter([Required][Address] string addre
if (ResponseCache.TryGet(query, out var cached))
return this.Bytes(cached);

var rawAccount = await Accounts.GetRawAsync(address);
var res = rawAccount == null || rawAccount is RawUser && rawAccount.Balance == 0
? State.Current.ManagerCounter
: rawAccount.Counter;
var res = await Accounts.GetCounterAsync(address);
cached = ResponseCache.Set(query, res);
return this.Bytes(cached);
}
Expand All @@ -508,7 +508,7 @@ public async Task<ActionResult<long>> GetBalance([Required][Address] string addr
if (ResponseCache.TryGet(query, out var cached))
return this.Bytes(cached);

var res = (await Accounts.GetRawAsync(address))?.Balance ?? 0;
var res = await Accounts.GetBalanceAsync(address);
cached = ResponseCache.Set(query, res);
return this.Bytes(cached);
}
Expand All @@ -517,7 +517,11 @@ public async Task<ActionResult<long>> GetBalance([Required][Address] string addr
/// Get balance at level
/// </summary>
/// <remarks>
/// Returns account balance at the specified block
/// Returns account balance* at the specified block.
/// \* - for non-baker tz-accounts historical balances do not include staked tez,
/// because stakers do not really have staked tez on their balance, they have staking pseudotokens instead.
/// If you want to get a full historical balance, including staked tez, use the Tezos node RPC:
/// `/chains/main/blocks/{level}/context/contracts/{address}/full_balance`.
/// </remarks>
/// <param name="address">Account address (starting with tz or KT)</param>
/// <param name="level">Block height at which you want to know account balance</param>
Expand All @@ -541,7 +545,11 @@ public async Task<ActionResult<long>> GetBalanceAtLevel(
/// Get balance at date
/// </summary>
/// <remarks>
/// Returns account balance at the specified datetime
/// Returns account balance* at the specified datetime.
/// \* - for non-baker tz-accounts historical balances do not include staked tez,
/// because stakers do not really have staked tez on their balance, they have staking pseudotokens instead.
/// If you want to get a full historical balance, including staked tez, use the Tezos node RPC:
/// `/chains/main/blocks/{level}/context/contracts/{address}/full_balance`.
/// </remarks>
/// <param name="address">Account address (starting with tz or KT)</param>
/// <param name="datetime">Datetime at which you want to know account balance (e.g. `2020-01-01`, or `2019-12-30T23:42:59Z`)</param>
Expand All @@ -565,7 +573,11 @@ public async Task<ActionResult<long>> GetBalanceAtDate(
/// Get balance history
/// </summary>
/// <remarks>
/// Returns time series with historical balances (only changes, without duplicates).
/// Returns time series with historical balances* (only changes, without duplicates).
/// \* - for non-baker tz-accounts historical balances do not include staked tez,
/// because stakers do not really have staked tez on their balance, they have staking pseudotokens instead.
/// If you want to get a full historical balance, including staked tez, use the Tezos node RPC:
/// `/chains/main/blocks/{level}/context/contracts/{address}/full_balance`.
/// </remarks>
/// <param name="address">Account address (starting with tz or KT)</param>
/// <param name="step">Step of the time series, for example if `step = 1000` you will get balances at blocks `1000, 2000, 3000, ...`.</param>
Expand Down
7 changes: 1 addition & 6 deletions Tzkt.Api/Controllers/BlocksController.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using Microsoft.AspNetCore.Mvc;
using NSwag.Annotations;

using Tzkt.Api.Models;
using Tzkt.Api.Repositories;
using Tzkt.Api.Services.Cache;
Expand Down
3 changes: 0 additions & 3 deletions Tzkt.Api/Controllers/CommitmentsController.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Threading.Tasks;
using Tzkt.Api.Models;
using Tzkt.Api.Repositories;
using Tzkt.Api.Services.Cache;
Expand Down
7 changes: 1 addition & 6 deletions Tzkt.Api/Controllers/ConstantsController.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using Microsoft.AspNetCore.Mvc;

using Tzkt.Api.Models;
using Tzkt.Api.Repositories;
using Tzkt.Api.Services.Cache;
Expand Down
19 changes: 6 additions & 13 deletions Tzkt.Api/Controllers/CyclesController.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using Microsoft.AspNetCore.Mvc;

using Tzkt.Api.Models;
using Tzkt.Api.Repositories;
using Tzkt.Api.Services.Cache;
Expand Down Expand Up @@ -43,7 +38,6 @@ public Task<int> GetCount()
/// <remarks>
/// Returns a list of cycles, including future cycles.
/// </remarks>
/// <param name="snapshotIndex">Filters cycles by snapshot index (0..15)</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 cycles by specified field. Supported fields: `index` (default, desc).</param>
/// <param name="offset">Specifies which or how many items should be skipped</param>
Expand All @@ -52,7 +46,6 @@ public Task<int> GetCount()
/// <returns></returns>
[HttpGet]
public async Task<ActionResult<IEnumerable<Cycle>>> Get(
Int32Parameter snapshotIndex,
SelectParameter select,
SortParameter sort,
OffsetParameter offset,
Expand All @@ -65,25 +58,25 @@ public async Task<ActionResult<IEnumerable<Cycle>>> Get(
#endregion

if (select == null)
return Ok(await Cycles.Get(snapshotIndex, sort, offset, limit, quote));
return Ok(await Cycles.Get(sort, offset, limit, quote));

if (select.Values != null)
{
if (select.Values.Length == 1)
return Ok(await Cycles.Get(snapshotIndex, sort, offset, limit, select.Values[0], quote));
return Ok(await Cycles.Get(sort, offset, limit, select.Values[0], quote));
else
return Ok(await Cycles.Get(snapshotIndex, sort, offset, limit, select.Values, quote));
return Ok(await Cycles.Get(sort, offset, limit, select.Values, quote));
}
else
{
if (select.Fields.Length == 1)
return Ok(await Cycles.Get(snapshotIndex, sort, offset, limit, select.Fields[0], quote));
return Ok(await Cycles.Get(sort, offset, limit, select.Fields[0], quote));
else
{
return Ok(new SelectionResponse
{
Cols = select.Fields,
Rows = await Cycles.Get(snapshotIndex, sort, offset, limit, select.Fields, quote)
Rows = await Cycles.Get(sort, offset, limit, select.Fields, quote)
});
}
}
Expand Down
6 changes: 1 addition & 5 deletions Tzkt.Api/Controllers/DomainsController.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;

using Microsoft.AspNetCore.Mvc;
using Tzkt.Api.Models;
using Tzkt.Api.Repositories;
using Tzkt.Api.Services;
Expand Down
5 changes: 1 addition & 4 deletions Tzkt.Api/Controllers/EventsController.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc;
using Tzkt.Api.Models;
using Tzkt.Api.Repositories;
using Tzkt.Api.Services;
Expand Down
7 changes: 1 addition & 6 deletions Tzkt.Api/Controllers/HeadController.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;

using Microsoft.AspNetCore.Mvc;
using Tzkt.Api.Models;
using Tzkt.Api.Repositories;

Expand Down
Loading
Loading