Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jcli make transaction #3230

Conversation

danielSanchezQ
Copy link
Contributor

I'm starting this as a draft. It is a close example of what jcli path to being a lib should lead to.

The simplified transaction command uses several of the other transaction commands.
I started extracting the common code into external functions. Also stripping some functionality like reading and writing to files that shouldn't be within the reusable computations.

@danielSanchezQ danielSanchezQ added enhancement New feature or request technical debt issue to track potential technical dept we are introducing but will need care later. A-jcli Area: Command Line Interface and tooling labels Apr 20, 2021
@danielSanchezQ danielSanchezQ self-assigned this Apr 20, 2021
@danielSanchezQ
Copy link
Contributor Author

This is related to #3216

@danielSanchezQ danielSanchezQ marked this pull request as ready for review April 23, 2021 08:04
jcli/src/jcli_lib/address.rs Outdated Show resolved Hide resolved
jcli/src/jcli_lib/rest/config.rs Show resolved Hide resolved
jcli/src/jcli_lib/rest/v0/account/mod.rs Outdated Show resolved Hide resolved
pub fn add_account(
account: interfaces::Address,
value: interfaces::Value,
transaction: &mut Staging,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is Staging defined in jcli? If so, this can be done into Staging::account and this would be much cleaner.

EDIT: now I see that this is common approach in this crate and we should make a note for future us to refactor that.

jcli/src/jcli_lib/transaction/mod.rs Outdated Show resolved Hide resolved
jcli/src/jcli_lib/transaction/mod.rs Outdated Show resolved Hide resolved
Ok((sk, address))
}

#[allow(clippy::too_many_arguments)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clippy has got a point here :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has indeed but is what is needed. Even if splitting it would have to receive such data. I'll try to do something to reduce that anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could refactor things inside in some smaller sections maybe. But the grouping function would still need to receive that. At the end we need all we have in the cli input to compute :/

jcli/src/jcli_lib/transaction/simplified.rs Outdated Show resolved Hide resolved
jcli/src/jcli_lib/transaction/simplified.rs Outdated Show resolved Hide resolved
jcli/src/jcli_lib/transaction/simplified.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@eugene-babichenko eugene-babichenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

grep-ing (or rg-ing for fellow Rustaceans) still shows notions of faucet and "simplified transactions".

@eugene-babichenko
Copy link
Contributor

eugene-babichenko commented Apr 26, 2021

Definitely not how errors should be reported.

thread 'main' panicked at 'Found positional argument which is not required with a lower index than a required positional argument: "change" index 4', /home/babichenko/.cargo/registry/src/github.com-1ecc6299db9ec823/clap-2.33.3/src/app/parser.rs:643:21
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

UPD: wait, this happening even for jcli transaction make-transaction --help

@eugene-babichenko
Copy link
Contributor

The help itself is fine and accessible via jcli help transaction make-transaction. This must be an issue with the library.

@danielSanchezQ
Copy link
Contributor Author

danielSanchezQ commented Apr 26, 2021

The failing test looks not related.

@eugene-babichenko
Copy link
Contributor

It works 👍. Here are my concerns:

  • It outputs Private key of receiver (to revert transaction for testing purposes) and I would rather remove it for security reasons.
  • We do actual transaction sending here, but (see the word "offline")
	❯ jcli transaction --help
	jcli-transaction 0.11.1
	Build and view offline transaction
  • I think it might be better to set the default values of fees to the Jormungandr defaults.
  • The help is still sort of broken (some arguments not showing) and I think this is due to structure fields ordering again.
	❯ jcli transaction make-transaction -h
	error: The following required arguments were not provided:
    	<ACCOUNT>
    	<VALUE>
    	<block0-hash>
	
	USAGE:

@danielSanchezQ
Copy link
Contributor Author

@eugene-babichenko how about?:

It outputs Private key of receiver (to revert transaction for testing purposes) and I would rather remove it for security reasons.

Maybe add flag to enable disable it?

We do actual transaction sending here, but (see the word "offline")

Didn't understand this. Could you elaborate?

I think it might be better to set the default values of fees to the Jormungandr defaults.

Definetly. Can you point me to the values please?

The help is still sort of broken (some arguments not showing) and I think this is due to structure fields ordering again.

wtf...it actually works with --help 😞

@eugene-babichenko
Copy link
Contributor

Maybe add flag to enable disable it?

Just remove IMO.

Didn't understand this. Could you elaborate?

Everything under jcli transactions is dedicated to building transactions and do not contact HTTP endpoints.

Definetly. Can you point me to the values please?

Uhm, well, I guess we don't have defaults for them, or I still did not wake up. Will need to ask.

pub fee: common::CommonFees,

#[structopt(flatten)]
rest_args: RestArgs,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They need to be removed since we don't do transaction sending here anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is still needed to query some account data.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oopsie, sorry.

@danielSanchezQ danielSanchezQ changed the title Jcli simplified transaction Jcli make transaction Apr 30, 2021
@danielSanchezQ
Copy link
Contributor Author

Added request fees from rest api

block0_hash.to_string(),
sk_file_path,
staging_file,
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we also make sure the transaction was successfully casted?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is internally asserted in the make_transaction method.

@eugene-babichenko eugene-babichenko merged commit e373202 into input-output-hk:master Jul 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-jcli Area: Command Line Interface and tooling enhancement New feature or request technical debt issue to track potential technical dept we are introducing but will need care later.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants