Skip to content

Commit

Permalink
Client: Add RPC client support
Browse files Browse the repository at this point in the history
  • Loading branch information
Muhammed Kadir Yücel authored and hewison-chris committed Apr 19, 2022
1 parent 2b0a492 commit 3ad1781
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
1 change: 0 additions & 1 deletion dub.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/*",
Expand Down
21 changes: 19 additions & 2 deletions source/agora/cli/client/main.d
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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] ~ "'";
Expand Down
1 change: 0 additions & 1 deletion source/agora/network/RPC.d
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 3ad1781

Please sign in to comment.