Skip to content

Commit

Permalink
Fix eth_subscribe to logs, add remaining chains to cli tool (#256)
Browse files Browse the repository at this point in the history
  • Loading branch information
KirillPamPam authored Jul 21, 2023
1 parent 121dcf0 commit 675f160
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 29 deletions.
40 changes: 29 additions & 11 deletions dshackle-cli/src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@ import arg from 'arg';
import clc from "cli-color";
import util from "util";

const chains = {
CHAIN_BSC__MAINNET: 1006,
CHAIN_OPTIMISM__MAINNET: 1005,
CHAIN_ARBITRUM__MAINNET: 1004,
CHAIN_POLYGON_POS__MAINNET: 1002,
CHAIN_ETHEREUM__MAINNET: 100
}
const path = require('path')
const protoLoader = require("@grpc/proto-loader");
const grpc = require("@grpc/grpc-js");

const options = {
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) {
let opts = parseArgumentsIntoOptions(args);
Expand All @@ -18,7 +26,9 @@ export function cli(args) {
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) => {
if (error) {
console.error(clc.red('Connection to ' + opts.url + ' failed: ' + error.message));
Expand All @@ -28,11 +38,11 @@ export function cli(args) {
if (opts.print) {
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 statuses = new Map()

Expand All @@ -58,7 +68,7 @@ function processDescribe(client, response, testRun) {
}

if (state === 'AVAIL_OK') {
promises.push(nativeCall(client, chains[chain], chain))
promises.push(nativeCall(client, chains.get(chain), chain))
} else {
status.failed = true
}
Expand Down Expand Up @@ -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) {
console.log(chain + ' -> ' + "state: " + clc.bold(status.state) + " gRPC: " + clc.bold(status.grpc))
}
Expand Down
18 changes: 1 addition & 17 deletions dshackle-cli/src/grpc-clent.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,9 @@
const grpc = require("@grpc/grpc-js");
const path = require('path')
const protoLoader = require("@grpc/proto-loader");
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

export function connect(url, ca, cert, key) {
export function connect(url, ca, cert, key, emerald) {
let credentials = grpc.credentials.createInsecure()
if (ca || cert || key) {
console.log("Using TLS")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ open class NativeSubscribe(
}

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 =
multistreamHolder.getUpstream(chain).let { it as EthereumLikeMultistream }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ open class EthereumEgressSubscription(
null
}
}
null -> emptyList()
else -> throw IllegalArgumentException("Invalid type of address field. Must be string or list of strings")
}
} else {
Expand All @@ -114,6 +115,7 @@ open class EthereumEgressSubscription(
null
}
}
null -> emptyList()
else -> throw IllegalArgumentException("Invalid type of topics field. Must be string or list of strings")
}
} else {
Expand Down

0 comments on commit 675f160

Please sign in to comment.