-
Notifications
You must be signed in to change notification settings - Fork 706
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mud Namespace, Systems, Tables structure, base classes, extensions in…
…cluding registration, batching, resources and reorganisation common into world, store
- Loading branch information
1 parent
0c7836a
commit 8c493f4
Showing
127 changed files
with
2,629 additions
and
1,166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/Nethereum.Mud.Contracts/Core/Namespaces/NamespaceBase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using Nethereum.Mud.Contracts.Core.Systems; | ||
using Nethereum.Mud.Contracts.Core.Tables; | ||
|
||
namespace Nethereum.Mud.Contracts.Core.Namespaces | ||
{ | ||
public class NamespaceBase<TNamespaceResource, TSystemServices, TTableServices> where TNamespaceResource : NamespaceResource | ||
where TSystemServices : SystemsServices | ||
where TTableServices : TablesServices | ||
{ | ||
public NamespaceBase(TNamespaceResource namespaceResource) | ||
{ | ||
NamespaceResource = namespaceResource; | ||
} | ||
|
||
public TNamespaceResource NamespaceResource { get; protected set; } | ||
|
||
public TSystemServices Systems { get; protected set; } | ||
public TTableServices Tables { get; protected set; } | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/Nethereum.Mud.Contracts/Core/Namespaces/UserNamespace.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using Nethereum.Web3; | ||
using Nethereum.Mud.Contracts.Core.Systems; | ||
using Nethereum.Mud.Contracts.World; | ||
using Nethereum.Mud.Contracts.Store; | ||
using Nethereum.Mud.Contracts.Core.Tables; | ||
|
||
namespace Nethereum.Mud.Contracts.Core.Namespaces | ||
{ | ||
public class UserNamespace<TNamespaceResource, TSystemServices, TTableServices> : NamespaceBase<TNamespaceResource, TSystemServices, TTableServices> | ||
where TNamespaceResource : NamespaceResource, new() | ||
where TSystemServices : SystemsServices | ||
where TTableServices : TablesServices | ||
{ | ||
public WorldNamespace World { get; protected set; } | ||
public StoreNamespace Store { get; protected set; } | ||
public UserNamespace(IWeb3 web3, string contractAddress) : base(new TNamespaceResource()) | ||
{ | ||
World = new WorldNamespace(web3, contractAddress); | ||
Store = new StoreNamespace(web3, contractAddress); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 40 additions & 36 deletions
76
...Events/StoreEventsLogProcessingService.cs → ...Events/StoreEventsLogProcessingService.cs
Large diffs are not rendered by default.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
src/Nethereum.Mud.Contracts/Core/Systems/EmptySystemsServices.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using Nethereum.Web3; | ||
using System.Collections.Generic; | ||
|
||
namespace Nethereum.Mud.Contracts.Core.Systems | ||
{ | ||
public class EmptySystemsServices : SystemsServices | ||
{ | ||
public EmptySystemsServices(IWeb3 web3, string contractAddress) : base(web3, contractAddress) | ||
{ | ||
SystemServices = new List<ISystemService>(); | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/Nethereum.Mud.Contracts/Core/Systems/ISystemService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using Nethereum.ABI.Model; | ||
using Nethereum.Contracts; | ||
using System.Collections.Generic; | ||
|
||
namespace Nethereum.Mud.Contracts.Core.Systems | ||
{ | ||
public interface ISystemService<TSystemResource>: ISystemService where TSystemResource : SystemResource | ||
{ | ||
|
||
} | ||
|
||
|
||
public interface ISystemService | ||
{ | ||
public List<FunctionABI> GetSystemFunctionABIs(); | ||
public IResource Resource { get; } | ||
|
||
public ISystemServiceResourceRegistration SystemServiceResourceRegistrator { get; } | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/Nethereum.Mud.Contracts/Core/Systems/ISystemServiceResourceRegistration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using Nethereum.Mud.Contracts.World.Systems.BatchCallSystem.ContractDefinition; | ||
using Nethereum.Mud.Contracts.World.Systems.RegistrationSystem.ContractDefinition; | ||
using Nethereum.Mud.Contracts.World.Tables; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
|
||
namespace Nethereum.Mud.Contracts.Core.Systems | ||
{ | ||
public interface ISystemServiceResourceRegistration | ||
{ | ||
Task<string> BatchRegisterRootFunctionSelectorsRequestAsync(List<FunctionSelectorsTableRecord> excludedFunctionSelectorRecords = null, bool excludeDefaultSystemFunctions = true); | ||
Task<string> BatchRegisterSystemAndRootFunctionSelectorsRequestAsync(string deployedAddress, bool publicAccess = true, List<FunctionSelectorsTableRecord> excludedFunctionSelectorRecords = null, bool excludeDefaultSystemFunctions = true); | ||
List<RegisterRootFunctionSelectorFunction> CreateRegisterRootFunctionSelectors(List<FunctionSelectorsTableRecord> excludedFunctionSelectorRecords = null, bool excludeDefaultSystemFunctions = true); | ||
List<SystemCallData> CreateRegisterRootFunctionSelectorsBatchSystemCallData(List<FunctionSelectorsTableRecord> excludedFunctionSelectorRecords = null, bool excludeDefaultSystemFunctions = true); | ||
List<SystemCallData> CreateRegisterSystemAndRegisterRootFunctionSelectorsBatchSystemCallData(string deployedAddress, bool publicAccess, List<FunctionSelectorsTableRecord> excludedFunctionSelectorRecords, bool excludeDefaultSystemFunctions); | ||
RegisterSystemFunction GetRegisterSystemFunction(string deployedAddress, bool publicAccess = true); | ||
Task<string> RegisterSystemAsync(string deployedAddress, bool publicAccess = true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
src/Nethereum.Mud.Contracts/Core/Systems/SystemRegistrationBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
using Nethereum.ABI.Model; | ||
using Nethereum.Contracts; | ||
using Nethereum.Hex.HexConvertors.Extensions; | ||
using Nethereum.Mud.Contracts.World.Systems.BatchCallSystem; | ||
using Nethereum.Mud.Contracts.World.Systems.BatchCallSystem.ContractDefinition; | ||
using Nethereum.Mud.Contracts.World.Systems.RegistrationSystem; | ||
using Nethereum.Mud.Contracts.World.Systems.RegistrationSystem.ContractDefinition; | ||
using Nethereum.Mud.Contracts.World.Tables; | ||
using Nethereum.Web3; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace Nethereum.Mud.Contracts.Core.Systems | ||
{ | ||
public class SystemRegistrationBuilder | ||
{ | ||
public List<RegisterRootFunctionSelectorFunction> CreateRegisterRootFunctionSelectors<TSystemResource>(ContractServiceBase systemService, List<FunctionSelectorsTableRecord> excludedFunctionSelectorRecords = null, bool excludeDefaultSystemFunctions = true) | ||
where TSystemResource : SystemResource, new() | ||
{ | ||
return CreateRegisterFunctionSelectors<TSystemResource>(systemService.GetAllFunctionABIs(), excludedFunctionSelectorRecords, excludeDefaultSystemFunctions); | ||
} | ||
|
||
public List<RegisterRootFunctionSelectorFunction> CreateRegisterRootFunctionSelectors<TSystemResource>(ISystemService<TSystemResource> systemService, List<FunctionSelectorsTableRecord> excludedFunctionSelectorRecords = null, bool excludeDefaultSystemFunctions = true) | ||
where TSystemResource : SystemResource, new() | ||
{ | ||
return CreateRegisterRootFunctionSelectors(systemService.GetSystemFunctionABIs(), systemService.GetResource().ResourceIdEncoded, excludedFunctionSelectorRecords, excludeDefaultSystemFunctions); | ||
} | ||
|
||
|
||
public List<RegisterRootFunctionSelectorFunction> CreateRegisterFunctionSelectors(List<FunctionABI> functionABIs, Type systemResourceType, List<FunctionSelectorsTableRecord> excludedFunctionSelectorRecords = null, bool excludeDefaultSystemFunctions = true) | ||
{ | ||
return CreateRegisterRootFunctionSelectors(functionABIs, ResourceRegistry.GetResourceEncoded(systemResourceType), excludedFunctionSelectorRecords, excludeDefaultSystemFunctions); | ||
} | ||
|
||
public List<RegisterRootFunctionSelectorFunction> CreateRegisterRootFunctionSelectors(List<FunctionABI> functionABIs, byte[] systemResourceId, List<FunctionSelectorsTableRecord> excludedFunctionSelectorRecords = null, bool excludeDefaultSystemFunctions = true) | ||
{ | ||
if (excludedFunctionSelectorRecords == null) | ||
{ | ||
excludedFunctionSelectorRecords = new List<FunctionSelectorsTableRecord>(); | ||
} | ||
var excludedRegisteredSelectors = excludedFunctionSelectorRecords.Select(x => x.Values.SystemFunctionSelector.ToString()).ToList(); | ||
if (excludeDefaultSystemFunctions) | ||
{ | ||
excludedRegisteredSelectors.AddRange(new SystemDefaultFunctions().GetAllFunctionSignatures().ToList()); | ||
} | ||
excludedRegisteredSelectors.AddRange(new SystemDefaultFunctions().GetAllFunctionSignatures().ToList()); | ||
var functionAbis = functionABIs; | ||
var functionSelectorsToRegister = functionAbis.Where(x => !excludedRegisteredSelectors.Any(y => y.IsTheSameHex(x.Sha3Signature))).ToList(); | ||
|
||
var registerFunctionSelectors = new List<RegisterRootFunctionSelectorFunction>(); | ||
foreach (var functionSelectorToRegister in functionSelectorsToRegister) | ||
{ | ||
var registerFunction = new RegisterRootFunctionSelectorFunction(); | ||
registerFunction.SystemFunctionSignature = functionSelectorToRegister.Signature; | ||
registerFunction.WorldFunctionSignature = functionSelectorToRegister.Signature; | ||
registerFunction.SystemId = systemResourceId; | ||
} | ||
return registerFunctionSelectors; | ||
} | ||
|
||
public List<RegisterRootFunctionSelectorFunction> CreateRegisterFunctionSelectors<TSystemResource>(List<FunctionABI> functionABIs, List<FunctionSelectorsTableRecord> excludedFunctionSelectorRecords = null, bool excludeDefaultSystemFunctions = true) | ||
where TSystemResource : SystemResource, new() | ||
{ | ||
|
||
return CreateRegisterFunctionSelectors(functionABIs, typeof(TSystemResource), excludedFunctionSelectorRecords, excludeDefaultSystemFunctions); | ||
} | ||
|
||
public RegisterSystemFunction CreateRegisterSystemFunction<TSystemResource, TService>(SystemServiceResourceRegistration<TSystemResource, TService> systemServiceResourceRegistration, string deployedAddress = null, bool publicAccess = true) | ||
where TSystemResource : SystemResource, new() | ||
where TService : ContractWeb3ServiceBase, ISystemService<TSystemResource> | ||
{ | ||
var registerSystemFunction = new RegisterSystemFunction(); | ||
registerSystemFunction.SystemId = systemServiceResourceRegistration.Resource.ResourceIdEncoded; | ||
registerSystemFunction.System = deployedAddress; | ||
registerSystemFunction.PublicAccess = true; | ||
return registerSystemFunction; | ||
} | ||
|
||
public List<SystemCallData> CreateRegisterRootFunctionSelectorsBatchSystemCallData<TSystemResource>(ISystemService<TSystemResource> systemService, | ||
List<FunctionSelectorsTableRecord> excludedFunctionSelectorRecords = null, | ||
bool excludeDefaultSystemFunctions = true) | ||
where TSystemResource : SystemResource, new() | ||
{ | ||
|
||
var registerFunctionSelectors = CreateRegisterRootFunctionSelectors(systemService, excludedFunctionSelectorRecords, excludeDefaultSystemFunctions); | ||
return registerFunctionSelectors.CreateBatchSystemCallData<RegistrationSystemResource, RegisterRootFunctionSelectorFunction>(); | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/Nethereum.Mud.Contracts/Core/Systems/SystemResourceExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using Nethereum.Web3; | ||
|
||
namespace Nethereum.Mud.Contracts.Core.Systems | ||
{ | ||
public static class SystemResourceExtensions | ||
{ | ||
public static TSystemResource GetResource<TSystemResource>(this ISystemService<TSystemResource> service) where TSystemResource : SystemResource, new() | ||
{ | ||
return ResourceRegistry.GetResource<TSystemResource>(); | ||
} | ||
|
||
public static SystemServiceResourceRegistration<TSystemResource, TService> GetSystemServiceResourceRegistration<TSystemResource, TService>(this TService service) where TSystemResource : SystemResource, new() where TService : ContractWeb3ServiceBase, ISystemService<TSystemResource> | ||
{ | ||
return new SystemServiceResourceRegistration<TSystemResource, TService>(service); | ||
} | ||
} | ||
} |
108 changes: 108 additions & 0 deletions
108
src/Nethereum.Mud.Contracts/Core/Systems/SystemServiceResourceRegistration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Nethereum.Web3; | ||
using Nethereum.Mud.Contracts.World.Systems.BatchCallSystem; | ||
using Nethereum.Mud.Contracts.World.Systems.BatchCallSystem.ContractDefinition; | ||
using Nethereum.Mud.Contracts.World.Systems.RegistrationSystem.ContractDefinition; | ||
using Nethereum.Mud.Contracts.World.Systems.RegistrationSystem; | ||
using Nethereum.Mud.Contracts.World.Tables; | ||
|
||
namespace Nethereum.Mud.Contracts.Core.Systems | ||
{ | ||
public class SystemServiceResourceRegistration<TSystemResource, TService> : ISystemServiceResourceRegistration where TSystemResource : SystemResource, new() | ||
where TService : ContractWeb3ServiceBase, ISystemService<TSystemResource> | ||
{ | ||
public TService Service { get; set; } | ||
public string WorldAddress { get; } | ||
|
||
protected SystemRegistrationBuilder systemRegistrationBuilder; | ||
|
||
protected RegistrationSystemService RegistrationSystemService { get; set; } | ||
protected BatchCallSystemService BatchCallSystemService { get; set; } | ||
|
||
public SystemServiceResourceRegistration(TService service, string worldAddress) | ||
{ | ||
Service = service; | ||
WorldAddress = worldAddress; | ||
InitialiseServices(); | ||
systemRegistrationBuilder = new SystemRegistrationBuilder(); | ||
} | ||
|
||
private void InitialiseServices() | ||
{ | ||
RegistrationSystemService = new RegistrationSystemService(Service.Web3, WorldAddress); | ||
BatchCallSystemService = new BatchCallSystemService(Service.Web3, WorldAddress); | ||
} | ||
|
||
public SystemServiceResourceRegistration(TService service, string worldAddress, SystemRegistrationBuilder systemRegistrationBuilder) | ||
{ | ||
Service = service; | ||
WorldAddress = worldAddress; | ||
InitialiseServices(); | ||
this.systemRegistrationBuilder = systemRegistrationBuilder; | ||
} | ||
|
||
public SystemServiceResourceRegistration(TService service) | ||
{ | ||
Service = service; | ||
WorldAddress = service.ContractAddress; | ||
InitialiseServices(); | ||
systemRegistrationBuilder = new SystemRegistrationBuilder(); | ||
} | ||
|
||
|
||
|
||
protected TSystemResource systemResource; | ||
|
||
public TSystemResource Resource | ||
{ | ||
get { if (systemResource == null) systemResource = new TSystemResource(); return systemResource; } | ||
set { systemResource = value; } | ||
} | ||
|
||
public List<RegisterRootFunctionSelectorFunction> CreateRegisterRootFunctionSelectors(List<FunctionSelectorsTableRecord> excludedFunctionSelectorRecords = null, bool excludeDefaultSystemFunctions = true) | ||
{ | ||
return systemRegistrationBuilder.CreateRegisterRootFunctionSelectors(Service, excludedFunctionSelectorRecords, excludeDefaultSystemFunctions); | ||
} | ||
|
||
public List<SystemCallData> CreateRegisterRootFunctionSelectorsBatchSystemCallData(List<FunctionSelectorsTableRecord> excludedFunctionSelectorRecords = null, bool excludeDefaultSystemFunctions = true) | ||
{ | ||
return systemRegistrationBuilder.CreateRegisterRootFunctionSelectorsBatchSystemCallData(Service, excludedFunctionSelectorRecords, excludeDefaultSystemFunctions); | ||
} | ||
|
||
public RegisterSystemFunction GetRegisterSystemFunction(string deployedAddress, bool publicAccess = true) | ||
{ | ||
return systemRegistrationBuilder.CreateRegisterSystemFunction(this, deployedAddress, publicAccess); | ||
} | ||
|
||
|
||
public Task<string> RegisterSystemAsync(string deployedAddress, bool publicAccess = true) | ||
{ | ||
var registerFunction = GetRegisterSystemFunction(deployedAddress, publicAccess); | ||
return RegistrationSystemService.RegisterSystemRequestAsync(registerFunction); | ||
} | ||
|
||
public Task<string> BatchRegisterRootFunctionSelectorsRequestAsync(List<FunctionSelectorsTableRecord> excludedFunctionSelectorRecords = null, bool excludeDefaultSystemFunctions = true) | ||
{ | ||
var callData = CreateRegisterRootFunctionSelectorsBatchSystemCallData(excludedFunctionSelectorRecords, excludeDefaultSystemFunctions); | ||
return BatchCallSystemService.BatchCallRequestAsync(callData); | ||
} | ||
|
||
public Task<string> BatchRegisterSystemAndRootFunctionSelectorsRequestAsync(string deployedAddress, bool publicAccess = true, List<FunctionSelectorsTableRecord> excludedFunctionSelectorRecords = null, bool excludeDefaultSystemFunctions = true) | ||
{ | ||
List<SystemCallData> registerFunctionBatchCallData = CreateRegisterSystemAndRegisterRootFunctionSelectorsBatchSystemCallData(deployedAddress, publicAccess, excludedFunctionSelectorRecords, excludeDefaultSystemFunctions); | ||
return BatchCallSystemService.BatchCallRequestAsync(registerFunctionBatchCallData); | ||
} | ||
|
||
public List<SystemCallData> CreateRegisterSystemAndRegisterRootFunctionSelectorsBatchSystemCallData(string deployedAddress, bool publicAccess, List<FunctionSelectorsTableRecord> excludedFunctionSelectorRecords, bool excludeDefaultSystemFunctions) | ||
{ | ||
var registerFunction = GetRegisterSystemFunction(deployedAddress, publicAccess); | ||
var registerFunctionBatchCallData = new List<SystemCallData> { registerFunction.CreateBatchSystemCallDataForFunction<RegistrationSystemResource, RegisterSystemFunction>() }; | ||
var registerFunctionSelectors = CreateRegisterRootFunctionSelectorsBatchSystemCallData(excludedFunctionSelectorRecords, excludeDefaultSystemFunctions); | ||
registerFunctionBatchCallData.AddRange(registerFunctionSelectors); | ||
return registerFunctionBatchCallData; | ||
} | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.