Skip to content
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

[Feature] Support arbitrary subscription ids #1158

Closed
mattsse opened this issue Aug 20, 2024 · 2 comments · Fixed by #1163
Closed

[Feature] Support arbitrary subscription ids #1158

mattsse opened this issue Aug 20, 2024 · 2 comments · Fixed by #1163
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@mattsse
Copy link
Member

mattsse commented Aug 20, 2024

Component

provider, pubsub

Describe the feature you would like

this currently only supports u256 ids:

pub(crate) fn fulfill(self, resp: Response) -> Option<(U256, Self)> {
if self.is_subscription() {
if let ResponsePayload::Success(val) = resp.payload {
let sub_id: serde_json::Result<U256> = serde_json::from_str(val.get());
return match sub_id {
Ok(alias) => Some((alias, self)),
Err(e) => {
let _ = self.tx.send(Err(TransportError::deser_err(e, val.get())));
None
}
};
}
}

and causes issues where servers don't return u256 as subscription ids #1155

TODO

  • introduce a new type that can handle both u256 and string:
pub enum SubscriptionId {
	/// Numeric id
	Num(U267),
	/// String id
	Str(String),
}

and use this as a replacement for the server_id: U256 where used:

fn handle_sub_response(&mut self, in_flight: InFlight, server_id: U256) -> TransportResult<()> {

Additional context

No response

@mattsse mattsse added enhancement New feature or request good first issue Good for newcomers labels Aug 20, 2024
@DaniPopes
Copy link
Member

pub enum Id {
/// A number.
Number(u64),
/// A string.
String(String),
/// Null.
None,
}

@HowHsu
Copy link

HowHsu commented Aug 20, 2024

As a beginner: why do we use an Enum rather than directly use String as Id

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants