Skip to content

Commit

Permalink
[NayNay] Exposing substrate (#435)
Browse files Browse the repository at this point in the history
<!-- Provide a brief description of the changes made in this PR -->

## Related Issue(s)
<!-- Link to the issue(s) that this PR addresses -->

- Resolves #427 

## Proposed Changes
<!-- List the changes made in this PR -->

- added new utility method to create substrate api instance, without
needing to create an entropy instance

## Testing
<!-- Describe how you tested the changes -->

- [ ] Unit tests added/updated
- [ ] Integration tests added/updated
- [ ] Manual testing performed

## Screenshots (if applicable)
<!-- Include any relevant screenshots here -->

## Additional Context
<!-- Add any other context or information that might be helpful for the
reviewer -->

## Checklist
<!-- Confirm that the following items are true and correct: -->

- [ ] I have performed a self-review of my code.
- [ ] I have commented my code.
- [ ] I have updated documentation, where necessary.
  • Loading branch information
frankiebee authored Dec 2, 2024
2 parents 36ba894 + 09220ac commit ce96745
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
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 {
const wsProvider = new WsProvider(endpoint)
return new ApiPromise({ provider: wsProvider, noInitWarn: true })
}

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

0 comments on commit ce96745

Please sign in to comment.