Skip to content
Open
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,13 @@ public sealed record ReducerContext : DbContext<Local>, Internal.IReducerContext

// **Note:** must be 0..=u32::MAX
internal int CounterUuid;
public Identity DatabaseIdentity => Internal.IReducerContext.GetDatabaseIdentity();

// We need this property to be non-static for parity with client SDK.
public Identity Identity => Internal.IReducerContext.GetIdentity();
// We keep this property for compatibility with existing module code.
[global::System.Obsolete(
"ReducerContext.Identity is deprecated. Use DatabaseIdentity instead."
)]
public Identity Identity => DatabaseIdentity;

internal ReducerContext(
Identity identity,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -499,9 +499,13 @@ public sealed record ReducerContext : DbContext<Local>, Internal.IReducerContext

// **Note:** must be 0..=u32::MAX
internal int CounterUuid;
public Identity DatabaseIdentity => Internal.IReducerContext.GetDatabaseIdentity();

// We need this property to be non-static for parity with client SDK.
public Identity Identity => Internal.IReducerContext.GetIdentity();
// We keep this property for compatibility with existing module code.
[global::System.Obsolete(
"ReducerContext.Identity is deprecated. Use DatabaseIdentity instead."
)]
public Identity Identity => DatabaseIdentity;

internal ReducerContext(
Identity identity,
Expand Down
6 changes: 4 additions & 2 deletions crates/bindings-csharp/Codegen/Module.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2189,8 +2189,10 @@ public sealed record ReducerContext : DbContext<Local>, Internal.IReducerContext
public readonly AuthCtx SenderAuth;
// **Note:** must be 0..=u32::MAX
internal int CounterUuid;
// We need this property to be non-static for parity with client SDK.
public Identity Identity => Internal.IReducerContext.GetIdentity();
public Identity DatabaseIdentity => Internal.IReducerContext.GetDatabaseIdentity();
// We keep this property for compatibility with existing module code.
[global::System.Obsolete("ReducerContext.Identity is deprecated. Use DatabaseIdentity instead.")]
public Identity Identity => DatabaseIdentity;

internal ReducerContext(Identity identity, ConnectionId? connectionId, Random random,
Timestamp time, AuthCtx? senderAuth = null)
Expand Down
6 changes: 5 additions & 1 deletion crates/bindings-csharp/Runtime/Internal/IReducer.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
namespace SpacetimeDB.Internal;

using System;
using System.Text;
using SpacetimeDB.BSATN;

public interface IReducerContext
{
public static Identity GetIdentity()
public static Identity GetDatabaseIdentity()
{
FFI.identity(out var identity);
return identity;
}

[Obsolete("IReducerContext.GetIdentity() is deprecated. Use GetDatabaseIdentity() instead.")]
public static Identity GetIdentity() => GetDatabaseIdentity();
}

public interface IReducer
Expand Down
10 changes: 8 additions & 2 deletions crates/bindings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ pub use spacetimedb_bindings_macro::table;
///
/// #[reducer]
/// fn scheduled(ctx: &ReducerContext, args: ScheduledArgs) -> Result<(), String> {
/// if ctx.sender() != ctx.identity() {
/// if ctx.sender() != ctx.database_identity() {
/// return Err("Reducer `scheduled` may not be invoked by clients, only via scheduling.".into());
/// }
/// // Reducer body...
Expand Down Expand Up @@ -1081,7 +1081,7 @@ impl ReducerContext {
}

/// Read the current module's [`Identity`].
pub fn identity(&self) -> Identity {
pub fn database_identity(&self) -> Identity {
// Hypothetically, we *could* read the module identity out of the system tables.
// However, this would be:
// - Onerous, because we have no tooling to inspect the system tables from module code.
Expand All @@ -1093,6 +1093,12 @@ impl ReducerContext {
Identity::from_byte_array(spacetimedb_bindings_sys::identity())
}

/// Read the current module's [`Identity`].
#[deprecated(note = "Use `ReducerContext::database_identity` instead.")]
pub fn identity(&self) -> Identity {
self.database_identity()
}

/// Create an anonymous (no sender) read-only view context
pub fn as_anonymous_read_only(&self) -> AnonymousViewContext {
AnonymousViewContext::default()
Expand Down
4 changes: 2 additions & 2 deletions modules/module-test-cs/Lib.cs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ public static void list_over_age(ReducerContext ctx, byte age)
public static void log_module_identity(ReducerContext ctx)
{
// Note: converting to lowercase to match the Rust formatting.
Log.Info($"Module identity: {ctx.Identity.ToString().ToLower()}");
Log.Info($"Module identity: {ctx.DatabaseIdentity.ToString().ToLower()}");
}

[Reducer]
Expand Down Expand Up @@ -464,7 +464,7 @@ public static void test_btree_index_args(ReducerContext ctx)
public static void assert_caller_identity_is_module_identity(ReducerContext ctx)
{
var caller = ctx.Sender;
var owner = ctx.Identity;
var owner = ctx.DatabaseIdentity;
if (!caller.Equals(owner))
{
throw new Exception($"Caller {caller} is not the owner {owner}");
Expand Down
4 changes: 2 additions & 2 deletions modules/module-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ pub fn list_over_age(ctx: &ReducerContext, age: u8) {

#[spacetimedb::reducer]
fn log_module_identity(ctx: &ReducerContext) {
log::info!("Module identity: {}", ctx.identity());
log::info!("Module identity: {}", ctx.database_identity());
}

#[spacetimedb::reducer]
Expand Down Expand Up @@ -471,7 +471,7 @@ fn test_btree_index_args(ctx: &ReducerContext) {
#[spacetimedb::reducer]
fn assert_caller_identity_is_module_identity(ctx: &ReducerContext) {
let caller = ctx.sender();
let owner = ctx.identity();
let owner = ctx.database_identity();
if caller != owner {
panic!("Caller {caller} is not the owner {owner}");
} else {
Expand Down