Skip to content

Muxed address support sketch for Soroban SDK.#1441

Closed
dmkozh wants to merge 2 commits intostellar:mainfrom
dmkozh:muxed_addr
Closed

Muxed address support sketch for Soroban SDK.#1441
dmkozh wants to merge 2 commits intostellar:mainfrom
dmkozh:muxed_addr

Conversation

@dmkozh
Copy link
Copy Markdown
Contributor

@dmkozh dmkozh commented Feb 24, 2025

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.

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.
Comment on lines -68 to -71
#[cfg(not(target_family = "wasm"))]
if !self.env.is_same_env(&other.env) {
return ScVal::from(self).cmp(&ScVal::from(other));
}
Copy link
Copy Markdown
Member

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?

Copy link
Copy Markdown
Contributor Author

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.

Comment on lines 20 to 33

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);
Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown
Contributor Author

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).

@leighmcculloch
Copy link
Copy Markdown
Member

I think this was superseded by:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants