mirror of
https://github.com/alexgo-io/clarity-codegen.git
synced 2026-01-12 14:34:34 +08:00
feat: add contract constant descriptor
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
import axios from "axios";
|
||||
import * as fs from "fs";
|
||||
import { camelCase } from "lodash";
|
||||
import path from "path";
|
||||
import { inspect } from "util";
|
||||
import { asyncAutoRetry } from "../utils/asyncAutoRetry";
|
||||
import { assertNever, mapValues } from "../utils/helpers";
|
||||
import {
|
||||
ClarityAbi,
|
||||
ClarityAbiFunction,
|
||||
@@ -17,9 +20,6 @@ import {
|
||||
isClarityAbiStringUtf8,
|
||||
isClarityAbiTuple,
|
||||
} from "./contractAbi";
|
||||
import { assertNever, mapValues } from "../utils/helpers";
|
||||
import { asyncAutoRetry } from "../utils/asyncAutoRetry";
|
||||
import axios from "axios";
|
||||
|
||||
type TranscoderDefArgument = TranscoderDef | Record<string, TranscoderDef>;
|
||||
type TranscoderDef = [string, ...TranscoderDefArgument[]];
|
||||
@@ -230,6 +230,16 @@ const toVariableDescriptorDef = (
|
||||
};
|
||||
};
|
||||
|
||||
const toConstantDescriptorDef = (
|
||||
entry: ClarityAbiVariable
|
||||
): ContractEntryDescriptorDef => {
|
||||
return {
|
||||
output: toTranscoderDef({ type: entry.type }).def,
|
||||
input: ["noneT"],
|
||||
mode: entry.access,
|
||||
};
|
||||
};
|
||||
|
||||
const toFunctionDescriptorDef = (
|
||||
func: ClarityAbiFunction
|
||||
): void | ContractEntryDescriptorDef => {
|
||||
@@ -275,8 +285,11 @@ export const generateContractFromAbi = async ({
|
||||
defs[mapEntry.name] = toMapEntryDescriptorDef(mapEntry);
|
||||
}
|
||||
for (const varEntry of interfaceData.variables) {
|
||||
if (varEntry.access !== "variable") continue;
|
||||
defs[varEntry.name] = toVariableDescriptorDef(varEntry);
|
||||
if (varEntry.access === "variable") {
|
||||
defs[varEntry.name] = toVariableDescriptorDef(varEntry);
|
||||
} else if (varEntry.access === "constant") {
|
||||
defs[varEntry.name] = toConstantDescriptorDef(varEntry);
|
||||
}
|
||||
}
|
||||
|
||||
const transcoderNames = getAllTranscoderName(
|
||||
|
||||
@@ -12,6 +12,12 @@ export type VariableDescriptor = {
|
||||
output: Transcoder<any>;
|
||||
};
|
||||
|
||||
export type ConstantDescriptor = {
|
||||
mode: "constant";
|
||||
input: Transcoder<void>;
|
||||
output: Transcoder<any>;
|
||||
};
|
||||
|
||||
export type ReadonlyFunctionDescriptor = {
|
||||
mode: "readonly";
|
||||
input: readonly { name: string; type: Transcoder<any> }[];
|
||||
@@ -27,6 +33,7 @@ export type OpenCallFunctionDescriptor = {
|
||||
export type ContractEntryDescriptor =
|
||||
| MapEntryDescriptor
|
||||
| VariableDescriptor
|
||||
| ConstantDescriptor
|
||||
| ReadonlyFunctionDescriptor
|
||||
| OpenCallFunctionDescriptor;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user