-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: refactor functions & prometheus logs
- Loading branch information
1 parent
93b71a9
commit 2703563
Showing
19 changed files
with
139 additions
and
114 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
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,16 @@ | ||
import { JSONRPCClient, JSONRPCResponse } from "json-rpc-2.0"; | ||
|
||
export function createClient(rpcEvmEndpoint: string) { | ||
const client = new JSONRPCClient(async jsonRPCRequest => { | ||
const response = await fetch(rpcEvmEndpoint, { | ||
method: "POST", | ||
headers: { "content-type": "application/json"}, | ||
body: JSON.stringify(jsonRPCRequest), | ||
}); | ||
if ( jsonRPCRequest.id !== undefined ) new Error(response.statusText); | ||
if ( response.status !== 200) new Error(response.statusText); | ||
const jsonRPCResponse: JSONRPCResponse = await response.json(); | ||
client.receive(jsonRPCResponse); | ||
}); | ||
return client; | ||
}; |
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,31 @@ | ||
import { ChainDefinitionType, Session } from "@wharfkit/session"; | ||
import { CHAIN_ID, MINER_PERMISSION, RPC_ENDPOINT, MINER_ACCOUNT } from "./config.js"; | ||
import { WalletPluginPrivateKey } from "@wharfkit/wallet-plugin-privatekey"; | ||
import { DefaultOptions } from "../bin/cli.js"; | ||
|
||
interface CreateSessionOptions extends DefaultOptions { | ||
chain?: ChainDefinitionType; | ||
rpcEndpoint?: string; | ||
} | ||
|
||
export function createSession(options: CreateSessionOptions) { | ||
// required | ||
const actor = options.actor ?? MINER_ACCOUNT; | ||
const privateKey = options.privateKey ?? process.env.PRIVATE_KEY; | ||
if (!actor) throw new Error('--actor is required (env=ACTOR)'); | ||
if (!privateKey) throw new Error('--privateKey is required (env=PRIVATE_KEY)'); | ||
|
||
// optional | ||
const permission = options.permission ?? MINER_PERMISSION; | ||
const chain = options.chain ?? { | ||
id: CHAIN_ID, | ||
url: options.rpcEndpoint ?? RPC_ENDPOINT, | ||
} | ||
|
||
return new Session({ | ||
chain, | ||
actor, | ||
permission, | ||
walletPlugin: new WalletPluginPrivateKey(privateKey), | ||
}) | ||
} |
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
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,13 @@ | ||
import { Session } from "@wharfkit/session"; | ||
|
||
export function getChain(session: Session) { | ||
if ( session.chain.id.equals("aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906") ) return "eos"; | ||
if ( session.chain.id.equals("73e4385a2708e6d7048834fbc1079f2fabb17b3c125b146af438971e90716c4d") ) return "jungle4"; | ||
if ( session.chain.id.equals("5fff1dae8dc8e2fc4d5b23b2c7665c97f9e9d8edf2b6485a86ba311c25639191") ) return "kylin"; | ||
if ( session.chain.id.equals("1064487b3cd1a897ce03ae5b6a865651747e2e152090f99c1d19d44e01aea5a4") ) return "wax"; | ||
if ( session.chain.id.equals("f16b1833c747c43682f4386fca9cbb327929334a762755ebec17f6f23c9b8a12") ) return "waxtest"; | ||
if ( session.chain.id.equals("4667b205c6838ef70ff7988f6e8257e8be0e1284a2f59699054a018f743b1d11") ) return "telos"; | ||
if ( session.chain.id.equals("1eaa0824707c8c16bd25145493bf062aecddfeb56c736f6ba6397f3195f33c9f") ) return "telostest"; | ||
if ( session.chain.id.equals("8fc6dce7942189f842170de953932b1f66693ad3788f766e777b6f9d22335c02") ) return "ux"; | ||
return null; | ||
} |
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,11 @@ | ||
import { Session } from "@wharfkit/session"; | ||
import { getChain } from "./getChain.js"; | ||
|
||
export function getExplorer(session: Session, trx_id: string) { | ||
const chain = getChain(session); | ||
if (!chain) return trx_id;; | ||
if (["eos", "wax", "jungle4", "kylin"].includes(chain)) return `https://${chain}.eosq.eosnation.io/tx/${trx_id}`; | ||
if (["telos"].includes(chain)) return `https://explorer.telos.net/transaction/${trx_id}`; | ||
if (["ux"].includes(chain)) return `https://explorer.uxnetwork.io/tx/${trx_id}`; | ||
return trx_id; | ||
} |
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.