Skip to content

Commit

Permalink
Update borsh dependency (near#8541)
Browse files Browse the repository at this point in the history
For the most part this is just a matter of replacing deserialize
function in BorshDeserialize implementation by deserialize_reader.  In
a few cases replace custom implementation for fixed-size arrays, by by
derives.  Really the only interesting change is in NonDelegateAction
which had to use `borsh::de::EnumExt`.
  • Loading branch information
mina86 authored Feb 11, 2023
1 parent 080ab7e commit b8196b1
Show file tree
Hide file tree
Showing 14 changed files with 123 additions and 116 deletions.
107 changes: 76 additions & 31 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ bitflags = "1.2"
blake2 = "0.9.1"
bn = { package = "zeropool-bn", version = "0.5.11" }
bolero = "0.8.0"
borsh = { version = "0.9", features = ["rc"] }
borsh = { version = "0.10.1", features = ["rc"] }
bs58 = "0.4"
byteorder = "1.3"
bytes = "1"
Expand Down
4 changes: 2 additions & 2 deletions chain/network/src/network_protocol/borsh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ struct HandshakeAutoDes {
// Use custom deserializer for HandshakeV2. Try to read version of the other peer from the header.
// If the version is supported then fallback to standard deserializer.
impl BorshDeserialize for Handshake {
fn deserialize(buf: &mut &[u8]) -> std::io::Result<Self> {
<HandshakeAutoDes as BorshDeserialize>::deserialize(buf).map(Into::into)
fn deserialize_reader<R: std::io::Read>(rd: &mut R) -> std::io::Result<Self> {
HandshakeAutoDes::deserialize_reader(rd).map(Into::into)
}
}

Expand Down
8 changes: 4 additions & 4 deletions core/account-id/src/borsh.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
use super::AccountId;

use std::io::{Error, Write};
use std::io::{Read, Write};

use borsh::{BorshDeserialize, BorshSerialize};

impl BorshSerialize for AccountId {
fn serialize<W: Write>(&self, writer: &mut W) -> Result<(), Error> {
fn serialize<W: Write>(&self, writer: &mut W) -> std::io::Result<()> {
self.0.serialize(writer)
}
}

impl BorshDeserialize for AccountId {
fn deserialize(buf: &mut &[u8]) -> Result<Self, std::io::Error> {
let account_id = Box::<str>::deserialize(buf)?;
fn deserialize_reader<R: Read>(rd: &mut R) -> std::io::Result<Self> {
let account_id = Box::<str>::deserialize_reader(rd)?;
Self::validate(&account_id).map_err(|err| {
std::io::Error::new(
std::io::ErrorKind::InvalidData,
Expand Down
Loading

0 comments on commit b8196b1

Please sign in to comment.