Skip to content

Commit

Permalink
wip: feat(devnet): get devnet
Browse files Browse the repository at this point in the history
- populate connectModes for devnet
- populate static devnet constructors
  • Loading branch information
egasimus committed Oct 14, 2023
1 parent 257df66 commit 1b8a32b
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 25 deletions.
1 change: 1 addition & 0 deletions agent/agent-chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export interface DevnetHandle {
url: URL
running: boolean
chainId: string
platform: string
start: () => Promise<this>
getAccount: (name: string) => Promise<Partial<Agent>>
assertPresence: () => Promise<void>
Expand Down
13 changes: 10 additions & 3 deletions connect/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,22 @@ export type ConnectMode =
|`Scrt${'Mocknet'|'Devnet'|'Testnet'|'Mainnet'}`
|`OKP4${'Devnet'|'Testnet'}`

export const connectModes: Record<ConnectMode, (...args: any[])=>Chain> = {
export const connectModes = {

// Support for Secret Network
ScrtMainnet: Scrt.mainnet,
ScrtTestnet: Scrt.testnet,
ScrtDevnet: () => { throw new Error('Devnets are only available via @hackbg/fadroma') },
ScrtDevnet: (...args: Parameters<typeof Scrt.Chain.devnet>): Scrt.Chain => {
throw new Error('Devnets are only available via @hackbg/fadroma')
},
ScrtMocknet: Scrt.Chain.mocknet,

// Support for OKP4
OKP4Testnet: CW.OKP4.testnet,
OKP4Devnet: () => { throw new Error('Devnets are only available via @hackbg/fadroma') },
OKP4Devnet: (...args: Parameters<typeof CW.OKP4.Chain.devnet>): CW.OKP4.Chain => {
throw new Error('Devnets are only available via @hackbg/fadroma')
},

// TODO: Support for custom chain
}

Expand Down
4 changes: 2 additions & 2 deletions connect/cw/okp4/okp4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ bindChainSupport(OKP4Chain, OKP4Agent, OKP4Bundle)
export { OKP4Config as Config, OKP4Chain as Chain, OKP4Agent as Agent, OKP4Bundle as Bundle }

/** Connect to OKP4 testnet. */
export const testnet = OKP4Chain.testnet
export const testnet = (...args: Parameters<typeof OKP4Chain.testnet>) => OKP4Chain.testnet(...args)

/** Connect to local OKP4 devnet. */
export const devnet = OKP4Chain.devnet
export const devnet = (...args: Parameters<typeof OKP4Chain.devnet>) => OKP4Chain.devnet(...args)
8 changes: 4 additions & 4 deletions connect/scrt/scrt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export * from './scrt-token'
export * as SecretJS from '@hackbg/secretjs-esm'

import { Chain } from './scrt-chain'
export const mainnet = Chain.mainnet
export const testnet = Chain.testnet
export const devnet = Chain.devnet
export const mocknet = Chain.mocknet
export const mainnet = (...args: Parameters<typeof Chain.mainnet>) => Chain.mainnet(...args)
export const testnet = (...args: Parameters<typeof Chain.testnet>) => Chain.testnet(...args)
export const devnet = (...args: Parameters<typeof Chain.devnet>) => Chain.devnet(...args)
export const mocknet = (...args: Parameters<typeof Chain.mocknet>) => Chain.mocknet(...args)
27 changes: 20 additions & 7 deletions fadroma-devnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,14 +384,27 @@ export class Devnet implements DevnetHandle {
}
}

/** Get a Chain object corresponding to this devnet. */
/** Get a Chain object wrapping this devnet. */
getChain = <C extends Chain, D extends ChainClass<C>> (
$C: ChainClass<C> = Chain as unknown as ChainClass<C>
): C => new $C({
id: this.chainId,
mode: Chain.Mode.Devnet,
devnet: this
})
$C: ChainClass<C> = Chain as unknown as ChainClass<C>,
options?: Partial<C>
): C => {
if (options?.id && options.id !== this.chainId) {
this.log.warn('Devnet#getChain: ignoring passed chain id')
}
if (options?.mode && options.mode !== Chain.Mode.Devnet) {
this.log.warn('Devnet#getChain: ignoring passed chain mode')
}
if (options?.devnet) {
this.log.warn('Devnet#getChain: ignoring passed devnet handle')
}
return new $C({
...options,
id: this.chainId,
mode: Chain.Mode.Devnet,
devnet: this
})
}

/** Get the info for a genesis account, including the mnemonic */
getAccount = async (name: string): Promise<Partial<Agent>> => {
Expand Down
18 changes: 11 additions & 7 deletions fadroma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,17 @@ export function getDevnet (options: Partial<Config["devnet"]> = {}) {
}

// Installs devnets as selectable chains:
connectModes['ScrtDevnet'] =
(options: Partial<Devnet> = { platform: 'scrt_1.9' }): Scrt.Chain =>
new Config().getDevnet(options).getChain(Scrt.Chain as ChainClass<Scrt.Chain>)

connectModes['OKP4Devnet'] =
(options: Partial<Devnet> = { platform: 'okp4_5.0' }): CW.OKP4.Chain =>
new Config().getDevnet(options).getChain(CW.OKP4.Chain as ChainClass<CW.OKP4.Chain>)
connectModes['ScrtDevnet'] = Scrt.Chain.devnet =
(options: Partial<Scrt.Chain>|undefined): Scrt.Chain =>
new Config()
.getDevnet({ platform: 'scrt_1.9' })
.getChain(Scrt.Chain as ChainClass<Scrt.Chain>, options)

connectModes['OKP4Devnet'] = CW.OKP4.Chain.devnet =
(options: Partial<CW.OKP4.Chain>|undefined): CW.OKP4.Chain =>
new Config()
.getDevnet({ platform: 'okp4_5.0' })
.getChain(CW.OKP4.Chain as ChainClass<CW.OKP4.Chain>, options)

const console = new Console(`@hackbg/fadroma ${version}`)

Expand Down
4 changes: 2 additions & 2 deletions spec/CW.spec.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import assert from 'node:assert'

Fadroma supports connecting to any chain that supports CosmWasm.

For this, we currently use our own fork of `@cosmjs/*`,
unified into a single package, `@hackbg/cosmjs-esm`.
For this, we currently use our own fork of the `@cosmjs/*` packages,
unified into a single package, [`@hackbg/cosmjs-esm`](https://www.npmjs.com/package/@hackbg/cosmjs-esm).

## OKP4 support

Expand Down

0 comments on commit 1b8a32b

Please sign in to comment.