Skip to content

Commit e29dd6d

Browse files
committed
rpc: implement network check and framing
1 parent 5ca11e8 commit e29dd6d

File tree

20 files changed

+890
-109
lines changed

20 files changed

+890
-109
lines changed

Cargo.lock

Lines changed: 20 additions & 43 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,15 @@ io-reactor = "0.6.0"
2828
cyphernet = { version = "0.5.2", features = ["tor", "dns", "ed25519", "p2p-ed25519"] }
2929
microservices = { version = "0.12.0" }
3030
netservices = { version = "0.12.0-beta.1", features = ["eidolon", "reactor"] }
31+
indexmap = "2.10.0"
3132
crossbeam-channel = "0.5.15"
3233
native_db = "0.8.2"
3334
native_model = "0.4.20"
3435

3536
serde = { version = "1", features = ["derive"] }
37+
serde_cbor_2 = "0.13.0"
3638
serde_yaml = "0.9.34"
3739
toml = "0.9.2"
38-
ciborium = "0.2.2"
3940

4041
clap = { version = "4.4.8", features = ["derive", "env"] }
4142
clap_complete = "4.5.7"
@@ -80,6 +81,7 @@ native_db.workspace = true
8081
native_model.workspace = true
8182
async-channel = { version = "2.3.1", optional = true }
8283
serde.workspace = true
84+
serde_cbor_2.workspace = true
8385
toml = { workspace = true, optional = true }
8486
log.workspace = true
8587
loglevel.workspace = true

client/Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ name = "rgbclient"
2121

2222
[dependencies]
2323
amplify.workspace = true
24-
bp-std = { workspace = true, optional = true }
24+
bp-std.workspace = true
2525
rgb-rpc = { version = "0.12.0-alpha.1", path = "../rpc" }
2626
io-reactor.workspace = true
2727
netservices.workspace = true
@@ -33,12 +33,13 @@ serde_yaml = { workspace = true, optional = true }
3333

3434
[build-dependencies]
3535
amplify.workspace = true
36+
bp-std.workspace = true
37+
rgb-rpc = { version = "0.12.0-alpha.1", path = "../rpc" }
3638
clap.workspace = true
3739
clap_complete.workspace = true
38-
rgb-rpc = { version = "0.12.0-alpha.1", path = "../rpc" }
3940

4041
[features]
4142
default = ["cli"]
4243
all = ["log", "cli"]
43-
cli = ["dep:bp-std", "log", "dep:clap", "dep:shellexpand", "dep:serde_yaml"]
44+
cli = ["log", "dep:clap", "dep:shellexpand", "dep:serde_yaml"]
4445
log = ["dep:log", "dep:loglevel", "io-reactor/log", "netservices/log"]

client/src/args.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,25 @@
1919
// or implied. See the License for the specific language governing permissions and limitations under
2020
// the License.
2121

22+
use bpstd::Network;
2223
use rgbrpc::RemoteAddr;
2324

