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

Make AccountId deserialization accept prefixes larger than 1 byte #2686

Merged
merged 4 commits into from
Aug 26, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions bin/wasm-node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

- In case of protocol error, or if a peer refuses a block announces substream, no new substream with the same peer will be attempted for 20 seconds. This avoids loops where the same peer is tried over and over again.

### Fixed

- Fix inability to decode addresses with prefixes longer than 1 byte in the RPC. ([#2686](https://github.com/paritytech/smoldot/pull/2686))
tomaka marked this conversation as resolved.
Show resolved Hide resolved

## 0.6.30 - 2022-08-12

### Fixed
Expand Down
9 changes: 6 additions & 3 deletions src/json_rpc/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,15 +572,18 @@ impl<'a> serde::Deserialize<'a> for AccountId {
Err(_) => return Err(serde::de::Error::custom("AccountId isn't in base58 format")),
};

// TODO: soon might be 36 bytes as well
if decoded.len() != 35 {
// TODO: retrieve the actual prefix length of the current chain
if decoded.len() < 35 {
return Err(serde::de::Error::custom("unexpected length for AccountId"));
}

// TODO: finish implementing this properly ; must notably check checksum
// see https://github.com/paritytech/substrate/blob/74a50abd6cbaad1253daf3585d5cdaa4592e9184/primitives/core/src/crypto.rs#L228

let account_id = <[u8; 32]>::try_from(&decoded[1..33]).unwrap();
// TODO: retrieve and use the actual prefix length of the current chain
let account_id =
<[u8; 32]>::try_from(&decoded[(decoded.len() - 34)..(decoded.len() - 2)]).unwrap();

Ok(AccountId(account_id))
}
}
Expand Down