@leofcoin/chain 1.8.4 → 1.8.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,106 @@
1
+ import { ContractMessage } from '@leofcoin/messages';
2
+ /**
3
+ * Registry for managing base contracts and contract inheritance
4
+ */
5
+ export declare class ContractRegistry {
6
+ private baseContracts;
7
+ private contractNames;
8
+ private contractDependencies;
9
+ /**
10
+ * Register a base contract that can be reused
11
+ * Uses the contract code hash as the identifier and registers the name in nameService
12
+ * @param name The name to register in nameService
13
+ * @param message The contract message
14
+ * @returns The contract hash
15
+ */
16
+ registerBaseContract(name: string, message: ContractMessage): Promise<string>;
17
+ /**
18
+ * Register a name for a contract hash in the nameService
19
+ * @param name The name to register
20
+ * @param hash The contract hash
21
+ * @param chain The chain instance (for making transactions)
22
+ * @param signer The wallet to sign the transaction
23
+ */
24
+ registerNameInNameService(name: string, hash: string, chain: any, signer: any): Promise<void>;
25
+ /**
26
+ * Get a base contract by name
27
+ * First checks local registry, then queries nameService if available
28
+ * @param name The name of the base contract
29
+ * @returns The contract message or undefined
30
+ */
31
+ getBaseContract(name: string): ContractMessage | undefined;
32
+ /**
33
+ * Get a base contract by hash
34
+ * @param hash The hash of the contract
35
+ * @returns The contract message or undefined
36
+ */
37
+ getBaseContractByHash(hash: string): ContractMessage | undefined;
38
+ /**
39
+ * Resolve a name to a hash (first local, then nameService)
40
+ * @param name The contract name
41
+ * @returns The contract hash or undefined
42
+ */
43
+ resolveNameToHash(name: string): string | undefined;
44
+ /**
45
+ * Register contract dependencies (inheritance chain)
46
+ * @param contractHash The hash of the contract
47
+ * @param dependencies Array of base contract hashes this contract depends on
48
+ */
49
+ registerDependencies(contractHash: string, dependencies: string[]): void;
50
+ /**
51
+ * Get all dependencies for a contract
52
+ * @param contractHash The hash of the contract
53
+ * @returns Array of dependency hashes
54
+ */
55
+ getDependencies(contractHash: string): string[];
56
+ /**
57
+ * Check if all dependencies for a contract are available
58
+ * @param contractHash The hash of the contract
59
+ * @returns true if all dependencies are available
60
+ */
61
+ areDependenciesAvailable(contractHash: string): Promise<boolean>;
62
+ /**
63
+ * Get all registered contract hashes
64
+ * @returns Array of contract hashes
65
+ */
66
+ getBaseContractHashes(): string[];
67
+ /**
68
+ * Get hash for a registered name
69
+ * @param name The contract name
70
+ * @returns The hash or undefined
71
+ */
72
+ getHashForName(name: string): string | undefined;
73
+ /**
74
+ * Analyze contract code and extract inheritance information
75
+ * @param contractCode The contract code to analyze
76
+ * @returns Inheritance information
77
+ */
78
+ analyzeContract(contractCode: string): {
79
+ className: string | null;
80
+ baseClass: string | null;
81
+ hasInheritance: boolean;
82
+ };
83
+ /**
84
+ * Build a complete contract by combining base contracts
85
+ * @param contractCode The derived contract code
86
+ * @param baseContractIdentifiers Names or hashes of base contracts to include
87
+ * @returns Combined contract code
88
+ */
89
+ buildContract(contractCode: string, baseContractIdentifiers?: string[]): Promise<string>;
90
+ /**
91
+ * Clear all registered contracts
92
+ */
93
+ clear(): void;
94
+ /**
95
+ * Get all registered base contract names
96
+ * @returns Array of base contract names
97
+ */
98
+ getBaseContractNames(): string[];
99
+ /**
100
+ * Get name for a hash if registered
101
+ * @param hash The contract hash
102
+ * @returns The name or undefined
103
+ */
104
+ getNameForHash(hash: string): string | undefined;
105
+ }
106
+ export declare const contractRegistry: ContractRegistry;
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Create a hash from contract code using ContractMessage's hash method
3
+ * For base contracts, omit constructorParameters to hash only the code
4
+ * @param creator The creator address
5
+ * @param contractCode The contract code to hash
6
+ * @param constructorParameters Constructor parameters (omit for base contracts)
7
+ * @returns Promise<string> The hash of the contract
8
+ */
9
+ export declare const hashContractCode: (creator: string, contractCode: string, constructorParameters?: any[]) => Promise<string>;
10
+ /**
11
+ * Check if a class is derived from another class
12
+ * @param derivedClass The class to check
13
+ * @param baseClass The potential base class
14
+ * @returns true if derivedClass extends baseClass
15
+ */
16
+ export declare const isDerivedFrom: (derivedClass: any, baseClass: any) => boolean;
17
+ /**
18
+ * Check if a class instance is derived from another class
19
+ * @param instance The instance to check
20
+ * @param baseClass The potential base class
21
+ * @returns true if instance's class extends baseClass
22
+ */
23
+ export declare const isInstanceOf: (instance: any, baseClass: any) => boolean;
24
+ /**
25
+ * Get the inheritance chain of a class
26
+ * @param classConstructor The class to get the inheritance chain for
27
+ * @returns Array of class names in the inheritance chain
28
+ */
29
+ export declare const getInheritanceChain: (classConstructor: any) => string[];
30
+ /**
31
+ * Extract base contract code from a contract
32
+ * Useful for separating reusable code into base contracts
33
+ * @param contractCode The contract code to analyze
34
+ * @returns Object with base contract and derived contract code
35
+ */
36
+ export declare const extractBaseContract: (contractCode: string) => {
37
+ baseCode: string;
38
+ derivedCode: string;
39
+ };
40
+ /**
41
+ * Parse contract inheritance information from contract code
42
+ * @param contractCode The contract code to parse
43
+ * @returns Information about the contract's inheritance
44
+ */
45
+ export declare const parseContractInheritance: (contractCode: string) => {
46
+ className: string | null;
47
+ baseClass: string | null;
48
+ hasInheritance: boolean;
49
+ };
@@ -34,6 +34,30 @@ export default class Contract extends Transaction {
34
34
  wait: Promise<unknown>;
35
35
  message: any;
36
36
  }>;
