Skip to content

Commit

Permalink
Make AccountId deserialization accept prefixes larger than 1 byte (#2686
Browse files Browse the repository at this point in the history
)

* fix: Make AccountId deserialization accept prefixes larger than 1 byte

* Update CHANGELOG.md

* Update bin/wasm-node/CHANGELOG.md

Co-authored-by: Pierre Krieger <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Aug 26, 2022
1 parent d33dae8 commit ccf3ba0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
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 when calling `system_accountNextIndex`. ([#2686](https://github.com/paritytech/smoldot/pull/2686))

## 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

0 comments on commit ccf3ba0

Please sign in to comment.