Skip to content

Commit 0ad8175

Browse files
authored
Merge pull request #733 from Emurgo/evgenii/js_object_ser_fix
Change serialization config for to_js_value, switch Rc to Arc, "dont-expose-wasm” feature
2 parents 5e0c12a + f9b7da3 commit 0ad8175

File tree

16 files changed

+121
-170
lines changed

16 files changed

+121
-170
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cardano-serialization-lib",
3-
"version": "14.1.2",
3+
"version": "15.0.0",
44
"description": "(De)serialization functions for the Cardano blockchain along with related utility functions",
55
"scripts": {
66
"publish-all:prod": "node scripts/build-helper.js publish-all --env prod",

rust/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cardano-serialization-lib"
3-
version = "14.1.2"
3+
version = "15.0.0"
44
edition = "2018"
55
authors = ["EMURGO"]
66
license = "MIT"
@@ -19,6 +19,7 @@ arbitrary-precision-json = ["serde_json/arbitrary_precision"]
1919
property-test-api = []
2020
generic-serialization = []
2121
with-bench = []
22+
dont-expose-wasm = []
2223

2324
[lib]
2425
crate-type = ["cdylib", "rlib"]

rust/json-gen/Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/src/error.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl std::fmt::Display for DeserializeError {
149149
}
150150
}
151151

152-
#[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))]
152+
#[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"), not(feature = "dont-expose-wasm"))))]
153153
impl std::error::Error for DeserializeError {}
154154