37
+ /**
38
+ * Register a base contract for reuse by other contracts
39
+ * The contract is stored by its hash, enabling inheritance and code reuse
40
+ * @param {String} name The name to register for this contract
41
+ * @param {String} contract The contract code
42
+ * @param {Array} constructorParameters Constructor parameters
43
+ * @returns {Promise<string>} The contract hash
44
+ */
45
+ registerBaseContract(name: string, contract: string, constructorParameters?: any[]): Promise<string>;
46
+ /**
47
+ * Deploy a contract with optional base contracts for inheritance
48
+ * @param {MultiWallet} signer The wallet to sign with
49
+ * @param {String} contract The contract code
50
+ * @param {Array} constructorParameters Constructor parameters
51
+ * @param {Array<string>} baseContracts Optional array of base contract names or hashes
52
+ * @returns Transaction result
53
+ */
54
+ deployDerivedContract(signer: MultiWallet, contract: string, baseContractIdentifier?: string, constructorParameters?: any[]): Promise<{
55
+ hash: any;
56
+ data: any;
57
+ fee: string | bigint | 0;
58
+ wait: Promise<unknown>;
59
+ message: any;
60
+ }>;
37
61
  deployContractMessage(signer: any, message: any): Promise<{
38
62
  hash: any;
39
63
  data: any;
@@ -41,4 +65,26 @@ export default class Contract extends Transaction {
41
65
  wait: Promise<unknown>;
42
66
  message: any;
43
67
  }>;
68
+ /**
69
+ * Check if a class is derived from another class
70
+ * @param derivedClass The class to check
71
+ * @param baseClass The potential base class
72
+ * @returns true if derivedClass extends baseClass
73
+ */
74
+ isDerivedFrom(derivedClass: any, baseClass: any): boolean;
75
+ /**
76
+ * Parse contract code to extract inheritance information
77
+ * @param contractCode The contract code to parse
78
+ * @returns Inheritance information
79
+ */
80
+ parseContractInheritance(contractCode: string): {
81
+ className: string | null;
82
+ baseClass: string | null;
83
+ hasInheritance: boolean;
84
+ };
85
+ /**
86
+ * Get the contract registry instance
87
+ * @returns {ContractRegistry} The contract registry
88
+ */
89
+ getRegistry(): import("./contract-registry.js").ContractRegistry;
44
90
  }
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Example: Using Contract Inheritance and Base Contracts
3
+ *
4
+ * This example demonstrates how to:
5
+ * 1. Check if a class is derived from another class
6
+ * 2. Register reusable base contracts
7
+ * 3. Deploy derived contracts that extend base contracts
8
+ */
9
+ import Contract from '../contract.js';
10
+ import type MultiWallet from '@leofcoin/multi-wallet';
11
+ /**
12
+ * Example usage of the contract system
13
+ */
14
+ export declare function exampleContractDeployment(contractInstance: Contract, signer: MultiWallet): Promise<{
15
+ baseHash: string;
16
+ deployResult: {
17
+ hash: any;
18
+ data: any;
19
+ fee: string | bigint | 0;
20
+ wait: Promise<unknown>;
21
+ message: any;
22
+ };
23
+ altDeployResult: {
24
+ hash: any;
25
+ data: any;
26
+ fee: string | bigint | 0;
27
+ wait: Promise<unknown>;
28
+ message: any;
29
+ };
30
+ }>;
31
+ /**
32
+ * Example: Creating a modular contract system
33
+ */
34
+ export declare function exampleModularContracts(contractInstance: Contract, signer: MultiWallet): Promise<{
35
+ hash: any;
36
+ data: any;
37
+ fee: string | bigint | 0;
38
+ wait: Promise<unknown>;
39
+ message: any;
40
+ }>;
41
+ /**
42
+ * Example: Best practices for contract organization
43
+ */
44
+ export declare const contractBestPractices: {
45
+ baseContracts: string[];
46
+ derivedContracts: string[];
47
+ benefits: string[];
48
+ };
49
+ declare const _default: {
50
+ exampleContractDeployment: typeof exampleContractDeployment;
51
+ exampleModularContracts: typeof exampleModularContracts;
52
+ contractBestPractices: {
53
+ baseContracts: string[];
54
+ derivedContracts: string[];
55
+ benefits: string[];
56
+ };
57
+ };
58
+ export default _default;
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Example: Hash-Based Contract Registry with NameService Integration
3
+ *
4
+ * This example demonstrates:
5
+ * 1. Hashing contract code for content-addressed storage
6
+ * 2. Registering contracts by hash with name mappings
7
+ * 3. Using nameService for on-chain name resolution
8
+ * 4. Deploying contracts by name or hash
9
+ */
10
+ import Contract from '../contract.js';
11
+ import type MultiWallet from '@leofcoin/multi-wallet';
12
+ export declare function exampleHashBasedRegistration(contract: Contract, signer: MultiWallet): Promise<{
13
+ codeHash: string;
14
+ registeredHash: string;
15
+ result: {
16
+ hash: any;
17
+ data: any;
18
+ fee: string | bigint | 0;
19
+ wait: Promise<unknown>;
20
+ message: any;
21
+ };
22
+ }>;
23
+ export declare function exampleNameServiceIntegration(contract: Contract, signer: MultiWallet): Promise<{
24
+ hash: string;
25
+ }>;
26
+ export declare function exampleContractAliases(contract: Contract): Promise<{
27
+ hash1: string;
28
+ hash2: string;
29
+ }>;
30
+ export declare function exampleVersionedContracts(contract: Contract, signer: MultiWallet): Promise<{
31
+ v1Hash: string;
32
+ v2Hash: string;
33
+ result: {
34
+ hash: any;
35
+ data: any;
36
+ fee: string | bigint | 0;
37
+ wait: Promise<unknown>;
38
+ message: any;
39
+ };
40
+ }>;
41
+ export declare function exampleDeployByHash(contract: Contract, signer: MultiWallet): Promise<{
42
+ baseHash: string;
43
+ result: {
44
+ hash: any;
45
+ data: any;
46
+ fee: string | bigint | 0;
47
+ wait: Promise<unknown>;
48
+ message: any;
49
+ };
50
+ }>;
51
+ export declare function exampleVerifyContract(contract: Contract): Promise<{
52
+ registeredHash: string;
53
+ computedHash: string;
54
+ }>;
55
+ export declare function exampleContractDiscovery(contract: Contract): Promise<{
56
+ names: string[];
57
+ hashes: string[];
58
+ nameToHash: {};
59
+ hashToName: {};
60
+ }>;
61
+ export declare function exampleDependencyResolution(contract: Contract, signer: MultiWallet): Promise<{
62
+ storageHash: string;
63
+ validationHash: string;
64
+ result: {
65
+ hash: any;
66
+ data: any;
67
+ fee: string | bigint | 0;
68
+ wait: Promise<unknown>;
69
+ message: any;
70
+ };
71
+ }>;
72
+ declare const _default: {
73
+ exampleHashBasedRegistration: typeof exampleHashBasedRegistration;
74
+ exampleNameServiceIntegration: typeof exampleNameServiceIntegration;
75
+ exampleContractAliases: typeof exampleContractAliases;
76
+ exampleVersionedContracts: typeof exampleVersionedContracts;
77
+ exampleDeployByHash: typeof exampleDeployByHash;
78
+ exampleVerifyContract: typeof exampleVerifyContract;
79
+ exampleContractDiscovery: typeof exampleContractDiscovery;
80
+ exampleDependencyResolution: typeof exampleDependencyResolution;
81
+ };
82
+ export default _default;
@@ -1,2 +1,2 @@
1
1
  export declare const reachedOneZeroZero = false;
