Cargo.toml missing expected `package` or `project` fields
alexnoxx opened this issue · comments
Hi, I'm new to rust, I've been very interested in the implementation of nakamoto's lightweight node. I have had some problems during installation and configuration.
In the Cargo.ml file I have the following parameters:
[dependencies]
cargo-edit = "0.7.0"
nakamoto-client = "0.2.0"
But when executing the command: cargo add nakamoto-client it gives me the following error:
[root@nakamoto ~]# cargo add nakamoto-client
Updating 'https://github.com/rust-lang/crates.io-index' index
Adding nakamoto-client v0.2.0 to dependencies
Command failed due to unhandled error: Cargo.toml missing expected `package` or `project` fields
I already have cargo_edit installed.
What could be happening?
Regards
I had never heard of cargo-edit, but I tried it out with a fresh project and it seems to work fine here:
mkdir test-project
cd test-project
cargo init
cargo install cargo-edit
cargo add nakamoto-client
Updating 'https://github.com/rust-lang/crates.io-index' index
Adding nakamoto-client v0.2.0 to dependencies
Could it be that cargo-edit is complaining about your Cargo.toml?
Dear,
I have been able to complete the installation, I did not have the manifest file well configured.
But when trying to run the test script to sync the node I get the following error:
I run the line:
cargo run --release -p nakamoto-node -- --testnet
and I get the following error:
[root@nakamoto ~]# cargo run --release -p nakamoto-node -- --testnet
Compiling nakamoto-node v0.1.0 (/root)
error[E0433]: failed to resolve: maybe a missing crate `nakamoto`?
--> test.rs:5:5
|
5 | use nakamoto::client::{Client, Config, Network};
| ^^^^^^^^ maybe a missing crate `nakamoto`?
error[E0433]: failed to resolve: maybe a missing crate `nakamoto`?
--> test.rs:6:5
|
6 | use nakamoto::client::error::Error;
| ^^^^^^^^ maybe a missing crate `nakamoto`?
error[E0433]: failed to resolve: maybe a missing crate `nakamoto`?
--> test.rs:7:5
|
7 | use nakamoto::client::handle::Handle as _;
| ^^^^^^^^ maybe a missing crate `nakamoto`?
error[E0433]: failed to resolve: use of undeclared type `Network`
--> test.rs:17:18
|
17 | network: Network::Testnet,
| ^^^^^^^ use of undeclared type `Network`
error[E0433]: failed to resolve: use of undeclared type `Config`
--> test.rs:18:11
|
18 | ..Config::default()
| ^^^^^^ use of undeclared type `Config`
error[E0433]: failed to resolve: use of undeclared type `Client`
--> test.rs:21:18
|
21 | let client = Client::<Reactor>::new(cfg)?;
| ^^^^^^ use of undeclared type `Client`
error[E0412]: cannot find type `Error` in this scope
--> test.rs:15:25
|
15 | fn main() -> Result<(), Error> {
| ^^^^^ not found in this scope
|
help: consider importing one of these items
|
3 | use std::error::Error;
|
3 | use std::fmt::Error;
|
3 | use std::io::Error;
|
error[E0422]: cannot find struct, variant or union type `Config` in this scope
--> test.rs:16:15
|
16 | let cfg = Config {
| ^^^^^^ not found in this scope
error: aborting due to 8 previous errors
Some errors have detailed explanations: E0412, E0422, E0433.
For more information about an error, try `rustc --explain E0412`.
error: could not compile `nakamoto-node`
To learn more, run the command again with --verbose.
[root@nakamoto ~]#
In Cargo.toml I have it configured as follows:
[dependencies]
cargo-edit = "0.7.0"
nakamoto-client = "0.2.0"
nakamoto = "0.2.0"
[project]
name = "nakamoto-node"
version = "0.1.0"
[package]
name = "nakamoto"
version = "0.1.0"
authors = ["Alex <support@mydomain.tk>"]
edition = "2021"
[[bin]]
name = "test"
path = "test.rs"
[workspace]
members = [""]
In test.rs I have the test scripts: (by cloudhead.io)
//! A trivial example of a client that connects to the Bitcoin
//! testnet and syncs the chain.
use std::{net, thread};
use nakamoto::client::{Client, Config, Network};
use nakamoto::client::error::Error;
use nakamoto::client::handle::Handle as _;
/// The network reactor we're going to use. This one ships with Nakamoto,
/// as part of the `nakamoto-net-poll` crate. It's a single-threaded
/// reactor using non-blocking sockets and `poll(2)`.
type Reactor = nakamoto::net::poll::Reactor<net::TcpStream>;
/// Run the light-client.
fn main() -> Result<(), Error> {
let cfg = Config {
network: Network::Testnet,
..Config::default()
};
// Create a client using the above network reactor.
let client = Client::<Reactor>::new(cfg)?;
let handle = client.handle();
// Run the client on a different thread, to not block the main thread.
thread::spawn(|| client.run().unwrap());
// Wait for the client to be in sync with the blockchain.
handle.wait_for_ready()?;
// The client is in sync. Ask it to shutdown.
handle.shutdown()?;
Ok(())
}
What could be happening?
Regards,
Alex
This is very confusing, I would start by not naming your package "nakamoto", as that is the name of this package too. You should also probably remove the [project]
section, I'm not sure what that does, it's surely not needed.
Once you've cleaned that up, try running just cargo check --all
and post the result here.
Hello,
I have removed the [project] section and renamed the package name.
In Cargo.toml we have:
[dependencies]
cargo-edit = "0.7.0"
nakamoto-client = "0.2.0"
nakamoto = "0.2.0"
[package]
name = "n201t"
version = "0.1.0"
authors = ["Alex <support@mydomain.com>"]
edition = "2018"
[[bin]]
name = "test"
path = "test.rs"
[workspace]
members = [""]
When executing cargo check --all I get the following:
[root@nakamoto ~]# cargo check --all
Checking n201t v0.1.0 (/root)
Finished dev [unoptimized + debuginfo] target(s) in 0.26s
Then when executing the following line:
cargo run --release -p n201t -- --testnet
I have the following result:
[root@nakamoto ~]# cargo run --release -p n201t -- --testnet
Compiling n201t v0.1.0 (/root)
Finished release [optimized] target(s) in 25.03s
Running `target/release/test --testnet`
Error: Handle(Timeout)
There you can see: Error: Handle (Timeout)
Ok, better. To find out exactly what is happening you should setup logging. Check out the node
package for a fuller example: https://github.com/cloudhead/nakamoto/tree/master/node
I have managed to solve the problem, the chain is synchronizing.
I was missing cloning some missing directories from github.
The question I have now is how do I connect my wallet to the node, what is the instruction that I should place to connect a wallet to the node. Is this instruction valid?:
cargo run --release -p nakamoto-wallet -- --debug --genesis 0 --connect
What ports should I use?
cargo run
is only meant to be used inside the project you want to run. Since nakamoto-wallet is part of the nakamoto crate, you'd have to run that command inside that directory.
Now, nakamoto-wallet is not a complete wallet, it's just a simple watcher that will tell you for a given address, what your balance is. It'll run its own nakamoto-client, so it won't connect to the other one you ran.
Nakamoto is meant to be used as a backend and p2p client to wallet software. It's a library that you must integrate in your wallet software.