*Remove local pokt node support while waiting on pokt v1

This commit is contained in:
Derrick Hammer 2022-08-24 13:05:38 -04:00
parent 61a0991bcd
commit a0cab03073
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 3 additions and 87 deletions

View File

@ -9,35 +9,25 @@ import NodeCache from "node-cache";
import { get as getDHT } from "./dht.js"; import { get as getDHT } from "./dht.js";
import { rpcMethods } from "./rpc/index.js"; import { rpcMethods } from "./rpc/index.js";
import { start as startDns } from "./dns.js"; import { start as startDns } from "./dns.js";
import {
Configuration,
HttpRpcProvider,
PocketAAT,
Pocket,
} from "@pokt-network/pocket-js/dist/index.js";
import { import {
JSONRPCError, JSONRPCError,
JSONRPCRequest, JSONRPCRequest,
JSONRPCResponseWithError, JSONRPCResponseWithError,
JSONRPCResponseWithResult, JSONRPCResponseWithResult,
} from "jayson"; } from "jayson";
import config, { updateUsePocketGateway, usePocketGateway } from "./config.js"; import config from "./config.js";
import { ERR_NOT_READY, errorExit } from "./error.js"; import { ERR_NOT_READY, errorExit } from "./error.js";
import log from "loglevel"; import log from "loglevel";
// @ts-ignore // @ts-ignore
import stringify from "json-stable-stringify"; import stringify from "json-stable-stringify";
import { getStream } from "./streams.js";
import type { StreamFileResponse } from "./streams.js"; import type { StreamFileResponse } from "./streams.js";
import { getStream } from "./streams.js";
const pendingRequests = new NodeCache(); const pendingRequests = new NodeCache();
const processedRequests = new NodeCache({ const processedRequests = new NodeCache({
stdTTL: 60 * 60 * 12, stdTTL: 60 * 60 * 12,
}); });
type PocketAATObject = typeof PocketAAT;
let pocketServer: typeof Pocket;
let _aat: PocketAATObject;
let jsonServer: jayson.Server; let jsonServer: jayson.Server;
interface RPCRequest { interface RPCRequest {
@ -152,55 +142,6 @@ async function processRequest(request: RPCRequest): Promise<RPCResponse> {
return dbData; return dbData;
} }
export function updateAat(aat: PocketAATObject): void {
_aat = aat;
}
export function getAat(): PocketAATObject {
return _aat;
}
export function getPocketServer(): typeof Pocket {
return pocketServer;
}
export async function unlockAccount(
accountPrivateKey: string,
accountPublicKey: string,
accountPassphrase: string
): Promise<PocketAATObject> {
try {
// @ts-ignore
const account = await pocketServer.keybase.importAccount(
Buffer.from(accountPrivateKey, "hex"),
accountPassphrase
);
if (account instanceof Error) {
// noinspection ExceptionCaughtLocallyJS
throw account;
}
// @ts-ignore
await pocketServer.keybase.unlockAccount(
account.addressHex,
accountPassphrase,
0
);
// @ts-ignore
return await PocketAAT.from(
"0.0.1",
accountPublicKey,
accountPublicKey,
accountPrivateKey
);
} catch (e) {
console.error(e);
process.exit(1);
}
}
export async function processRpcRequest( export async function processRpcRequest(
request: JSONRPCRequest, request: JSONRPCRequest,
chain: string chain: string
@ -224,32 +165,7 @@ export async function processRpcRequest(
export async function start() { export async function start() {
if (!config.str("pocket-app-id") || !config.str("pocket-app-key")) { if (!config.str("pocket-app-id") || !config.str("pocket-app-key")) {
const pocketHost = config.str("pocket-host"); errorExit("Please set pocket-app-id and pocket-app-key config options.");
const pocketPort = config.uint("pocket-port");
if (!pocketHost || !pocketPort) {
errorExit(
"Please set pocket-host and pocket-port config options if you do not have an API key set"
);
}
const dispatchURL = new URL(
`http://${config.str("pocket-host")}:${config.uint("pocket-port")}`
);
const rpcProvider = new HttpRpcProvider(dispatchURL);
const configuration = new Configuration();
// @ts-ignore
pocketServer = new Pocket([dispatchURL], rpcProvider, configuration);
updateUsePocketGateway(false);
}
if (!usePocketGateway()) {
updateAat(
await unlockAccount(
<string>config.str("pocket-account-private-key"),
<string>config.str("pocket-account-public-key"),
"0"
)
);
} }
jsonServer = new jayson.Server(rpcMethods, { useContext: true }); jsonServer = new jayson.Server(rpcMethods, { useContext: true });