hyperledger-iroha / iroha

Iroha - A simple, enterprise-grade decentralized ledger
https://wiki.hyperledger.org/display/iroha
Apache License 2.0
443 stars 278 forks source link

Improve transactions submitting API in Client #3591

Open mversic opened 1 year ago

mversic commented 1 year ago

check here for suggestions

appetrosyan commented 1 year ago

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.