Skip to content

Commit

Permalink
Update all types with typedoc
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmyshchyshyn committed Nov 13, 2024
1 parent 8419ef6 commit f395932
Show file tree
Hide file tree
Showing 99 changed files with 4,074 additions and 841 deletions.
39 changes: 39 additions & 0 deletions src/types/Account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@ import { jsonObject, jsonMember, jsonArrayMember } from 'typedjson';
import { AccountHash, URef } from './key';
import { NamedKeys } from './NamedKey';

/**
* Represents an associated key for an account, linking an `AccountHash`
* with a weight that determines its permission level.
*/
@jsonObject
export class AssociatedKey {
/**
* The account hash associated with this key, uniquely identifying the account.
*/
@jsonMember({
name: 'account_hash',
constructor: AccountHash,
Expand All @@ -12,30 +19,50 @@ export class AssociatedKey {
})
accountHash: AccountHash;

/**
* The weight assigned to this key, which determines the key’s authority level.
*/
@jsonMember({
name: 'weight',
constructor: Number
})
weight: number;
}

/**
* Represents action thresholds for an account, specifying minimum weights
* required for deployment and key management actions.
*/
@jsonObject
export class ActionThresholds {
/**
* The threshold for performing deployment actions, represented as a weight.
*/
@jsonMember({
name: 'deployment',
constructor: Number
})
deployment: number;

/**
* The threshold for performing key management actions, represented as a weight.
*/
@jsonMember({
name: 'key_management',
constructor: Number
})
keyManagement: number;
}

/**
* Represents an account in the blockchain, containing account details such as
* associated keys, named keys, main purse, and action thresholds.
*/
@jsonObject
export class Account {
/**
* The account hash for this account, which serves as a unique identifier.
*/
@jsonMember({
name: 'account_hash',
deserializer: json => AccountHash.fromJSON(json),
Expand All @@ -44,12 +71,18 @@ export class Account {
})
accountHash: AccountHash;

/**
* The named keys associated with this account, mapping key names to `URef` values.
*/
@jsonMember({
name: 'named_keys',
constructor: NamedKeys
})
namedKeys: NamedKeys;

/**
* The main purse associated with this account, represented as a `URef`.
*/
@jsonMember({
name: 'main_purse',
constructor: URef,
Expand All @@ -58,9 +91,15 @@ export class Account {
})
mainPurse: URef;

/**
* The list of associated keys for this account, each with an `AccountHash` and weight.
*/
@jsonArrayMember(AssociatedKey, { name: 'associated_keys' })
associatedKeys: AssociatedKey[];

/**
* The action thresholds for this account, setting required weights for specific actions.
*/
@jsonMember({ name: 'action_thresholds', constructor: ActionThresholds })
actionThresholds: ActionThresholds;
}
81 changes: 73 additions & 8 deletions src/types/AddressableEntity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,67 +7,110 @@ import { AccountHash, URef } from './key';
export type SystemEntityType = string;
export type TransactionRuntime = 'VmCasperV1' | 'VmCasperV2';

/**
* Defines different kinds of entities within the system, such as system entities,
* accounts, and smart contracts. Provides details on each entity type.
*/
@jsonObject
export class EntityKind {
/**
* Represents a system entity type, allowing flexible naming of system-specific entities.
*/
@jsonMember({ name: 'System', constructor: String })
system?: SystemEntityType;

/**
* Represents an account entity, identified by an `AccountHash`.
*/
@jsonMember({
name: 'Account',
constructor: AccountHash,
deserializer: json => {
if (!json) return;
return AccountHash.fromJSON(json);
},
serializer: value => {
if (!value) return;
return value.toJSON();
}
deserializer: json => (json ? AccountHash.fromJSON(json) : undefined),
serializer: value => (value ? value.toJSON() : undefined)
})
account?: AccountHash;

/**
* Represents a smart contract entity, specified by its transaction runtime version.
*/
@jsonMember({
name: 'SmartContract',
constructor: String
})
smartContract?: TransactionRuntime;
}

/**
* Defines thresholds for various actions that an entity can perform,
* with each threshold represented as a weight.
*/
@jsonObject
export class EntityActionThresholds {
/**
* The weight required to authorize deployment actions.
*/
@jsonMember({ name: 'deployment', constructor: Number })
deployment: number;

/**
* The weight required to authorize upgrade management actions.
*/
@jsonMember({ name: 'upgrade_management', constructor: Number })
upgradeManagement: number;

/**
* The weight required to authorize key management actions.
*/
@jsonMember({ name: 'key_management', constructor: Number })
keyManagement: number;
}

/**
* Represents an addressable entity, which can be a smart contract, account, or system entity.
* Each entity contains various properties such as action thresholds, associated keys,
* and message topics.
*/
@jsonObject
export class AddressableEntity {
/**
* Specifies the kind of the entity, such as system entity, account, or smart contract.
*/
@jsonMember({
name: 'entity_kind',
constructor: EntityKind
})
entityKind: EntityKind;

/**
* The unique package hash associated with this entity.
*/
@jsonMember({ name: 'package_hash', constructor: String })
packageHash: string;

/**
* The bytecode hash associated with this entity, representing its executable code.
*/
@jsonMember({ name: 'byte_code_hash', constructor: String })
byteCodeHash: string;

/**
* The associated keys for this entity, each with an `AccountHash` and a weight.
*/
@jsonArrayMember(AssociatedKey, { name: 'associated_keys' })
associatedKeys: AssociatedKey[];

/**
* The action thresholds required for different operations, such as deployment or key management.
*/
@jsonMember({
name: 'action_thresholds',
constructor: EntityActionThresholds
})
actionThresholds: EntityActionThresholds;

/**
* The main purse associated with this entity, used for managing funds.
*/
@jsonMember({
name: 'main_purse',
constructor: URef,
Expand All @@ -76,25 +119,47 @@ export class AddressableEntity {
})
mainPurse: URef;

/**
* The protocol version in use by this entity.
*/
@jsonMember({ name: 'protocol_version', constructor: String })
protocolVersion: string;

/**
* A list of topics for messaging associated with this entity.
*/
@jsonArrayMember(MessageTopic, { name: 'message_topics' })
messageTopics: MessageTopic[];
}

/**
* Represents an entry point in a smart contract, with a specific name and configuration.
*/
@jsonObject
export class NamedEntryPoint {
/**
* The entry point configuration, specifying the method and parameters.
*/
@jsonMember({
name: 'entry_point',
constructor: EntryPointV1
})
entryPoint: EntryPointV1;

/**
* The name of the entry point, used for identifying and invoking it.
*/
@jsonMember({ name: 'name', constructor: String })
name: string;
}

/**
* Returns the numeric tag associated with a given transaction runtime version.
* Useful for distinguishing between different virtual machine versions.
*
* @param runtime - The transaction runtime to retrieve the tag for.
* @returns A number representing the tag for the given runtime.
*/
export function getRuntimeTag(runtime: TransactionRuntime): number {
switch (runtime) {
case 'VmCasperV1':
Expand Down
Loading

0 comments on commit f395932

Please sign in to comment.