Skip to content

Commit

Permalink
Merge pull request #2506 from happybeing/create-register-option-value
Browse files Browse the repository at this point in the history
api: allow creation of a register with optional value
  • Loading branch information
b-zee authored Dec 9, 2024
2 parents dbcd2ab + 0e5a1a9 commit ca1bdff
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 10 deletions.
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

0 comments on commit ca1bdff

Please sign in to comment.