Skip to content

Commit

Permalink
add thor class for read-only opts
Browse files Browse the repository at this point in the history
  • Loading branch information
libotony committed Sep 6, 2023
1 parent 4c0a2bd commit 6b9c709
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions packages/connex/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,36 @@ export type Options = {
signer? : BuiltinSigner
}

/** Thor class which can work stand alone to provide reading-services only */
class ThorClass implements Connex.Thor {
genesis !: Connex.Thor['genesis']
status !: Connex.Thor['status']
ticker !: Connex.Thor['ticker']
account !: Connex.Thor['account']
block !: Connex.Thor['block']
transaction !: Connex.Thor['transaction']
filter !: Connex.Thor['filter']
explain !: Connex.Thor['explain']

constructor(opts: Omit<Options, 'signer'>) {
const genesis = normalizeNetwork(opts.network)

const driver = createNoVendor(opts.node, genesis)
const framework = new Framework(driver)

return {
get genesis() { return framework.thor.genesis },
get status() { return framework.thor.status },
get ticker() { return framework.thor.ticker.bind(framework.thor) },
get account() { return framework.thor.account.bind(framework.thor) },
get block() { return framework.thor.block.bind(framework.thor) },
get transaction() { return framework.thor.transaction.bind(framework.thor) },
get filter() { return framework.thor.filter.bind(framework.thor) },
get explain() { return framework.thor.explain.bind(framework.thor) }
}
}
}

/** Vendor class which can work standalone to provides signing-services only */
class VendorClass implements Connex.Vendor {
sign !: Connex.Vendor['sign']
Expand All @@ -101,6 +131,7 @@ class VendorClass implements Connex.Vendor {

/** Connex class */
class ConnexClass implements Connex {
static readonly Thor = ThorClass
static readonly Vendor = VendorClass

thor!: Connex.Thor
Expand Down

0 comments on commit 6b9c709

Please sign in to comment.