Page MenuHomePhabricator

D17686.id52799.diff
No OneTemporary

D17686.id52799.diff

diff --git a/chronik/chronik-cpp/chronik.h b/chronik/chronik-cpp/chronik.h
--- a/chronik/chronik-cpp/chronik.h
+++ b/chronik/chronik-cpp/chronik.h
@@ -29,6 +29,8 @@
static const uint32_t DEFAULT_ELECTRUM_MAX_HISTORY{200'000};
+static constexpr size_t MAX_LENGTH_DONATION_ADDRESS{80};
+
// Registers Chronik indexer as ValidationInterface, listens to HTTP queries
bool Start(const ArgsManager &args, const Config &config,
const node::NodeContext &node, bool fWipe);
diff --git a/chronik/chronik-cpp/chronik.cpp b/chronik/chronik-cpp/chronik.cpp
--- a/chronik/chronik-cpp/chronik.cpp
+++ b/chronik/chronik-cpp/chronik.cpp
@@ -83,6 +83,17 @@
.c_str())}};
}
+ const std::string donation_address =
+ args.GetArg("-chronikelectrumdonationaddress", "");
+ if (donation_address.length() > MAX_LENGTH_DONATION_ADDRESS) {
+ return {
+ {_(strprintf(
+ "The -chronikelectrumdonationaddress parameter must be at "
+ "most %u characters long.",
+ MAX_LENGTH_DONATION_ADDRESS)
+ .c_str())}};
+ }
+
return {{
.net = ParseNet(params.NetworkIDString()),
.datadir = args.GetDataDirBase().u8string(),
@@ -116,6 +127,8 @@
.electrum_cert_path = args.GetArg("-chronikelectrumcert", ""),
.electrum_privkey_path = args.GetArg("-chronikelectrumprivkey", ""),
.electrum_max_history = static_cast<uint32_t>(electrum_max_history),
+ .electrum_donation_address =
+ args.GetArg("-chronikelectrumdonationaddress", ""),
}};
}
diff --git a/chronik/chronik-http/src/electrum.rs b/chronik/chronik-http/src/electrum.rs
--- a/chronik/chronik-http/src/electrum.rs
+++ b/chronik/chronik-http/src/electrum.rs
@@ -64,6 +64,8 @@
pub tls_privkey_path: String,
/// Maximum transaction history length
pub max_history: u32,
+ /// Server donation address
+ pub donation_address: String,
}
/// Chronik Electrum server, holding all the data/handles required to serve an
@@ -76,6 +78,7 @@
tls_cert_path: String,
tls_privkey_path: String,
max_history: u32,
+ donation_address: String,
}
/// Errors for [`ChronikElectrumServer`].
@@ -136,6 +139,7 @@
tls_cert_path: params.tls_cert_path,
tls_privkey_path: params.tls_privkey_path,
max_history: params.max_history,
+ donation_address: params.donation_address,
})
}
@@ -143,7 +147,9 @@
pub async fn serve(self) -> Result<()> {
// The behavior is to bind the endpoint name to its method name like so:
// endpoint.method as the name of the RPC
- let server_endpoint = Arc::new(ChronikElectrumRPCServerEndpoint {});
+ let server_endpoint = Arc::new(ChronikElectrumRPCServerEndpoint {
+ donation_address: self.donation_address,
+ });
let blockchain_endpoint =
Arc::new(ChronikElectrumRPCBlockchainEndpoint {
indexer: self.indexer,
@@ -333,7 +339,9 @@
}};
}
-struct ChronikElectrumRPCServerEndpoint {}
+struct ChronikElectrumRPCServerEndpoint {
+ donation_address: String,
+}
struct ChronikElectrumRPCBlockchainEndpoint {
indexer: ChronikIndexerRef,
@@ -343,6 +351,11 @@
#[rpc_impl(name = "server")]
impl ChronikElectrumRPCServerEndpoint {
+ async fn donation_address(&self, params: Value) -> Result<Value, RPCError> {
+ check_max_number_of_params!(params, 0);
+ Ok(json!(self.donation_address))
+ }
+
async fn ping(&self, params: Value) -> Result<Value, RPCError> {
check_max_number_of_params!(params, 0);
Ok(Value::Null)
diff --git a/chronik/chronik-lib/src/bridge.rs b/chronik/chronik-lib/src/bridge.rs
--- a/chronik/chronik-lib/src/bridge.rs
+++ b/chronik/chronik-lib/src/bridge.rs
@@ -190,6 +190,7 @@
tls_cert_path: params.electrum_cert_path,
tls_privkey_path: params.electrum_privkey_path,
max_history: params.electrum_max_history,
+ donation_address: params.electrum_donation_address,
})?;
runtime.spawn({
let node = Arc::clone(&node);
diff --git a/chronik/chronik-lib/src/ffi.rs b/chronik/chronik-lib/src/ffi.rs
--- a/chronik/chronik-lib/src/ffi.rs
+++ b/chronik/chronik-lib/src/ffi.rs
@@ -55,6 +55,8 @@
pub electrum_privkey_path: String,
/// Maximum transaction history length for an Electrum request
pub electrum_max_history: u32,
+ /// Donation address for public Electrum servers.
+ pub electrum_donation_address: String,
}
/// Settings for tuning the TxNumCache.
diff --git a/src/init.cpp b/src/init.cpp
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -752,6 +752,14 @@
strprintf("Largest tx history we are willing to serve. (default: %u)",
chronik::DEFAULT_ELECTRUM_MAX_HISTORY),
ArgsManager::ALLOW_INT, OptionsCategory::HIDDEN);
+ argsman.AddArg(
+ "-chronikelectrumdonationaddress",
+ strprintf(
+ "The server donation address. No checks are done on the server "
+ "side to ensure this is a valid eCash address, it is just relayed "
+ "to clients verbatim as a text string (%u characters maximum).",
+ chronik::MAX_LENGTH_DONATION_ADDRESS),
+ ArgsManager::ALLOW_STRING, OptionsCategory::HIDDEN);
#endif
argsman.AddArg(
"-blockfilterindex=<type>",
diff --git a/test/functional/chronik_electrum_basic.py b/test/functional/chronik_electrum_basic.py
--- a/test/functional/chronik_electrum_basic.py
+++ b/test/functional/chronik_electrum_basic.py
@@ -4,6 +4,7 @@
"""
Test Chronik's electrum interface
"""
+from test_framework.address import ADDRESS_ECREG_UNSPENDABLE
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, chronikelectrum_port, get_cli_version
@@ -29,6 +30,7 @@
self.node = self.nodes[0]
self.client = self.node.get_chronik_electrum_client()
self.test_rpc_errors()
+ self.test_donation_address()
self.test_ping()
self.test_server_version()
# Run this last as it invalidates self.client
@@ -51,6 +53,24 @@
response.error, {"code": -32602, "message": "Expected at most 0 parameters"}
)
+ def test_donation_address(self):
+ assert_equal(self.client.server.donation_address().result, "")
+
+ self.node.stop_node()
+ self.node.assert_start_raises_init_error(
+ self.extra_args[0] + [f"-chronikelectrumdonationaddress={81 * 'a'}"],
+ "Error: The -chronikelectrumdonationaddress parameter must be at most 80 characters long.",
+ )
+
+ for address in ("lorem_ipsum", ADDRESS_ECREG_UNSPENDABLE, 80 * "a"):
+ self.restart_node(
+ 0,
+ extra_args=self.extra_args[0]
+ + [f"-chronikelectrumdonationaddress={address}"],
+ )
+ self.client = self.node.get_chronik_electrum_client()
+ assert_equal(self.client.server.donation_address().result, address)
+
def test_ping(self):
# This method return {... "result":null} which JSON-decodes to None
response = self.client.server.ping()

File Metadata

Mime Type
text/plain
Expires
Tue, May 20, 23:01 (4 h, 49 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5865685
Default Alt Text
D17686.id52799.diff (7 KB)

Event Timeline