inkdevhub / drink

De-chained Ready-to-play ink! playground
Apache License 2.0
69 stars 15 forks source link

Accept any stringish arguments in session API #55

Closed pmikolajczyk41 closed 1 year ago

pmikolajczyk41 commented 1 year ago

Previously, calling/deploying with Session required that all arguments are converted to String. This was onerous to add ".to_string()" for string literals. Instead we accept anything that is AsRef<str> + Debug (the Debug bound is required for encoding), which accepts now String and &str.

Since often messages don't have arguments, passing &[] requires specifying the explicit type. For that we define auxiliary constant NO_ARGS which is just empty &[String].


Alternatively, we could be less restrictive and require only Debug or Into<String> + Debug. However, this might introduce problems / confusion for non-homogenic argument lists. Consider:

fn message1(account: AccountId) {..}
fn message2(account: AccountId, value: u128) {..}

let account: AccountId = ...;
let value: u128 = ...;

session.call("message1", &[account]) // works fine
session.call("message1", &[account.to_string()]) // works fine as well

session.call("message", &[account, value]) // this won't work - slice must contain values of the same type
session.call("message", &[account.to_string(), value.to_string()]) // we have to convert to string anyway