Rip out the C and Java bindings (#11346)
* Remove the C and Java bindings * update Cargo.lock * [ci]: don't build removed `parity-clib` * [ci]: fix grumbles Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com>
This commit is contained in:
parent
424b38a8d7
commit
b8d9b6f826
@ -113,12 +113,6 @@ validate-chainspecs:
|
||||
script:
|
||||
- ./scripts/gitlab/validate-chainspecs.sh
|
||||
|
||||
test-cpp:
|
||||
stage: build
|
||||
<<: *docker-cache-status
|
||||
script:
|
||||
- ./scripts/gitlab/test-cpp.sh
|
||||
|
||||
test-linux:
|
||||
stage: build
|
||||
<<: *docker-cache-status
|
||||
@ -140,12 +134,6 @@ test-linux-nightly:
|
||||
- ./scripts/gitlab/test-linux.sh nightly
|
||||
allow_failure: true
|
||||
|
||||
build-android:
|
||||
<<: *build-on-linux
|
||||
image: ${REGISTRY}/parity-ci-android:stretch
|
||||
variables:
|
||||
CARGO_TARGET: armv7-linux-androideabi
|
||||
|
||||
build-linux:
|
||||
<<: *build-on-linux
|
||||
only: *releaseable_branches
|
||||
|
@ -1,3 +1,5 @@
|
||||
* The C and Java bindings have been removed. Please use the IPC interface instead.
|
||||
|
||||
## Parity-Ethereum [v2.6.0](https://github.com/paritytech/parity-ethereum/releases/tag/v2.6.0)
|
||||
|
||||
Parity-Ethereum 2.6.0-beta is a minor release that stabilizes the 2.6 branch by
|
||||
|
75
Cargo.lock
generated
75
Cargo.lock
generated
@ -143,11 +143,6 @@ name = "arrayvec"
|
||||
version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "ascii"
|
||||
version = "0.9.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "assert_matches"
|
||||
version = "1.3.0"
|
||||
@ -483,11 +478,6 @@ dependencies = [
|
||||
"num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cesu8"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "cexpr"
|
||||
version = "0.3.6"
|
||||
@ -625,18 +615,6 @@ dependencies = [
|
||||
"cc 1.0.46 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "combine"
|
||||
version = "3.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"ascii 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"either 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "common-types"
|
||||
version = "0.1.0"
|
||||
@ -998,9 +976,6 @@ dependencies = [
|
||||
name = "error-chain"
|
||||
version = "0.12.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"backtrace 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ethabi"
|
||||
@ -2272,24 +2247,6 @@ dependencies = [
|
||||
"libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "jni"
|
||||
version = "0.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"cesu8 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"combine 3.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"jni-sys 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"walkdir 2.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "jni-sys"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "jobserver"
|
||||
version = "0.1.16"
|
||||
@ -3015,18 +2972,6 @@ name = "parity-bytes"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "parity-clib"
|
||||
version = "1.12.0"
|
||||
dependencies = [
|
||||
"futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"jni 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"panic_hook 0.1.0",
|
||||
"parity-ethereum 2.7.0",
|
||||
"tokio 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"tokio-current-thread 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "parity-crypto"
|
||||
version = "0.4.2"
|
||||
@ -5101,14 +5046,6 @@ name = "unicode-xid"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "unreachable"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "untrusted"
|
||||
version = "0.6.2"
|
||||
@ -5270,11 +5207,6 @@ dependencies = [
|
||||
"rlp 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "void"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "walkdir"
|
||||
version = "2.2.7"
|
||||
@ -5478,7 +5410,6 @@ dependencies = [
|
||||
"checksum arrayref 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0d382e583f07208808f6b1249e60848879ba3543f57c32277bf52d69c2f0f0ee"
|
||||
"checksum arrayvec 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)" = "b8d73f9beda665eaa98ab9e4f7442bd4e7de6652587de55b2525e52e29c1b0ba"
|
||||
"checksum arrayvec 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cff77d8686867eceff3105329d4698d96c2391c176d5d03adc90c7389162b5b8"
|
||||
"checksum ascii 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)" = "eab1c04a571841102f5345a8fc0f6bb3d31c315dec879b5c6e42e40ce7ffa34e"
|
||||
"checksum assert_matches 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7deb0a829ca7bcfaf5da70b073a8d128619259a7be8216a355e23f00763059e5"
|
||||
"checksum attohttpc 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "eaf0ec4b0e00f61ee75556ca027485b7b354f4a714d88cc03f4468abd9378c86"
|
||||
"checksum atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652"
|
||||
@ -5509,7 +5440,6 @@ dependencies = [
|
||||
"checksum c2-chacha 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7d64d04786e0f528460fc884753cf8dddcc466be308f6026f8e355c41a0e4101"
|
||||
"checksum cast 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "926013f2860c46252efceabb19f4a6b308197505082c609025aa6706c011d427"
|
||||
"checksum cc 1.0.46 (registry+https://github.com/rust-lang/crates.io-index)" = "0213d356d3c4ea2c18c40b037c3be23cd639825c18f25ee670ac7813beeef99c"
|
||||
"checksum cesu8 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c"
|
||||
"checksum cexpr 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "fce5b5fb86b0c57c20c834c1b412fd09c77c8a59b9473f86272709e78874cd1d"
|
||||
"checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
|
||||
"checksum chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "45912881121cb26fad7c38c17ba7daa18764771836b34fab7d3fbd93ed633878"
|
||||
@ -5518,7 +5448,6 @@ dependencies = [
|
||||
"checksum clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9"
|
||||
"checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f"
|
||||
"checksum cmake 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)" = "6ec65ee4f9c9d16f335091d23693457ed4928657ba4982289d7fafee03bc614a"
|
||||
"checksum combine 3.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "da3da6baa321ec19e1cc41d31bf599f00c783d0517095cdaf0332e3fe8d20680"
|
||||
"checksum const-random 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7b641a8c9867e341f3295564203b1c250eb8ce6cb6126e007941f78c4d2ed7fe"
|
||||
"checksum const-random-macro 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c750ec12b83377637110d5a57f5ae08e895b06c4b16e2bdbf1a94ef717428c59"
|
||||
"checksum criterion 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "938703e165481c8d612ea3479ac8342e5615185db37765162e762ec3523e2fc6"
|
||||
@ -5610,8 +5539,6 @@ dependencies = [
|
||||
"checksum itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1306f3464951f30e30d12373d31c79fbd52d236e5e896fd92f96ec7babbbe60b"
|
||||
"checksum jemalloc-sys 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "0d3b9f3f5c9b31aa0f5ed3260385ac205db665baa41d49bb8338008ae94ede45"
|
||||
"checksum jemallocator 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "43ae63fcfc45e99ab3d1b29a46782ad679e98436c3169d15a167a1108a724b69"
|
||||
"checksum jni 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "294eca097d1dc0bf59de5ab9f7eafa5f77129e9f6464c957ed3ddeb705fb4292"
|
||||
"checksum jni-sys 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130"
|
||||
"checksum jobserver 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "f74e73053eaf95399bf926e48fc7a2a3ce50bd0eaaa2357d391e95b2dcdd4f10"
|
||||
"checksum jsonrpc-core 14.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "fe3b688648f1ef5d5072229e2d672ecb92cbff7d1c79bcf3fd5898f3f3df0970"
|
||||
"checksum jsonrpc-derive 14.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "8609af8f63b626e8e211f52441fcdb6ec54f1a446606b10d5c89ae9bf8a20058"
|
||||
@ -5848,7 +5775,6 @@ dependencies = [
|
||||
"checksum unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526"
|
||||
"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
|
||||
"checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c"
|
||||
"checksum unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56"
|
||||
"checksum untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "55cd1f4b4e96b46aeb8d4855db4a7a9bd96eeeb5c6a1ab54593328761642ce2f"
|
||||
"checksum url 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2a321979c09843d272956e73700d12c4e7d3d92b2ee112b31548aef0d4efc5a6"
|
||||
"checksum url 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "75b414f6c464c879d7f9babf951f23bc3743fb7313c081b2e6ca719067ea9d61"
|
||||
@ -5858,7 +5784,6 @@ dependencies = [
|
||||
"checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a"
|
||||
"checksum vergen 3.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "6aba5e34f93dc7051dfad05b98a18e9156f27e7b431fe1d2398cb6061c0a1dba"
|
||||
"checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd"
|
||||
"checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
|
||||
"checksum walkdir 2.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "9d9d7ed3431229a144296213105a390676cc49c9b6a72bd19f3176c98e129fa1"
|
||||
"checksum want 0.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "797464475f30ddb8830cc529aaaae648d581f99e2036a928877dfde027ddf6b3"
|
||||
"checksum wasi 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fd5442abcac6525a045cc8c795aedb60da7a2e5e89c7bf18a0d5357849bb23c7"
|
||||
|
@ -135,5 +135,4 @@ members = [
|
||||
"chainspec",
|
||||
"ethcore/wasm/run",
|
||||
"evmbin",
|
||||
"parity-clib",
|
||||
]
|
||||
|
@ -1,22 +0,0 @@
|
||||
[package]
|
||||
description = "C bindings for the Parity Ethereum client"
|
||||
name = "parity-clib"
|
||||
version = "1.12.0"
|
||||
license = "GPL-3.0"
|
||||
authors = ["Parity Technologies <admin@parity.io>"]
|
||||
|
||||
[lib]
|
||||
name = "parity"
|
||||
crate-type = ["cdylib", "staticlib"]
|
||||
|
||||
[dependencies]
|
||||
futures = "0.1.6"
|
||||
jni = { version = "0.11", optional = true }
|
||||
panic_hook = { path = "../util/panic-hook" }
|
||||
parity-ethereum = { path = "../", default-features = false }
|
||||
tokio = "0.1.22"
|
||||
tokio-current-thread = "0.1.3"
|
||||
|
||||
[features]
|
||||
default = []
|
||||
final = ["parity-ethereum/final"]
|
@ -1,86 +0,0 @@
|
||||
// Copyright 2018-2019 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Parity.
|
||||
|
||||
// Parity is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Parity is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package io.parity.ethereum;
|
||||
|
||||
/**
|
||||
* Interface to the Parity client.
|
||||
*/
|
||||
public class Parity {
|
||||
/**
|
||||
* Starts the Parity client with the CLI options passed as an array of strings.
|
||||
*
|
||||
* Each space-delimited option corresponds to an array entry.
|
||||
* For example: `["--port", "12345"]`
|
||||
*
|
||||
* @param options The CLI options to start Parity with
|
||||
*/
|
||||
public Parity(String[] options, String loggerMode, String loggerFile) {
|
||||
long config = configFromCli(options);
|
||||
inner = build(config, loggerMode, loggerFile);
|
||||
}
|
||||
|
||||
/** Performs an asynchronous RPC query by spawning a background thread that is executed until
|
||||
* either a response is received or the timeout has been expired.
|
||||
*
|
||||
* @param query The JSON-encoded RPC query to perform
|
||||
* @param timeoutMillis The maximum time in milliseconds that the query will run
|
||||
* @param callback An instance of class which must have a instance method named `callback` that will be
|
||||
* invoke when the result is ready
|
||||
*/
|
||||
public void rpcQuery(String query, long timeoutMillis, Object callback) {
|
||||
rpcQueryNative(inner, query, timeoutMillis, callback);
|
||||
}
|
||||
|
||||
/** Subscribes to a specific WebSocket event that will run in a background thread until it is canceled.
|
||||
*
|
||||
* @param query The JSON-encoded RPC query to perform
|
||||
* @param callback An instance of class which must have a instance method named `callback` that will be invoked
|
||||
* when the result is ready
|
||||
*
|
||||
* @return A pointer to the current sessions which can be used to terminate the session later
|
||||
*/
|
||||
public long subscribeWebSocket(String query, Object callback) {
|
||||
return subscribeWebSocketNative(inner, query, callback);
|
||||
}
|
||||
|
||||
/** Unsubscribes to a specific WebSocket event
|
||||
*
|
||||
* @param session Pointer the the session to terminate
|
||||
*/
|
||||
public void unsubscribeWebSocket(long session) {
|
||||
unsubscribeWebSocketNative(session);
|
||||
}
|
||||
|
||||
// FIXME: `finalize` is deprecated - https://github.com/paritytech/parity-ethereum/issues/10066
|
||||
@Override
|
||||
protected void finalize() {
|
||||
destroy(inner);
|
||||
}
|
||||
|
||||
static {
|
||||
System.loadLibrary("parity");
|
||||
}
|
||||
|
||||
private static native long configFromCli(String[] cliOptions);
|
||||
private static native long build(long config, String loggerMode, String loggerFile);
|
||||
private static native void destroy(long inner);
|
||||
private static native void rpcQueryNative(long inner, String rpc, long timeoutMillis, Object callback);
|
||||
private static native long subscribeWebSocketNative(long inner, String rpc, Object callback);
|
||||
private static native void unsubscribeWebSocketNative(long session);
|
||||
|
||||
private long inner;
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
include(ExternalProject)
|
||||
include_directories("${CMAKE_SOURCE_DIR}/../..")
|
||||
set (CMAKE_CXX_STANDARD 11) # Enforce C++11
|
||||
add_executable(parity-example main.cpp)
|
||||
|
||||
ExternalProject_Add(
|
||||
libparity
|
||||
DOWNLOAD_COMMAND ""
|
||||
CONFIGURE_COMMAND ""
|
||||
BUILD_COMMAND ""
|
||||
COMMAND cargo build -p parity-clib --verbose --color=always # Note: use --release in a real project
|
||||
BINARY_DIR "${CMAKE_SOURCE_DIR}/../../../target"
|
||||
INSTALL_COMMAND ""
|
||||
LOG_BUILD ON)
|
||||
|
||||
add_dependencies(parity-example libparity)
|
||||
target_link_libraries(parity-example "${CMAKE_SOURCE_DIR}/../../../target/debug/${CMAKE_SHARED_LIBRARY_PREFIX}parity${CMAKE_SHARED_LIBRARY_SUFFIX}")
|
@ -1,185 +0,0 @@
|
||||
// Copyright 2015-2019 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Parity Ethereum.
|
||||
|
||||
// Parity Ethereum is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Parity Ethereum is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include <chrono>
|
||||
#include <parity.h>
|
||||
#include <regex>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
void* parity_run(std::vector<const char*>);
|
||||
int parity_subscribe_to_websocket(void*);
|
||||
int parity_rpc_queries(void*);
|
||||
|
||||
const int SUBSCRIPTION_ID_LEN = 18;
|
||||
const size_t TIMEOUT_ONE_MIN_AS_MILLIS = 60 * 1000;
|
||||
const unsigned int CALLBACK_RPC = 1;
|
||||
const unsigned int CALLBACK_WS = 2;
|
||||
|
||||
struct Callback {
|
||||
unsigned int type;
|
||||
long unsigned int counter;
|
||||
};
|
||||
|
||||
// list of rpc queries
|
||||
const std::vector<std::string> rpc_queries {
|
||||
"{\"method\":\"parity_versionInfo\",\"params\":[],\"id\":1,\"jsonrpc\":\"2.0\"}",
|
||||
"{\"method\":\"eth_getTransactionReceipt\",\"params\":[\"0x444172bef57ad978655171a8af2cfd89baa02a97fcb773067aef7794d6913fff\"],\"id\":1,\"jsonrpc\":\"2.0\"}",
|
||||
"{\"method\":\"eth_estimateGas\",\"params\":[{\"from\":\"0x0066Dc48bb833d2B59f730F33952B3c29fE926F5\"}],\"id\":1,\"jsonrpc\":\"2.0\"}",
|
||||
"{\"method\":\"eth_getBalance\",\"params\":[\"0x0066Dc48bb833d2B59f730F33952B3c29fE926F5\"],\"id\":1,\"jsonrpc\":\"2.0\"}"
|
||||
};
|
||||
|
||||
// list of subscriptions
|
||||
const std::vector<std::string> ws_subscriptions {
|
||||
"{\"method\":\"parity_subscribe\",\"params\":[\"eth_getBalance\",[\"0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826\",\"latest\"]],\"id\":1,\"jsonrpc\":\"2.0\"}",
|
||||
"{\"method\":\"parity_subscribe\",\"params\":[\"parity_netPeers\"],\"id\":1,\"jsonrpc\":\"2.0\"}",
|
||||
"{\"method\":\"eth_subscribe\",\"params\":[\"newHeads\"],\"id\":1,\"jsonrpc\":\"2.0\"}"
|
||||
};
|
||||
|
||||
// callback that gets invoked upon an event
|
||||
void callback(void* user_data, const char* response, size_t _len) {
|
||||
Callback* cb = static_cast<Callback*>(user_data);
|
||||
if (cb->type == CALLBACK_RPC) {
|
||||
cb->counter -= 1;
|
||||
} else if (cb->type == CALLBACK_WS) {
|
||||
std::regex is_subscription ("\\{\"jsonrpc\":\"2.0\",\"result\":\"0[xX][a-fA-F0-9]{16}\",\"id\":1\\}");
|
||||
if (std::regex_match(response, is_subscription) == true) {
|
||||
cb->counter -= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
// run full-client
|
||||
{
|
||||
std::vector<const char*> config = {"--no-ipc" , "--jsonrpc-apis=all", "--chain", "kovan"};
|
||||
void* parity = parity_run(config);
|
||||
if (parity_rpc_queries(parity)) {
|
||||
printf("rpc_queries failed\r\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (parity_subscribe_to_websocket(parity)) {
|
||||
printf("ws_queries failed\r\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (parity != nullptr) {
|
||||
parity_destroy(parity);
|
||||
}
|
||||
}
|
||||
|
||||
// run light-client
|
||||
{
|
||||
std::vector<const char*> light_config = {"--no-ipc", "--light", "--jsonrpc-apis=all", "--chain", "kovan"};
|
||||
void* parity = parity_run(light_config);
|
||||
|
||||
if (parity_rpc_queries(parity)) {
|
||||
printf("rpc_queries failed\r\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (parity_subscribe_to_websocket(parity)) {
|
||||
printf("ws_queries failed\r\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (parity != nullptr) {
|
||||
parity_destroy(parity);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int parity_rpc_queries(void* parity) {
|
||||
if (!parity) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
Callback cb { .type = CALLBACK_RPC, .counter = rpc_queries.size() };
|
||||
|
||||
for (auto query : rpc_queries) {
|
||||
if (parity_rpc(parity, query.c_str(), query.length(), TIMEOUT_ONE_MIN_AS_MILLIS, callback, &cb) != 0) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
while(cb.counter != 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int parity_subscribe_to_websocket(void* parity) {
|
||||
if (!parity) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::vector<const void*> sessions;
|
||||
|
||||
Callback cb { .type = CALLBACK_WS, .counter = ws_subscriptions.size() };
|
||||
|
||||
for (auto sub : ws_subscriptions) {
|
||||
void *const session = parity_subscribe_ws(parity, sub.c_str(), sub.length(), callback, &cb);
|
||||
if (!session) {
|
||||
return 1;
|
||||
}
|
||||
sessions.push_back(session);
|
||||
}
|
||||
|
||||
while(cb.counter != 0);
|
||||
std::this_thread::sleep_for(std::chrono::seconds(60));
|
||||
for (auto session : sessions) {
|
||||
parity_unsubscribe_ws(session);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void* parity_run(std::vector<const char*> args) {
|
||||
ParityParams cfg = {
|
||||
.configuration = nullptr,
|
||||
.on_client_restart_cb = callback,
|
||||
.on_client_restart_cb_custom = nullptr,
|
||||
.logger = nullptr
|
||||
};
|
||||
|
||||
std::vector<size_t> str_lens;
|
||||
|
||||
for (auto arg: args) {
|
||||
str_lens.push_back(std::strlen(arg));
|
||||
}
|
||||
|
||||
// make sure no out-of-range access happens here
|
||||
if (args.empty()) {
|
||||
if (parity_config_from_cli(nullptr, nullptr, 0, &cfg.configuration) != 0) {
|
||||
return nullptr;
|
||||
}
|
||||
} else {
|
||||
if (parity_config_from_cli(&args[0], &str_lens[0], args.size(), &cfg.configuration) != 0) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
// enable logging but only the `rpc module` and don't write it to a file
|
||||
char log_mode [] = "rpc=trace";
|
||||
parity_set_logger(log_mode, strlen(log_mode), nullptr, 0, &cfg.logger);
|
||||
|
||||
void *parity = nullptr;
|
||||
if (parity_start(&cfg, &parity) != 0) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return parity;
|
||||
}
|
@ -1,105 +0,0 @@
|
||||
// Copyright 2018-2019 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Parity.
|
||||
|
||||
// Parity is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Parity is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import java.util.Vector;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import io.parity.ethereum.Parity;
|
||||
|
||||
class Main {
|
||||
public static final int ONE_MINUTE_AS_MILLIS = 60 * 1000;
|
||||
|
||||
public static final String[] rpc_queries = {
|
||||
"{\"method\":\"parity_versionInfo\",\"params\":[],\"id\":1,\"jsonrpc\":\"2.0\"}",
|
||||
"{\"method\":\"eth_getTransactionReceipt\",\"params\":[\"0x444172bef57ad978655171a8af2cfd89baa02a97fcb773067aef7794d6913fff\"],\"id\":1,\"jsonrpc\":\"2.0\"}",
|
||||
"{\"method\":\"eth_estimateGas\",\"params\":[{\"from\":\"0x0066Dc48bb833d2B59f730F33952B3c29fE926F5\"}],\"id\":1,\"jsonrpc\":\"2.0\"}",
|
||||
"{\"method\":\"eth_getBalance\",\"params\":[\"0x0066Dc48bb833d2B59f730F33952B3c29fE926F5\"],\"id\":1,\"jsonrpc\":\"2.0\"}"
|
||||
};
|
||||
|
||||
public static final String[] ws_queries = {
|
||||
"{\"method\":\"parity_subscribe\",\"params\":[\"eth_getBalance\",[\"0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826\",\"latest\"]],\"id\":1,\"jsonrpc\":\"2.0\"}",
|
||||
"{\"method\":\"parity_subscribe\",\"params\":[\"parity_netPeers\"],\"id\":1,\"jsonrpc\":\"2.0\"}",
|
||||
"{\"method\":\"eth_subscribe\",\"params\":[\"newHeads\"],\"id\":1,\"jsonrpc\":\"2.0\"}"
|
||||
};
|
||||
|
||||
public static void runParity(String[] config) {
|
||||
String loggerMode = "rpc=trace";
|
||||
String loggerFile = "foo.log";
|
||||
Parity parity = new Parity(config, loggerMode, loggerFile);
|
||||
|
||||
Callback rpcCallback = new Callback(1);
|
||||
Callback webSocketCallback = new Callback(2);
|
||||
|
||||
for (String query : rpc_queries) {
|
||||
parity.rpcQuery(query, ONE_MINUTE_AS_MILLIS, rpcCallback);
|
||||
}
|
||||
|
||||
while (rpcCallback.getNumCallbacks() != 4);
|
||||
|
||||
Vector<Long> sessions = new Vector<Long>();
|
||||
|
||||
for (String ws : ws_queries) {
|
||||
long session = parity.subscribeWebSocket(ws, webSocketCallback);
|
||||
sessions.add(session);
|
||||
}
|
||||
|
||||
try {
|
||||
Thread.sleep(ONE_MINUTE_AS_MILLIS);
|
||||
} catch (Exception e) {
|
||||
System.out.println(e);
|
||||
}
|
||||
|
||||
for (long session : sessions) {
|
||||
parity.unsubscribeWebSocket(session);
|
||||
}
|
||||
|
||||
// Force GC to destroy parity
|
||||
parity = null;
|
||||
System.gc();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String[] full = {"--no-ipc" , "--jsonrpc-apis=all", "--chain", "kovan"};
|
||||
String[] light = {"--no-ipc", "--light", "--jsonrpc-apis=all", "--chain", "kovan"};
|
||||
|
||||
runParity(full);
|
||||
|
||||
try {
|
||||
Thread.sleep(ONE_MINUTE_AS_MILLIS);
|
||||
} catch (Exception e) {
|
||||
System.out.println(e);
|
||||
}
|
||||
|
||||
runParity(light);
|
||||
}
|
||||
}
|
||||
|
||||
class Callback {
|
||||
private AtomicInteger counter;
|
||||
private final int callbackType;
|
||||
|
||||
public Callback(int type) {
|
||||
counter = new AtomicInteger();
|
||||
callbackType = type;
|
||||
}
|
||||
|
||||
public void callback(Object response) {
|
||||
counter.getAndIncrement();
|
||||
}
|
||||
|
||||
public int getNumCallbacks() {
|
||||
return counter.intValue();
|
||||
}
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
parity-clib: Java example
|
||||
===================================
|
||||
|
||||
An example Java application to demonstrate how to use `jni` bindings to parity-ethereum. Note, that the example is built in debug-mode to reduce the build time. If you want to use it in real project use release-mode instead to facilitate all compiler optimizations.
|
||||
|
||||
## How to compile and run
|
||||
|
||||
1. Make sure you have installed [JDK](https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html)
|
||||
2. Run `run.sh`
|
@ -1,15 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
FLAGS="-Xlint:deprecation"
|
||||
PARITY_JAVA="../../Parity.java"
|
||||
# parity-clib must be built with feature `jni` in debug-mode to work
|
||||
PARITY_LIB=".:../../../target/debug/"
|
||||
|
||||
# build
|
||||
cd ..
|
||||
cargo build --features jni
|
||||
cd -
|
||||
javac $FLAGS -d $PWD $PARITY_JAVA
|
||||
javac $FLAGS *.java
|
||||
# Setup the path `libparity.so` and run
|
||||
java -Djava.library.path=$PARITY_LIB Main
|
@ -1,179 +0,0 @@
|
||||
// Copyright 2018-2019 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Parity.
|
||||
|
||||
// Parity is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Parity is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#ifndef _PARITY_H_INCLUDED_
|
||||
#define _PARITY_H_INCLUDED_
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
/// Parameters to pass to `parity_start`.
|
||||
struct ParityParams {
|
||||
/// Configuration object, as handled by the `parity_config_*` functions.
|
||||
/// Note that calling `parity_start` will destroy the configuration object (even on failure).
|
||||
void *configuration;
|
||||
|
||||
/// Callback function to call when the client receives an RPC request to change its chain spec.
|
||||
///
|
||||
/// Will only be called if you enable the `--can-restart` flag.
|
||||
///
|
||||
/// The first parameter of the callback is the value of `on_client_restart_cb_custom`.
|
||||
/// The second and third parameters of the callback are the string pointer and length.
|
||||
void (*on_client_restart_cb)(void* custom, const char* new_chain, size_t new_chain_len);
|
||||
|
||||
/// Custom parameter passed to the `on_client_restart_cb` callback as first parameter.
|
||||
void *on_client_restart_cb_custom;
|
||||
|
||||
/// Logger object which must be created by the `parity_config_logger` function
|
||||
void *logger;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/// Builds a new configuration object by parsing a list of CLI arguments.
|
||||
///
|
||||
/// The first two parameters are string pointers and string lengths. They must have a length equal
|
||||
/// to `len`. The strings don't need to be zero-terminated.
|
||||
///
|
||||
/// On success, the produced object will be written to the `void*` pointed by `out`.
|
||||
///
|
||||
/// Returns 0 on success, and non-zero on error.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```no_run
|
||||
/// void* cfg;
|
||||
/// const char *args[] = {"--light", "--can-restart"};
|
||||
/// size_t str_lens[] = {7, 13};
|
||||
/// if (parity_config_from_cli(args, str_lens, 2, &cfg) != 0) {
|
||||
/// return 1;
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
int parity_config_from_cli(char const* const* args, size_t const* arg_lens, size_t len, void** out);
|
||||
|
||||
/// Builds a new logger object which should be a member of the `ParityParams struct`
|
||||
///
|
||||
/// - log_mode : String representing the log mode according to `Rust LOG` or nullptr to disable logging.
|
||||
/// See module documentation for `ethcore-logger` for more info.
|
||||
/// - log_mode_len : Length of the log_mode or zero to disable logging
|
||||
/// - log_file : String respresenting the file name to write to log to or nullptr to disable logging to a file
|
||||
/// - log_mode_len : Length of the log_file or zero to disable logging to a file
|
||||
/// - logger : Pointer to point to the created `Logger` object
|
||||
|
||||
/// **Important**: This function must only be called exactly once otherwise it will panic. If you want to disable a
|
||||
/// logging mode or logging to a file make sure that you pass the `length` as zero
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```no_run
|
||||
/// void* cfg;
|
||||
/// const char *args[] = {"--light", "--can-restart"};
|
||||
/// size_t str_lens[] = {7, 13};
|
||||
/// if (parity_config_from_cli(args, str_lens, 2, &cfg) != 0) {
|
||||
/// return 1;
|
||||
/// }
|
||||
/// char[] logger_mode = "rpc=trace";
|
||||
/// parity_set_logger(logger_mode, strlen(logger_mode), nullptr, 0, &cfg.logger);
|
||||
/// ```
|
||||
///
|
||||
int parity_set_logger(const char* log_mode, size_t log_mode_len, const char* log_file, size_t log_file_len, void** logger);
|
||||
|
||||
/// Destroys a configuration object created earlier.
|
||||
///
|
||||
/// **Important**: You probably don't need to call this function. Calling `parity_start` destroys
|
||||
/// the configuration object as well (even on failure).
|
||||
void parity_config_destroy(void* cfg);
|
||||
|
||||
/// Starts the parity client in background threads. Returns a pointer to a struct that represents
|
||||
/// the running client. Can also return NULL if the execution completes instantly.
|
||||
///
|
||||
/// **Important**: The configuration object passed inside `cfg` is destroyed when you
|
||||
/// call `parity_start` (even on failure).
|
||||
///
|
||||
/// On success, the produced object will be written to the `void*` pointed by `out`.
|
||||
///
|
||||
/// Returns 0 on success, and non-zero on error.
|
||||
int parity_start(const ParityParams* params, void** out);
|
||||
|
||||
/// Destroys the parity client created with `parity_start`.
|
||||
///
|
||||
/// **Warning**: `parity_start` can return NULL if execution finished instantly, in which case you
|
||||
/// must not call this function.
|
||||
void parity_destroy(void* parity);
|
||||
|
||||
/// Performs an asynchronous RPC request running in a background thread for at most X milliseconds
|
||||
///
|
||||
/// - parity : Reference to the running parity client
|
||||
/// - rpc_query : JSON encoded string representing the RPC request.
|
||||
/// - len : Length of the RPC query
|
||||
/// - timeout_ms : Maximum time that request is waiting for a response
|
||||
/// - response : Callback to invoke when the query gets answered. It will respond with a JSON encoded the string
|
||||
/// with the result both on success and error.
|
||||
/// - ud : Specific user defined data that can used in the callback
|
||||
///
|
||||
/// - On success : The function returns 0
|
||||
/// - On error : The function returns 1
|
||||
///
|
||||
int parity_rpc(const void *const parity, const char* rpc_query, size_t rpc_len, size_t timeout_ms,
|
||||
void (*subscribe)(void* ud, const char* response, size_t len), void* ud);
|
||||
|
||||
|
||||
/// Subscribes to a specific websocket event that will run until it is canceled
|
||||
///
|
||||
/// - parity : Reference to the running parity client
|
||||
/// - ws_query : JSON encoded string representing the websocket event to subscribe to
|
||||
/// - len : Length of the query
|
||||
/// - response : Callback to invoke when a websocket event occurs
|
||||
/// - ud : Specific user defined data that can used in the callback
|
||||
///
|
||||
/// - On success : The function returns an object to the current session
|
||||
/// which can be used cancel the subscription
|
||||
/// - On error : The function returns a null pointer
|
||||
///
|
||||
void* parity_subscribe_ws(const void *const parity, const char* ws_query, size_t len,
|
||||
void (*subscribe)(void* ud, const char* response, size_t len), void* ud);
|
||||
|
||||
/// Unsubscribes from a websocket subscription. Caution this function consumes the session object and must only be
|
||||
/// used exactly once per session.
|
||||
///
|
||||
/// - session : Pointer to the session to unsubscribe from
|
||||
///
|
||||
int parity_unsubscribe_ws(const void *const session);
|
||||
|
||||
/// Sets a callback to call when a panic happens in the Rust code.
|
||||
///
|
||||
/// The callback takes as parameter the custom param (the one passed to this function), plus the
|
||||
/// panic message. You are expected to log the panic message somehow, in order to communicate it to
|
||||
/// the user. A panic always indicates a bug in Parity.
|
||||
///
|
||||
/// Note that this method sets the panic hook for the whole program, and not just for Parity. In
|
||||
/// other words, if you use multiple Rust libraries at once (and not just Parity), then a panic
|
||||
/// in any Rust code will call this callback as well.
|
||||
///
|
||||
/// ## Thread safety
|
||||
///
|
||||
/// The callback can be called from any thread and multiple times simultaneously. Make sure that
|
||||
/// your code is thread safe.
|
||||
///
|
||||
int parity_set_panic_hook(void (*cb)(void* param, const char* msg, size_t msg_len), void* param);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // include guard
|
@ -1,186 +0,0 @@
|
||||
// Copyright 2015-2019 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Parity Ethereum.
|
||||
|
||||
// Parity Ethereum is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Parity Ethereum is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use std::{mem, ptr};
|
||||
use std::ffi::c_void;
|
||||
use std::sync::Arc;
|
||||
|
||||
use {Callback, parity_config_from_cli, parity_destroy, parity_rpc_worker, parity_start, parity_set_logger,
|
||||
parity_unsubscribe_ws, parity_ws_worker, ParityParams};
|
||||
|
||||
use jni::{JavaVM, JNIEnv};
|
||||
use jni::objects::{JClass, JString, JObject, JValue, GlobalRef};
|
||||
use jni::sys::{jlong, jobjectArray, va_list};
|
||||
use parity_ethereum::RunningClient;
|
||||
|
||||
type CheckedQuery<'a> = (&'a RunningClient, String, JavaVM, GlobalRef);
|
||||
|
||||
// Creates a Java callback to a static method named `void callback(Object)`
|
||||
struct JavaCallback<'a> {
|
||||
jvm: JavaVM,
|
||||
callback: GlobalRef,
|
||||
method_name: &'a str,
|
||||
method_descriptor: &'a str,
|
||||
}
|
||||
|
||||
impl<'a> JavaCallback<'a> {
|
||||
fn new(jvm: JavaVM, callback: GlobalRef) -> Self {
|
||||
Self {
|
||||
jvm,
|
||||
callback,
|
||||
method_name: "callback",
|
||||
method_descriptor: "(Ljava/lang/Object;)V",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Callback for JavaCallback<'a> {
|
||||
fn call(&self, msg: &str) {
|
||||
let env = self.jvm.attach_current_thread().expect("JavaVM should have an environment; qed");
|
||||
let java_str = env.new_string(msg.to_string()).expect("Rust String is valid JString; qed");
|
||||
let val = &[JValue::Object(JObject::from(java_str))];
|
||||
env.call_method(self.callback.as_obj(), self.method_name, self.method_descriptor, val).expect(
|
||||
"The callback must be an instance method and be named \"void callback(Object)\"; qed)");
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "system" fn Java_io_parity_ethereum_Parity_configFromCli(env: JNIEnv, _: JClass, cli: jobjectArray) -> jlong {
|
||||
let cli_len = env.get_array_length(cli).expect("invalid Java bindings") as usize;
|
||||
|
||||
let mut jni_strings = Vec::with_capacity(cli_len);
|
||||
let mut opts = Vec::with_capacity(cli_len);
|
||||
let mut opts_lens = Vec::with_capacity(cli_len);
|
||||
|
||||
for n in 0..cli_len as i32 {
|
||||
let elem = env.get_object_array_element(cli, n).expect("invalid Java bindings");
|
||||
let elem_str: JString = elem.into();
|
||||
match env.get_string(elem_str) {
|
||||
Ok(s) => {
|
||||
opts.push(s.as_ptr());
|
||||
opts_lens.push(s.to_bytes().len());
|
||||
jni_strings.push(s);
|
||||
}
|
||||
Err(err) => {
|
||||
let _ = env.throw_new("java/lang/Exception", err.to_string());
|
||||
return 0
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
let mut out = ptr::null_mut();
|
||||
match parity_config_from_cli(opts.as_ptr(), opts_lens.as_ptr(), cli_len, &mut out) {
|
||||
0 => out as jlong,
|
||||
_ => {
|
||||
let _ = env.throw_new("java/lang/Exception", "failed to create config object");
|
||||
0
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "system" fn Java_io_parity_ethereum_Parity_build(
|
||||
env: JNIEnv,
|
||||
_: JClass,
|
||||
config: va_list,
|
||||
logger_mode: JString,
|
||||
logger_file: JString
|
||||
) -> jlong {
|
||||
let mut params = ParityParams {
|
||||
configuration: config,
|
||||
.. mem::zeroed()
|
||||
};
|
||||
|
||||
let logger_mode: String = env.get_string(logger_mode).expect("valid JString; qed").into();
|
||||
let logger_file: String = env.get_string(logger_file).expect("valid JString; qed").into();
|
||||
|
||||
parity_set_logger(logger_mode.as_ptr(), logger_mode.as_bytes().len(), logger_file.as_ptr(),
|
||||
logger_file.as_bytes().len(), &mut params.logger);
|
||||
|
||||
let mut out = ptr::null_mut();
|
||||
match parity_start(¶ms, &mut out) {
|
||||
0 => out as jlong,
|
||||
_ => {
|
||||
let _ = env.throw_new("java/lang/Exception", "failed to start Parity");
|
||||
0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "system" fn Java_io_parity_ethereum_Parity_destroy(_env: JNIEnv, _: JClass, parity: va_list) {
|
||||
parity_destroy(parity);
|
||||
}
|
||||
|
||||
unsafe fn java_query_checker<'a>(client: va_list, rpc: JString, callback: JObject, env: &JNIEnv<'a>)
|
||||
-> Result<CheckedQuery<'a>, String> {
|
||||
let query: String = env.get_string(rpc)
|
||||
.map(Into::into)
|
||||
.map_err(|e| e.to_string())?;
|
||||
|
||||
let client: &RunningClient = &*(client as *const RunningClient);
|
||||
let jvm = env.get_java_vm().map_err(|e| e.to_string())?;
|
||||
let global_ref = env.new_global_ref(callback).map_err(|e| e.to_string())?;
|
||||
Ok((client, query, jvm, global_ref))
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "system" fn Java_io_parity_ethereum_Parity_rpcQueryNative(
|
||||
env: JNIEnv,
|
||||
_: JClass,
|
||||
parity: va_list,
|
||||
rpc: JString,
|
||||
timeout_ms: jlong,
|
||||
callback: JObject,
|
||||
)
|
||||
{
|
||||
let _ = java_query_checker(parity, rpc, callback, &env)
|
||||
.map(|(client, query, jvm, global_ref)| {
|
||||
let callback = Arc::new(JavaCallback::new(jvm, global_ref));
|
||||
parity_rpc_worker(client, &query, callback, timeout_ms as u64);
|
||||
})
|
||||
.map_err(|e| {
|
||||
let _ = env.throw_new("java/lang/Exception", e);
|
||||
});
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "system" fn Java_io_parity_ethereum_Parity_subscribeWebSocketNative(
|
||||
env: JNIEnv,
|
||||
_: JClass,
|
||||
parity: va_list,
|
||||
rpc: JString,
|
||||
callback: JObject,
|
||||
) -> va_list {
|
||||
|
||||
java_query_checker(parity, rpc, callback, &env)
|
||||
.map(move |(client, query, jvm, global_ref)| {
|
||||
let callback = Arc::new(JavaCallback::new(jvm, global_ref));
|
||||
parity_ws_worker(client, &query, callback) as va_list
|
||||
})
|
||||
.unwrap_or_else(|e| {
|
||||
let _ = env.throw_new("java/lang/Exception", e);
|
||||
ptr::null_mut()
|
||||
})
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "system" fn Java_io_parity_ethereum_Parity_unsubscribeWebSocketNative(
|
||||
_: JNIEnv,
|
||||
_: JClass,
|
||||
session: va_list) {
|
||||
parity_unsubscribe_ws(session as *const c_void);
|
||||
}
|
@ -1,304 +0,0 @@
|
||||
// Copyright 2015-2019 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Parity Ethereum.
|
||||
|
||||
// Parity Ethereum is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Parity Ethereum is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Note that all the structs and functions here are documented in `parity.h`, to avoid
|
||||
//! duplicating documentation.
|
||||
|
||||
extern crate futures;
|
||||
extern crate panic_hook;
|
||||
extern crate parity_ethereum;
|
||||
extern crate tokio;
|
||||
extern crate tokio_current_thread;
|
||||
|
||||
#[cfg(feature = "jni")]
|
||||
extern crate jni;
|
||||
|
||||
#[cfg(feature = "jni")]
|
||||
mod java;
|
||||
|
||||
use std::ffi::CString;
|
||||
use std::os::raw::{c_char, c_void, c_int};
|
||||
use std::{panic, ptr, slice, str, thread};
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
||||
use futures::{Future, Stream};
|
||||
use futures::sync::mpsc;
|
||||
use parity_ethereum::{PubSubSession, RunningClient};
|
||||
use tokio_current_thread::CurrentThread;
|
||||
|
||||
type CCallback = Option<extern "C" fn(*mut c_void, *const c_char, usize)>;
|
||||
type CheckedQuery<'a> = (&'a RunningClient, &'static str);
|
||||
|
||||
pub mod error {
|
||||
pub const EMPTY: &str = r#"{"jsonrpc":"2.0","result":"null","id":1}"#;
|
||||
pub const TIMEOUT: &str = r#"{"jsonrpc":"2.0","result":"timeout","id":1}"#;
|
||||
pub const SUBSCRIBE: &str = r#"{"jsonrpc":"2.0","result":"subcribe_fail","id":1}"#;
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct ParityParams {
|
||||
pub configuration: *mut c_void,
|
||||
pub on_client_restart_cb: CCallback,
|
||||
pub on_client_restart_cb_custom: *mut c_void,
|
||||
pub logger: *mut c_void
|
||||
}
|
||||
|
||||
/// Trait representing a callback that passes a string
|
||||
pub(crate) trait Callback: Send + Sync {
|
||||
fn call(&self, msg: &str);
|
||||
}
|
||||
|
||||
// Internal structure for handling callbacks that get passed a string.
|
||||
struct CallbackStr {
|
||||
user_data: *mut c_void,
|
||||
function: CCallback,
|
||||
}
|
||||
|
||||
unsafe impl Send for CallbackStr {}
|
||||
unsafe impl Sync for CallbackStr {}
|
||||
impl Callback for CallbackStr {
|
||||
fn call(&self, msg: &str) {
|
||||
if let Some(ref cb) = self.function {
|
||||
let cstr = CString::new(msg).expect("valid string with no nul bytes in the middle; qed").into_raw();
|
||||
cb(self.user_data, cstr, msg.len())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern fn parity_config_from_cli(
|
||||
args: *const *const c_char,
|
||||
args_lens: *const usize,
|
||||
len: usize,
|
||||
output: *mut *mut c_void
|
||||
) -> c_int {
|
||||
panic::catch_unwind(|| {
|
||||
*output = ptr::null_mut();
|
||||
|
||||
let args = {
|
||||
let arg_ptrs = slice::from_raw_parts(args, len);
|
||||
let arg_lens = slice::from_raw_parts(args_lens, len);
|
||||
|
||||
let mut args = Vec::with_capacity(len + 1);
|
||||
args.push("parity".to_owned());
|
||||
|
||||
for (&arg, &len) in arg_ptrs.iter().zip(arg_lens.iter()) {
|
||||
let string = slice::from_raw_parts(arg as *const u8, len);
|
||||
match String::from_utf8(string.to_owned()) {
|
||||
Ok(a) => args.push(a),
|
||||
Err(_) => return 1,
|
||||
};
|
||||
}
|
||||
args
|
||||
};
|
||||
|
||||
match parity_ethereum::Configuration::parse_cli(&args) {
|
||||
Ok(mut cfg) => {
|
||||
// Always disable the auto-updater when used as a library.
|
||||
cfg.args.arg_auto_update = "none".to_owned();
|
||||
|
||||
let cfg = Box::into_raw(Box::new(cfg));
|
||||
*output = cfg as *mut _;
|
||||
0
|
||||
},
|
||||
Err(_) => {
|
||||
1
|
||||
},
|
||||
}
|
||||
}).unwrap_or(1)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern fn parity_config_destroy(cfg: *mut c_void) {
|
||||
let _ = panic::catch_unwind(|| {
|
||||
let _cfg = Box::from_raw(cfg as *mut parity_ethereum::Configuration);
|
||||
});
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern fn parity_start(cfg: *const ParityParams, output: *mut *mut c_void) -> c_int {
|
||||
panic::catch_unwind(|| {
|
||||
*output = ptr::null_mut();
|
||||
let cfg: &ParityParams = &*cfg;
|
||||
let logger = Arc::from_raw(cfg.logger as *mut parity_ethereum::RotatingLogger);
|
||||
let config = Box::from_raw(cfg.configuration as *mut parity_ethereum::Configuration);
|
||||
|
||||
let on_client_restart_cb = {
|
||||
let cb = CallbackStr {
|
||||
user_data: cfg.on_client_restart_cb_custom,
|
||||
function: cfg.on_client_restart_cb,
|
||||
};
|
||||
move |new_chain: String| { cb.call(&new_chain); }
|
||||
};
|
||||
|
||||
let action = match parity_ethereum::start(*config, logger, on_client_restart_cb, || {}) {
|
||||
Ok(action) => action,
|
||||
Err(_) => return 1,
|
||||
};
|
||||
|
||||
match action {
|
||||
parity_ethereum::ExecutionAction::Instant(Some(s)) => { println!("{}", s); 0 },
|
||||
parity_ethereum::ExecutionAction::Instant(None) => 0,
|
||||
parity_ethereum::ExecutionAction::Running(client) => {
|
||||
*output = Box::into_raw(Box::new(client)) as *mut c_void;
|
||||
0
|
||||
}
|
||||
}
|
||||
}).unwrap_or(1)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern fn parity_destroy(client: *mut c_void) {
|
||||
let _ = panic::catch_unwind(|| {
|
||||
let client = Box::from_raw(client as *mut RunningClient);
|
||||
client.shutdown();
|
||||
});
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern fn parity_rpc(
|
||||
client: *const c_void,
|
||||
query: *const c_char,
|
||||
len: usize,
|
||||
timeout_ms: usize,
|
||||
callback: CCallback,
|
||||
user_data: *mut c_void,
|
||||
) -> c_int {
|
||||
panic::catch_unwind(|| {
|
||||
if let Some((client, query)) = parity_rpc_query_checker(client, query, len) {
|
||||
let callback = Arc::new(CallbackStr {user_data, function: callback} );
|
||||
parity_rpc_worker(client, query, callback, timeout_ms as u64);
|
||||
0
|
||||
} else {
|
||||
1
|
||||
}
|
||||
}).unwrap_or(1)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern fn parity_subscribe_ws(
|
||||
client: *const c_void,
|
||||
query: *const c_char,
|
||||
len: usize,
|
||||
callback: CCallback,
|
||||
user_data: *mut c_void,
|
||||
) -> *const c_void {
|
||||
panic::catch_unwind(|| {
|
||||
if let Some((client, query)) = parity_rpc_query_checker(client, query, len) {
|
||||
let callback = Arc::new(CallbackStr { user_data, function: callback});
|
||||
parity_ws_worker(client, query, callback)
|
||||
} else {
|
||||
ptr::null()
|
||||
}
|
||||
})
|
||||
.unwrap_or(ptr::null())
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern fn parity_unsubscribe_ws(session: *const c_void) {
|
||||
let _ = panic::catch_unwind(|| {
|
||||
let _session = Arc::from_raw(session as *const PubSubSession);
|
||||
});
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern fn parity_set_panic_hook(callback: CCallback, param: *mut c_void) {
|
||||
let cb = CallbackStr {user_data: param, function: callback};
|
||||
panic_hook::set_with(move |panic_msg| {
|
||||
cb.call(panic_msg);
|
||||
});
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern fn parity_set_logger(
|
||||
logger_mode: *const u8,
|
||||
logger_mode_len: usize,
|
||||
log_file: *const u8,
|
||||
log_file_len: usize,
|
||||
logger: *mut *mut c_void) {
|
||||
|
||||
let mut logger_cfg = parity_ethereum::LoggerConfig::default();
|
||||
logger_cfg.mode = String::from_utf8(slice::from_raw_parts(logger_mode, logger_mode_len).to_owned()).ok();
|
||||
|
||||
// Make sure an empty string is not constructed as file name (to prevent panic)
|
||||
if log_file_len != 0 && !log_file.is_null() {
|
||||
logger_cfg.file = String::from_utf8(slice::from_raw_parts(log_file, log_file_len).to_owned()).ok();
|
||||
}
|
||||
|
||||
*logger = Arc::into_raw(parity_ethereum::setup_log(&logger_cfg).expect("Logger initialized only once; qed")) as *mut _;
|
||||
}
|
||||
|
||||
// WebSocket event loop
|
||||
fn parity_ws_worker(client: &RunningClient, query: &str, callback: Arc<dyn Callback>) -> *const c_void {
|
||||
let (tx, mut rx) = mpsc::channel(1);
|
||||
let session = Arc::new(PubSubSession::new(tx));
|
||||
let query_future = client.rpc_query(query, Some(session.clone()));
|
||||
let weak_session = Arc::downgrade(&session);
|
||||
let _handle = thread::Builder::new()
|
||||
.name("ws-subscriber".into())
|
||||
.spawn(move || {
|
||||
// Wait for subscription ID
|
||||
// Note this may block forever and be can't destroyed using the session object
|
||||
// However, this will likely timeout or be catched the RPC layer
|
||||
if let Ok(Some(response)) = query_future.wait() {
|
||||
callback.call(&response);
|
||||
} else {
|
||||
callback.call(error::SUBSCRIBE);
|
||||
return;
|
||||
}
|
||||
|
||||
while weak_session.upgrade().map_or(0, |session| Arc::strong_count(&session)) > 1 {
|
||||
for response in rx.by_ref().wait() {
|
||||
if let Ok(r) = response {
|
||||
callback.call(&r);
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.expect("rpc-subscriber thread shouldn't fail; qed");
|
||||
Arc::into_raw(session) as *const c_void
|
||||
}
|
||||
|
||||
// RPC event loop that runs for at most `timeout_ms`
|
||||
fn parity_rpc_worker(client: &RunningClient, query: &str, callback: Arc<dyn Callback>, timeout_ms: u64) {
|
||||
let cb = callback.clone();
|
||||
let query = client.rpc_query(query, None).map(move |response| {
|
||||
let response = response.unwrap_or_else(|| error::EMPTY.to_string());
|
||||
callback.call(&response);
|
||||
});
|
||||
|
||||
let _handle = thread::Builder::new()
|
||||
.name("rpc_query".to_string())
|
||||
.spawn(move || {
|
||||
let mut current_thread = CurrentThread::new();
|
||||
current_thread.spawn(query);
|
||||
let _ = current_thread
|
||||
.run_timeout(Duration::from_millis(timeout_ms))
|
||||
.map_err(|_e| {
|
||||
cb.call(error::TIMEOUT);
|
||||
});
|
||||
})
|
||||
.expect("rpc-query thread shouldn't fail; qed");
|
||||
}
|
||||
|
||||
unsafe fn parity_rpc_query_checker<'a>(client: *const c_void, query: *const c_char, len: usize)
|
||||
-> Option<CheckedQuery<'a>>
|
||||
{
|
||||
let query_str = str::from_utf8(slice::from_raw_parts(query as *const u8, len)).ok()?;
|
||||
let client: &RunningClient = &*(client as *const RunningClient);
|
||||
Some((client, query_str))
|
||||
}
|
@ -6,45 +6,33 @@ set -u # treat unset variables as error
|
||||
export CC="sccache "$CC
|
||||
export CXX="sccache "$CXX
|
||||
echo "__________Show ENVIROMENT__________"
|
||||
echo "CI_SERVER_NAME: " $CI_SERVER_NAME
|
||||
echo "CARGO_HOME: " $CARGO_HOME
|
||||
echo "CARGO_TARGET: " $CARGO_TARGET
|
||||
echo "CC: " $CC
|
||||
echo "CXX: " $CXX
|
||||
#strip ON
|
||||
export RUSTFLAGS=" -C link-arg=-s"
|
||||
export RUSTFLAGS+=" -C link-arg=-s"
|
||||
|
||||
echo "_____ Building target: "$CARGO_TARGET" _____"
|
||||
if [ "${CARGO_TARGET}" = "armv7-linux-androideabi" ]
|
||||
if [ "${CARGO_TARGET}" = "x86_64-unknown-linux-gnu" ] || [ "${CARGO_TARGET}" = "x86_64-apple-darwin" ]
|
||||
then
|
||||
time cargo build --target $CARGO_TARGET --verbose --color=always --release -p parity-clib --features final
|
||||
else
|
||||
if [ "${CARGO_TARGET}" = "x86_64-unknown-linux-gnu" ] || [ "${CARGO_TARGET}" = "x86_64-apple-darwin" ]
|
||||
then
|
||||
# NOTE: Enables the aes-ni instructions for RustCrypto dependency.
|
||||
# If you change this please remember to also update .cargo/config
|
||||
export RUSTFLAGS="$RUSTFLAGS -Ctarget-feature=+aes,+sse2,+ssse3"
|
||||
fi
|
||||
time cargo build --target $CARGO_TARGET --verbose --color=always --release --features final
|
||||
time cargo build --target $CARGO_TARGET --verbose --color=always --release -p evmbin
|
||||
time cargo build --target $CARGO_TARGET --verbose --color=always --release -p ethstore-cli
|
||||
time cargo build --target $CARGO_TARGET --verbose --color=always --release -p ethkey-cli
|
||||
# NOTE: Enables the aes-ni instructions for RustCrypto dependency.
|
||||
# If you change this please remember to also update .cargo/config
|
||||
export RUSTFLAGS+=" -C target-feature=+aes,+sse2,+ssse3"
|
||||
fi
|
||||
time cargo build --target $CARGO_TARGET --verbose --color=always --release --features final
|
||||
time cargo build --target $CARGO_TARGET --verbose --color=always --release -p evmbin
|
||||
time cargo build --target $CARGO_TARGET --verbose --color=always --release -p ethstore-cli
|
||||
time cargo build --target $CARGO_TARGET --verbose --color=always --release -p ethkey-cli
|
||||
|
||||
echo "_____ Post-processing binaries _____"
|
||||
rm -rf artifacts/*
|
||||
mkdir -p artifacts/$CARGO_TARGET
|
||||
cd artifacts/$CARGO_TARGET
|
||||
|
||||
if [ "${CARGO_TARGET}" = "armv7-linux-androideabi" ]
|
||||
then
|
||||
cp -v ../../target/$CARGO_TARGET/release/libparity.so ./libparity.so
|
||||
else
|
||||
cp -v ../../target/$CARGO_TARGET/release/parity ./parity
|
||||
cp -v ../../target/$CARGO_TARGET/release/parity-evm ./parity-evm
|
||||
cp -v ../../target/$CARGO_TARGET/release/ethstore ./ethstore
|
||||
cp -v ../../target/$CARGO_TARGET/release/ethkey ./ethkey
|
||||
fi
|
||||
cp -v ../../target/$CARGO_TARGET/release/parity ./parity
|
||||
cp -v ../../target/$CARGO_TARGET/release/parity-evm ./parity-evm
|
||||
cp -v ../../target/$CARGO_TARGET/release/ethstore ./ethstore
|
||||
cp -v ../../target/$CARGO_TARGET/release/ethkey ./ethkey
|
||||
|
||||
echo "_____ Calculating checksums _____"
|
||||
for binary in $(ls)
|
||||
|
@ -1,21 +0,0 @@
|
||||
#!/bin/bash
|
||||
echo "________Running test-cpp.sh________"
|
||||
set -e # fail on any error
|
||||
set -u # treat unset variables as error
|
||||
#use nproc `linux only
|
||||
THREADS=$(nproc)
|
||||
export CC="sccache gcc"
|
||||
export CXX="sccache g++"
|
||||
|
||||
echo "________Running the C++ example________"
|
||||
DIR=parity-clib/examples/cpp/build
|
||||
mkdir -p $DIR
|
||||
cd $DIR
|
||||
cmake ..
|
||||
make VERBOSE=1 -j $THREADS
|
||||
# Note: we don't try to run the example because it tries to sync Kovan, and we don't want
|
||||
# that to happen on CI
|
||||
cd -
|
||||
rm -rf $DIR
|
||||
#show sccache statistics
|
||||
sccache --show-stats
|
Loading…
Reference in New Issue
Block a user