Skip to content

Commit

Permalink
Remove CRTP from psibase::Service
Browse files Browse the repository at this point in the history
  • Loading branch information
swatanabe committed Oct 17, 2024
1 parent a27dce8 commit 4f2b542
Show file tree
Hide file tree
Showing 47 changed files with 62 additions and 59 deletions.
14 changes: 8 additions & 6 deletions libraries/psibase/common/include/psibase/Service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ namespace psibase
{
/// Services may optionally inherit from this to gain the [emit] and [events] convenience methods
///
/// Template arguments:
/// - `DerivedService`: the most-derived service class that inherits from `Service`
template <typename DerivedService>
class Service
{
public:
Expand Down Expand Up @@ -43,7 +40,11 @@ namespace psibase
/// auto eventBNumber = emitter.ui().updateDisplay();
/// auto eventCNumber = emitter.merkle().credit(from, to, amount);
/// ```
EventEmitter<DerivedService> emit() const { return EventEmitter<DerivedService>(); }
template <typename DerivedService>
EventEmitter<DerivedService> emit(this const DerivedService&)
{
return EventEmitter<DerivedService>();
}

/// Read events
///
Expand Down Expand Up @@ -81,12 +82,13 @@ namespace psibase
/// auto eventBArguments = reader.ui().updateDisplay(eventBNumber).unpack();
/// auto eventCArguments = reader.merkle().credit(eventCNumber).unpack();
/// ```
EventReader<DerivedService> events() const
template <typename DerivedService>
EventReader<DerivedService> events(this const DerivedService&)
{
return EventReader<DerivedService>(DerivedService::service);
}
}; // Service
}; // namespace psibase
}; // namespace psibase

#define PSIBASE_REFLECT_EVENTS(SERVICE) \
using SERVICE##_Events = SERVICE ::Events; \
Expand Down
2 changes: 1 addition & 1 deletion libraries/psibase/sdk/psibase-config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function(add_libs suffix)
boost
wasm-base${suffix}
)
target_compile_features(psio${suffix} INTERFACE cxx_std_20)
target_compile_features(psio${suffix} INTERFACE cxx_std_23)

add_library(psibase${suffix} INTERFACE)
target_include_directories(psibase${suffix} INTERFACE ${root}/include)
Expand Down
2 changes: 1 addition & 1 deletion libraries/psibase/sdk/psibase-config.cmake.build
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function(add_libs suffix)
boost
wasm-base${suffix}
)
target_compile_features(psio${suffix} INTERFACE cxx_std_20)
target_compile_features(psio${suffix} INTERFACE cxx_std_23)

add_library(psibase${suffix} INTERFACE)
target_include_directories(psibase${suffix} INTERFACE
Expand Down
1 change: 1 addition & 0 deletions libraries/psibase/tester/src/semver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <cassert>
#include <compare>
#include <optional>
#include <psibase/check.hpp>
#include <string>
#include <string_view>
Expand Down
2 changes: 1 addition & 1 deletion native/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set(IS_NATIVE YES)
set(ROOT_SOURCE_DIR ${CMAKE_SOURCE_DIR})
set(ROOT_BINARY_DIR ${CMAKE_BINARY_DIR})

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS ON)

