-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Accept address as String
instead of Address
#748
Comments
I would advocate accepting only Still on the same wave about avoiding parameter type overloading and why it sounds like the thing to do. For this issue, this means that:
Still, I think it is worth it. Thoughts?
|
I think is good to accept both once the code you implement the call can have an Address instance and forcing it to transform into a string to then pass the param, would not be so good as just accepting both. |
@arboleya I would lean towards simplicity, too. Our methods only accepting The former approach sounds like it makes things super simple for the users, while the latter sounds like it involves a compromise on both ends. |
I agree inputs should be more flexible.. but I remember we kept |
@LuizAsFight It looks like you have a valid point with the @luizstacio By having the address class SampleClass {
address: string; // always accessible
constructor(address: string) {
this.address = address;
this.abstractAddress = Address.fromDynamicInput(this.address);
}
}
class OtherClass {
constructor(address: string) {
// ...
}
}
const abc = new SampleClass('0x...');
const xyz = new OtherClass(abc.address); // `abc.address` instead of `abc` @Dhaiwat10 Precisely, thanks for putting it so eloquently. Reducing the number of questions one will ask when reading the code seems favorable, and that's the opposite of what types-overloading causes, IMO. I suspect that upon seeing
Whereas
Seeing one thing in isolation might not transmit the complexity that simple decisions can add (or remove), but it can quickly become noticeable when the same habit is repeated throughout the codebase. |
The main issue here is that we want application developers to be fully aware of what kind of address they have. If they don't know what the format is and allow incorrect data, then failures are the least of their worries. One could easily misuse a string in the wrong place and send coins to an incorrect address. This was originally written to be strict following how the Rust SDK works, where everything is within an Address wrapper. By forcing developers to use an Address object they are actually less worried about knowing the format, but also internally our code should be very strict about inputs when talking to each package, the end-user can convert a string to an Address and be done with it. After much thought I'm not too sold on this change making Address data less trustworthy between packages. @digorithm any thoughts here? |
@camsjams All address formats are represented as a Our code strictness will not change regardless; the detection/validation logic is already in place and can never be removed. Nothing will change internally. We'd be adding an obstacle, not a feature. It also adds no security. No matter what or how many steps we add, the underlying format will forever be a The point @LuizAsFight brought up about No matter the angle I look at it, I continue adamantly about simplicity being the ultimate aim. |
The idea is that we should accept strings but check for a format bech32. This will keep the security but make it simpler for developers. The utilities around the Address will be provided if the user doesn't have the correct address, it would be possible to convert. But asking for an Address object makes things more complex and does not add security, as mentioned, when using it, we always do Address.from<...> and pass it along. In the future, fuel-core should also accept bech32 removing all the need to parse bech32 to hex and vice-versa |
@arboleya I'd agree with that sentiment if we did use I only see Here was the original PR btw: For this comment @Dhaiwat10 @arboleya
I'd argue we are already like this former approach - allowing We want bad addresses to fail as quickly as possible right?In current style:
In string style my fear is:
If we optimized string style:
|
@camsjams Thanks for the thorough explanation and link to the original PR. Could you please exemplify these three cases ( I will also try simulating these cases while reviewing the source code again to understand it better. |
@LuizAsFight Do you remember the places where you mentioned that |
feels bikeshedding such a long discussion because of 1 type more in input... this problem only happens because we don't have a standard way of using this inputs for Address What I would do: same pattern of
then Address constructor is the place that validate everything and guarantee a valid/safe Address. for example
On this way you don't have problems or decisions to do regarding inputsanywhere you need address input you will use:
or if you don't wanna allow flexible inputs, but only string... would work on exact same way:
plusUsing different
it can be broken because it suppose when it's not a Bech32, it's a b256 ?? I didn't test but looks like. but this will only happen if you use |
@arboleya it's a new thing I guess it's not used everywhere, sorry if I meant it. My comment was just pointing it out because this issue mention using Address.fromDynamicInput |
I open a draft PR for better understand the issue, and open it for discussion #801 |
String
instead of Address
Completed via #1583. |
When using;
BaseWalletLocked.<transfer|buildPredicateTransaction |submitPredicate>
Provider.<getCoins|getResourcesToSpend|getBalance|getBalances|getMessages|buildSpendPredicate|submitSpendPredicate>
BaseTransactionRequest.<updateWitnessByOwner>
These methods require the Application to instantiate an Address object before executing the methods, as bech32 and hex are both strings and can be differentiated by string evaluation. All the methods should be able also to receive a string. Making address param type from
AbstractAddress
to something likestring | AbstractAddress
. And useAddress.fromDynamicInput
internally for the correctness of the data.Note
The text was updated successfully, but these errors were encountered: