Skip to content

Commit 14144a9

Browse files
authored
add 'pc-node smart-contracts upsert-script' command (#1016)
1 parent b744de5 commit 14144a9

File tree

11 files changed

+343
-42
lines changed

11 files changed

+343
-42
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,7 @@ substrate-prometheus-endpoint = { package = "substrate-prometheus-endpoint", git
258258
substrate-test-runtime-client = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2506-2" }
259259
substrate-wasm-builder = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2506-2" }
260260

261-
raw-scripts = { git = "https://github.com/input-output-hk/partner-chains-smart-contracts.git", tag = "v8.1.0" }
262-
261+
raw-scripts = { git = "https://github.com/input-output-hk/partner-chains-smart-contracts.git", tag = "v8.2.0" }
263262
# local dependencies
264263

265264
# utils

changelog.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,19 @@ This changelog is based on [Keep A Changelog](https://keepachangelog.com/en/1.1.
66

77
## Changed
88

9+
* **BREAKING**: Updated partner-chains-smart-contracts (raw-scripts) dependency to v8.2.0.
10+
Possibility to interact with smart-contracts used by earlier versions is lost.
11+
Governance authority will have to establish new partner chain on Cardano.
12+
All initialization and candidates registrations have to be repeated.
13+
914
## Removed
1015

1116
## Fixed
1217

1318
## Added
1419

20+
* Added `partner-chains-node smart-contracts upsert-script` command for inserting and updating versioned scripts.
21+
1522
# v1.8.0
1623

1724
## Changed

toolkit/sidechain/domain/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,11 @@ impl From<ecdsa::Public> for SidechainPublicKey {
661661
}
662662
}
663663

664+
/// CBOR bytes of Plutus smart contract.
665+
#[derive(Clone, Encode, Decode, DecodeWithMemTracking, TypeInfo, PartialEq, Eq, Hash)]
666+
#[byte_string(debug, hex_serialize, hex_deserialize, decode_hex)]
667+
pub struct PlutusScriptCbor(pub Vec<u8>);
668+
664669
/// CBOR bytes of Cardano Transaction.
665670
#[derive(Clone, Encode, Decode, DecodeWithMemTracking, TypeInfo, PartialEq, Eq, Hash)]
666671
#[byte_string(debug, hex_serialize, hex_deserialize, decode_hex)]

toolkit/smart-contracts/commands/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ pub mod permissioned_candidates;
4242
pub mod register;
4343
pub mod reserve;
4444
pub mod sign_tx;
45+
pub mod versioning;
4546

4647
#[derive(Clone, Debug, clap::Subcommand)]
4748
#[allow(clippy::large_enum_variant)]
@@ -73,6 +74,8 @@ pub enum SmartContractsCmd {
7374
#[command(subcommand)]
7475
/// Send token to bridge contract
7576
Bridge(bridge::BridgeCmd),
77+
/// Upsert versioned smart contract
78+
UpsertScript(versioning::UpsertScriptCmd),
7679
}
7780

7881
#[derive(Clone, Debug, clap::Parser)]
@@ -132,6 +135,7 @@ impl SmartContractsCmd {
132135
Self::SignTx(cmd) => cmd.execute().await,
133136
Self::GovernedMap(cmd) => cmd.execute().await,
134137
Self::Bridge(cmd) => cmd.execute().await,
138+
Self::UpsertScript(cmd) => cmd.execute().await,
135139
}?;
136140
println!("{}", result);
137141
Ok(())
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
use crate::{GenesisUtxo, PaymentFilePath, option_to_json};
2+
use partner_chains_cardano_offchain::{
3+
plutus_script::PlutusScript, versioning_system::upsert_script,
4+
};
5+
use sidechain_domain::PlutusScriptCbor;
6+
7+
#[derive(Clone, Debug, clap::Parser)]
8+
/// Command for upserting the versioned script on the mainchain
9+
pub struct UpsertScriptCmd {
10+
#[clap(flatten)]
11+
common_arguments: crate::CommonArguments,
12+
#[arg(long)]
13+
/// Script ID
14+
script_id: u32,
15+
#[arg(long)]
16+
/// CBOR encoded Plutus V2 script
17+
plutus_script: PlutusScriptCbor,
18+
#[clap(flatten)]
19+
/// Path to the payment key file
20+
payment_key_file: PaymentFilePath,
21+
#[clap(flatten)]
22+
/// Genesis UTXO
23+
genesis_utxo: GenesisUtxo,
24+
}
25+
26+
impl UpsertScriptCmd {
27+
/// Creates or updates a versioning utxo with reference script
28+
pub async fn execute(self) -> crate::SubCmdResult {
29+
let payment_key = self.payment_key_file.read_key()?;
30+
31+
let client = self.common_arguments.get_ogmios_client().await?;
32+
33+
let result = upsert_script(
34+
PlutusScript::v2_from_cbor(&self.plutus_script.0)?,
35+
self.script_id,
36+
self.genesis_utxo.into(),
37+
&payment_key,
38+
&client,
39+
&self.common_arguments.retries(),
40+
)
41+
.await?;
42+
43+
Ok(option_to_json(result))
44+
}
45+
}

toolkit/smart-contracts/offchain/src/bridge/init.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
use crate::{
22
await_tx::AwaitTx,
33
cardano_keys::CardanoPaymentSigningKey,
4+
csl::TransactionContext,
45
multisig::MultiSigSmartContractResult,
5-
plutus_script,
6+
plutus_script, scripts_data,
67
versioning_system::{ScriptData, initialize_script},
78
};
89
use ogmios_client::{
@@ -29,16 +30,25 @@ pub async fn init_ics_scripts<
2930
client: &T,
3031
await_tx: &A,
3132
) -> anyhow::Result<Vec<MultiSigSmartContractResult>> {
33+
let payment_ctx = TransactionContext::for_payment_key(payment_key, client).await?;
34+
let version_oracle = scripts_data::version_oracle(genesis_utxo, payment_ctx.network)?;
35+
3236
let ics_validator = ScriptData::new(
3337
"Illiquid Circulation Supply Validator",
34-
ILLIQUID_CIRCULATION_SUPPLY_VALIDATOR.0.to_vec(),
38+
plutus_script![
39+
ILLIQUID_CIRCULATION_SUPPLY_VALIDATOR,
40+
version_oracle.policy_id_as_plutus_data()
41+
]?
42+
.bytes
43+
.to_vec(),
3544
ScriptId::IlliquidCirculationSupplyValidator,
3645
);
3746
let ics_auth_token_policy = ScriptData::new(
3847
"Illiquid Circulation Supply Auth Token Policy",
3948
plutus_script![
4049
ILLIQUID_CIRCULATION_SUPPLY_AUTHORITY_TOKEN_POLICY,
41-
ScriptId::IlliquidCirculationSupplyAuthorityTokenPolicy
50+
ScriptId::IlliquidCirculationSupplyAuthorityTokenPolicy,
51+
version_oracle.policy_id_as_plutus_data()
4252
]?
4353
.bytes
4454
.to_vec(),

toolkit/smart-contracts/offchain/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ pub mod sign_tx;
3838
mod test_values;
3939
/// Supports governance updates
4040
pub mod update_governance;
41-
42-
mod versioning_system;
41+
/// Supports versioning system
42+
pub mod versioning_system;
4343

4444
/// Simply wraps asset id with amount.
4545
#[derive(Clone)]

toolkit/smart-contracts/offchain/src/reserve/init.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
use crate::{
1717
await_tx::AwaitTx,
1818
cardano_keys::CardanoPaymentSigningKey,
19+
csl::TransactionContext,
1920
multisig::MultiSigSmartContractResult,
21+
plutus_script, scripts_data,
2022
versioning_system::{ScriptData, initialize_script},
2123
};
2224
use ogmios_client::{
@@ -42,14 +44,21 @@ pub async fn init_reserve_management<
4244
client: &T,
4345
await_tx: &A,
4446
) -> anyhow::Result<Vec<MultiSigSmartContractResult>> {
47+
let payment_ctx = TransactionContext::for_payment_key(payment_key, client).await?;
48+
let version_oracle = scripts_data::version_oracle(genesis_utxo, payment_ctx.network)?;
49+
4550
let reserve_validator = ScriptData::new(
4651
"Reserve Management Validator",
47-
RESERVE_VALIDATOR.0.to_vec(),
52+
plutus_script![RESERVE_VALIDATOR, version_oracle.policy_id_as_plutus_data()]?
53+
.bytes
54+
.to_vec(),
4855
ScriptId::ReserveValidator,
4956
);
5057
let reserve_policy = ScriptData::new(
5158
"Reserve Management Policy",
52-
RESERVE_AUTH_POLICY.0.to_vec(),
59+
plutus_script![RESERVE_AUTH_POLICY, version_oracle.policy_id_as_plutus_data()]?
60+
.bytes
61+
.to_vec(),
5362
ScriptId::ReserveAuthPolicy,
5463
);
5564

0 commit comments

Comments
 (0)