Skip to content

Commit

Permalink
Fix variant interface and update mock contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
apporc committed Dec 19, 2023
1 parent 66f45af commit 298d024
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 140 deletions.
30 changes: 14 additions & 16 deletions src/commands/contract/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,30 +46,28 @@ export function generateActionInterface(
types = abiVariant.types

const variantTypeNodes = types.map((type) =>
ts.factory.createTypeReferenceNode(parseType(findExternalType(type, 'Types.', abi)))
ts.factory.createTypeReferenceNode(parseType(findExternalType(type, 'Base.', abi)))
)

const variantInterface = ts.factory.createInterfaceDeclaration(
[ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
removeCommas(abiVariant.name),
const allTypeNodes = [
...variantTypeNodes,
ts.factory.createTypeReferenceNode(`Types.${abiVariant.name}`),
]

const variantTypeAlias = ts.factory.createTypeAliasDeclaration(
undefined,
[ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
abiVariant.name,
undefined,
[
ts.factory.createPropertySignature(
undefined,
'value',
undefined,
ts.factory.createUnionTypeNode(variantTypeNodes)
),
]
ts.factory.createUnionTypeNode(allTypeNodes)
)

typeInterfaces.push(variantInterface)
typeInterfaces.push(variantTypeAlias)
} else {
types = [field.type]
}

const variantName = variantType && `Types.${variantType}`
const variantName = variantType && `Base.${variantType}`

types.forEach((type) => {
const typeStruct = findAbiStruct(type, abi)
Expand All @@ -82,7 +80,7 @@ export function generateActionInterface(
})

const typeReferenceNode = ts.factory.createTypeReferenceNode(
variantName || findParamTypeString(aliasType || field.type, 'Types.', abi)
variantName || findParamTypeString(aliasType || field.type, 'Base.', abi)
)

return ts.factory.createPropertySignature(
Expand Down Expand Up @@ -125,7 +123,7 @@ export function generateActionsNamespace(abi: ABI.Def): ts.ModuleDeclaration {

const actionParamsTypes = ts.factory.createModuleDeclaration(
[ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
ts.factory.createIdentifier('Types'),
ts.factory.createIdentifier('Base'),
ts.factory.createModuleBlock(removeDuplicateInterfaces(typeInterfaces)),
ts.NodeFlags.Namespace
)
Expand Down
44 changes: 22 additions & 22 deletions test/data/contracts/mock-atomicassets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,17 @@ export interface ActionNameParams {
withdraw: ActionParams.withdraw
}
export namespace ActionParams {
export namespace Types {
export namespace Base {
export interface FORMAT {
name: string
type: string
}
export interface pair_string_ATOMIC_ATTRIBUTE {
key: string
value: Types.variant_int8_int16_int32_int64_uint8_uint16_uint32_uint64_float32_float64_string_INT8_VEC_INT16_VEC_INT32_VEC_INT64_VEC_UINT8_VEC_UINT16_VEC_UINT32_VEC_UINT64_VEC_FLOAT_VEC_DOUBLE_VEC_STRING_VEC
value: Base.variant_int8_int16_int32_int64_uint8_uint16_uint32_uint64_float32_float64_string_INT8_VEC_INT16_VEC_INT32_VEC_INT64_VEC_UINT8_VEC_UINT16_VEC_UINT32_VEC_UINT64_VEC_FLOAT_VEC_DOUBLE_VEC_STRING_VEC
}
export interface variant_int8_int16_int32_int64_uint8_uint16_uint32_uint64_float32_float64_string_INT8_VEC_INT16_VEC_INT32_VEC_INT64_VEC_UINT8_VEC_UINT16_VEC_UINT32_VEC_UINT64_VEC_FLOAT_VEC_DOUBLE_VEC_STRING_VEC {
value:
export type variant_int8_int16_int32_int64_uint8_uint16_uint32_uint64_float32_float64_string_INT8_VEC_INT16_VEC_INT32_VEC_INT64_VEC_UINT8_VEC_UINT16_VEC_UINT32_VEC_UINT64_VEC_FLOAT_VEC_DOUBLE_VEC_STRING_VEC =

| Int8Type
| Int16Type
| Int32Type
Expand All @@ -129,7 +129,7 @@ export namespace ActionParams {
| Float32Type[]
| Float64Type[]
| string[]
}
| Types.variant_int8_int16_int32_int64_uint8_uint16_uint32_uint64_float32_float64_string_INT8_VEC_INT16_VEC_INT32_VEC_INT64_VEC_UINT8_VEC_UINT16_VEC_UINT32_VEC_UINT64_VEC_FLOAT_VEC_DOUBLE_VEC_STRING_VEC
}
export interface acceptoffer {
offer_id: UInt64Type
Expand All @@ -147,7 +147,7 @@ export namespace ActionParams {
account_to_add: NameType
}
export interface admincoledit {
collection_format_extension: Types.FORMAT[]
collection_format_extension: Base.FORMAT[]
}
export interface announcedepo {
owner: NameType
Expand All @@ -173,7 +173,7 @@ export namespace ActionParams {
authorized_accounts: NameType[]
notify_accounts: NameType[]
market_fee: Float64Type
data: Types.pair_string_ATOMIC_ATTRIBUTE[]
data: Base.pair_string_ATOMIC_ATTRIBUTE[]
}
export interface createoffer {
sender: NameType
Expand All @@ -186,7 +186,7 @@ export namespace ActionParams {
authorized_creator: NameType
collection_name: NameType
schema_name: NameType
schema_format: Types.FORMAT[]
schema_format: Base.FORMAT[]
}
export interface createtempl {
authorized_creator: NameType
Expand All @@ -195,7 +195,7 @@ export namespace ActionParams {
transferable: boolean
burnable: boolean
max_supply: UInt32Type
immutable_data: Types.pair_string_ATOMIC_ATTRIBUTE[]
immutable_data: Base.pair_string_ATOMIC_ATTRIBUTE[]
}
export interface declineoffer {
offer_id: UInt64Type
Expand All @@ -204,7 +204,7 @@ export namespace ActionParams {
authorized_editor: NameType
collection_name: NameType
schema_name: NameType
schema_format_extension: Types.FORMAT[]
schema_format_extension: Base.FORMAT[]
}
export interface forbidnotify {
collection_name: NameType
Expand All @@ -227,8 +227,8 @@ export namespace ActionParams {
schema_name: NameType
template_id: Int32Type
backed_tokens: AssetType[]
old_immutable_data: Types.pair_string_ATOMIC_ATTRIBUTE[]
old_mutable_data: Types.pair_string_ATOMIC_ATTRIBUTE[]
old_immutable_data: Base.pair_string_ATOMIC_ATTRIBUTE[]
old_mutable_data: Base.pair_string_ATOMIC_ATTRIBUTE[]
asset_ram_payer: NameType
}
export interface logmint {
Expand All @@ -238,10 +238,10 @@ export namespace ActionParams {
schema_name: NameType
template_id: Int32Type
new_asset_owner: NameType
immutable_data: Types.pair_string_ATOMIC_ATTRIBUTE[]
mutable_data: Types.pair_string_ATOMIC_ATTRIBUTE[]
immutable_data: Base.pair_string_ATOMIC_ATTRIBUTE[]
mutable_data: Base.pair_string_ATOMIC_ATTRIBUTE[]
backed_tokens: AssetType[]
immutable_template_data: Types.pair_string_ATOMIC_ATTRIBUTE[]
immutable_template_data: Base.pair_string_ATOMIC_ATTRIBUTE[]
}
export interface lognewoffer {
offer_id: UInt64Type
Expand All @@ -259,13 +259,13 @@ export namespace ActionParams {
transferable: boolean
burnable: boolean
max_supply: UInt32Type
immutable_data: Types.pair_string_ATOMIC_ATTRIBUTE[]
immutable_data: Base.pair_string_ATOMIC_ATTRIBUTE[]
}
export interface logsetdata {
asset_owner: NameType
asset_id: UInt64Type
old_data: Types.pair_string_ATOMIC_ATTRIBUTE[]
new_data: Types.pair_string_ATOMIC_ATTRIBUTE[]
old_data: Base.pair_string_ATOMIC_ATTRIBUTE[]
new_data: Base.pair_string_ATOMIC_ATTRIBUTE[]
}
export interface logtransfer {
collection_name: NameType
Expand All @@ -280,8 +280,8 @@ export namespace ActionParams {
schema_name: NameType
template_id: Int32Type
new_asset_owner: NameType
immutable_data: Types.pair_string_ATOMIC_ATTRIBUTE[]
mutable_data: Types.pair_string_ATOMIC_ATTRIBUTE[]
immutable_data: Base.pair_string_ATOMIC_ATTRIBUTE[]
mutable_data: Base.pair_string_ATOMIC_ATTRIBUTE[]
tokens_to_back: AssetType[]
}
export interface payofferram {
Expand All @@ -300,11 +300,11 @@ export namespace ActionParams {
authorized_editor: NameType
asset_owner: NameType
asset_id: UInt64Type
new_mutable_data: Types.pair_string_ATOMIC_ATTRIBUTE[]
new_mutable_data: Base.pair_string_ATOMIC_ATTRIBUTE[]
}
export interface setcoldata {
collection_name: NameType
data: Types.pair_string_ATOMIC_ATTRIBUTE[]
data: Base.pair_string_ATOMIC_ATTRIBUTE[]
}
export interface setmarketfee {
collection_name: NameType
Expand Down
Loading

0 comments on commit 298d024

Please sign in to comment.