-
Notifications
You must be signed in to change notification settings - Fork 9
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 #82 from w3f/test-endpoint
alert now has to be triggered manually
- Loading branch information
Showing
14 changed files
with
145 additions
and
110 deletions.
There are no files selected for viewing
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 @@ | ||
description: Polkadot Watcher | ||
name: polkadot-watcher | ||
version: v3.1.2 | ||
version: v3.1.3 | ||
apiVersion: v2 |
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,51 @@ | ||
import { ApiPromise, WsProvider } from '@polkadot/api'; | ||
import { Logger } from '@w3f/logger'; | ||
|
||
import { | ||
InputConfig, | ||
} from './types'; | ||
|
||
export class Client { | ||
private api: ApiPromise; | ||
private endpoint: string; | ||
|
||
constructor( | ||
cfg: InputConfig, | ||
private readonly logger: Logger) { | ||
this.endpoint = cfg.endpoint; | ||
} | ||
|
||
public async connect(): Promise<ApiPromise> { | ||
try { | ||
await this._initAPI(); | ||
} catch (error) { | ||
this.logger.error("initAPI error... exiting: "+JSON.stringify(error)) | ||
process.exit(1) | ||
} | ||
return this.api | ||
} | ||
|
||
private async _initAPI(): Promise<void> { | ||
const provider = new WsProvider(this.endpoint); | ||
this.api = new ApiPromise({provider}) | ||
if(this.api){ | ||
this.api.on("error", error => { | ||
if( error.toString().includes("FATAL") || JSON.stringify(error).includes("FATAL") ){ | ||
this.logger.error("The API had a FATAL error... exiting!") | ||
process.exit(1) | ||
} | ||
}) | ||
} | ||
await this.api.isReadyOrError; | ||
|
||
const [chain, nodeName, nodeVersion] = await Promise.all([ | ||
this.api.rpc.system.chain(), | ||
this.api.rpc.system.name(), | ||
this.api.rpc.system.version() | ||
]); | ||
this.logger.info( | ||
`You are connected to chain ${chain} using ${nodeName} v${nodeVersion}` | ||
); | ||
} | ||
|
||
} |
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
Oops, something went wrong.