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!: global publish template, malleability fix, pub templates in wallet #1228

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
3 changes: 2 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions applications/tari_dan_app_utilities/src/base_layer_scanner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,8 @@ impl<TAddr: NodeAddressable + 'static> BaseLayerScanner<TAddr> {
target: LOG_TARGET,
"🌠 new template found with address {} at height {}", template_address, block_info.height
);
let consensus_constants = self.epoch_manager.get_base_layer_consensus_constants().await?;
let epoch = consensus_constants.height_to_epoch(block_info.height);
self.template_manager
.add_template(
registration.author_public_key,
Expand All @@ -484,6 +486,7 @@ impl<TAddr: NodeAddressable + 'static> BaseLayerScanner<TAddr> {
registration.binary_sha,
),
Some(template_name),
epoch,
)
.await?;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ use chrono::Utc;
use log::*;
use tari_common_types::types::{FixedHash, PublicKey};
use tari_crypto::tari_utilities::ByteArray;
use tari_dan_common_types::{optional::Optional, services::template_provider::TemplateProvider, NodeAddressable};
use tari_dan_common_types::{
optional::Optional,
services::template_provider::TemplateProvider,
Epoch,
NodeAddressable,
};
use tari_dan_engine::{
flow::FlowFactory,
function_definitions::FlowFunctionDefinition,
Expand Down Expand Up @@ -192,6 +197,7 @@ impl<TAddr: NodeAddressable> TemplateManager<TAddr> {
template: TemplateExecutable,
template_name: Option<String>,
template_status: Option<TemplateStatus>,
epoch: Epoch,
) -> Result<(), TemplateManagerError> {
enum TemplateHash {
Hash(Hash),
Expand Down Expand Up @@ -244,6 +250,7 @@ impl<TAddr: NodeAddressable> TemplateManager<TAddr> {
flow_json,
manifest,
url: template_url,
epoch,
};

let mut tx = self.global_db.create_transaction()?;
Expand Down Expand Up @@ -326,21 +333,6 @@ impl<TAddr: NodeAddressable + Send + Sync + 'static> TemplateProvider for Templa

Ok(Some(loaded))
}

fn add_wasm_template(
&self,
author_public_key: PublicKey,
template_address: tari_engine_types::TemplateAddress,
template: &[u8],
) -> Result<(), Self::Error> {
self.add_template(
author_public_key,
template_address,
TemplateExecutable::CompiledWasm(template.to_vec()),
None,
Some(TemplateStatus::Active),
)
}
}

impl<TAddr> Clone for TemplateManager<TAddr> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

use log::*;
use tari_common_types::types::PublicKey;
use tari_dan_common_types::{services::template_provider::TemplateProvider, NodeAddressable};
use tari_dan_common_types::{services::template_provider::TemplateProvider, Epoch, NodeAddressable};
use tari_dan_engine::function_definitions::FlowFunctionDefinition;
use tari_dan_storage::global::{DbTemplateType, DbTemplateUpdate, TemplateStatus};
use tari_engine_types::calculate_template_binary_hash;
Expand Down Expand Up @@ -124,11 +124,12 @@ impl<TAddr: NodeAddressable + 'static> TemplateManagerService<TAddr> {
template_address,
template,
template_name,
epoch,
reply,
} => {
handle(
reply,
self.handle_add_template(author_public_key, template_address, template, template_name)
self.handle_add_template(author_public_key, template_address, template, template_name, epoch)
.await,
);
},
Expand Down Expand Up @@ -243,6 +244,7 @@ impl<TAddr: NodeAddressable + 'static> TemplateManagerService<TAddr> {
template_address: tari_engine_types::TemplateAddress,
template: TemplateExecutable,
template_name: Option<String>,
epoch: Epoch,
) -> Result<(), TemplateManagerError> {
let template_status = if matches!(template, TemplateExecutable::DownloadableWasm(_, _)) {
TemplateStatus::New
Expand All @@ -255,6 +257,7 @@ impl<TAddr: NodeAddressable + 'static> TemplateManagerService<TAddr> {
template.clone(),
template_name,
Some(template_status),
epoch,
)?;

// TODO: remove when we remove support for base layer template registration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use tari_common_types::types::PublicKey;
use tari_dan_common_types::Epoch;
use tari_template_lib::models::TemplateAddress;
use tari_validator_node_client::types::TemplateAbi;
use tokio::sync::{mpsc, oneshot};
Expand Down Expand Up @@ -70,6 +71,7 @@ impl TemplateManagerHandle {
template_address: TemplateAddress,
template: TemplateExecutable,
template_name: Option<String>,
epoch: Epoch,
) -> Result<(), TemplateManagerError> {
let (tx, rx) = oneshot::channel();
self.request_tx
Expand All @@ -78,6 +80,7 @@ impl TemplateManagerHandle {
template_address,
template,
template_name,
epoch,
reply: tx,
})
.await
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

use reqwest::Url;
use tari_common_types::types::{FixedHash, PublicKey};
use tari_dan_common_types::Epoch;
use tari_dan_storage::global::{DbTemplate, DbTemplateType};
use tari_template_lib::models::TemplateAddress;
use tari_validator_node_client::types::TemplateAbi;
Expand Down Expand Up @@ -91,6 +92,7 @@ pub enum TemplateManagerRequest {
template_address: tari_engine_types::TemplateAddress,
template: TemplateExecutable,
template_name: Option<String>,
epoch: Epoch,
reply: oneshot::Sender<Result<(), TemplateManagerError>>,
},
GetTemplate {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ where TTemplateProvider: TemplateProvider<Template = LoadedTemplate>
let initial_ownership_proofs = transaction
.signatures()
.iter()
.map(|sig| public_key_to_fungible_address(sig.public_key()))
.map(|p| p.public_key())
.chain(Some(transaction.seal_signature().public_key()).filter(|_| transaction.is_seal_signer_authorized()))
.map(public_key_to_fungible_address)
.collect();
let auth_params = AuthParams {
initial_ownership_proofs,
Expand Down
7 changes: 3 additions & 4 deletions applications/tari_dan_wallet_cli/src/command/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,7 @@ async fn handle_submit_manifest(
component_address: fee_account.address.as_component_address().unwrap(),
method: "pay_fee".to_string(),
args: args![Amount::try_from(common.max_fee.unwrap_or(1000))?],
}])
.collect(),
}]),
)
.with_instructions(instructions.instructions)
.with_inputs(common.inputs)
Expand Down Expand Up @@ -472,12 +471,12 @@ fn summarize_transaction(transaction: &UnsignedTransaction) {
}
println!();
println!("🌟 Submitting fee instructions:");
for instruction in &transaction.fee_instructions {
for instruction in transaction.fee_instructions() {
println!("- {}", instruction);
}
println!();
println!("🌟 Submitting instructions:");
for instruction in &transaction.instructions {
for instruction in transaction.instructions() {
println!("- {}", instruction);
}
println!();
Expand Down
10 changes: 5 additions & 5 deletions applications/tari_dan_wallet_daemon/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ fn exit_on_ci() {
}

const BUILD: &[(&str, &[&str])] = &[
("../../bindings", &["ci"]),
("../../bindings", &["run", "tsc"]),
("../../clients/javascript/wallet_daemon_client", &["ci"]),
("../../bindings", &["install"]),
("../../bindings", &["run", "ts-build"]),
("../../clients/javascript/wallet_daemon_client", &["install"]),
("../../clients/javascript/wallet_daemon_client", &["run", "build"]),
("../tari_dan_wallet_web_ui", &["run", "build"]),
];
Expand All @@ -48,8 +48,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let npm = if cfg!(windows) { "npm.cmd" } else { "npm" };

for (target, args) in BUILD {
if let Err(error) = Command::new(npm).arg("ci").current_dir(target).status() {
println!("cargo:warning='npm ci' error : {:?}", error);
if let Err(error) = Command::new(npm).args(["install"]).current_dir(target).status() {
println!("cargo:warning='npm install' error : {:?}", error);
exit_on_ci();
break;
}
Expand Down
14 changes: 5 additions & 9 deletions applications/tari_dan_wallet_daemon/src/handlers/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@ pub async fn handle_create(
.fee_transaction_pay_from_component(default_account.address.as_component_address().unwrap(), max_fee)
.create_account(owner_pk.clone())
.with_inputs(inputs)
.sign(&signing_key.key)
.build();
.build_and_seal(&signing_key.key);

let mut events = context.notifier().subscribe();
let tx_id = context
Expand Down Expand Up @@ -227,8 +226,7 @@ pub async fn handle_invoke(
.fee_transaction_pay_from_component(account_address, req.max_fee.unwrap_or(DEFAULT_FEE))
.call_method(account_address, &req.method, req.args)
.with_inputs(inputs)
.sign(&signing_key.key)
.build();
.build_and_seal(&signing_key.key);

let mut events = context.notifier().subscribe();
let tx_id = context
Expand Down Expand Up @@ -433,7 +431,7 @@ pub async fn handle_reveal_funds(
.into_iter()
.map(|addr| SubstateRequirement::new(addr.substate_id.clone(), Some(addr.version)));

let transaction = builder.with_inputs(inputs).sign(&account_key.key).build();
let transaction = builder.with_inputs(inputs).build_and_seal(&account_key.key);

sdk.confidential_outputs_api()
.proofs_set_transaction_hash(proof_id, *transaction.id())?;
Expand Down Expand Up @@ -698,8 +696,7 @@ async fn finish_claiming<T: WalletStore>(
let transaction = Transaction::builder()
.with_fee_instructions(instructions)
.with_inputs(inputs)
.sign(&account_secret_key.key)
.build();
.build_and_seal(&account_secret_key.key);
let is_first_account = accounts_api.count()? == 0;
let mut events = context.notifier().subscribe();
let tx_id = context
Expand Down Expand Up @@ -948,8 +945,7 @@ pub async fn handle_transfer(
.with_fee_instructions(fee_instructions)
.with_instructions(instructions)
.with_inputs(vec![resource_substate_address])
.sign(&account_secret_key.key)
.build();
.build_and_seal(&account_secret_key.key);

let required_inputs = inputs.into_iter().map(Into::into).collect();
// If dry run we can return the result immediately
Expand Down
6 changes: 2 additions & 4 deletions applications/tari_dan_wallet_daemon/src/handlers/nfts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,7 @@ async fn mint_account_nft(
let transaction = Transaction::builder()
.fee_transaction_pay_from_component(account.address.as_component_address().unwrap(), fee)
.with_instructions(instructions)
.sign(owner_sk)
.build();
.build_and_seal(owner_sk);

let mut events = context.notifier().subscribe();
let tx_id = context
Expand Down Expand Up @@ -254,8 +253,7 @@ async fn create_account_nft(
.fee_transaction_pay_from_component(account.address.as_component_address().unwrap(), fee)
.call_function(ACCOUNT_NFT_TEMPLATE_ADDRESS, "create", args![owner_token,])
.with_inputs(inputs)
.sign(owner_sk)
.build();
.build_and_seal(owner_sk);

let tx_id = sdk
.transaction_api()
Expand Down
Loading
Loading