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

feat!: add claim public key to OutputFeatures #5239

Merged
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
5 changes: 5 additions & 0 deletions applications/tari_app_grpc/proto/sidechain_types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ message SideChainFeature {
oneof side_chain_feature {
ValidatorNodeRegistration validator_node_registration = 1;
TemplateRegistration template_registration = 2;
ConfidentialOutputData confidential_output = 3;
}
}

Expand All @@ -48,6 +49,10 @@ message TemplateRegistration {
string binary_url = 8;
}

message ConfidentialOutputData {
bytes claim_public_key = 1;
}

message TemplateType {
oneof template_type {
WasmInfo wasm = 1;
Expand Down
26 changes: 26 additions & 0 deletions applications/tari_app_grpc/src/conversions/sidechain_feature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use tari_core::{
transactions::transaction_components::{
BuildInfo,
CodeTemplateRegistration,
ConfidentialOutputData,
SideChainFeature,
TemplateType,
ValidatorNodeRegistration,
Expand Down Expand Up @@ -56,6 +57,9 @@ impl From<SideChainFeature> for grpc::side_chain_feature::SideChainFeature {
SideChainFeature::TemplateRegistration(template_reg) => {
grpc::side_chain_feature::SideChainFeature::TemplateRegistration(template_reg.into())
},
SideChainFeature::ConfidentialOutput(output_data) => {
grpc::side_chain_feature::SideChainFeature::ConfidentialOutput(output_data.into())
},
}
}
}
Expand All @@ -71,6 +75,9 @@ impl TryFrom<grpc::side_chain_feature::SideChainFeature> for SideChainFeature {
grpc::side_chain_feature::SideChainFeature::TemplateRegistration(template_reg) => {
Ok(SideChainFeature::TemplateRegistration(template_reg.try_into()?))
},
grpc::side_chain_feature::SideChainFeature::ConfidentialOutput(output_data) => {
Ok(SideChainFeature::ConfidentialOutput(output_data.try_into()?))
},
}
}
}
Expand Down Expand Up @@ -144,6 +151,25 @@ impl From<CodeTemplateRegistration> for grpc::TemplateRegistration {
}
}

// -------------------------------- ConfidentialOutputData -------------------------------- //
impl TryFrom<grpc::ConfidentialOutputData> for ConfidentialOutputData {
type Error = String;

fn try_from(value: grpc::ConfidentialOutputData) -> Result<Self, Self::Error> {
Ok(ConfidentialOutputData {
claim_public_key: PublicKey::from_bytes(&value.claim_public_key).map_err(|e| e.to_string())?,
})
}
}

impl From<ConfidentialOutputData> for grpc::ConfidentialOutputData {
fn from(value: ConfidentialOutputData) -> Self {
Self {
claim_public_key: value.claim_public_key.to_vec(),
}
}
}

// -------------------------------- TemplateType -------------------------------- //
impl TryFrom<grpc::TemplateType> for TemplateType {
type Error = String;
Expand Down
5 changes: 5 additions & 0 deletions base_layer/core/src/proto/sidechain_feature.proto
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ message SideChainFeature {
oneof side_chain_feature {
ValidatorNodeRegistration validator_node_registration = 1;
TemplateRegistration template_registration = 2;
ConfidentialOutputData confidential_output = 3;
}
}

Expand All @@ -30,6 +31,10 @@ message TemplateRegistration {
string binary_url = 8;
}

message ConfidentialOutputData {
bytes claim_public_key = 1;
}

message TemplateType {
oneof template_type {
WasmInfo wasm = 1;
Expand Down
26 changes: 26 additions & 0 deletions base_layer/core/src/proto/sidechain_feature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use crate::{
transactions::transaction_components::{
BuildInfo,
CodeTemplateRegistration,
ConfidentialOutputData,
SideChainFeature,
TemplateType,
ValidatorNodeRegistration,
Expand All @@ -58,6 +59,9 @@ impl From<SideChainFeature> for proto::types::side_chain_feature::SideChainFeatu
SideChainFeature::TemplateRegistration(template_reg) => {
proto::types::side_chain_feature::SideChainFeature::TemplateRegistration(template_reg.into())
},
SideChainFeature::ConfidentialOutput(output_data) => {
proto::types::side_chain_feature::SideChainFeature::ConfidentialOutput(output_data.into())
},
}
}
}
Expand All @@ -73,6 +77,9 @@ impl TryFrom<proto::types::side_chain_feature::SideChainFeature> for SideChainFe
proto::types::side_chain_feature::SideChainFeature::TemplateRegistration(template_reg) => {
Ok(SideChainFeature::TemplateRegistration(template_reg.try_into()?))
},
proto::types::side_chain_feature::SideChainFeature::ConfidentialOutput(output_data) => {
Ok(SideChainFeature::ConfidentialOutput(output_data.try_into()?))
},
}
}
}
Expand Down Expand Up @@ -146,6 +153,25 @@ impl From<CodeTemplateRegistration> for proto::types::TemplateRegistration {
}
}

