-
Notifications
You must be signed in to change notification settings - Fork 68
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
Muxed address support sketch for Soroban SDK. #1441
base: main
Are you sure you want to change the base?
Conversation
This introduces the `MuxedAddress` type that maps to either `AddressObject` or `MuxedAddressObject`. In order to not 'leak' the muxed addresses everywhere (as they have pretty narrow use cases), introduce a separate token interface that supports muxed addresses for transfer (could also support e.g. transfer_from). This is basically token extension, but a bit clunkier due to the lack of overload support. The amount of copy-paste could be reduced though with some code generation (I'm not sure that's necessary though). Also only expose muxed addresses to generate clients when that's explicitly requested, as again users normally don't need to worry about them.
#[cfg(not(target_family = "wasm"))] | ||
if !self.env.is_same_env(&other.env) { | ||
return ScVal::from(self).cmp(&ScVal::from(other)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are the comparison functions changing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's unrelated to the sketch, I just didn't want to refactor the SDK to support stellar/rs-soroban-env#1516.
pub fn transfer(&self, from: Address, to: Address, amount: i128) { | ||
pub fn transfer<AddressType: sealed::IsAddressType + IntoVal<Env, Val>>( | ||
&self, | ||
from: AddressType, | ||
to: AddressType, | ||
amount: i128, | ||
) { | ||
let topics = (symbol_short!("transfer"), from, to); | ||
self.env.events().publish(topics, amount); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like the muxed address is emitted in the topic, so it wouldn't be very easy for a consumer to filter only on the underlying address.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, the sketch was about the issue of 'passing the muxed addresses to the contracts' and I didn't want to spend much time on the events. I've just implemented the simplest option; with one more host fn we could also be emit id separately (the library interface won't change for the caller though).
This introduces the
MuxedAddress
type that maps to eitherAddressObject
orMuxedAddressObject
.In order to not 'leak' the muxed addresses everywhere (as they have pretty narrow use cases), introduce a separate token interface that supports muxed addresses for transfer (could also support e.g. transfer_from). This is basically token extension, but a bit clunkier due to the lack of overload support. The amount of copy-paste could be reduced though with some code generation (I'm not sure that's necessary though). Also only expose muxed addresses to generate clients when that's explicitly requested, as again users normally don't need to worry about them.