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

api: allow creation of a register with optional value #2506

Merged
merged 1 commit into from
Dec 9, 2024
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
4 changes: 2 additions & 2 deletions ant-cli/src/commands/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub async fn create(name: &str, value: &str, public: bool, peers: Vec<Multiaddr>
let permissions = RegisterPermissions::new_anyone_can_write();
client
.register_create_with_permissions(
value.as_bytes().to_vec().into(),
Some(value.as_bytes().to_vec().into()),
name,
register_key,
permissions,
Expand All @@ -80,7 +80,7 @@ pub async fn create(name: &str, value: &str, public: bool, peers: Vec<Multiaddr>
info!("With private write access");
client
.register_create(
value.as_bytes().to_vec().into(),
Some(value.as_bytes().to_vec().into()),
name,
register_key,
&wallet,
Expand Down
7 changes: 6 additions & 1 deletion ant-node/tests/data_with_churn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,12 @@ fn create_registers_task(
let mut retries = 1;
loop {
match client
.register_create(random_data.clone(), &random_name, owner.clone(), &wallet)
.register_create(
Some(random_data.clone()),
&random_name,
owner.clone(),
&wallet,
)
.await
{
Ok(register) => {
Expand Down
7 changes: 6 additions & 1 deletion ant-node/tests/verify_data_location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,12 @@ async fn store_registers(
.map(char::from)
.collect();
let register = client
.register_create(vec![1, 2, 3, 4].into(), &rand_name, key.clone(), wallet)
.register_create(
Some(vec![1, 2, 3, 4].into()),
&rand_name,
key.clone(),
wallet,
)
.await?;

println!("Created Register at {:?}", register.address());
Expand Down
10 changes: 5 additions & 5 deletions autonomi/src/client/registers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,12 +265,12 @@ impl Client {
RegisterAddress::new(name, pk)
}

/// Creates a new Register with a name and an initial value and uploads it to the network.
/// Creates a new Register with a name and optional initial value and uploads it to the network.
///
/// The Register is created with the owner as the only writer.
pub async fn register_create(
&self,
value: Bytes,
value: Option<Bytes>,
name: &str,
owner: RegisterSecretKey,
wallet: &EvmWallet,
Expand All @@ -282,12 +282,12 @@ impl Client {
.await
}

/// Creates a new Register with a name and an initial value and uploads it to the network.
/// Creates a new Register with a name and optional initial value and uploads it to the network.
///
/// Unlike `register_create`, this function allows you to specify the permissions for the register.
pub async fn register_create_with_permissions(
&self,
value: Bytes,
value: Option<Bytes>,
name: &str,
owner: RegisterSecretKey,
permissions: RegisterPermissions,
Expand All @@ -297,7 +297,7 @@ impl Client {
let name = XorName::from_content_parts(&[name.as_bytes()]);

// Owner can write to the register.
let register = Register::new(Some(value), name, owner, permissions)?;
let register = Register::new(value, name, owner, permissions)?;
let address = register.address();

let reg_xor = address.xorname();
Expand Down
7 changes: 6 additions & 1 deletion autonomi/tests/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ async fn register() -> Result<()> {
.map(char::from)
.collect();
let register = client
.register_create(vec![1, 2, 3, 4].into(), &rand_name, key.clone(), &wallet)
.register_create(
Some(vec![1, 2, 3, 4].into()),
&rand_name,
key.clone(),
&wallet,
)
.await
.unwrap();

Expand Down
Loading