Skip to content

Commit

Permalink
[Publishing Tool 2]: Various updates
Browse files Browse the repository at this point in the history
  • Loading branch information
0xOmarA committed May 20, 2024
1 parent c398b7a commit 67bf42e
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 62 deletions.
9 changes: 4 additions & 5 deletions tools/publishing-tool-2/src/cli/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use publishing_tool_2::publishing::*;
use publishing_tool_2::utils::*;
use radix_common::prelude::*;
use radix_transactions::prelude::*;
use state_manager::ActualStateManagerDatabase;
use state_manager::*;
use std::path::*;

#[derive(Parser, Debug)]
Expand Down Expand Up @@ -89,9 +89,8 @@ impl Publish {
retries: 10,
},
);
// let receipt = publish(&configuration, &mut gateway_network_provider)?;
// writeln!(f, "{}", to_json(&receipt, &network_definition))
// .map_err(Error::IoError)
Ok(())
let receipt = publish(&configuration, &mut gateway_network_provider)?;
writeln!(f, "{}", to_json(&receipt, &network_definition))
.map_err(Error::IoError)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -198,5 +198,10 @@ pub fn mainnet_production(
},
}),
},
oracle_handling: OracleHandling::UseExisting {
component_address: component_address!(
"component_rdx1cr3psyfptwkktqusfg8ngtupr4wwfg32kz2xvh9tqh4c7pwkvlk2kn"
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ impl NetworkConnectionProvider for GatewayNetworkConnector {
GatewayExecutorError::TransactionHashBech32mEncoderError,
)?
};
println!("{intent_hash_string}");

for _ in 0..self.polling_configuration.retries {
let transaction_status_response = transaction_status(
Expand Down
10 changes: 10 additions & 0 deletions tools/publishing-tool-2/src/publishing/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ pub struct PublishingConfiguration {
pub exchange_information: ExchangeIndexedData<
Option<ExchangeInformation<PoolHandling, LiquidityReceiptHandling>>,
>,

/// Defines how the tool should handle the oracle and whether it should
/// instantiate a new one or make use of an existing one.
pub oracle_handling: OracleHandling,
}

#[derive(Debug, Clone, ScryptoSbor)]
pub enum OracleHandling {
UseExisting { component_address: ComponentAddress },
CreateNew,
}

#[derive(Debug, Clone, ScryptoSbor)]
Expand Down
115 changes: 58 additions & 57 deletions tools/publishing-tool-2/src/publishing/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ pub fn publish<N: NetworkConnectionProvider>(
}

// Creating transactions of the batches
let mut addresses_map = IndexMap::<String, BlueprintId>::new();
let mut blueprint_id_map = IndexMap::<String, BlueprintId>::new();
for batch in batches {
let mut manifest_builder = ManifestBuilder::new();
for (_, (code, definition, metadata, _)) in batch.iter() {
Expand All @@ -488,7 +488,7 @@ pub fn publish<N: NetworkConnectionProvider>(
}
let manifest = manifest_builder.build();

addresses_map.extend(
blueprint_id_map.extend(
execution_service
.execute_manifest(manifest.clone())?
.new_entities
Expand All @@ -512,31 +512,29 @@ pub fn publish<N: NetworkConnectionProvider>(
);
}

let addresses_map = configuration
let blueprint_id_map = configuration
.packages
.protocol_entities
.into_map()
.into_iter()
.chain(configuration.packages.exchange_adapter_entities.into_map())
.filter_map(|(key, value)| {
if let PackageHandling::UseExisting {
blueprint_id: package_address,
} = value
{
Some((key.to_owned(), package_address.clone()))
if let PackageHandling::UseExisting { blueprint_id } = value {
Some((key.to_owned(), blueprint_id.clone()))
} else {
None
}
})
.chain(addresses_map)
.chain(blueprint_id_map)
.collect::<IndexMap<_, _>>();

Entities {
protocol_entities: ProtocolIndexedData::from_map(
addresses_map.clone(),
blueprint_id_map.clone(),
)
.expect("Can't fail!"),
exchange_adapter_entities: ExchangeIndexedData::from_map(
addresses_map,
blueprint_id_map,
)
.expect("Can't fail!"),
}
Expand Down Expand Up @@ -638,54 +636,57 @@ pub fn publish<N: NetworkConnectionProvider>(
};

// Instantiating the oracle component
let oracle_component_address = {
let mut metadata_init = configuration
.protocol_configuration
.entities_metadata
.protocol_entities
.simple_oracle
.clone();
let oracle_component_address = match configuration.oracle_handling {
OracleHandling::UseExisting { component_address } => component_address,
OracleHandling::CreateNew => {
let mut metadata_init = configuration
.protocol_configuration
.entities_metadata
.protocol_entities
.simple_oracle
.clone();

metadata_init.data.insert(
"dapp_definition".to_owned(),
KeyValueStoreInitEntry {
value: Some(MetadataValue::GlobalAddress(
dapp_definition_account.into(),
)),
lock: false,
},
);
metadata_init.data.insert(
"dapp_definition".to_owned(),
KeyValueStoreInitEntry {
value: Some(MetadataValue::GlobalAddress(
dapp_definition_account.into(),
)),
lock: false,
},
);

let manifest = ManifestBuilder::new()
.call_function(
resolved_blueprint_ids
.protocol_entities
.simple_oracle
.package_address,
resolved_blueprint_ids
.protocol_entities
.simple_oracle
.blueprint_name
.clone(),
"instantiate",
(
resolved_rules.oracle_manager_badge.clone(),
metadata_init,
OwnerRole::Fixed(
resolved_rules.protocol_owner_badge.clone(),
let manifest = ManifestBuilder::new()
.call_function(
resolved_blueprint_ids
.protocol_entities
.simple_oracle
.package_address,
resolved_blueprint_ids
.protocol_entities
.simple_oracle
.blueprint_name
.clone(),
"instantiate",
(
resolved_rules.oracle_manager_badge.clone(),
metadata_init,
OwnerRole::Fixed(
resolved_rules.protocol_owner_badge.clone(),
),
None::<ManifestAddressReservation>,
),
None::<ManifestAddressReservation>,
),
)
.build();
)
.build();

execution_service
.execute_manifest(manifest)?
.new_entities
.new_component_addresses
.first()
.copied()
.unwrap()
execution_service
.execute_manifest(manifest)?
.new_entities
.new_component_addresses
.first()
.copied()
.unwrap()
}
};

// Instantiating the Ignition component
Expand Down Expand Up @@ -825,8 +826,8 @@ pub fn publish<N: NetworkConnectionProvider>(
{
let manifest = ManifestBuilder::new()
.create_proof_from_account_of_amount(
resolved_badges.protocol_owner_badge.0,
resolved_badges.protocol_owner_badge.1,
resolved_badges.protocol_manager_badge.0,
resolved_badges.protocol_manager_badge.1,
dec!(1),
)
.then(|builder| {
Expand Down

0 comments on commit 67bf42e

Please sign in to comment.