// -------------------------------- ConfidentialOutputData -------------------------------- //
impl TryFrom<proto::types::ConfidentialOutputData> for ConfidentialOutputData {
type Error = String;

fn try_from(value: proto::types::ConfidentialOutputData) -> Result<Self, Self::Error> {
Ok(ConfidentialOutputData {
claim_public_key: PublicKey::from_bytes(&value.claim_public_key).map_err(|e| e.to_string())?,
})
}
}

impl From<ConfidentialOutputData> for proto::types::ConfidentialOutputData {
fn from(value: ConfidentialOutputData) -> Self {
Self {
claim_public_key: value.claim_public_key.to_vec(),
}
}
}

// -------------------------------- TemplateType -------------------------------- //
impl TryFrom<proto::types::TemplateType> for TemplateType {
type Error = String;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use super::OutputFeaturesVersion;
use crate::transactions::transaction_components::{
side_chain::SideChainFeature,
CodeTemplateRegistration,
ConfidentialOutputData,
OutputType,
ValidatorNodeRegistration,
ValidatorNodeSignature,
Expand Down Expand Up @@ -107,6 +108,17 @@ impl OutputFeatures {
}
}

/// creates output features for a burned output with confidential output data
pub fn create_burn_confidential_output(claim_public_key: PublicKey) -> OutputFeatures {
OutputFeatures {
output_type: OutputType::Burn,
sidechain_feature: Some(SideChainFeature::ConfidentialOutput(ConfidentialOutputData {
claim_public_key,
})),
..Default::default()
}
}

/// Creates template registration output features
pub fn for_template_registration(template_registration: CodeTemplateRegistration) -> OutputFeatures {
OutputFeatures {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2023. The Tari Project
//
// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
// following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following
// disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
// following disclaimer in the documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote
// products derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use borsh::{BorshDeserialize, BorshSerialize};
use serde::{Deserialize, Serialize};
use tari_common_types::types::PublicKey;

#[derive(Debug, Clone, Hash, PartialEq, Deserialize, Serialize, Eq, BorshSerialize, BorshDeserialize)]
pub struct ConfidentialOutputData {
pub claim_public_key: PublicKey,
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@
mod sidechain_feature;
pub use sidechain_feature::SideChainFeature;

mod confidential_output;
mod template_registration;
mod validator_node_registration;
mod validator_node_signature;

pub use confidential_output::ConfidentialOutputData;
use tari_crypto::{hash::blake2::Blake256, hash_domain, hashing::DomainSeparatedHasher};
pub use template_registration::{BuildInfo, CodeTemplateRegistration, TemplateType};
pub use validator_node_registration::ValidatorNodeRegistration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,17 @@
use borsh::{BorshDeserialize, BorshSerialize};
use serde::{Deserialize, Serialize};

use crate::transactions::transaction_components::{CodeTemplateRegistration, ValidatorNodeRegistration};
use crate::transactions::transaction_components::{
side_chain::confidential_output::ConfidentialOutputData,
CodeTemplateRegistration,
ValidatorNodeRegistration,
};

#[derive(Debug, Clone, Hash, PartialEq, Deserialize, Serialize, Eq, BorshSerialize, BorshDeserialize)]
pub enum SideChainFeature {
ValidatorNodeRegistration(ValidatorNodeRegistration),
TemplateRegistration(CodeTemplateRegistration),
ConfidentialOutput(ConfidentialOutputData),
}

impl SideChainFeature {
Expand All @@ -45,4 +50,11 @@ impl SideChainFeature {
_ => None,
}
}

pub fn confidential_output_data(&self) -> Option<&ConfidentialOutputData> {
match self {
Self::ConfidentialOutput(v) => Some(v),
_ => None,
}
}
}
Loading