-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: load rpc additional methods by cli
- Loading branch information
Showing
3 changed files
with
26 additions
and
3 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
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,17 @@ | ||
import { Handlers, isUrl } from '@acala-network/chopsticks-core' | ||
import { readFileSync } from 'node:fs' | ||
import { resolve } from 'node:path' | ||
import axios from 'axios' | ||
|
||
// This is a global value that store the loaded methods by cli | ||
export let rpcExtensionMethods: Handlers = {} | ||
|
||
// Use cli to load rpc methods of external scripts | ||
export const loadMethodsByScripts = async (path: string) => { | ||
try { | ||
const scriptContent = isUrl(path) ? await axios.get(path).then((x) => x.data) : readFileSync(resolve(path), 'utf8') | ||
rpcExtensionMethods = new Function(scriptContent)() | ||
} catch (error) { | ||
console.log('Failed to load rpc extension methods') | ||
} | ||
} |