From 89bfb293da84fff4ea15b8334fefc1afa8a31336 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Tue, 20 Aug 2024 13:27:37 +0200 Subject: [PATCH] define Address as u128 --- .../bindings-csharp/BSATN.Runtime/Builtins.cs | 39 ++++---- .../Runtime/Internal/Module.cs | 2 +- crates/bindings/src/rt.rs | 2 +- crates/core/src/client/messages.rs | 2 +- .../locking_tx_datastore/datastore.rs | 6 +- crates/core/src/db/datastore/system_tables.rs | 15 +-- .../core/src/host/wasmtime/wasmtime_module.rs | 2 +- crates/core/src/sql/compiler.rs | 12 +-- crates/core/src/sql/type_check.rs | 6 +- crates/lib/src/address.rs | 91 +++++++++---------- crates/sats/src/algebraic_type.rs | 2 +- crates/sats/src/product_type.rs | 12 +-- crates/sdk/src/callbacks.rs | 2 +- .../insert_primitives_as_strings_reducer.rs | 14 +-- crates/standalone/src/control_db.rs | 11 ++- crates/standalone/src/control_db/tests.rs | 2 +- 16 files changed, 105 insertions(+), 115 deletions(-) diff --git a/crates/bindings-csharp/BSATN.Runtime/Builtins.cs b/crates/bindings-csharp/BSATN.Runtime/Builtins.cs index 40f4b7a634a..fd45ac634f6 100644 --- a/crates/bindings-csharp/BSATN.Runtime/Builtins.cs +++ b/crates/bindings-csharp/BSATN.Runtime/Builtins.cs @@ -61,44 +61,37 @@ string wrapperPropertyName ); } -public record Address : BytesWrapper +public struct Address { - protected override int SIZE => 16; + private readonly U128 value; public Address() { } - - private Address(byte[] bytes) - : base(bytes) { } - - public static Address? From(byte[] bytes) - { - if (bytes.All(b => b == 0)) + public Address(U128 v) => value = v; + public static Address? From(ulong upper, ulong lower) { + if (upper == 0 && lower == 0) { return null; } - return new(bytes); - } - - public static Address Random() - { - var random = new Random(); - var addr = new Address(); - random.NextBytes(addr.bytes); - return addr; + else + { + return new Address(new U128(upper, lower)); + } } public readonly struct BSATN : IReadWrite
{ - public Address Read(BinaryReader reader) => new(ReadRaw(reader)); + public Address Read(BinaryReader reader) => new(new SpacetimeDB.BSATN.U128Stdb().Read(reader)); - public void Write(BinaryWriter writer, Address value) => value.Write(writer); + public void Write(BinaryWriter writer, Address value) + => new SpacetimeDB.BSATN.U128Stdb().Write(writer, value.value); public AlgebraicType GetAlgebraicType(ITypeRegistrar registrar) => - BytesWrapper.GetAlgebraicType(registrar, "__address_bytes"); + new AlgebraicType.Product( + [new("__address__", new AlgebraicType.U128(default))] + ); } - // This must be explicitly forwarded to base, otherwise record will generate a new implementation. - public override string ToString() => base.ToString(); + public override string ToString() => value.ToString(); } public record Identity : BytesWrapper diff --git a/crates/bindings-csharp/Runtime/Internal/Module.cs b/crates/bindings-csharp/Runtime/Internal/Module.cs index 9e60a778359..4bae22bdba0 100644 --- a/crates/bindings-csharp/Runtime/Internal/Module.cs +++ b/crates/bindings-csharp/Runtime/Internal/Module.cs @@ -312,7 +312,7 @@ BytesSink error var sender = Identity.From(MemoryMarshal.AsBytes([sender_0, sender_1, sender_2, sender_3]).ToArray()); // Piece together the sender address. - var address = Address.From(MemoryMarshal.AsBytes([address_0, address_1]).ToArray()); + var address = Address.From(address_1, address_0); try { diff --git a/crates/bindings/src/rt.rs b/crates/bindings/src/rt.rs index 080f2f155ed..07284c29cf8 100644 --- a/crates/bindings/src/rt.rs +++ b/crates/bindings/src/rt.rs @@ -414,7 +414,7 @@ extern "C" fn __describe_module__(description: BytesSink) { /// - `sender_3` contains bytes `[24..32]`. /// /// The `address_{0-1}` are the pieces of a `[u8; 16]` (`u128`) representing the callers's `Address`. -/// They are encoded as follows (assuming `identity.__address_bytes: [u8; 16]`): +/// They are encoded as follows (assuming `address.__address__: u128`): /// - `address_0` contains bytes `[0 ..8 ]`. /// - `address_1` contains bytes `[8 ..16]`. /// diff --git a/crates/core/src/client/messages.rs b/crates/core/src/client/messages.rs index a28b3a669c8..d82e9401019 100644 --- a/crates/core/src/client/messages.rs +++ b/crates/core/src/client/messages.rs @@ -250,7 +250,7 @@ impl> ToProtocol for TransactionUpda }, energy_quanta_used: event.energy_quanta_used, host_execution_duration_micros: event.host_execution_duration.as_micros() as u64, - caller_address: event.caller_address.unwrap_or(Address::zero()), + caller_address: event.caller_address.unwrap_or(Address::ZERO), }; ws::ServerMessage::TransactionUpdate(tx_update) diff --git a/crates/core/src/db/datastore/locking_tx_datastore/datastore.rs b/crates/core/src/db/datastore/locking_tx_datastore/datastore.rs index d6f42b31f26..9000f830c80 100644 --- a/crates/core/src/db/datastore/locking_tx_datastore/datastore.rs +++ b/crates/core/src/db/datastore/locking_tx_datastore/datastore.rs @@ -1044,7 +1044,7 @@ mod tests { } fn get_datastore() -> Result { - Locking::bootstrap(Address::zero()) + Locking::bootstrap(Address::ZERO) } fn col(col: u16) -> ColList { @@ -1352,14 +1352,14 @@ mod tests { ColRow { table: ST_CONSTRAINT_ID.into(), pos: 3, name: "table_id", ty: TableId::get_type() }, ColRow { table: ST_CONSTRAINT_ID.into(), pos: 4, name: "columns", ty: AlgebraicType::array(ColId::get_type()) }, - ColRow { table: ST_MODULE_ID.into(), pos: 0, name: "database_address", ty: AlgebraicType::bytes() }, + ColRow { table: ST_MODULE_ID.into(), pos: 0, name: "database_address", ty: AlgebraicType::U128 }, ColRow { table: ST_MODULE_ID.into(), pos: 1, name: "owner_identity", ty: AlgebraicType::bytes() }, ColRow { table: ST_MODULE_ID.into(), pos: 2, name: "program_kind", ty: AlgebraicType::U8 }, ColRow { table: ST_MODULE_ID.into(), pos: 3, name: "program_hash", ty: AlgebraicType::bytes() }, ColRow { table: ST_MODULE_ID.into(), pos: 4, name: "program_bytes", ty: AlgebraicType::bytes() }, ColRow { table: ST_CLIENT_ID.into(), pos: 0, name: "identity", ty: AlgebraicType::bytes()}, - ColRow { table: ST_CLIENT_ID.into(), pos: 1, name: "address", ty: AlgebraicType::bytes()}, + ColRow { table: ST_CLIENT_ID.into(), pos: 1, name: "address", ty: AlgebraicType::U128}, ColRow { table: ST_VAR_ID.into(), pos: 0, name: "name", ty: AlgebraicType::String }, ColRow { table: ST_VAR_ID.into(), pos: 1, name: "value", ty: StVarValue::type_of() }, diff --git a/crates/core/src/db/datastore/system_tables.rs b/crates/core/src/db/datastore/system_tables.rs index 3a28b8150d8..54966291aeb 100644 --- a/crates/core/src/db/datastore/system_tables.rs +++ b/crates/core/src/db/datastore/system_tables.rs @@ -386,7 +386,7 @@ pub(crate) fn st_module_schema() -> TableSchema { RawTableDefV8::new( ST_MODULE_NAME.into(), vec![ - RawColumnDefV8::sys(StModuleFields::DatabaseAddress.name(), AlgebraicType::bytes()), + RawColumnDefV8::sys(StModuleFields::DatabaseAddress.name(), AlgebraicType::U128), RawColumnDefV8::sys(StModuleFields::OwnerIdentity.name(), AlgebraicType::bytes()), RawColumnDefV8::sys(StModuleFields::ProgramKind.name(), AlgebraicType::U8), RawColumnDefV8::sys(StModuleFields::ProgramHash.name(), AlgebraicType::bytes()), @@ -401,7 +401,7 @@ pub(crate) fn st_module_schema() -> TableSchema { /// // identity | address // -----------------------------------------------------------------------------------------+-------------------------------------------------------- -// (__identity_bytes = 0x7452047061ea2502003412941d85a42f89b0702588b823ab55fc4f12e9ea8363) | (__address_bytes = 0x6bdea3ab517f5857dc9b1b5fe99e1b14) +// (__identity_bytes = 0x7452047061ea2502003412941d85a42f89b0702588b823ab55fc4f12e9ea8363) | (__address__ = 0x6bdea3ab517f5857dc9b1b5fe99e1b14) fn st_client_schema() -> TableSchema { TableSchema::from_def( ST_CLIENT_ID, @@ -409,7 +409,7 @@ fn st_client_schema() -> TableSchema { ST_CLIENT_NAME.into(), vec![ RawColumnDefV8::sys(StClientFields::Identity.name(), AlgebraicType::bytes()), - RawColumnDefV8::sys(StClientFields::Address.name(), AlgebraicType::bytes()), + RawColumnDefV8::sys(StClientFields::Address.name(), AlgebraicType::U128), ], ) .with_type(StTableType::System) @@ -794,9 +794,10 @@ pub fn read_bytes_from_col(row: RowRef<'_>, col: impl StFields) -> Result, col: impl StFields) -> Result { - read_bytes_from_col(row, col).map(Address::from_slice) + let val: u128 = row.read_col(col.col_id())?; + Ok(val.into()) } /// Read an [`Identity`] directly from the column `col` in `row`. @@ -838,7 +839,7 @@ impl From for ProductValue { }: StModuleRow, ) -> Self { product![ - database_address.as_slice().as_slice(), + database_address.to_u128(), owner_identity.as_bytes().as_slice(), program_kind, program_hash.as_slice(), @@ -855,7 +856,7 @@ pub struct StClientsRow { impl From<&StClientsRow> for ProductValue { fn from(x: &StClientsRow) -> Self { - product![x.identity.as_bytes().as_slice(), x.address.as_slice().as_slice()] + product![x.identity.as_bytes().as_slice(), x.address.to_u128()] } } diff --git a/crates/core/src/host/wasmtime/wasmtime_module.rs b/crates/core/src/host/wasmtime/wasmtime_module.rs index 8013634173b..f4a2462aaa0 100644 --- a/crates/core/src/host/wasmtime/wasmtime_module.rs +++ b/crates/core/src/host/wasmtime/wasmtime_module.rs @@ -195,7 +195,7 @@ impl module_host_actor::WasmInstance for WasmtimeInstance { // Prepare sender identity and address. let [sender_0, sender_1, sender_2, sender_3] = bytemuck::must_cast(*op.caller_identity.as_bytes()); - let [address_0, address_1] = bytemuck::must_cast(*op.caller_address.as_slice()); + let [address_0, address_1] = bytemuck::must_cast(op.caller_address.as_byte_array()); // Prepare arguments to the reducer + the error sink & start timings. let (args_source, errors_sink) = store.data_mut().start_reducer(op.name, op.arg_bytes); diff --git a/crates/core/src/sql/compiler.rs b/crates/core/src/sql/compiler.rs index ed5f73abcbc..eb524153bdc 100644 --- a/crates/core/src/sql/compiler.rs +++ b/crates/core/src/sql/compiler.rs @@ -236,8 +236,7 @@ mod tests { use spacetimedb_lib::{Address, Identity}; use spacetimedb_primitives::{col_list, ColList, TableId}; use spacetimedb_sats::{ - product, satn, AlgebraicType, AlgebraicValue, GroundSpacetimeType as _, ProductType, ProductTypeElement, - Typespace, ValueWithType, + product, satn, AlgebraicType, AlgebraicValue, GroundSpacetimeType as _, ProductType, Typespace, ValueWithType, }; use spacetimedb_vm::expr::{ColumnOp, IndexJoin, IndexScan, JoinExpr, Query}; use std::convert::From; @@ -398,10 +397,7 @@ mod tests { #[test] fn output_identity_address() -> ResultTest<()> { let row = product![AlgebraicValue::from(Identity::__dummy())]; - let kind = ProductType::new(Box::new([ProductTypeElement::new( - Identity::get_type(), - Some("i".into()), - )])); + let kind: ProductType = [("i", Identity::get_type())].into(); let ty = Typespace::EMPTY.with_type(&kind); let out = ty .with_values(&row) @@ -426,7 +422,7 @@ mod tests { AlgebraicValue::String("a".into()), AlgebraicValue::Bytes((*Identity::ZERO.as_bytes()).into()), AlgebraicValue::Bytes((*Identity::ZERO.as_bytes()).into()), - AlgebraicValue::Bytes((*Address::__DUMMY.as_slice()).into()), + Address::__DUMMY.to_u128().into(), ]); assert_eq!( @@ -441,7 +437,7 @@ mod tests { AlgebraicValue::String("a".into()), AlgebraicValue::Bytes((*Identity::ZERO.as_bytes()).into()), AlgebraicValue::product([AlgebraicValue::Bytes((*Identity::ZERO.as_bytes()).into())]), - AlgebraicValue::product([AlgebraicValue::Bytes((*Address::__DUMMY.as_slice()).into())]), + AlgebraicValue::product([Address::__DUMMY.to_u128().into()]), ]; let value = ValueWithType::new(ty, &value); diff --git a/crates/core/src/sql/type_check.rs b/crates/core/src/sql/type_check.rs index 00b15074f3e..d2573e6238f 100644 --- a/crates/core/src/sql/type_check.rs +++ b/crates/core/src/sql/type_check.rs @@ -109,7 +109,9 @@ fn resolve_type(field: &FieldExpr, ty: AlgebraicType) -> Result Result<(), PlanError> { fn patch_type(lhs: &FieldOp, ty_lhs: &mut Typed, ty_rhs: &Typed) -> Result<(), PlanError> { if let FieldOp::Field(lhs_field) = lhs { if let Some(ty) = ty_rhs.ty() { - if ty.is_sum() || ty.as_product().map_or(false, |x| x.is_special()) { + if ty.is_sum() || ty.as_product().is_some_and(|x| x.is_special()) { ty_lhs.set_ty(resolve_type(lhs_field, ty.clone())?); } } diff --git a/crates/lib/src/address.rs b/crates/lib/src/address.rs index 58c5c9ac810..7d7ae95e9c8 100644 --- a/crates/lib/src/address.rs +++ b/crates/lib/src/address.rs @@ -3,11 +3,11 @@ use core::{fmt, net::Ipv6Addr}; use spacetimedb_bindings_macro::{Deserialize, Serialize}; use spacetimedb_lib::from_hex_pad; use spacetimedb_sats::hex::HexString; -use spacetimedb_sats::product_type::ADDRESS_TAG; -use spacetimedb_sats::{impl_deserialize, impl_serialize, impl_st, AlgebraicType, AlgebraicValue, ProductValue}; +use spacetimedb_sats::{impl_deserialize, impl_serialize, impl_st, AlgebraicType, AlgebraicValue}; /// This is the address for a SpacetimeDB database or client connection. /// +/// TODO: This is wrong; the address can change, but the Identity cannot. /// It is a unique identifier for a particular database and once set for a database, /// does not change. /// @@ -17,10 +17,10 @@ use spacetimedb_sats::{impl_deserialize, impl_serialize, impl_st, AlgebraicType, // This is likely #[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)] pub struct Address { - __address_bytes: [u8; 16], + __address__: u128, } -impl_st!([] Address, AlgebraicType::product([(ADDRESS_TAG, AlgebraicType::bytes())])); +impl_st!([] Address, AlgebraicType::address()); #[cfg(feature = "metrics_impls")] impl spacetimedb_metrics::typed_prometheus::AsPrometheusLabel for Address { @@ -48,20 +48,22 @@ impl fmt::Debug for Address { } impl Address { - pub const ZERO: Self = Self { - __address_bytes: [0; 16], - }; + pub const ZERO: Self = Self::from_u128(0); - pub fn from_byte_array(arr: [u8; 16]) -> Self { - Self { __address_bytes: arr } + pub const fn from_u128(__address__: u128) -> Self { + Self { __address__ } } - pub const fn zero() -> Self { - Self::ZERO + pub const fn to_u128(&self) -> u128 { + self.__address__ + } + + pub const fn from_byte_array(arr: [u8; 16]) -> Self { + Self::from_u128(u128::from_le_bytes(arr)) } - pub fn from_u128(u: u128) -> Self { - Self::from_byte_array(u.to_be_bytes()) + pub const fn as_byte_array(&self) -> [u8; 16] { + self.__address__.to_le_bytes() } pub fn from_hex(hex: &str) -> Result { @@ -71,11 +73,11 @@ impl Address { } pub fn to_hex(self) -> HexString<16> { - spacetimedb_sats::hex::encode(self.as_slice()) + spacetimedb_sats::hex::encode(&self.as_byte_array()) } pub fn abbreviate(&self) -> [u8; 8] { - self.as_slice()[..8].try_into().unwrap() + self.as_byte_array()[..8].try_into().unwrap() } pub fn to_abbreviated_hex(self) -> HexString<8> { @@ -89,12 +91,8 @@ impl Address { Self::from_byte_array(dst) } - pub fn as_slice(&self) -> &[u8; 16] { - &self.__address_bytes - } - pub fn to_ipv6(self) -> Ipv6Addr { - Ipv6Addr::from(self.__address_bytes) + Ipv6Addr::from(self.__address__) } #[allow(dead_code)] @@ -104,10 +102,6 @@ impl Address { #[doc(hidden)] pub const __DUMMY: Self = Self::ZERO; - - pub fn to_u128(&self) -> u128 { - u128::from_be_bytes(self.__address_bytes) - } } impl From for Address { @@ -118,9 +112,7 @@ impl From for Address { impl From
for AlgebraicValue { fn from(value: Address) -> Self { - AlgebraicValue::Product(ProductValue::from(AlgebraicValue::Bytes( - value.__address_bytes.to_vec().into(), - ))) + AlgebraicValue::product([value.to_u128().into()]) } } @@ -129,7 +121,7 @@ pub struct AddressForUrl(u128); impl From
for AddressForUrl { fn from(addr: Address) -> Self { - AddressForUrl(u128::from_be_bytes(addr.__address_bytes)) + AddressForUrl(addr.to_u128()) } } @@ -139,9 +131,9 @@ impl From for Address { } } -impl_serialize!([] AddressForUrl, (self, ser) => self.0.to_be_bytes().serialize(ser)); -impl_deserialize!([] AddressForUrl, de => <[u8; 16]>::deserialize(de).map(|v| Self(u128::from_be_bytes(v)))); -impl_st!([] AddressForUrl, AlgebraicType::bytes()); +impl_serialize!([] AddressForUrl, (self, ser) => self.0.serialize(ser)); +impl_deserialize!([] AddressForUrl, de => u128::deserialize(de).map(Self)); +impl_st!([] AddressForUrl, AlgebraicType::U128); #[cfg(feature = "serde")] impl serde::Serialize for AddressForUrl { @@ -149,7 +141,7 @@ impl serde::Serialize for AddressForUrl { where S: serde::Serializer, { - spacetimedb_sats::ser::serde::serialize_to(&Address::from(*self).as_slice(), serializer) + spacetimedb_sats::ser::serde::serialize_to(&Address::from(*self).as_byte_array(), serializer) } } @@ -170,7 +162,7 @@ impl serde::Serialize for Address { where S: serde::Serializer, { - spacetimedb_sats::ser::serde::serialize_to(&self.as_slice(), serializer) + spacetimedb_sats::ser::serde::serialize_to(&self.as_byte_array(), serializer) } } @@ -188,28 +180,33 @@ impl<'de> serde::Deserialize<'de> for Address { #[cfg(test)] mod tests { use super::*; + use proptest::prelude::*; use spacetimedb_sats::bsatn; - #[test] - fn test_bsatn_roundtrip() { - let addr = Address::from_u128(rand::random()); - let ser = bsatn::to_vec(&addr).unwrap(); - let de = bsatn::from_slice(&ser).unwrap(); - assert_eq!(addr, de); + proptest! { + #[test] + fn test_bsatn_roundtrip(val: u128) { + let addr = Address::from_u128(val); + let ser = bsatn::to_vec(&addr).unwrap(); + let de = bsatn::from_slice(&ser).unwrap(); + assert_eq!(addr, de); + } } #[cfg(feature = "serde")] mod serde { use super::*; - #[test] - fn test_serde_roundtrip() { - let addr = Address::from_u128(rand::random()); - let to_url = AddressForUrl::from(addr); - let ser = serde_json::to_vec(&to_url).unwrap(); - let de = serde_json::from_slice::(&ser).unwrap(); - let from_url = Address::from(de); - assert_eq!(addr, from_url); + proptest! { + #[test] + fn test_serde_roundtrip(val: u128) { + let addr = Address::from_u128(val); + let to_url = AddressForUrl::from(addr); + let ser = serde_json::to_vec(&to_url).unwrap(); + let de = serde_json::from_slice::(&ser).unwrap(); + let from_url = Address::from(de); + prop_assert_eq!(addr, from_url); + } } } } diff --git a/crates/sats/src/algebraic_type.rs b/crates/sats/src/algebraic_type.rs index e0791702fcb..7f2859b81a8 100644 --- a/crates/sats/src/algebraic_type.rs +++ b/crates/sats/src/algebraic_type.rs @@ -285,7 +285,7 @@ impl AlgebraicType { /// Construct a copy of the `Address` type. pub fn address() -> Self { - AlgebraicType::product([(ADDRESS_TAG, AlgebraicType::bytes())]) + AlgebraicType::product([(ADDRESS_TAG, AlgebraicType::U128)]) } /// Returns a sum type of unit variants with names taken from `var_names`. diff --git a/crates/sats/src/product_type.rs b/crates/sats/src/product_type.rs index 09768286184..ca6c601f143 100644 --- a/crates/sats/src/product_type.rs +++ b/crates/sats/src/product_type.rs @@ -5,7 +5,7 @@ use crate::{de::Deserialize, ser::Serialize}; use crate::{AlgebraicType, AlgebraicValue, ProductTypeElement, ValueWithType, WithTypespace}; pub const IDENTITY_TAG: &str = "__identity_bytes"; -pub const ADDRESS_TAG: &str = "__address_bytes"; +pub const ADDRESS_TAG: &str = "__address__"; /// A structural product type of the factors given by `elements`. /// @@ -46,25 +46,25 @@ impl ProductType { Self { elements } } - /// Returns whether this is a "newtype" over bytes. - fn is_bytes_newtype(&self, check: &str) -> bool { + /// Returns whether this is a "newtype" with `label` and satisfying `inner`. + fn is_newtype(&self, check: &str, inner: impl FnOnce(&AlgebraicType) -> bool) -> bool { match &*self.elements { [ProductTypeElement { name: Some(name), algebraic_type, - }] => &**name == check && algebraic_type.is_bytes(), + }] => &**name == check && inner(algebraic_type), _ => false, } } /// Returns whether this is the special case of `spacetimedb_lib::Identity`. pub fn is_identity(&self) -> bool { - self.is_bytes_newtype(IDENTITY_TAG) + self.is_newtype(IDENTITY_TAG, |i| i.is_bytes()) } /// Returns whether this is the special case of `spacetimedb_lib::Address`. pub fn is_address(&self) -> bool { - self.is_bytes_newtype(ADDRESS_TAG) + self.is_newtype(ADDRESS_TAG, |i| i.is_u128()) } /// Returns whether this is a special known `tag`, currently `Address` or `Identity`. diff --git a/crates/sdk/src/callbacks.rs b/crates/sdk/src/callbacks.rs index f0ac83621d0..ae99460269e 100644 --- a/crates/sdk/src/callbacks.rs +++ b/crates/sdk/src/callbacks.rs @@ -697,7 +697,7 @@ impl ReducerCallbacks { .. } = event; let status = Status::from_update_status(status); - let address = (caller_address != Address::zero()).then_some(caller_address); + let address = (caller_address != Address::ZERO).then_some(caller_address); match bsatn::from_slice::(reducer_call.args.as_binary().unwrap()) { Err(e) => { log::error!("Error while deserializing reducer args from FunctionCall: {:?}", e); diff --git a/crates/sdk/tests/test-client/src/module_bindings/insert_primitives_as_strings_reducer.rs b/crates/sdk/tests/test-client/src/module_bindings/insert_primitives_as_strings_reducer.rs index e8fdb704c64..bdf1d86dc5c 100644 --- a/crates/sdk/tests/test-client/src/module_bindings/insert_primitives_as_strings_reducer.rs +++ b/crates/sdk/tests/test-client/src/module_bindings/insert_primitives_as_strings_reducer.rs @@ -15,7 +15,7 @@ use spacetimedb_sdk::{ #[derive(Serialize, Deserialize, Clone, PartialEq, Debug)] pub struct InsertPrimitivesAsStringsArgs { - pub t: EveryPrimitiveStruct, + pub s: EveryPrimitiveStruct, } impl Reducer for InsertPrimitivesAsStringsArgs { @@ -23,8 +23,8 @@ impl Reducer for InsertPrimitivesAsStringsArgs { } #[allow(unused)] -pub fn insert_primitives_as_strings(t: EveryPrimitiveStruct) { - InsertPrimitivesAsStringsArgs { t }.invoke(); +pub fn insert_primitives_as_strings(s: EveryPrimitiveStruct) { + InsertPrimitivesAsStringsArgs { s }.invoke(); } #[allow(unused)] @@ -32,8 +32,8 @@ pub fn on_insert_primitives_as_strings( mut __callback: impl FnMut(&Identity, Option
, &Status, &EveryPrimitiveStruct) + Send + 'static, ) -> ReducerCallbackId { InsertPrimitivesAsStringsArgs::on_reducer(move |__identity, __addr, __status, __args| { - let InsertPrimitivesAsStringsArgs { t } = __args; - __callback(__identity, __addr, __status, t); + let InsertPrimitivesAsStringsArgs { s } = __args; + __callback(__identity, __addr, __status, s); }) } @@ -42,8 +42,8 @@ pub fn once_on_insert_primitives_as_strings( __callback: impl FnOnce(&Identity, Option
, &Status, &EveryPrimitiveStruct) + Send + 'static, ) -> ReducerCallbackId { InsertPrimitivesAsStringsArgs::once_on_reducer(move |__identity, __addr, __status, __args| { - let InsertPrimitivesAsStringsArgs { t } = __args; - __callback(__identity, __addr, __status, t); + let InsertPrimitivesAsStringsArgs { s } = __args; + __callback(__identity, __addr, __status, s); }) } diff --git a/crates/standalone/src/control_db.rs b/crates/standalone/src/control_db.rs index c6877dc0ca9..563383dbaf7 100644 --- a/crates/standalone/src/control_db.rs +++ b/crates/standalone/src/control_db.rs @@ -86,7 +86,7 @@ impl ControlDb { pub fn spacetime_reverse_dns(&self, address: &Address) -> Result> { let tree = self.db.open_tree("reverse_dns")?; - let value = tree.get(address.as_slice())?; + let value = tree.get(address.as_byte_array())?; if let Some(value) = value { let vec: Vec = serde_json::from_slice(&value[..])?; return Ok(vec); @@ -141,18 +141,19 @@ impl ControlDb { } } + let addr_bytes = address.as_byte_array(); let tree = self.db.open_tree("dns")?; - tree.insert(domain.to_lowercase().as_bytes(), &address.as_slice()[..])?; + tree.insert(domain.to_lowercase().as_bytes(), &addr_bytes)?; let tree = self.db.open_tree("reverse_dns")?; - match tree.get(address.as_slice())? { + match tree.get(addr_bytes)? { Some(value) => { let mut vec: Vec = serde_json::from_slice(&value[..])?; vec.push(domain.clone()); - tree.insert(address.as_slice(), serde_json::to_string(&vec)?.as_bytes())?; + tree.insert(addr_bytes, serde_json::to_string(&vec)?.as_bytes())?; } None => { - tree.insert(address.as_slice(), serde_json::to_string(&vec![&domain])?.as_bytes())?; + tree.insert(addr_bytes, serde_json::to_string(&vec![&domain])?.as_bytes())?; } } diff --git a/crates/standalone/src/control_db/tests.rs b/crates/standalone/src/control_db/tests.rs index b36ce0c8a84..26de5dd570e 100644 --- a/crates/standalone/src/control_db/tests.rs +++ b/crates/standalone/src/control_db/tests.rs @@ -48,7 +48,7 @@ fn test_domain() -> anyhow::Result<()> { let cdb = ControlDb::at(tmp.path())?; - let addr = Address::zero(); + let addr = Address::ZERO; let res = cdb.spacetime_insert_domain(&addr, domain.clone(), *ALICE, true)?; assert!(matches!(res, InsertDomainResult::Success { .. }));