Skip to content

Commit c8cea6b

Browse files
authored
Switch from Rc to Arc (#120)
1 parent 4e93b94 commit c8cea6b

File tree

15 files changed

+59
-46
lines changed

15 files changed

+59
-46
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ homepage = "https://github.com/Cardinal-Cryptography/drink"
1818
license = "Apache-2.0"
1919
readme = "README.md"
2020
repository = "https://github.com/Cardinal-Cryptography/drink"
21-
version = "0.15.0"
21+
version = "0.16.0"
2222

2323
[workspace.dependencies]
2424
anyhow = { version = "1.0.71" }
@@ -51,5 +51,5 @@ sp-runtime-interface = { version = "26.0.0" }
5151

5252
# Local dependencies
5353

54-
drink = { version = "=0.15.0", path = "drink" }
55-
drink-test-macro = { version = "=0.15.0", path = "drink/test-macro" }
54+
drink = { version = "=0.16.0", path = "drink" }
55+
drink-test-macro = { version = "=0.16.0", path = "drink/test-macro" }

drink-cli/src/app_state/contracts.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{path::PathBuf, rc::Rc};
1+
use std::{path::PathBuf, sync::Arc};
22

33
use contract_transcode::ContractMessageTranscoder;
44
use drink::AccountId32;
@@ -10,7 +10,7 @@ pub struct Contract {
1010
pub name: String,
1111
pub address: AccountId32,
1212
pub base_path: PathBuf,
13-
pub transcoder: Rc<ContractMessageTranscoder>,
13+
pub transcoder: Arc<ContractMessageTranscoder>,
1414
}
1515

1616
#[derive(Copy, Clone, Eq, PartialEq, Debug, Default)]

drink-cli/src/executor/contract.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::{
22
fs,
33
path::{Path, PathBuf},
4-
rc::Rc,
4+
sync::Arc,
55
};
66

77
use contract_build::{BuildMode, ExecuteArgs, ManifestPath, OptimizationPasses, Verbosity};
@@ -71,7 +71,7 @@ pub fn deploy(app_state: &mut AppState, constructor: String, args: Vec<String>,
7171
app_state.print_error("Failed to create transcoder from metadata file.");
7272
return;
7373
};
74-
let transcoder = Rc::new(transcoder);
74+
let transcoder = Arc::new(transcoder);
7575

7676
match app_state.session.deploy(
7777
contract_bytes,

drink/src/session.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
use std::{
44
fmt::Debug,
55
mem,
6-
rc::Rc,
76
sync::{Arc, Mutex},
87
};
98

@@ -63,7 +62,7 @@ pub const NO_ENDOWMENT: Option<BalanceOf<MinimalSandboxRuntime>> = None;
6362
///
6463
/// `Session` has two APIs: chain-ish and for singular actions. The first one can be used like:
6564
/// ```rust, no_run
66-
/// # use std::rc::Rc;
65+
/// # use std::sync::Arc;
6766
/// # use contract_transcode::ContractMessageTranscoder;
6867
/// # use ink_sandbox::AccountId32;
6968
/// # use drink::{
@@ -72,8 +71,8 @@ pub const NO_ENDOWMENT: Option<BalanceOf<MinimalSandboxRuntime>> = None;
7271
/// # minimal::MinimalSandbox
7372
/// # };
7473
/// #
75-
/// # fn get_transcoder() -> Rc<ContractMessageTranscoder> {
76-
/// # Rc::new(ContractMessageTranscoder::load("").unwrap())
74+
/// # fn get_transcoder() -> Arc<ContractMessageTranscoder> {
75+
/// # Arc::new(ContractMessageTranscoder::load("").unwrap())
7776
/// # }
7877
/// # fn contract_bytes() -> Vec<u8> { vec![] }
7978
/// # fn bob() -> AccountId32 { AccountId32::new([0; 32]) }
@@ -90,16 +89,16 @@ pub const NO_ENDOWMENT: Option<BalanceOf<MinimalSandboxRuntime>> = None;
9089
///
9190
/// The second one serves for one-at-a-time actions:
9291
/// ```rust, no_run
93-
/// # use std::rc::Rc;
92+
/// # use std::sync::Arc;
9493
/// # use contract_transcode::ContractMessageTranscoder;
9594
/// # use ink_sandbox::AccountId32;
9695
/// # use drink::{
9796
/// # session::Session,
9897
/// # minimal::MinimalSandbox,
9998
/// # session::{NO_ARGS, NO_ENDOWMENT, NO_SALT}
10099
/// # };
101-
/// # fn get_transcoder() -> Rc<ContractMessageTranscoder> {
102-
/// # Rc::new(ContractMessageTranscoder::load("").unwrap())
100+
/// # fn get_transcoder() -> Arc<ContractMessageTranscoder> {
101+
/// # Arc::new(ContractMessageTranscoder::load("").unwrap())
103102
/// # }
104103
/// # fn contract_bytes() -> Vec<u8> { vec![] }
105104
/// # fn bob() -> AccountId32 { AccountId32::new([0; 32]) }
@@ -224,7 +223,7 @@ where
224223
pub fn with_transcoder(
225224
mut self,
226225
contract_address: AccountIdFor<T::Runtime>,
227-
transcoder: &Rc<ContractMessageTranscoder>,
226+
transcoder: &Arc<ContractMessageTranscoder>,
228227
) -> Self {
229228
self.set_transcoder(contract_address, transcoder);
230229
self
@@ -234,7 +233,7 @@ where
234233
pub fn set_transcoder(
235234
&mut self,
236235
contract_address: AccountIdFor<T::Runtime>,
237-
transcoder: &Rc<ContractMessageTranscoder>,
236+
transcoder: &Arc<ContractMessageTranscoder>,
238237
) {
239238
self.transcoders.register(contract_address, transcoder);
240239
}
@@ -263,7 +262,7 @@ where
263262
args: &[S],
264263
salt: Vec<u8>,
265264
endowment: Option<BalanceOf<T::Runtime>>,
266-
transcoder: &Rc<ContractMessageTranscoder>,
265+
transcoder: &Arc<ContractMessageTranscoder>,
267266
) -> Result<Self, SessionError> {
268267
self.deploy(
269268
contract_bytes,
@@ -292,7 +291,7 @@ where
292291
args: &[S],
293292
salt: Vec<u8>,
294293
endowment: Option<BalanceOf<T::Runtime>>,
295-
transcoder: &Rc<ContractMessageTranscoder>,
294+
transcoder: &Arc<ContractMessageTranscoder>,
296295
) -> Result<AccountIdFor<T::Runtime>, SessionError> {
297296
let data = transcoder
298297
.encode(constructor, args)

drink/src/session/bundle.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! This module provides simple utilities for loading and parsing `.contract` files in context of `drink` tests.
22
3-
use std::{path::PathBuf, rc::Rc};
3+
use std::{path::PathBuf, sync::Arc};
44

55
use contract_metadata::ContractMetadata;
66
use contract_transcode::ContractMessageTranscoder;
@@ -19,7 +19,7 @@ pub struct ContractBundle {
1919
/// WASM blob of the contract
2020
pub wasm: Vec<u8>,
2121
/// Transcoder derived from the ABI/metadata
22-
pub transcoder: Rc<ContractMessageTranscoder>,
22+
pub transcoder: Arc<ContractMessageTranscoder>,
2323
}
2424

2525
impl ContractBundle {
@@ -40,7 +40,7 @@ impl ContractBundle {
4040
))
4141
})?;
4242

43-
let transcoder = Rc::new(ContractMessageTranscoder::new(ink_metadata));
43+
let transcoder = Arc::new(ContractMessageTranscoder::new(ink_metadata));
4444

4545
let wasm = metadata
4646
.source

drink/src/session/record.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::rc::Rc;
1+
use std::sync::Arc;
22

33
use contract_transcode::{ContractMessageTranscoder, Value};
44
use frame_system::Config as SysConfig;
@@ -176,7 +176,7 @@ impl EventBatch<MinimalSandboxRuntime> {
176176
/// **WARNING 2**: This method will ignore anonymous events.
177177
pub fn contract_events_decoded(
178178
&self,
179-
transcoder: &Rc<ContractMessageTranscoder>,
179+
transcoder: &Arc<ContractMessageTranscoder>,
180180
) -> Vec<Value> {
181181
let signature_topics = transcoder
182182
.metadata()

drink/src/session/transcoding.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
use std::{collections::BTreeMap, rc::Rc};
1+
use std::{collections::BTreeMap, sync::Arc};
22

33
use contract_transcode::ContractMessageTranscoder;
44

55
pub struct TranscoderRegistry<Contract: Ord> {
6-
transcoders: BTreeMap<Contract, Rc<ContractMessageTranscoder>>,
6+
transcoders: BTreeMap<Contract, Arc<ContractMessageTranscoder>>,
77
}
88

99
impl<Contract: Ord> TranscoderRegistry<Contract> {
@@ -13,11 +13,11 @@ impl<Contract: Ord> TranscoderRegistry<Contract> {
1313
}
1414
}
1515

16-
pub fn register(&mut self, contract: Contract, transcoder: &Rc<ContractMessageTranscoder>) {
17-
self.transcoders.insert(contract, Rc::clone(transcoder));
16+
pub fn register(&mut self, contract: Contract, transcoder: &Arc<ContractMessageTranscoder>) {
17+
self.transcoders.insert(contract, Arc::clone(transcoder));
1818
}
1919

20-
pub fn get(&self, contract: &Contract) -> Option<Rc<ContractMessageTranscoder>> {
21-
self.transcoders.get(contract).map(Rc::clone)
20+
pub fn get(&self, contract: &Contract) -> Option<Arc<ContractMessageTranscoder>> {
21+
self.transcoders.get(contract).map(Arc::clone)
2222
}
2323
}

examples/chain-extension/Cargo.lock

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

examples/contract-events/Cargo.lock

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

examples/flipper/Cargo.lock

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

examples/mocking/Cargo.lock

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

examples/multiple-contracts/Cargo.lock

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

examples/quick-start-with-drink/Cargo.lock

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

0 commit comments

Comments
 (0)