Expand Down
2 changes: 1 addition & 1 deletion rust/gen-cpp-doc/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ fn parse<'tu>(
let clang_include_dir = get_clang_include_dir(&wasi_sdk_prefix);
parser.arguments(&[
"-fcolor-diagnostics",
"-std=c++2a",
"-std=c++23",
"-c",
"--target=wasm32-wasi",
"-fno-exceptions",
Expand Down
6 changes: 3 additions & 3 deletions services/psibase_tests/AsyncQueryService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ PSIO_REFLECT(CounterRow, value)

using CounterTable = psibase::Table<CounterRow, &CounterRow::key>;

struct AsyncQueryService : psibase::Service<AsyncQueryService>
struct AsyncQueryService : psibase::Service
{
using Subjective = psibase::SubjectiveTables<AsyncResponseTable, CounterTable>;
static constexpr auto service = psibase::AccountNumber{"as-query"};
void onBlock();
auto serveSys(const HttpRequest& req, std::optional<std::int32_t> socket)
-> std::optional<HttpReply>;
auto serveSys(const HttpRequest& req,
std::optional<std::int32_t> socket) -> std::optional<HttpReply>;
};
PSIO_REFLECT(AsyncQueryService, method(onBlock), method(serveSys, request, socket))

Expand Down
2 changes: 1 addition & 1 deletion services/psibase_tests/CounterService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ PSIO_REFLECT(CounterRow, key, value)

using CounterTable = psibase::Table<CounterRow, &CounterRow::key>;

struct CounterService : psibase::Service<CounterService>
struct CounterService : psibase::Service
{
using Tables = psibase::ServiceTables<CounterTable>;
static constexpr auto service = psibase::AccountNumber{"counter"};
Expand Down
2 changes: 1 addition & 1 deletion services/psibase_tests/MockCpuLimit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

// This is a replacement for CpuLimit that always returns a fixed value
// to make tests deterministic
class MockCpuLimit : public psibase::Service<MockCpuLimit>
class MockCpuLimit : public psibase::Service
{
public:
static constexpr auto service = psibase::AccountNumber("cpu-limit");
Expand Down
2 changes: 1 addition & 1 deletion services/psibase_tests/ParallelSubjectiveService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ PSIO_REFLECT(GeRow, key)

using GeTable = Table<GeRow, &GeRow::key>;

struct ParallelSubjectiveService : psibase::Service<ParallelSubjectiveService>
struct ParallelSubjectiveService : psibase::Service
{
using Tables = psibase::SubjectiveTables<ParallelSubjectiveTable, GeTable>;
static constexpr auto service = psibase::AccountNumber{"psubjective"};
Expand Down
2 changes: 1 addition & 1 deletion services/psibase_tests/SubjectiveCounterService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ PSIO_REFLECT(SubjectiveCounterRow, key, value)

using SubjectiveCounterTable = psibase::Table<SubjectiveCounterRow, &SubjectiveCounterRow::key>;

struct SubjectiveCounterService : psibase::Service<SubjectiveCounterService>
struct SubjectiveCounterService : psibase::Service
{
using Tables = psibase::SubjectiveTables<SubjectiveCounterTable>;
static constexpr auto service = psibase::AccountNumber{"counter"};
Expand Down
2 changes: 1 addition & 1 deletion services/psibase_tests/clock-service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <psibase/Service.hpp>
#include <psibase/nativeTables.hpp>

struct ClockService : psibase::Service<ClockService>
struct ClockService : psibase::Service
{
static constexpr auto service = psibase::AccountNumber{"clock-service"};
static constexpr uint64_t serviceFlags = psibase::CodeRow::isSubjective;
Expand Down
2 changes: 1 addition & 1 deletion services/psibase_tests/event-service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <psibase/Actor.hpp>
#include <psibase/Service.hpp>

struct EventService : psibase::Service<EventService>
struct EventService : psibase::Service
{
static constexpr auto service = psibase::AccountNumber{"event-service"};
struct Events
Expand Down
2 changes: 1 addition & 1 deletion services/psibase_tests/subjective-service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ PSIO_REFLECT(SubjectiveRow, key, value)

using SubjectiveTable = psibase::Table<SubjectiveRow, &SubjectiveRow::key>;

struct SubjectiveService : psibase::Service<SubjectiveService>
struct SubjectiveService : psibase::Service
{
using Tables = psibase::SubjectiveTables<SubjectiveTable>;
static constexpr auto service = psibase::AccountNumber{"subjective"};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ namespace SystemService
/// Only the Accounts service itself and the `inviteService` may create new accounts.
/// Other services may also use this service to check if an account exists.
// TODO: account deletion, with an index to prevent reusing IDs
class Accounts : public psibase::Service<Accounts>
class Accounts : public psibase::Service
{
public:
/// "accounts"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace SystemService
{
struct RAccounts : public psibase::Service<RAccounts>
struct RAccounts : public psibase::Service
{
static constexpr auto service = psibase::AccountNumber("r-accounts");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace SystemService
{
struct AuthAny : psibase::Service<AuthAny>
struct AuthAny : psibase::Service
{
static constexpr psibase::AccountNumber service = psibase::AccountNumber("auth-any");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace SystemService
///
/// Any account using this auth service must store in this service the name of
/// the other account that owns it.
class AuthDelegate : public psibase::Service<AuthDelegate>
class AuthDelegate : public psibase::Service
{
public:
static constexpr auto service = psibase::AccountNumber("auth-delegate");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace SystemService
/// transaction sent by this account.
///
/// This service supports K1 or R1 keys (Secp256K1 or Secp256R1) keys.
class AuthSig : public psibase::Service<AuthSig>
class AuthSig : public psibase::Service
{
public:
static constexpr auto service = psibase::AccountNumber("auth-sig");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace SystemService
{
namespace AuthSig
{
class RAuthSig : public psibase::Service<RAuthSig>
class RAuthSig : public psibase::Service
{
public:
static constexpr auto service = psibase::AccountNumber("r-auth-sig");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace SystemService
{
// This service manages the active producers.
// It must have native write permission
class CpuLimit : public psibase::Service<CpuLimit>
class CpuLimit : public psibase::Service
{
public:
static constexpr auto service = psibase::AccountNumber("cpu-limit");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace SystemService
/// an HTTP request that services may serve. This function does the actual routing.
/// `psinode` has a local option (TODO: implement) which may choose an alternative
/// routing service instead.
struct HttpServer : psibase::Service<HttpServer>
struct HttpServer : psibase::Service
{
static constexpr auto service = psibase::proxyServiceNum;
using Tables = psibase::ServiceTables<RegServTable>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace SystemService
{
struct RHttpServer : public psibase::Service<RHttpServer>
struct RHttpServer : public psibase::Service
{
static constexpr auto service = psibase::AccountNumber("rhttp-server");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace SystemService
{
// This service manages the active producers.
// It must have native write permission
class Producers : public psibase::Service<Producers>
class Producers : public psibase::Service
{
public:
static constexpr auto service = psibase::AccountNumber("producers");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace SystemService
{
struct RProducers : public psibase::Service<RProducers>
struct RProducers : public psibase::Service
{
static constexpr auto service = psibase::AccountNumber("r-producers");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace SystemService
{

/// All compiled code is uploaded to the chain through this service
struct SetCode : psibase::Service<SetCode>
struct SetCode : psibase::Service
{
/// "setcode"
static constexpr auto service = psibase::AccountNumber("setcode");
Expand Down
12 changes: 6 additions & 6 deletions services/system/Transact/include/services/system/RTransact.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,23 +79,23 @@ namespace SystemService

using TraceClientTable = psibase::Table<TraceClientRow, &TraceClientRow::id>;

class RTransact : psibase::Service<RTransact>
class RTransact : psibase::Service
{
public:
static constexpr auto service = psibase::AccountNumber{"r-transact"};
using Subjective = psibase::SubjectiveTables<PendingTransactionTable,
TransactionDataTable,
AvailableSequenceTable,
TraceClientTable>;
TransactionDataTable,
AvailableSequenceTable,
TraceClientTable>;
using WriteOnly = psibase::WriteOnlyTables<UnappliedTransactionTable, ReversibleBlocksTable>;
std::optional<psibase::SignedTransaction> next();
// Handles transactions coming over P2P
void recv(const psibase::SignedTransaction& transaction);
// Callbacks used to track successful/expired transactions
void onTrx(const psibase::Checksum256& id, const psibase::TransactionTrace& trace);
void onBlock();
auto serveSys(const psibase::HttpRequest& request, std::optional<std::int32_t> socket)
-> std::optional<psibase::HttpReply>;
auto serveSys(const psibase::HttpRequest& request,
std::optional<std::int32_t> socket) -> std::optional<psibase::HttpReply>;
};
PSIO_REFLECT(RTransact,
method(next),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ namespace SystemService
/// Other services use it to get information about the chain,
/// current block, and head block. They also use it to call actions
/// using other accounts' authorities via [runAs].
struct Transact : psibase::Service<Transact>
struct Transact : psibase::Service
{
/// "transact"
static constexpr auto service = psibase::AccountNumber("transact");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace SystemService
{
struct VerifySig : psibase::Service<VerifySig>
struct VerifySig : psibase::Service
{
static constexpr auto service = psibase::AccountNumber("verify-sig");
static constexpr uint64_t serviceFlags = psibase::CodeRow::isAuthService;
Expand Down
2 changes: 1 addition & 1 deletion services/user/Chainmail/include/services/user/Webmail.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace UserService
{
class Chainmail : public psibase::Service<Chainmail>
class Chainmail : public psibase::Service
{
public:
static constexpr auto service = psibase::AccountNumber("chainmail");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace SystemService
///
/// See [HTTP requests](../development/front-ends/reference/http-requests.md) and
/// [JS libraries](../development/front-ends/reference/js-libraries.md)
struct CommonApi : psibase::Service<CommonApi>
struct CommonApi : psibase::Service
{
/// "common-api"
static constexpr auto service = psibase::AccountNumber("common-api");
Expand Down
2 changes: 1 addition & 1 deletion services/user/Events/include/services/user/Events.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace UserService
/// [{"x":5,"y":7,"sum":12},{"x":6,"y":5,"sum":11}]
/// ```
///
struct EventIndex : psibase::Service<EventIndex>
struct EventIndex : psibase::Service
{
static constexpr psibase::AccountNumber service{"events"};
static constexpr auto serviceFlags =
Expand Down
2 changes: 1 addition & 1 deletion services/user/Events/include/services/user/REvents.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace UserService
{
struct REvents : psibase::Service<REvents>
struct REvents : psibase::Service
{
static constexpr psibase::AccountNumber service{"r-events"};

Expand Down
2 changes: 1 addition & 1 deletion services/user/Events/test/TestService.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <psibase/AccountNumber.hpp>
#include <psibase/Service.hpp>

struct TestService : psibase::Service<TestService>
struct TestService : psibase::Service
{
static constexpr auto service = psibase::AccountNumber{"test-service"};
//
Expand Down
2 changes: 1 addition & 1 deletion services/user/Explorer/include/services/user/Explorer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace SystemService
{
struct Explorer : public psibase::Service<Explorer>
struct Explorer : public psibase::Service
{
static constexpr auto service = psibase::AccountNumber("explorer");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace UserService
{
namespace FractalNs
{
class CoreFractal : public psibase::Service<CoreFractal>
class CoreFractal : public psibase::Service
{
public:
using Tables = psibase::ServiceTables<InitTable>;
Expand Down
2 changes: 1 addition & 1 deletion services/user/Fractal/include/services/user/Fractal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace UserService
{
namespace FractalNs
{
class Fractal : public psibase::Service<Fractal>
class Fractal : public psibase::Service
{
public:
using Tables = psibase::ServiceTables<InitTable,
Expand Down
2 changes: 1 addition & 1 deletion services/user/Invite/include/services/user/Invite.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace UserService
/// by third party applications to streamline their user onboarding.
///
/// Only this system service and Accounts are permitted to create new accounts.
class Invite : public psibase::Service<Invite>
class Invite : public psibase::Service
{
public:
using Tables =
Expand Down
Loading

0 comments on commit 4f2b542

Please sign in to comment.