Skip to content

Commit

Permalink
Api 0.1.10 (#1228)
Browse files Browse the repository at this point in the history
* Update dependencies
  • Loading branch information
alistair-singh authored Jun 12, 2024
1 parent 9026a7c commit 6bb4c8a
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 246 deletions.
6 changes: 3 additions & 3 deletions web/packages/api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@snowbridge/api",
"version": "0.1.9",
"version": "0.1.10",
"description": "Snowbridge API client",
"license": "Apache-2.0",
"repository": {
Expand All @@ -27,9 +27,9 @@
"typescript": "^5.4.5"
},
"dependencies": {
"@polkadot/api": "^11.0.3",
"@polkadot/api": "^11.2.1",
"@polkadot/keyring": "^12.6.2",
"@polkadot/types": "^11.0.3",
"@polkadot/types": "^11.2.1",
"@polkadot/util": "^12.6.2",
"@polkadot/util-crypto": "^12.6.2",
"@snowbridge/contract-types": "workspace:*",
Expand Down
29 changes: 12 additions & 17 deletions web/packages/api/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// import '@polkadot/api-augment/polkadot'
import { ApiPromise, WsProvider } from "@polkadot/api"
import { AbstractProvider, ethers } from "ethers"
import { AbstractProvider, JsonRpcProvider, WebSocketProvider, BrowserProvider } from "ethers"
import {
BeefyClient,
BeefyClient__factory,
Expand All @@ -10,7 +10,7 @@ import {

interface Config {
ethereum: {
execution_url: string
execution_url: string | AbstractProvider
beacon_url: string
}
polkadot: {
Expand Down Expand Up @@ -45,10 +45,10 @@ export class Context {
}

class EthereumContext {
api: ethers.AbstractProvider
api: AbstractProvider
contracts: AppContracts

constructor(api: ethers.AbstractProvider, contracts: AppContracts) {
constructor(api: AbstractProvider, contracts: AppContracts) {
this.api = api
this.contracts = contracts
}
Expand Down Expand Up @@ -78,23 +78,16 @@ class PolkadotContext {
}
}

interface ContextOverride {
ethereum?: AbstractProvider
}

export const contextFactory = async (
config: Config,
options: ContextOverride = {}
): Promise<Context> => {
export const contextFactory = async (config: Config): Promise<Context> => {
let ethApi: AbstractProvider
if (options.ethereum == null) {
if (typeof config.ethereum.execution_url === "string") {
if (config.ethereum.execution_url.startsWith("http")) {
ethApi = new ethers.JsonRpcProvider(config.ethereum.execution_url)
ethApi = new JsonRpcProvider(config.ethereum.execution_url)
} else {
ethApi = new ethers.WebSocketProvider(config.ethereum.execution_url)
ethApi = new WebSocketProvider(config.ethereum.execution_url)
}
} else {
ethApi = options.ethereum
ethApi = config.ethereum.execution_url
}

const parasConnect: Promise<{ paraId: number; api: ApiPromise }>[] = []
Expand Down Expand Up @@ -154,7 +147,9 @@ export const destroyContext = async (context: Context): Promise<void> => {
// clean up etheruem
await context.ethereum.contracts.beefyClient.removeAllListeners()
await context.ethereum.contracts.gateway.removeAllListeners()
await context.ethereum.api.destroy()
if (typeof context.config.ethereum.execution_url === "string") {
context.ethereum.api.destroy()
}
// clean up polkadot
await context.polkadot.api.relaychain.disconnect()
await context.polkadot.api.bridgeHub.disconnect()
Expand Down
2 changes: 1 addition & 1 deletion web/packages/contract-types/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@snowbridge/contract-types",
"version": "0.1.9",
"version": "0.1.10",
"description": "Snowbridge contract type bindings",
"license": "Apache-2.0",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion web/packages/contracts/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@snowbridge/contracts",
"version": "0.1.9",
"version": "0.1.10",
"description": "Snowbridge contract source and abi.",
"license": "Apache-2.0",
"repository": {
Expand Down
4 changes: 2 additions & 2 deletions web/packages/operations/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
"@ethersproject/providers": "^5.7.2",
"@ethersproject/units": "^5.7.0",
"@fastify/rate-limit": "^9.1.0",
"@polkadot/api": "^11.0.3",
"@polkadot/api": "^11.2.1",
"@polkadot/keyring": "^12.6.2",
"@polkadot/types": "^11.0.3",
"@polkadot/types": "^11.2.1",
"@polkadot/types-codec": "^11.0.2",
"@polkadot/util": "^12.6.2",
"@polkadot/util-crypto": "^12.6.2",
Expand Down
5 changes: 1 addition & 4 deletions web/packages/operations/src/global_transfer_history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const monitor = async () => {
const context = await contextFactory(
{
ethereum: {
execution_url: "badurl",
execution_url: ethereumProvider,
beacon_url: config.BEACON_HTTP_API,
},
polkadot: {
Expand All @@ -35,9 +35,6 @@ const monitor = async () => {
gateway: config.GATEWAY_CONTRACT,
beefy: config.BEEFY_CONTRACT,
},
},
{
ethereum: ethereumProvider,
}
)

Expand Down
Loading

0 comments on commit 6bb4c8a

Please sign in to comment.