iroha icon indicating copy to clipboard operation
iroha copied to clipboard

Improve transactions submitting API in Client

Open mversic opened this issue 2 years ago • 1 comments

check here for suggestions

mversic avatar Jun 09 '23 07:06 mversic

Extension traits

Firstly we can't use Into and TryInto for this purpose, primarily because that trait has too many variables and the type inference often can't tell what it needs to do. This can eventually be fixed upstream, but makes the usage harder than it needs to be.

So we could have IntoIsiExt which has one function into_isi and blanket impl for all things that impl Into<InstructionBox>. This would allow usage similar to

let register_alice = RegisterBox::new(/* ... */);
// ...
let instructions = [register_alice.into_isi(), register_bob.into_isi(), register_claire.into_isi()];

which passes type inference trivially.

This is similar to the special handling of to_string() in the core::str and core::fmt.

Domain knowledge

Each id can be uniquely identified from the string representation. Further, thanks to our usage of Box-ing, we have a single monomorphic type that can be parsed. So in principle, something like

let thing /* (inferred) : RegisterBox*/ = "alice@wonderland".register();
client.submit(thing.into_isi());

is also feasible.

Further a module expr can be very useful for composing such expressions:

let thing = expr::concat(expr::evals_to("alice@wonderland".register()), "some_domain");
let arithmetic = expr::add(query::get_balance("alice@wonderland"), expr::exp(expr::multiply(Fixed::try_from(2.5), 15), 12);

Key point is that this would help with the DSL but not eliminate the need for it, much as intel assembly didn't replace C.

appetrosyan avatar Jun 09 '23 12:06 appetrosyan