Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
3 changes: 0 additions & 3 deletions examples/amm/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,6 @@ impl AmmContract {
"Unauthorized"
)
}
MultiAddress::Chain => {
panic!("Using chain balance is not authorized")
}
}
}

Expand Down
3 changes: 0 additions & 3 deletions examples/fungible/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,6 @@ impl FungibleTokenContract {
"The requested transfer is not correctly authenticated."
)
}
MultiAddress::Chain => {
panic!("Chain account is not supported")
}
}
}

Expand Down
3 changes: 0 additions & 3 deletions examples/gen-nft/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,6 @@ impl GenNftContract {
"The requested transfer is not correctly authenticated."
)
}
MultiAddress::Chain => {
panic!("Chain account is not supported")
}
}
}

Expand Down
3 changes: 0 additions & 3 deletions examples/matching-engine/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,6 @@ impl MatchingEngineContract {
"Unauthorized."
)
}
MultiAddress::Chain => {
panic!("Chain account is not supported")
}
}
}

Expand Down
6 changes: 2 additions & 4 deletions examples/native-fungible/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ impl Contract for NativeFungibleTokenContract {
chain_id: self.runtime.chain_id(),
owner,
};
self.runtime.transfer(MultiAddress::Chain, account, amount);
self.runtime
.transfer(MultiAddress::chain(), account, amount);
}
}

Expand Down Expand Up @@ -143,9 +144,6 @@ impl NativeFungibleTokenContract {
"The requested transfer is not correctly authenticated."
)
}
MultiAddress::Chain => {
panic!("Chain accounts are not supported")
}
}
}
}
8 changes: 4 additions & 4 deletions examples/native-fungible/tests/transfers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async fn chain_balance_transfers() {

let transfer_certificate = funding_chain
.add_block(|block| {
block.with_native_token_transfer(MultiAddress::Chain, recipient, transfer_amount);
block.with_native_token_transfer(MultiAddress::chain(), recipient, transfer_amount);
})
.await;

Expand Down Expand Up @@ -69,7 +69,7 @@ async fn transfer_to_owner() {

let transfer_certificate = funding_chain
.add_block(|block| {
block.with_native_token_transfer(MultiAddress::Chain, recipient, transfer_amount);
block.with_native_token_transfer(MultiAddress::chain(), recipient, transfer_amount);
})
.await;

Expand Down Expand Up @@ -114,7 +114,7 @@ async fn transfer_to_multiple_owners() {
let transfer_certificate = funding_chain
.add_block(|block| {
for (recipient, transfer_amount) in recipients.zip(transfer_amounts.clone()) {
block.with_native_token_transfer(MultiAddress::Chain, recipient, transfer_amount);
block.with_native_token_transfer(MultiAddress::chain(), recipient, transfer_amount);
}
})
.await;
Expand Down Expand Up @@ -154,7 +154,7 @@ async fn emptied_account_disappears_from_queries() {

let transfer_certificate = funding_chain
.add_block(|block| {
block.with_native_token_transfer(MultiAddress::Chain, recipient, transfer_amount);
block.with_native_token_transfer(MultiAddress::chain(), recipient, transfer_amount);
})
.await;

Expand Down
3 changes: 0 additions & 3 deletions examples/non-fungible/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,6 @@ impl NonFungibleTokenContract {
"The requested transfer is not correctly authenticated."
)
}
MultiAddress::Chain => {
panic!("Chain account is not supported")
}
}
}

Expand Down
11 changes: 10 additions & 1 deletion linera-base/src/crypto/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#[cfg(with_testing)]
use std::ops::RangeInclusive;
use std::{borrow::Cow, fmt, io, str::FromStr};
use std::{borrow::Cow, fmt, io, str::FromStr, sync::LazyLock};

#[cfg(with_testing)]
use alloy_primitives::FixedBytes;
Expand All @@ -28,6 +28,15 @@ use crate::{
doc_scalar,
};

#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
struct Chain;

impl BcsHashable<'_> for Chain {}

/// The CryptoHash of `Chain` newtype struct.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// The CryptoHash of `Chain` newtype struct.
/// The `CryptoHash` of `Chain` newtype struct.

(It's also not ideal that the comment of a pub item refers to a private type.)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, but this will go away when we switch to Account::Reserved variant.

/// It's a marker for a generic `Chain` object.
pub static CHAIN_CRYPTO_HASH: LazyLock<CryptoHash> = LazyLock::new(|| CryptoHash::new(&Chain));

/// A Keccak256 value.
#[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Hash)]
#[cfg_attr(with_testing, derive(Default))]
Expand Down
15 changes: 8 additions & 7 deletions linera-base/src/data_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ use crate::{
crypto::{BcsHashable, CryptoHash},
doc_scalar, hex_debug, http,
identifiers::{
BlobId, BlobType, ChainId, Destination, EventId, GenericApplicationId, ModuleId,
MultiAddress, StreamId,
BlobId, BlobType, ChainId, Destination, EventId, ModuleId, MultiAddress, StreamId,
},
limited_writer::{LimitedWriter, LimitedWriterError},
time::{Duration, SystemTime},
Expand Down Expand Up @@ -765,12 +764,14 @@ impl ApplicationPermissions {
}

/// Returns whether operations with the given application ID are allowed on this chain.
pub fn can_execute_operations(&self, app_id: &GenericApplicationId) -> bool {
match (app_id, &self.execute_operations) {
(_, None) => true,
(GenericApplicationId::System, Some(_)) => false,
(GenericApplicationId::User(app_id), Some(app_ids)) => app_ids.contains(app_id),
pub fn can_execute_operations(&self, app_id: &MultiAddress) -> bool {
if self.execute_operations.is_none() {
return true;
}
if app_id.is_chain() {
return false;
}
self.execute_operations.as_ref().unwrap().contains(app_id)
}

/// Returns whether the given application is allowed to close this chain.
Expand Down
Loading