Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NayNay] Exposing substrate #435

Merged
merged 5 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Version header format: `[version] Name - year-month-day (entropy-core compatibil
## [UNRELEASED]

### Added
- utility method to return substrate api instance to interact with without needing to instantiate entropy instance (#435)[https://github.com/entropyxyz/sdk/pull/435]

### Fixed

Expand Down
7 changes: 3 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ApiPromise, WsProvider } from '@polkadot/api'
import { ApiPromise } from '@polkadot/api'
import xtend from 'xtend'
import { isValidSubstrateAddress as isDeployer } from './utils'
import { createSubstrate, isValidSubstrateAddress as isDeployer } from './utils'
import RegistrationManager, { RegistrationParams } from './registration'
import SignatureRequestManager, { SigOps, SigWithAdaptersOps } from './signing'
import { crypto, loadCryptoLib } from './utils/crypto'
Expand Down Expand Up @@ -96,8 +96,7 @@ export default class Entropy {

async #init (opts: EntropyOpts) {
this.keyring = opts.keyring
const wsProvider = new WsProvider(opts.endpoint)
this.substrate = new ApiPromise({ provider: wsProvider, noInitWarn: true })
this.substrate = createSubstrate(opts.endpoint)
await this.substrate.isReadyOrError // throws an error if fails

this.registrationManager = new RegistrationManager({
Expand Down
11 changes: 11 additions & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { WsProvider, ApiPromise } from '@polkadot/api'
import { decodeAddress, encodeAddress } from '@polkadot/keyring'
import { hexToU8a, isHex } from '@polkadot/util'
import Debug from 'debug'
Expand Down Expand Up @@ -112,7 +113,17 @@ export async function sendHttpPost (url: string, data: any): Promise<any> {
return oks
}

/**
* Creates substrate api provider without needing to instantiate an entropy instance
*
* @param {string} endpoint - Endpoint for the api
* @returns {ApiPromise} Api tool to interact with protocol
*/

export function createSubstrate (endpoint: string): ApiPromise {
rh0delta marked this conversation as resolved.
Show resolved Hide resolved
const wsProvider = new WsProvider(endpoint)
return new ApiPromise({ provider: wsProvider, noInitWarn: true })
}

/**
* Converts an ArrayBuffer to a hexadecimal string.
Expand Down
Loading