2
- export declare const currentVersion = "0.1.0";
2
+ export declare const currentVersion = "0.1.1";
@@ -22,7 +22,10 @@ export default class Machine {
22
22
  };
23
23
  };
24
24
  wantList: string[];
25
- constructor(blocks: any);
25
+ readyResolve: (value: Machine | PromiseLike<Machine>) => void;
26
+ ready: Promise<Machine>;
27
+ constructor(blocks?: any[]);
28
+ init(blocks: any): Promise<Machine>;
26
29
  updateState(): Promise<void>;
27
30
  /**
28
31
  *
package/exports/node.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export default class Node {
2
2
  #private;
3
+ ready: Promise<this>;
3
4
  constructor(config: any, password: any);
4
5
  _init(config: {
5
6
  autoStart: boolean;
package/exports/node.js CHANGED
@@ -13,8 +13,7 @@ const DEFAULT_NODE_OPTIONS = {
13
13
  class Node {
14
14
  #node;
15
15
  constructor(config, password) {
16
- // @ts-ignore
17
- return this._init(config, password);
16
+ this.ready = this._init(config, password);
18
17
  }
19
18
  async _init(config = {
20
19
  autoStart: false
@@ -1,6 +1,6 @@
1
1
  import type { ChainConfig } from './types.js';
2
2
  export declare const limit = 1800;
3
- export declare const transactionLimit = 1000;
3
+ export declare const transactionLimit = 2500;
4
4
  export declare const requestTimeout = 30000;
5
5
  export declare const syncTimeout = 30000;
6
6
  export declare class Protocol {