24-
/// Command-line tool for working with the RGB daemon
25+
pub const RGB_NODE_NETWORK_ENV: &str = "RGB_NODE_NETWORK";
26+
27+
/// Command-line tool for working with the RGB Node
2528
#[derive(Parser, Clone, PartialEq, Eq, Debug)]
26-
#[command(name = "bp-cli", bin_name = "bp-cli", author, version)]
29+
#[command(name = "rgb-cli", bin_name = "rgb-cli", author, version)]
2730
pub struct Args {
2831
/// Set a verbosity level
2932
///
3033
/// Can be used multiple times to increase verbosity
3134
#[arg(short, long, global = true, action = clap::ArgAction::Count)]
3235
pub verbose: u8,
3336

37+
/// Bitcoin network
38+
#[arg(short, long, global = true, default_value = "testnet4", env = RGB_NODE_NETWORK_ENV)]
39+
pub network: Network,
40+
3441
/// Remote address of the RGB node to connect to
3542
#[arg(short, long, default_value = "127.0.0.1:5343")]
3643
pub remote: RemoteAddr,

client/src/client.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@ use std::net::TcpStream;
2626
use std::process::exit;
2727

2828
use amplify::confinement::TinyBlob;
29+
use bpstd::Network;
2930
use netservices::client::{
3031
Client, ClientCommand, ClientDelegate, ConnectionDelegate, OnDisconnect,
3132
};
3233
use netservices::{Frame, ImpossibleResource, NetSession, NetTransport};
33-
use rgbrpc::{RemoteAddr, RgbRpcReq, RgbRpcResp, Session};
34+
use rgbrpc::{AgentInfo, RemoteAddr, RgbRpcReq, RgbRpcResp, Session};
3435

3536
pub struct Delegate {
3637
cb: fn(RgbRpcResp),
@@ -41,9 +42,11 @@ pub struct RgbClient {
4142
}
4243

4344
impl RgbClient {
44-
pub fn new(remote: RemoteAddr, cb: fn(RgbRpcResp)) -> io::Result<Self> {
45+
pub fn new(remote: RemoteAddr, network: Network, cb: fn(RgbRpcResp)) -> io::Result<Self> {
4546
let delegate = Delegate { cb };
4647
let inner = Client::new::<_, Session, _>(delegate, remote)?;
48+
let info = AgentInfo::new(network, "RGBNodeCLI", 0, 12, 0);
49+
inner.send(RgbRpcReq::Hello(info))?;
4750
Ok(Self { inner })
4851
}
4952

client/src/main.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ fn main() -> Result<(), ExecError> {
4848
LogLevel::from_verbosity_flag_count(args.verbose).apply();
4949
trace!("Command-line arguments: {:#?}", &args);
5050

51-
let client = RgbClient::new(args.remote, cb)?;
51+
let client = RgbClient::new(args.remote, args.network, cb)?;
5252

5353
args.command.exec(client)
5454
}
@@ -60,12 +60,18 @@ fn cb(reply: RgbRpcResp) {
6060
}
6161
RgbRpcResp::Message(msg) => {
6262
println!("Message from RGB Node: {msg}");
63+
return;
64+
}
65+
RgbRpcResp::Pong(_noise) => {
66+
return;
6367
}
64-
RgbRpcResp::Pong(_noise) => {}
6568
RgbRpcResp::Status(status) => {
6669
println!("{}", serde_yaml::to_string(&status).unwrap());
6770
}
6871
RgbRpcResp::Contracts(contracts) => {
72+
if contracts.is_empty() {
73+
println!("No contracts found");
74+
}
6975
for contract in contracts {
7076
println!("---");
7177
println!("{}", serde_yaml::to_string(&contract).expect("Unable to generate YAML"));
@@ -78,6 +84,9 @@ fn cb(reply: RgbRpcResp) {
7884
RgbRpcResp::Wallets(wallets) => {
7985
println!("Wallets:");
8086
println!("Id\tName\tDescriptor class");
87+
if wallets.is_empty() {
88+
println!("No wallets found");
89+
}
8190
for wallet in wallets {
8291
println!("{}\t{}\t{}", wallet.id, wallet.name, wallet.descriptor.class())
8392
}

rpc/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@ amplify = { workspace = true, features = ["serde"] }
1818
strict_types = { workspace = true, features = ["serde"] }
1919
sonic-api = { workspace = true, features = ["serde"] }
2020
bp-std = { workspace = true, features = ["serde", "client-side-validation"] }
21-
bp-rpc = { workspace = true, features = ["serde"] }
2221
rgb-std = { workspace = true, features = ["serde"] }
2322
rgb-runtime = { workspace = true, features = ["serde"] }
23+
cyphernet = { workspace = true, features = ["serde"] }
2424
netservices.workspace = true
25+
indexmap = { workspace = true, features = ["serde"] }
2526
serde.workspace = true
26-
ciborium.workspace = true
27+
serde_cbor_2.workspace = true
2728

2829
[features]
2930
default = []

0 commit comments

Comments
 (0)