Skip to content

Commit

Permalink
get genesis with ApiPromise
Browse files Browse the repository at this point in the history
Signed-off-by: Shreevatsa N <[email protected]>
  • Loading branch information
vatsa287 committed Jun 27, 2024
1 parent 208ce34 commit ac51535
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
29 changes: 25 additions & 4 deletions packages/utils/src/genesis.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,34 @@
import { connect, disconnect } from '@cord.network/config'
import { SDKErrors } from '.'
import { connect, disconnect } from '@cord.network/config';
import { SDKErrors } from '.';
import { ApiPromise } from '@polkadot/api';

/**
* Connects to chain and returnns the genesis hash in hexadecimal format for a given networkAddress.
* Returns the genesis hash in hexadecimal format for a given network object which is a ApiPromise.
*
* @param networkAddress Network Address for which the genesis hash is required.
* @param network network object of type ApiPromise for which the genesis hash is required.
* @returns Returns the genesis hash in Hexadecimal format.
*/
export async function getGenesisHash(
network: ApiPromise,
): Promise<string> {
try {
return network.genesisHash.toHex();
} catch (error) {
const errorMessage =
error instanceof Error ? error.message : JSON.stringify(error)

throw new SDKErrors.CordQueryError(
`Error querying asset entry: ${errorMessage}`
)}
}

/**
* Connects to chain and returns the genesis hash in hexadecimal format for a given networkAddress.
*
* @param networkAddress Network Address for which the genesis hash is required.
* @returns Returns the genesis hash in Hexadecimal format.
*/
export async function getGenesisHashWithConnect(
networkAddress: string,
): Promise<string> {
try {
Expand Down
1 change: 1 addition & 0 deletions packages/utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export * as DataUtils from './DataUtils.js'
export * as DecoderUtils from './Decode.js'
export * as SDKErrors from './SDKErrors.js'
export * as JsonSchema from './json-schema/index.js'
export * as Genesis from './genesis.js'
export { ss58Format } from './ss58Format.js'
export { Keyring } from '@polkadot/keyring'
export * as Cbor from 'cbor-x'

0 comments on commit ac51535

Please sign in to comment.