Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transfer command uses AccountOwner type. #3573

Merged
merged 2 commits into from
Mar 16, 2025
Merged
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
14 changes: 9 additions & 5 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(None, recipient, transfer_amount);
block.with_native_token_transfer(AccountOwner::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(None, recipient, transfer_amount);
block.with_native_token_transfer(AccountOwner::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(None, recipient, transfer_amount);
block.with_native_token_transfer(AccountOwner::Chain, recipient, transfer_amount);
}
})
.await;
Expand Down Expand Up @@ -155,7 +155,7 @@ async fn emptied_account_disappears_from_queries() {

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

Expand All @@ -167,7 +167,11 @@ async fn emptied_account_disappears_from_queries() {

recipient_chain
.add_block(|block| {
block.with_native_token_transfer(Some(owner), Recipient::Burn, transfer_amount);
block.with_native_token_transfer(
AccountOwner::User(owner),
Recipient::Burn,
Copy link
Contributor

@ma2bd ma2bd Mar 16, 2025

Choose a reason for hiding this comment

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

We can probably kill this Burn thing by the way and simplify (away?) Recipient now. People will be able to send to address 0x0 (or anything really) if they really want to burn tokens.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

transfer_amount,
);
})
.await;

Expand Down
8 changes: 4 additions & 4 deletions linera-chain/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use linera_base::{
crypto::{AccountPublicKey, AccountSecretKey},
data_types::{Amount, BlockHeight, Round, Timestamp},
hashed::Hashed,
identifiers::{ChainId, Owner},
identifiers::{AccountOwner, ChainId, Owner},
};
use linera_execution::{
committee::{Committee, Epoch, ValidatorState},
Expand Down Expand Up @@ -62,7 +62,7 @@ pub trait BlockTestExt: Sized {
fn with_operation(self, operation: impl Into<Operation>) -> Self;

/// Returns the block with a transfer operation appended at the end.
fn with_transfer(self, owner: Option<Owner>, recipient: Recipient, amount: Amount) -> Self;
fn with_transfer(self, owner: AccountOwner, recipient: Recipient, amount: Amount) -> Self;

/// Returns the block with a simple transfer operation appended at the end.
fn with_simple_transfer(self, chain_id: ChainId, amount: Amount) -> Self;
Expand Down Expand Up @@ -97,7 +97,7 @@ impl BlockTestExt for ProposedBlock {
self
}

fn with_transfer(self, owner: Option<Owner>, recipient: Recipient, amount: Amount) -> Self {
fn with_transfer(self, owner: AccountOwner, recipient: Recipient, amount: Amount) -> Self {
self.with_operation(SystemOperation::Transfer {
owner,
recipient,
Expand All @@ -106,7 +106,7 @@ impl BlockTestExt for ProposedBlock {
}

fn with_simple_transfer(self, chain_id: ChainId, amount: Amount) -> Self {
self.with_transfer(None, Recipient::chain(chain_id), amount)
self.with_transfer(AccountOwner::Chain, Recipient::chain(chain_id), amount)
}

fn with_incoming_bundle(mut self, incoming_bundle: IncomingBundle) -> Self {
Expand Down
4 changes: 2 additions & 2 deletions linera-chain/src/unit_tests/chain_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use linera_base::{
UserApplicationDescription,
},
hashed::Hashed,
identifiers::{ApplicationId, ChainId, MessageId, ModuleId},
identifiers::{AccountOwner, ApplicationId, ChainId, MessageId, ModuleId},
ownership::ChainOwnership,
vm::VmRuntime,
};
Expand Down Expand Up @@ -168,7 +168,7 @@ async fn test_block_size_limit() {
let invalid_block = valid_block
.clone()
.with_operation(SystemOperation::Transfer {
owner: None,
owner: AccountOwner::Chain,
recipient: Recipient::root(0),
amount: Amount::ONE,
});
Expand Down
2 changes: 1 addition & 1 deletion linera-client/src/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ where
amount,
),
None => Operation::System(SystemOperation::Transfer {
owner: None,
owner: AccountOwner::Chain,
recipient: Recipient::chain(previous_chain_id),
amount,
}),
Expand Down
6 changes: 4 additions & 2 deletions linera-client/src/unit_tests/chain_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use futures::{lock::Mutex, FutureExt as _};
use linera_base::{
crypto::{AccountPublicKey, AccountSecretKey, Secp256k1SecretKey},
data_types::{Amount, BlockHeight, TimeDelta, Timestamp},
identifiers::ChainId,
identifiers::{AccountOwner, ChainId},
ownership::{ChainOwnership, TimeoutConfig},
};
use linera_core::{
Expand Down Expand Up @@ -160,7 +160,9 @@ async fn test_chain_listener() -> anyhow::Result<()> {
// Transfer one token to chain 0. The listener should eventually become leader and receive
// the message.
let recipient0 = Recipient::chain(chain_id0);
client1.transfer(None, Amount::ONE, recipient0).await?;
client1
.transfer(AccountOwner::Chain, Amount::ONE, recipient0)
.await?;
for i in 0.. {
client0.synchronize_from_validators().boxed().await?;
let balance = client0.local_balance().await?;
Expand Down
8 changes: 6 additions & 2 deletions linera-core/benches/client_benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
// SPDX-License-Identifier: Apache-2.0

use criterion::{criterion_group, criterion_main, measurement::Measurement, BatchSize, Criterion};
use linera_base::{data_types::Amount, identifiers::Account, time::Duration};
use linera_base::{
data_types::Amount,
identifiers::{Account, AccountOwner},
time::Duration,
};
use linera_core::{
client,
test_utils::{MemoryStorageBuilder, NodeProvider, StorageBuilder, TestBuilder},
Expand Down Expand Up @@ -55,7 +59,7 @@ where

let account = Account::owner(chain2.chain_id(), owner1);
let cert = chain1
.transfer_to_account(None, amt, account)
.transfer_to_account(AccountOwner::Chain, amt, account)
.await
.unwrap()
.unwrap();
Expand Down
8 changes: 4 additions & 4 deletions linera-core/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1610,7 +1610,7 @@ where
#[instrument(level = "trace")]
pub async fn transfer(
&self,
owner: Option<Owner>,
owner: AccountOwner,
amount: Amount,
recipient: Recipient,
) -> Result<ClientOutcome<ConfirmedBlockCertificate>, ChainClientError> {
Expand Down Expand Up @@ -2432,7 +2432,7 @@ where
#[instrument(level = "trace")]
pub async fn transfer_to_account(
&self,
owner: Option<Owner>,
owner: AccountOwner,
amount: Amount,
account: Account,
) -> Result<ClientOutcome<ConfirmedBlockCertificate>, ChainClientError> {
Expand All @@ -2444,7 +2444,7 @@ where
#[instrument(level = "trace")]
pub async fn burn(
&self,
owner: Option<Owner>,
owner: AccountOwner,
amount: Amount,
) -> Result<ClientOutcome<ConfirmedBlockCertificate>, ChainClientError> {
self.transfer(owner, amount, Recipient::Burn).await
Expand Down Expand Up @@ -3159,7 +3159,7 @@ where
#[instrument(level = "trace")]
pub async fn transfer_to_account_unsafe_unconfirmed(
&self,
owner: Option<Owner>,
owner: AccountOwner,
amount: Amount,
account: Account,
) -> Result<ClientOutcome<ConfirmedBlockCertificate>, ChainClientError> {
Expand Down
Loading