155155
impl From<DeserializeError> for JsError {
@@ -197,16 +197,16 @@ impl From<chain_crypto::PublicKeyError> for DeserializeError {
197197
// Generic string error that is replaced with JsError on wasm builds but still usable from non-wasm builds
198198
// since JsError panics when used for non-constants in non-wasm builds even just creating one
199199

200-
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
200+
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten"), not(feature = "dont-expose-wasm")))]
201201
pub type JsError = JsValue;
202202

203-
#[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))]
203+
#[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"), not(feature = "dont-expose-wasm"))))]
204204
#[derive(Debug, Clone)]
205205
pub struct JsError {
206206
msg: String,
207207
}
208208

209-
#[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))]
209+
#[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"), not(feature = "dont-expose-wasm"))))]
210210
impl JsError {
211211
pub fn from_str(s: &str) -> Self {
212212
Self { msg: s.to_owned() }
@@ -218,14 +218,14 @@ impl JsError {
218218
}
219219
}
220220

221-
#[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))]
221+
#[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"), not(feature = "dont-expose-wasm"))))]
222222
impl std::fmt::Display for JsError {
223223
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
224224
write!(f, "{}", self.msg)
225225
}
226226
}
227227

228-
#[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))]
228+
#[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"), not(feature = "dont-expose-wasm"))))]
229229
impl std::error::Error for JsError {}
230230

231231
pub(crate) enum BuilderError {

rust/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ extern crate num_derive;
2424
use std::convert::TryInto;
2525
use std::io::{BufRead, Seek, Write};
2626

27-
#[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))]
27+
#[cfg(any(not(all(target_arch = "wasm32", not(target_os = "emscripten"))), feature = "dont-expose-wasm"))]
2828
use noop_proc_macro::wasm_bindgen;
2929

30-
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
30+
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten"), not(feature = "dont-expose-wasm")))]
3131
use wasm_bindgen::prelude::{wasm_bindgen, JsValue};
3232

3333
// This file was code-generated using an experimental CDDL to rust tool:

rust/src/protocol_types/certificates/certificates_collection.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ use std::hash::{Hash, Hasher};
44
use std::iter::Map;
55
use itertools::Itertools;
66
use std::ops::Deref;
7-
use std::rc::Rc;
87
use std::slice;
8+
use std::sync::Arc;
99

1010
#[wasm_bindgen]
1111
#[derive(Clone, Debug)]
1212
pub struct Certificates {
13-
pub(crate) certs: Vec<Rc<Certificate>>,
14-
pub(crate) dedup: HashSet<Rc<Certificate>>,
13+
pub(crate) certs: Vec<Arc<Certificate>>,
14+
pub(crate) dedup: HashSet<Arc<Certificate>>,
1515
pub(crate) cbor_set_type: CborSetType,
1616
}
1717

@@ -44,7 +44,7 @@ impl Certificates {
4444
/// Add a new `Certificate` to the set.
4545
/// Returns `true` if the element was not already present in the set.
4646
pub fn add(&mut self, elem: &Certificate) -> bool {
47-
let rc_elem = Rc::new(elem.clone());
47+
let rc_elem = Arc::new(elem.clone());
4848
if self.dedup.insert(rc_elem.clone()) {
4949
self.certs.push(rc_elem.clone());
5050
true
@@ -54,7 +54,7 @@ impl Certificates {
5454
}
5555

5656
pub(crate) fn add_move(&mut self, elem: Certificate) {
57-
let rc_elem = Rc::new(elem);
57+
let rc_elem = Arc::new(elem);
5858
if self.dedup.insert(rc_elem.clone()) {
5959
self.certs.push(rc_elem.clone());
6060
}
@@ -106,8 +106,8 @@ impl Hash for Certificates {
106106
impl<'a> IntoIterator for &'a Certificates {
107107
type Item = &'a Certificate;
108108
type IntoIter = Map<
109-
slice::Iter<'a, Rc<Certificate>>,
110-
fn(&'a Rc<Certificate>) -> &'a Certificate,
109+
slice::Iter<'a, Arc<Certificate>>,
110+
fn(&'a Arc<Certificate>) -> &'a Certificate,
111111
>;
112112

113113
fn into_iter(self) -> Self::IntoIter {

rust/src/protocol_types/credentials.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::collections::HashSet;
22
use std::hash::{Hash, Hasher};
33
use std::ops::Deref;
4-
use std::rc::Rc;
4+
use std::sync::Arc;
55
use itertools::Itertools;
66
use crate::*;
77

@@ -11,8 +11,8 @@ use crate::*;
1111
Debug,
1212
)]
1313
pub struct Credentials {
14-
pub(crate) credentials: Vec<Rc<Credential>>,
15-
pub(crate) dedup: HashSet<Rc<Credential>>,
14+
pub(crate) credentials: Vec<Arc<Credential>>,
15+
pub(crate) dedup: HashSet<Arc<Credential>>,
1616
pub(crate) cbor_set_type: CborSetType,
1717
}
1818

@@ -29,8 +29,8 @@ impl Credentials {
2929
}
3030

3131
pub(crate) fn new_from_prepared_fields(
32-
credentials: Vec<Rc<Credential>>,
33-
dedup: HashSet<Rc<Credential>>,
32+
credentials: Vec<Arc<Credential>>,
33+
dedup: HashSet<Arc<Credential>>,
3434
) -> Self {
3535
Self {
3636
credentials,
@@ -50,7 +50,7 @@ impl Credentials {
5050
/// Add a new `Credential` to the set.
5151
/// Returns `true` if the element was not already present in the set.
5252
pub fn add(&mut self,credential: &Credential) -> bool {
53-
let credential_rc = Rc::new(credential.clone());
53+
let credential_rc = Arc::new(credential.clone());
5454
if self.dedup.insert(credential_rc.clone()) {
5555
self.credentials.push(credential_rc);
5656
true
@@ -60,7 +60,7 @@ impl Credentials {
6060
}
6161

6262
pub(crate) fn add_move(&mut self, credential: Credential) {
63-
let credential_rc = Rc::new(credential);
63+
let credential_rc = Arc::new(credential);
6464
if self.dedup.insert(credential_rc.clone()) {
6565
self.credentials.push(credential_rc);
6666
}
@@ -75,7 +75,7 @@ impl Credentials {
7575
let mut dedup = HashSet::new();
7676
let mut credentials = Vec::new();
7777
for elem in vec {
78-
let elem_rc = Rc::new(elem);
78+
let elem_rc = Arc::new(elem);
7979
if dedup.insert(elem_rc.clone()) {
8080
credentials.push(elem_rc);
8181
}
@@ -87,7 +87,7 @@ impl Credentials {
8787
let mut dedup = HashSet::new();
8888
let mut credentials = Vec::new();
8989
for elem in iter {
90-
let elem_rc = Rc::new(elem);
90+
let elem_rc = Arc::new(elem);
9191
if dedup.insert(elem_rc.clone()) {
9292
credentials.push(elem_rc);
9393
}

rust/src/protocol_types/ed25519_key_hashes.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use std::collections::HashSet;
22
use std::hash::{Hash, Hasher};
33
use std::ops::Deref;
4-
use std::rc::Rc;
54
use std::slice;
65
use std::iter::Map;
6+
use std::sync::Arc;
77
use itertools::Itertools;
88
pub use crate::*;
99

@@ -15,8 +15,8 @@ pub type RequiredSigners = Ed25519KeyHashes;
1515
Debug,
1616
)]
1717
pub struct Ed25519KeyHashes {
18-
keyhashes: Vec<Rc<Ed25519KeyHash>>,
19-
dedup: HashSet<Rc<Ed25519KeyHash>>,
18+
keyhashes: Vec<Arc<Ed25519KeyHash>>,
19+
dedup: HashSet<Arc<Ed25519KeyHash>>,
2020
cbor_set_type: CborSetType,
2121
}
2222

@@ -33,8 +33,8 @@ impl Ed25519KeyHashes {
3333
}
3434

3535
pub(crate) fn new_from_prepared_fields(
36-
keyhashes: Vec<Rc<Ed25519KeyHash>>,
37-
dedup: HashSet<Rc<Ed25519KeyHash>>,
36+
keyhashes: Vec<Arc<Ed25519KeyHash>>,
37+
dedup: HashSet<Arc<Ed25519KeyHash>>,
3838
) -> Self {
3939
Self {
4040
keyhashes,
@@ -54,7 +54,7 @@ impl Ed25519KeyHashes {
5454
/// Add a new `Ed25519KeyHash` to the set.
5555
/// Returns `true` if the element was not already present in the set.
5656
pub fn add(&mut self, keyhash: &Ed25519KeyHash) -> bool {
57-
let keyhash_rc = Rc::new(keyhash.clone());
57+
let keyhash_rc = Arc::new(keyhash.clone());
5858
if self.dedup.insert(keyhash_rc.clone()) {
5959
self.keyhashes.push(keyhash_rc.clone());
6060
true
@@ -76,7 +76,7 @@ impl Ed25519KeyHashes {
7676
}
7777

7878
pub(crate) fn add_move(&mut self, keyhash: Ed25519KeyHash) {
79-
let keyhash_rc = Rc::new(keyhash);
79+
let keyhash_rc = Arc::new(keyhash);
8080
if self.dedup.insert(keyhash_rc.clone()) {
8181
self.keyhashes.push(keyhash_rc);
8282
}
@@ -100,7 +100,7 @@ impl Ed25519KeyHashes {
100100
let mut dedup = HashSet::new();
101101
let mut keyhashes = Vec::new();
102102
for keyhash in keyhash_vec {
103-
let keyhash_rc = Rc::new(keyhash.clone());
103+
let keyhash_rc = Arc::new(keyhash.clone());
104104
if dedup.insert(keyhash_rc.clone()) {
105105
keyhashes.push(keyhash_rc);
106106
}
@@ -121,8 +121,8 @@ impl Ed25519KeyHashes {
121121
impl<'a> IntoIterator for &'a Ed25519KeyHashes {
122122
type Item = &'a Ed25519KeyHash;
123123
type IntoIter = Map<
124-
slice::Iter<'a, Rc<Ed25519KeyHash>>,
125-
fn(&'a Rc<Ed25519KeyHash>) -> &'a Ed25519KeyHash,
124+
slice::Iter<'a, Arc<Ed25519KeyHash>>,
125+
fn(&'a Arc<Ed25519KeyHash>) -> &'a Ed25519KeyHash,
126126
>;
127127

128128
fn into_iter(self) -> Self::IntoIter {

rust/src/protocol_types/governance/proposals/voting_proposals.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use std::hash::{Hash, Hasher};
22
use std::ops::Deref;
3-
use std::rc::Rc;
43
use std::slice;
54
use std::iter::Map;
65
use std::collections::HashSet;
76
use std::cmp::Ordering;
7+
use std::sync::Arc;
88
use itertools::Itertools;
99
use schemars::JsonSchema;
1010
use crate::*;
@@ -15,8 +15,8 @@ use crate::*;
1515
Debug,
1616
)]
1717
pub struct VotingProposals {
18-
proposals: Vec<Rc<VotingProposal>>,
19-
dedup: HashSet<Rc<VotingProposal>>,
18+
proposals: Vec<Arc<VotingProposal>>,
19+
dedup: HashSet<Arc<VotingProposal>>,
2020
cbor_set_type: CborSetType,
2121
}
2222

@@ -39,8 +39,8 @@ impl VotingProposals {
3939
}
4040

4141
pub(crate) fn new_from_prepared_fields(
42-
proposals: Vec<Rc<VotingProposal>>,
43-
dedup: HashSet<Rc<VotingProposal>>,
42+
proposals: Vec<Arc<VotingProposal>>,
43+
dedup: HashSet<Arc<VotingProposal>>,
4444
) -> Self {
4545
Self {
4646
proposals,
@@ -60,7 +60,7 @@ impl VotingProposals {
6060
/// Add a new `VotingProposal` to the set.
6161
/// Returns `true` if the element was not already present in the set.
6262
pub fn add(&mut self, proposal: &VotingProposal) -> bool {
63-
let proposal_rc = Rc::new(proposal.clone());
63+
let proposal_rc = Arc::new(proposal.clone());
6464
if self.dedup.insert(proposal_rc.clone()) {
6565
self.proposals.push(proposal_rc.clone());
6666
true
@@ -85,7 +85,7 @@ impl VotingProposals {
8585
let mut dedup = HashSet::new();
8686
let mut proposals = Vec::new();
8787
for proposal in proposal_vec {
88-
let proposal_rc = Rc::new(proposal.clone());
88+
let proposal_rc = Arc::new(proposal.clone());
8989
if dedup.insert(proposal_rc.clone()) {
9090
proposals.push(proposal_rc);
9191
}
@@ -105,8 +105,8 @@ impl VotingProposals {
105105
impl<'a> IntoIterator for &'a VotingProposals {
106106
type Item = &'a VotingProposal;
107107
type IntoIter = Map<
108-
slice::Iter<'a, Rc<VotingProposal>>,
109-
fn(&'a Rc<VotingProposal>) -> &'a VotingProposal,
108+
slice::Iter<'a, Arc<VotingProposal>>,
109+
fn(&'a Arc<VotingProposal>) -> &'a VotingProposal,
110110
>;
111111

112112
fn into_iter(self) -> Self::IntoIter {

0 commit comments

Comments
 (0)