-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from subspace/feat/improve-auto-utils
Improve auto utils
- Loading branch information
Showing
34 changed files
with
185 additions
and
99 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import type { ApiPromise } from '@polkadot/api' | ||
import type { ApiPromise } from '@autonomys/auto-utils' | ||
|
||
export const batch = async (api: ApiPromise, txs: any[]) => await api.tx.utility.batch(txs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import type { ApiPromise } from '@polkadot/api' | ||
import type { ApiPromise } from '@autonomys/auto-utils' | ||
|
||
export const remark = async (api: ApiPromise, remark: string, withEvent?: boolean) => | ||
!withEvent ? await api.tx.system.remark(remark) : await api.tx.system.remarkWithEvent(remark) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// file: src/address.ts | ||
|
||
import { decodeAddress, encodeAddress } from '@polkadot/keyring' | ||
import { DEFAULT_SS58_FORMAT } from './constants/wallet' | ||
|
||
export const address = (address: string | Uint8Array): string => | ||
encodeAddress(address, DEFAULT_SS58_FORMAT) | ||
|
||
export const decode = (address: string): Uint8Array => decodeAddress(address) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,32 @@ | ||
import { ApiPromise as PolkadotApiPromise, WsProvider } from '@polkadot/api' | ||
import { ApiPromise, WsProvider } from '@polkadot/api' | ||
import { getNetworkDomainRpcUrls, getNetworkRpcUrls } from './network' | ||
import type { ApiPromise } from './types/api' | ||
import type { DomainInput, NetworkInput } from './types/network' | ||
|
||
let provider: WsProvider | null = null | ||
let apiInstance: ApiPromise | null = null | ||
|
||
let domainProvider: WsProvider | null = null | ||
let apiDomainInstance: ApiPromise | null = null | ||
|
||
export const activate = async (input?: NetworkInput): Promise<ApiPromise> => { | ||
// Get the first rpc urls for the network | ||
const rpcUrl = getNetworkRpcUrls(input) | ||
// Create the provider | ||
provider = new WsProvider(rpcUrl[0]) | ||
const provider = new WsProvider(rpcUrl[0]) | ||
// Create the API instance | ||
apiInstance = await PolkadotApiPromise.create({ provider }) | ||
const api = await ApiPromise.create({ provider }) | ||
await api.isReady | ||
|
||
return apiInstance | ||
return api | ||
} | ||
|
||
export const activateDomain = async (input: DomainInput): Promise<ApiPromise> => { | ||
// Get the first rpc urls for the network | ||
const rpcUrl = getNetworkDomainRpcUrls(input) | ||
// Create the provider | ||
domainProvider = new WsProvider(rpcUrl[0]) | ||
const provider = new WsProvider(rpcUrl[0]) | ||
// Create the API instance | ||
apiDomainInstance = await PolkadotApiPromise.create({ provider: domainProvider }) | ||
|
||
return apiDomainInstance | ||
} | ||
const api = await ApiPromise.create({ provider }) | ||
await api.isReady | ||
|
||
export const disconnect = async (): Promise<void> => { | ||
// Disconnect the API instance and the provider if they exist | ||
if (apiInstance) { | ||
await apiInstance.disconnect() | ||
apiInstance = null | ||
provider = null | ||
} | ||
return api | ||
} | ||
|
||
export const disconnectDomain = async (): Promise<void> => { | ||
// Disconnect the API instance and the provider if they exist | ||
if (apiDomainInstance) { | ||
await apiDomainInstance.disconnect() | ||
apiDomainInstance = null | ||
domainProvider = null | ||
} | ||
export const disconnect = async (api: ApiPromise): Promise<void> => { | ||
// Disconnect the API instance and the provider | ||
await api.disconnect() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,5 @@ export const mockURIs = [ | |
'//Ivy', | ||
'//Jacob', | ||
] | ||
|
||
export const DEFAULT_SS58_FORMAT = 2254 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import type { EventRecord } from '@polkadot/types/interfaces' | ||
|
||
export type { EventRecord } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// file: src/types/extrinsic.ts | ||
|
||
import type { SubmittableExtrinsic, SubmittableModuleExtrinsics } from '@polkadot/api/types' | ||
import type { Hash } from '@polkadot/types/interfaces' | ||
import type { ISubmittableResult } from '@polkadot/types/types' | ||
|
||
export type { Hash, ISubmittableResult, SubmittableExtrinsic, SubmittableModuleExtrinsics } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
export * from './api' | ||
import type { BN } from '@polkadot/util' | ||
|
||
export * from './event' | ||
export * from './extrinsic' | ||
export * from './network' | ||
export * from './wallet' | ||
|
||
export type { BN } |
Oops, something went wrong.