Fix eth_subscribe to logs, add remaining chains to cli tool (#256)
This commit is contained in:
@@ -3,13 +3,21 @@ import arg from 'arg';
|
|||||||
import clc from "cli-color";
|
import clc from "cli-color";
|
||||||
import util from "util";
|
import util from "util";
|
||||||
|
|
||||||
const chains = {
|
const path = require('path')
|
||||||
CHAIN_BSC__MAINNET: 1006,
|
const protoLoader = require("@grpc/proto-loader");
|
||||||
CHAIN_OPTIMISM__MAINNET: 1005,
|
const grpc = require("@grpc/grpc-js");
|
||||||
CHAIN_ARBITRUM__MAINNET: 1004,
|
|
||||||
CHAIN_POLYGON_POS__MAINNET: 1002,
|
const options = {
|
||||||
CHAIN_ETHEREUM__MAINNET: 100
|
keepCase: true,
|
||||||
}
|
longs: String,
|
||||||
|
enums: String,
|
||||||
|
defaults: true,
|
||||||
|
oneofs: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
const PROTO_PATH = path.join(__dirname, "../../emerald-grpc/proto/blockchain.proto");
|
||||||
|
const packageDefinition = protoLoader.loadSync(PROTO_PATH, options);
|
||||||
|
const emerald = grpc.loadPackageDefinition(packageDefinition).emerald
|
||||||
|
|
||||||
export function cli(args) {
|
export function cli(args) {
|
||||||
let opts = parseArgumentsIntoOptions(args);
|
let opts = parseArgumentsIntoOptions(args);
|
||||||
@@ -18,7 +26,9 @@ export function cli(args) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const client = connect(opts.url, opts.ca, opts.cert, opts.key)
|
const chains = mapChains()
|
||||||
|
|
||||||
|
const client = connect(opts.url, opts.ca, opts.cert, opts.key, emerald)
|
||||||
describe(client, (error, response) => {
|
describe(client, (error, response) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
console.error(clc.red('Connection to ' + opts.url + ' failed: ' + error.message));
|
console.error(clc.red('Connection to ' + opts.url + ' failed: ' + error.message));
|
||||||
@@ -28,11 +38,11 @@ export function cli(args) {
|
|||||||
if (opts.print) {
|
if (opts.print) {
|
||||||
console.log(util.inspect(response, false, null, true /* enable colors */));
|
console.log(util.inspect(response, false, null, true /* enable colors */));
|
||||||
}
|
}
|
||||||
processDescribe(client, response, opts.testRun)
|
processDescribe(client, response, opts.testRun, chains)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function processDescribe(client, response, testRun) {
|
function processDescribe(client, response, testRun, chains) {
|
||||||
let promises = []
|
let promises = []
|
||||||
let statuses = new Map()
|
let statuses = new Map()
|
||||||
|
|
||||||
@@ -58,7 +68,7 @@ function processDescribe(client, response, testRun) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (state === 'AVAIL_OK') {
|
if (state === 'AVAIL_OK') {
|
||||||
promises.push(nativeCall(client, chains[chain], chain))
|
promises.push(nativeCall(client, chains.get(chain), chain))
|
||||||
} else {
|
} else {
|
||||||
status.failed = true
|
status.failed = true
|
||||||
}
|
}
|
||||||
@@ -95,6 +105,14 @@ function processDescribe(client, response, testRun) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function mapChains() {
|
||||||
|
return new Map(
|
||||||
|
emerald.ChainRef.type.value.map(obj => {
|
||||||
|
return [obj.name, obj.number]
|
||||||
|
})
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
function printState(chain, status) {
|
function printState(chain, status) {
|
||||||
console.log(chain + ' -> ' + "state: " + clc.bold(status.state) + " gRPC: " + clc.bold(status.grpc))
|
console.log(chain + ' -> ' + "state: " + clc.bold(status.state) + " gRPC: " + clc.bold(status.grpc))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,25 +1,9 @@
|
|||||||
const grpc = require("@grpc/grpc-js");
|
const grpc = require("@grpc/grpc-js");
|
||||||
const path = require('path')
|
|
||||||
const protoLoader = require("@grpc/proto-loader");
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
const PROTO_PATH = path.join(__dirname, "../../emerald-grpc/proto/blockchain.proto");
|
|
||||||
|
|
||||||
const options = {
|
|
||||||
keepCase: true,
|
|
||||||
longs: String,
|
|
||||||
enums: String,
|
|
||||||
defaults: true,
|
|
||||||
oneofs: true,
|
|
||||||
};
|
|
||||||
|
|
||||||
const packageDefinition = protoLoader.loadSync(PROTO_PATH, options);
|
|
||||||
const emerald = grpc.loadPackageDefinition(packageDefinition).emerald
|
|
||||||
|
|
||||||
|
|
||||||
var id = 100
|
var id = 100
|
||||||
|
|
||||||
export function connect(url, ca, cert, key) {
|
export function connect(url, ca, cert, key, emerald) {
|
||||||
let credentials = grpc.credentials.createInsecure()
|
let credentials = grpc.credentials.createInsecure()
|
||||||
if (ca || cert || key) {
|
if (ca || cert || key) {
|
||||||
console.log("Using TLS")
|
console.log("Using TLS")
|
||||||
|
|||||||
@@ -97,7 +97,11 @@ open class NativeSubscribe(
|
|||||||
}
|
}
|
||||||
|
|
||||||
open fun subscribe(chain: Chain, method: String, params: Any?, matcher: Selector.Matcher): Flux<out Any> =
|
open fun subscribe(chain: Chain, method: String, params: Any?, matcher: Selector.Matcher): Flux<out Any> =
|
||||||
getUpstream(chain).getEgressSubscription().subscribe(method, params, matcher)
|
getUpstream(chain).getEgressSubscription()
|
||||||
|
.subscribe(method, params, matcher)
|
||||||
|
.doOnError {
|
||||||
|
log.error("Error during subscription to $method, chain $chain, params $params", it)
|
||||||
|
}
|
||||||
|
|
||||||
private fun getUpstream(chain: Chain): EthereumLikeMultistream =
|
private fun getUpstream(chain: Chain): EthereumLikeMultistream =
|
||||||
multistreamHolder.getUpstream(chain).let { it as EthereumLikeMultistream }
|
multistreamHolder.getUpstream(chain).let { it as EthereumLikeMultistream }
|
||||||
|
|||||||
@@ -93,6 +93,7 @@ open class EthereumEgressSubscription(
|
|||||||
null
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
null -> emptyList()
|
||||||
else -> throw IllegalArgumentException("Invalid type of address field. Must be string or list of strings")
|
else -> throw IllegalArgumentException("Invalid type of address field. Must be string or list of strings")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -114,6 +115,7 @@ open class EthereumEgressSubscription(
|
|||||||
null
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
null -> emptyList()
|
||||||
else -> throw IllegalArgumentException("Invalid type of topics field. Must be string or list of strings")
|
else -> throw IllegalArgumentException("Invalid type of topics field. Must be string or list of strings")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user