From 3ad178194ea9694229227e672253815af2701639 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Muhammed=20Kadir=20Y=C3=BCcel?= Date: Tue, 19 Apr 2022 15:09:14 +0300 Subject: [PATCH] Client: Add RPC client support --- dub.json | 1 - source/agora/cli/client/main.d | 21 +++++++++++++++++++-- source/agora/network/RPC.d | 1 - 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/dub.json b/dub.json index d9bf91842d3..03eb0baa82a 100644 --- a/dub.json +++ b/dub.json @@ -68,7 +68,6 @@ "source/agora/consensus/Quorum.d", "source/agora/network/Client.d", "source/agora/network/Manager.d", - "source/agora/network/RPC.d", "source/agora/network/VibeManager.d", "source/agora/api/Registry.d", "source/agora/node/*", diff --git a/source/agora/cli/client/main.d b/source/agora/cli/client/main.d index edbb9ae4f6f..ee3691e19a2 100644 --- a/source/agora/cli/client/main.d +++ b/source/agora/cli/client/main.d @@ -16,14 +16,18 @@ module agora.client.main; import agora.api.FullNode; import agora.client.GenTxProcess; import agora.client.SendTxProcess; +import agora.common.Types : Address; +import agora.network.RPC; import vibe.core.core; import vibe.web.rest; import configy.Read; +import std.algorithm; import std.getopt; import std.stdio; +import core.time; /// Application entry point private int main (string[] args) @@ -47,15 +51,28 @@ int runProcess (string[] args, ref string[] outputs) return 1; } + API makeClient (Address address) + { + if (address.schema == "agora") + return new RPCClient!(API)( + address.host, address.port, + 0.seconds, 1, 5.seconds, 5.seconds, 5.seconds); + + if (address.schema.startsWith("http")) + return new RestInterfaceClient!(API)(address); + + assert(0, "Unsupported address schema"); + } + switch (args[0]) { case "sendtx": return sendTxProcess(args, outputs, (address) { - return new RestInterfaceClient!API(address); + return makeClient(address); }); case "gentx": return genTxProcess(args, outputs, (address) { - return new RestInterfaceClient!API(address); + return makeClient(address); }); default: outputs ~= "Invalid command: '" ~ args[0] ~ "'"; diff --git a/source/agora/network/RPC.d b/source/agora/network/RPC.d index 281da3a988b..4e6ad8ce8ee 100644 --- a/source/agora/network/RPC.d +++ b/source/agora/network/RPC.d @@ -19,7 +19,6 @@ module agora.network.RPC; -static import agora.api.Validator; import agora.common.Ensure; import agora.common.Types; import agora.crypto.Hash;