@hashgraph/solo
Version:
An opinionated CLI tool to deploy and manage private Hedera Networks.
187 lines (186 loc) • 9.55 kB
TypeScript
import { AccountId, Client, type Key, PrivateKey } from '@hashgraph/sdk';
import { type NetworkNodeServices } from './network_node_services.js';
import { type SoloLogger } from './logging.js';
import { type K8Factory } from './kube/k8_factory.js';
import { type AccountIdWithKeyPairObject, type Optional } from '../types/index.js';
import { type NodeAlias } from '../types/aliases.js';
import { type NamespaceName } from './kube/resources/namespace/namespace_name.js';
import { type ClusterRefs, type DeploymentName } from './config/remote/types.js';
export declare class AccountManager {
private readonly logger?;
private readonly k8Factory?;
private _portForwards;
private _forcePortForward;
_nodeClient: Client | null;
constructor(logger?: SoloLogger, k8Factory?: K8Factory);
/**
* Gets the account keys from the Kubernetes secret from which it is stored
* @param accountId - the account ID for which we want its keys
* @param namespace - the namespace storing the secret
* @param [context]
*/
getAccountKeysFromSecret(accountId: string, namespace: NamespaceName, context?: Optional<string>): Promise<AccountIdWithKeyPairObject>;
/**
* Gets the treasury account private key from Kubernetes secret if it exists, else
* returns the Genesis private key, then will return an AccountInfo object with the
* accountId, ed25519PrivateKey, publicKey
* @param namespace - the namespace that the secret is in
* @param [context]
*/
getTreasuryAccountKeys(namespace: NamespaceName, context?: Optional<string>): Promise<AccountIdWithKeyPairObject>;
/**
* batch up the accounts into sets to be processed
* @param [accountRange]
* @returns an array of arrays of numbers representing the accounts to update
*/
batchAccounts(accountRange?: number[][]): number[][];
/** stops and closes the port forwards and the _nodeClient */
close(): Promise<void>;
/**
* loads and initializes the Node Client
* @param namespace - the namespace of the network
* @param clusterRefs - the cluster references to use
* @param deployment - k8 deployment name
* @param context - k8 context name
* @param forcePortForward - whether to force the port forward
*/
loadNodeClient(namespace: NamespaceName, clusterRefs?: ClusterRefs, deployment?: DeploymentName, forcePortForward?: boolean, context?: Optional<string>): Promise<Client>;
/**
* loads and initializes the Node Client, throws a SoloError if anything fails
* @param namespace - the namespace of the network
* @param skipNodeAlias - the node alias to skip
* @param [clusterRefs]
* @param [deployment]
* @param [context]
* @param forcePortForward - whether to force the port forward
*/
refreshNodeClient(namespace: NamespaceName, skipNodeAlias?: NodeAlias, clusterRefs?: ClusterRefs, deployment?: DeploymentName, context?: Optional<string>, forcePortForward?: boolean): Promise<Client>;
/**
* if the load balancer IP is not set, then we should use the local host port forward
* @param networkNodeServices
* @returns whether to use the local host port forward
*/
private shouldUseLocalHostPortForward;
/**
* Returns a node client that can be used to make calls against
* @param namespace - the namespace for which the node client resides
* @param networkNodeServicesMap - a map of the service objects that proxy the nodes
* @param operatorId - the account id of the operator of the transactions
* @param operatorKey - the private key of the operator of the transactions
* @param skipNodeAlias - the node alias to skip
* @returns a node client that can be used to call transactions
*/
_getNodeClient(namespace: NamespaceName, networkNodeServicesMap: Map<string, NetworkNodeServices>, operatorId: string, operatorKey: string, skipNodeAlias: string): Promise<Client>;
/**
* pings the node client at a set interval, can throw an exception if the ping fails
* @param operatorId
* @private
*/
private startIntervalPinger;
private configureNodeAccess;
/**
* pings the network node to ensure that the connection is working
* @param obj - the object containing the network node service and the account id
* @param accountId - the account id to ping
* @throws {@link SoloError} if the ping fails
* @private
*/
private testNodeClientConnection;
/**
* Gets a Map of the Hedera node services and the attributes needed, throws a SoloError if anything fails
* @param namespace - the namespace of the solo network deployment
* @param clusterRefs - the cluster references to use
* @param deployment - the deployment to use
* @returns a map of the network node services
*/
getNodeServiceMap(namespace: NamespaceName, clusterRefs?: ClusterRefs, deployment?: string): Promise<Map<`node${number}`, NetworkNodeServices>>;
/**
* updates a set of special accounts keys with a newly generated key and stores them in a Kubernetes secret
* @param namespace the namespace of the nodes network
* @param currentSet - the accounts to update
* @param updateSecrets - whether to delete the secret prior to creating a new secret
* @param resultTracker - an object to keep track of the results from the accounts that are being updated
* @returns the updated resultTracker object
*/
updateSpecialAccountsKeys(namespace: NamespaceName, currentSet: number[], updateSecrets: boolean, resultTracker: {
skippedCount: number;
rejectedCount: number;
fulfilledCount: number;
}): Promise<{
skippedCount: number;
rejectedCount: number;
fulfilledCount: number;
}>;
/**
* update the account keys for a given account and store its new key in a Kubernetes secret
* @param namespace - the namespace of the nodes network
* @param accountId - the account that will get its keys updated
* @param genesisKey - the genesis key to compare against
* @param updateSecrets - whether to delete the secret prior to creating a new secret
* @returns the result of the call
*/
updateAccountKeys(namespace: NamespaceName, accountId: AccountId, genesisKey: PrivateKey, updateSecrets: boolean): Promise<{
value: string;
status: string;
} | {
reason: string;
value: string;
status: string;
}>;
/**
* gets the account info from Hedera network
* @param accountId - the account
* @returns the private key of the account
*/
accountInfoQuery(accountId: AccountId | string): Promise<import("@hashgraph/sdk").AccountInfo>;
/**
* gets the account private and public key from the Kubernetes secret from which it is stored
* @param accountId - the account
* @returns the private key of the account
*/
getAccountKeys(accountId: AccountId | string): Promise<Key[]>;
/**
* send an account key update transaction to the network of nodes
* @param accountId - the account that will get its keys updated
* @param newPrivateKey - the new private key
* @param oldPrivateKey - the genesis key that is the current key
* @returns whether the update was successful
*/
sendAccountKeyUpdate(accountId: AccountId | string, newPrivateKey: PrivateKey | string, oldPrivateKey: PrivateKey | string): Promise<boolean>;
/**
* creates a new Hedera account
* @param namespace - the namespace to store the Kubernetes key secret into
* @param privateKey - the private key of type PrivateKey
* @param amount - the amount of HBAR to add to the account
* @param [setAlias] - whether to set the alias of the account to the public key, requires the ed25519PrivateKey supplied to be ECDSA
* @returns a custom object with the account information in it
*/
createNewAccount(namespace: NamespaceName, privateKey: PrivateKey, amount: number, setAlias?: boolean): Promise<{
accountId: string;
privateKey: string;
publicKey: string;
balance: number;
accountAlias?: string;
}>;
/**
* transfer the specified amount of HBAR from one account to another
* @param fromAccountId - the account to pull the HBAR from
* @param toAccountId - the account to put the HBAR
* @param hbarAmount - the amount of HBAR
* @returns if the transaction was successfully posted
*/
transferAmount(fromAccountId: AccountId | string, toAccountId: AccountId | string, hbarAmount: number): Promise<boolean>;
/**
* Fetch and prepare address book as a base64 string
*/
prepareAddressBookBase64(namespace: NamespaceName, clusterRefs?: ClusterRefs, deployment?: DeploymentName, operatorId?: string, operatorKey?: string, forcePortForward?: boolean, context?: string): Promise<string>;
getFileContents(namespace: NamespaceName, fileNum: number, clusterRefs?: ClusterRefs, deployment?: DeploymentName, forcePortForward?: boolean, context?: string): Promise<string>;
/**
* Pings the network node with a grpc call to ensure it is working, throws a SoloError if the ping fails
* @param obj - the network node object where the key is the network endpoint and the value is the account id
* @param accountId - the account id to ping
* @throws {@link SoloError} if the ping fails
* @private
*/
private pingNetworkNode;
}