最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

blockchain - Is it expected for typescript target files generated by compactc to be empty? - Stack Overflow

programmeradmin7浏览0评论

I'm learning Midnight's tooling and compact language. I currently have two contracts: apact:

module a {
   export sealed ledger num: Uint<8>;
}

bpact:

import "a";

constructor() {
  num = 10;
}

Is it expected for typescript target files generated by compactc to be empty and look like this:

import type * as __compactRuntime from '@midnight-ntwrk/compact-runtime';

export type Witnesses<T> = {
}

export type ImpureCircuits<T> = {
}

export type PureCircuits = {
}

export type Circuits<T> = {
}

export type Ledger = {
}

export type ContractReferenceLocations = any;

export declare const contractReferenceLocations : ContractReferenceLocations;

export declare class Contract<T, W extends Witnesses<T> = Witnesses<T>> {
  witnesses: W;
  circuits: Circuits<T>;
  impureCircuits: ImpureCircuits<T>;
  constructor(witnesses: W);
  initialState(context: __compactRuntime.ConstructorContext<T>): __compactRuntime.ConstructorResult<T>;
}

export declare function ledger(state: __compactRuntime.StateValue): Ledger;
export declare const pureCircuits: PureCircuits;

I'm learning Midnight's tooling and compact language. I currently have two contracts: apact:

module a {
   export sealed ledger num: Uint<8>;
}

bpact:

import "a";

constructor() {
  num = 10;
}

Is it expected for typescript target files generated by compactc to be empty and look like this:

import type * as __compactRuntime from '@midnight-ntwrk/compact-runtime';

export type Witnesses<T> = {
}

export type ImpureCircuits<T> = {
}

export type PureCircuits = {
}

export type Circuits<T> = {
}

export type Ledger = {
}

export type ContractReferenceLocations = any;

export declare const contractReferenceLocations : ContractReferenceLocations;

export declare class Contract<T, W extends Witnesses<T> = Witnesses<T>> {
  witnesses: W;
  circuits: Circuits<T>;
  impureCircuits: ImpureCircuits<T>;
  constructor(witnesses: W);
  initialState(context: __compactRuntime.ConstructorContext<T>): __compactRuntime.ConstructorResult<T>;
}

export declare function ledger(state: __compactRuntime.StateValue): Ledger;
export declare const pureCircuits: PureCircuits;
Share Improve this question edited yesterday lolocoding 635 bronze badges asked Mar 31 at 19:40 Petlover620Petlover620 1572 silver badges13 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

Hey @petlover620,

Yes, that's expected. That contract actually does have a ledger field num in its public state, but the field's not been exported from the contract (bpact) so it's not visible from the DApp's JS code. You need:

export { num };

in bpact for that. If contract b doesn't re-export members of module a then they're "private" from the JS code.

It's moderately confusing that export does something (slightly) different in a module definition (makes it available to Compact code that imports the module) and at the top level of a contract (makes it available to the JS code).

The compiler is sometimes aggressive about throwing away unneeded code, but in this case you can see that the constructor is there even when you don't re-export the module's field. Search for 10n in index.cjs to see it.

发布评论

评论列表(0)

  1. 暂无评论