-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Annotations for pallets and their storages #13
Conversation
0967419
to
eb7bb80
Compare
748dd45
to
59105ba
Compare
val ctor = implClazz.getConstructor(Rpc.class); | ||
|
||
return interfaceClass.cast(ctor.newInstance(rpc)); | ||
} catch (ClassCastException | ClassNotFoundException | NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ClassCastException
is already a RuntimeException
also all the rest exceptions are subtypes of ReflectiveOperationException
, so can be reduced to
catch (ReflectiveOperationException e)
if you want
|
||
@Override | ||
public <T> T pallet(@NonNull Class<T> clazz) { | ||
return palletResolver.resolve(clazz); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pallet can be memoized to not instantiate it each time
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface Pallet { | ||
@NonNull | ||
String name(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't it better to call this field value
instead of name
so that an enduser can write @Pallet("System")
instead of @Pallet(name = "System")
.build(); | ||
} | ||
|
||
private MethodSpec privateMethod(String palletName, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this name is a bit misleading. I expected it to generate some internal method that it triggered by the public method defined later. But it turned out to be a some sort of initializer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed to backFieldInitializer
.addAnnotation(suppressWarnings("unchecked", "rawtypes")) | ||
.returns(TypeName.get(returnType)); | ||
|
||
declareReaderAndWriterRegistries(methodSpecBuilder); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cannot it be moved upper to a class level? registries are threadsafe and needed by multiple implementations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's not necessary because there are just variables which refer to singletons.
871ff7b
to
d2811c1
Compare
996ae0b
to
280c558
Compare
280c558
to
7243809
Compare
|
||
/** | ||
* Indicates the pallet which represents a proxy to the blockchain's pallet. | ||
* For interfaces annotated with it processor will generate proper implementations. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The processor will generate proper implementations for the interfaces annotated with this method.
public <T> T resolve(Class<T> interfaceClass) { | ||
if (interfaceClass.getDeclaredAnnotationsByType(Pallet.class).length == 0) { | ||
throw new IllegalArgumentException( | ||
String.format("`%s` can't be constructed because isn't annotated with `@%s`.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
String.format("%s
can't be constructed because it is not annotated with @%s
.",
|
||
assertThat(compilation).failed(); | ||
assertThat(compilation) | ||
.hadErrorContaining("Must be set `type` or `generic` of `@StorageKey`"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.hadErrorContaining("Please set either type
or generic
parameter of @StorageKey
");
|
||
/** | ||
* Provides the ability to query a node and interact with the Polkadot or Substrate chains. | ||
* It allows interacting with blockchain in different ways: using RPC's queries directly or |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It allows interacting with blockchain in two different ways: using RPC's queries directly or
OR
It allows interacting with blockchain in various ways: using RPC's queries directly or
/** | ||
* Provides the ability to query a node and interact with the Polkadot or Substrate chains. | ||
* It allows interacting with blockchain in different ways: using RPC's queries directly or | ||
* accessing Pallets and its APIs such storages, transactions, etc. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
accessing Pallets and its APIs, such as storages, transactions, etc.
} | ||
|
||
/** | ||
* @return the instance that provides proper API for querying RPC's methods. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@return the instance that provides a proper API for querying the RPC's methods.
Rpc rpc(); | ||
|
||
/** | ||
* Resolves the instance of pallet by its definition. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolves the instance of a pallet by its definition.
OR
Resolves a pallet instance by its definition.
|
||
assertThat(compilation).failed(); | ||
assertThat(compilation) | ||
.hadErrorContaining("Must be set only one of both parameters of `@StorageKey`: `type` or `generic`."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.hadErrorContaining("Please set only one parameter of @StorageKey
: type
or generic
.");
throw new ProcessingException( | ||
palletElement, | ||
"`@%s` of `%s.%s` isn't adjusted correctly. " + | ||
"Must be set `type` or `generic` of `@StorageKey`.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Please set either type
or generic
parameter of @StorageKey
.",
palletElement, | ||
"`@%s` of `%s.%s` isn't adjusted correctly. " + | ||
"Ambiguous scale type of key. " + | ||
"Must be set only one of both parameters of `@StorageKey`: `type` or `generic`.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Please set only one parameter of @StorageKey
: type
or generic
.",
Added annotations `Pallet` and `Storage` and related entities: `StorageKey`, `StorageHasher`. Added `PalletInterfaceProccessor` which generates proxies for pallets to the blockchain by their annotations. Added corresponding and auxiliary classes.
7243809
to
8b5fe92
Compare
Added annotations
Pallet
andStorage
and related entities:StorageKey
,StorageHasher
.Added
PalletInterfaceProccessor
which generates proxies for pallets to the blockchain by their annotations.Added corresponding and auxiliary classes.