-
Notifications
You must be signed in to change notification settings - Fork 7
Types
Types in the substrate net API are grouped into base types, enum types, and struct types, currently, no other type category exists.
All types inherit in the end from IType interface. For information on how to add types for an extension, please look in the extension readme.
Adding a custom type consist of two steps.
-
- Step Add the custom type as class inheriting from IType, or using one of the following abstract classes:
- BaseType BaseType is for basic implementation of a type that represents one value, like a Hash or a U8.
- StructType StructType is for complex types composed of other Types, for example AccountInfo
- EnumType EnumType is for enums like DispatchClass.
-
- Step Register your class as a GenericTypeConverter to the client.
var WEBSOCKETURL = "wss://xyz.node.com"; // or local node ws://127.0.0.1:9944
using var client = new SubstrateClient(new Uri(WEBSOCKETURL));
client.RegisterTypeConverter(new GenericTypeConverter<MogwaiStruct>()); // custom types
client.RegisterTypeConverter(new GenericTypeConverter<MogwaiBios>()); // custom types
await client.ConnectAsync(cancellationToken);Base types inherit BaseType and have a C# primitive or class as generic type added.
public class U32 : BaseType<uint>Adding simple enum types is simply done by inheriting from EnumType, and is handled by adding the specific enum type.
public enum GameEventType
{
Default,
Hatch
}If the enum has variants that involve parameters, you can choose to implement it as a structure or inheriting the ExtEnumType.
In the tests there is an application for both, check here.
Struct types inherit the StructType class and are considered as a full implementation of each field.
public class DispatchInfo : StructTypeThis API is being developed and maintained by the BloGa Tech AG (Switzerland) and is part of Open Grants Program of the Web3 Foundation.