-
Notifications
You must be signed in to change notification settings - Fork 2.7k
contracts: Expose environment types for offchain tooling #14750
Conversation
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.
You could use a wrapper type e.g.:
#[derive(TypeInfo)]
struct EnvironmentType<T>(PhantomData<T>)
pub struct Environment<T: Config> {
account_id: EnvironmentType<AccountIdOf<T>>,|
Hmm yes that could work. This whole solution seems a bit hacky. Even without the wrapper type. But I guess our only way to get this in without introducing a whole new way of just expressing types into the metadata. |
|
Implemented your idea. Seems to be working. This is the output. I think we can work with that: {
"id": 576,
"type": {
"path": [
"pallet_contracts",
"Environment"
],
"params": [
{
"name": "T",
"type": null
}
],
"def": {
"composite": {
"fields": [
{
"name": "account_id",
"type": 577,
"typeName": "EnvironmentType<AccountIdOf<T>>"
},
{
"name": "balance",
"type": 578,
"typeName": "EnvironmentType<BalanceOf<T>>"
},
{
"name": "hash",
"type": 579,
"typeName": "EnvironmentType<<T as frame_system::Config>::Hash>"
},
{
"name": "hasher",
"type": 580,
"typeName": "EnvironmentType<<T as frame_system::Config>::Hashing>"
},
{
"name": "timestamp",
"type": 582,
"typeName": "EnvironmentType<MomentOf<T>>"
},
{
"name": "block_number",
"type": 583,
"typeName": "EnvironmentType<BlockNumberFor<T>>"
}
]
}
}
}
},
{
"id": 577,
"type": {
"path": [
"pallet_contracts",
"EnvironmentType"
],
"params": [
{
"name": "T",
"type": 0
}
],
"def": {
"composite": {}
}
}
},
{
"id": 578,
"type": {
"path": [
"pallet_contracts",
"EnvironmentType"
],
"params": [
{
"name": "T",
"type": 6
}
],
"def": {
"composite": {}
}
}
},
{
"id": 579,
"type": {
"path": [
"pallet_contracts",
"EnvironmentType"
],
"params": [
{
"name": "T",
"type": 12
}
],
"def": {
"composite": {}
}
}
},
{
"id": 580,
"type": {
"path": [
"pallet_contracts",
"EnvironmentType"
],
"params": [
{
"name": "T",
"type": 581
}
],
"def": {
"composite": {}
}
}
}, |
A little bit hacky, perhaps. But a very neat way of getting the information we need into the metadata without adding any additional configuration schema. Of course the downstream tooling will need to do some explicit name lookups to pull out the types, but I think it might be worth it to keep things simple on the node side. |
SkymanOne
left a comment
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.
Yes, we can definitely work with this
|
bot rebase |
|
Rebased |
|
Please also approve the companion. |
|
bot rebase |
|
Rebased |
|
bot merge |
In order to implement use-ink/cargo-contract#1167 we need to expose all types passed between
pallet-contractsand the deployed contracts. The idea is to bundle all relevant types in anEnvironmentstruct mirroring the ink!Environmenttype. In order to expose it we add it to the config trait asGet<Environment>. The types are obviously only mentioned asPhantomDatabecause we don't ever want to construct them. I did just this in this PR.I think this would be an elegant solution if it wouldn't be for paritytech/scale-info#111. @ascjones Can we maybe add an attribute to
scale-infothat allows to opt-in toPhantomDatatypes?cc @SkymanOne
cumulus companion: paritytech/cumulus#3036