Combine contract type get/init (#2718)
This commit is contained in:
+5
-4
@@ -4,10 +4,10 @@
|
||||
|
||||
Changes:
|
||||
|
||||
- Expose `.tx` & `.query` on `Contract` (messages) & `.tx` on `Blueprint` (constructors)
|
||||
- Adjust api-contract to expose `Contract.{query, tx}.<message>` and `Blueprint.tx.<constructor>`
|
||||
|
||||
|
||||
## 2.2.1 Oct 13, 2020
|
||||
## 2.2.1 Oct 12, 2020
|
||||
|
||||
Upgrade priority: Low.
|
||||
|
||||
@@ -21,10 +21,11 @@ Contributed:
|
||||
Changes:
|
||||
|
||||
- Introduce `OriginCaller` type (& apply to scheduler types)
|
||||
- Adjust `ContractInfo` struct to cater for latest Substrate
|
||||
- Adjust `ContractInfo` type for latest Substrate (contracts)
|
||||
- Adjust `Schedule` type for latest Substrate (contracts)
|
||||
- Allow snake_case to be handled transparently in structs
|
||||
- Full new api-contract developer interfaces (Code, Blueprint, Contract)
|
||||
- Rework Abi & Abi Registry use & parse (on-top-of-contributed) for efficiency & non-global clobber
|
||||
- Rework Abi & Abi Registry use & parse (based on contributed) for efficiency & non-global clobber
|
||||
- Allow `null` input on `Text` values in addition to existing `undefined`
|
||||
- Remove all documentation after move to https://github.com/polkadot-js/docs repo
|
||||
- Adjust type encoding from TypeDef, s/encodeType/encodeTypeDef/
|
||||
|
||||
@@ -50,7 +50,7 @@ export default class Abi extends ContractRegistry {
|
||||
isMutating: spec.mutates.isTrue,
|
||||
isPayable: spec.payable.isTrue,
|
||||
returnType: typeSpec
|
||||
? this.typeDefAt(typeSpec.type, { displayName: typeSpec.displayName.map((s) => s.toString()).join('::') || undefined })
|
||||
? this.typeDefAt(typeSpec.type)
|
||||
: null
|
||||
});
|
||||
});
|
||||
|
||||
@@ -29,39 +29,36 @@ export default class ContractRegistry {
|
||||
this.project = this.registry.createType('InkProject', json);
|
||||
|
||||
// Generate TypeDefs for each provided registry type
|
||||
this.project.types.forEach((_, index) => this.setTypeDef(this.registry.createType('MtLookupTypeId', index + 1)));
|
||||
this.project.types.forEach((_, index) => this.typeDefAt(this.registry.createType('MtLookupTypeId', index + 1)));
|
||||
}
|
||||
|
||||
public getAbiType (id: MtLookupTypeId): MtType {
|
||||
const offset = getRegistryOffset(id);
|
||||
const type = this.project.types[offset];
|
||||
const type = this.project.types[getRegistryOffset(id)];
|
||||
|
||||
assert(!isUndefined(type), `getAbiType:: Unable to find ${id.toNumber()} in type values`);
|
||||
|
||||
return this.registry.createType('MtType', type);
|
||||
}
|
||||
|
||||
public typeDefAt (id: MtLookupTypeId, extra: Pick<TypeDef, never> = {}): TypeDef {
|
||||
if (!this.typeDefs[getRegistryOffset(id)]) {
|
||||
this.setTypeDef(id);
|
||||
public typeDefAt (id: MtLookupTypeId): TypeDef {
|
||||
const offset = getRegistryOffset(id);
|
||||
let typeDef = this.typeDefs[offset];
|
||||
|
||||
if (!typeDef) {
|
||||
typeDef = this.extractType(this.getAbiType(id), id) as TypeDef;
|
||||
|
||||
this.typeDefs[offset] = typeDef;
|
||||
|
||||
// Here we protect against the following cases
|
||||
// - No displayName present, these are generally known primitives
|
||||
// - displayName === type, these generate circular references
|
||||
// - displayName Option & type Option<...something...>
|
||||
if (typeDef.displayName && !(typeDef.type === typeDef.displayName || typeDef.type.startsWith(`${typeDef.displayName}<`))) {
|
||||
this.registry.register({ [typeDef.displayName]: typeDef.type });
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
...this.typeDefs[getRegistryOffset(id)],
|
||||
...extra
|
||||
};
|
||||
}
|
||||
|
||||
public setTypeDef (id: MtLookupTypeId): void {
|
||||
const typeDef = this.extractType(this.getAbiType(id), id) as TypeDef;
|
||||
|
||||
this.typeDefs[getRegistryOffset(id)] = typeDef;
|
||||
|
||||
// We have a displayName for non-primitives and non-results
|
||||
// FIXME here we protect against "Option: 'Option<...something...>' definitions (same with result)
|
||||
if (typeDef.displayName && typeDef.info !== TypeDefInfo.Plain && !typeDef.type.startsWith(typeDef.displayName)) {
|
||||
this.registry.register({ [typeDef.displayName]: typeDef.type });
|
||||
}
|
||||
return typeDef;
|
||||
}
|
||||
|
||||
private extractType (inkType: MtType, id: MtLookupTypeId): Pick<TypeDef, never> {
|
||||
|
||||
Reference in New Issue
Block a user