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
Changes from 3 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
@@ -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

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 { getSubstrate, isValidSubstrateAddress as isDeployer } from './utils'

Check failure on line 3 in src/index.ts

GitHub Actions / Build, test, and lint

Module '"./utils"' has no exported member 'getSubstrate'.
import RegistrationManager, { RegistrationParams } from './registration'
import SignatureRequestManager, { SigOps, SigWithAdaptersOps } from './signing'
import { crypto, loadCryptoLib } from './utils/crypto'
@@ -96,8 +96,7 @@

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

this.registrationManager = new RegistrationManager({
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'
@@ -112,7 +113,17 @@ export async function sendHttpPost (url: string, data: any): Promise<any> {
return oks
}

/**
* Returns substrate api without needing to instantiate an entropy instance
rh0delta marked this conversation as resolved.
Show resolved Hide resolved
*
* @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.