Skip to content

Commit

Permalink
introduce feature gate for new features
Browse files Browse the repository at this point in the history
  • Loading branch information
biryukovmaxim committed Jun 16, 2024
1 parent 38d526a commit 5098caf
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 50 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions crypto/txscript/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ kip-10-mutual-tx = []
[dependencies]
blake2b_simd.workspace = true
borsh.workspace = true
cfg-if.workspace = true
indexmap.workspace = true
itertools.workspace = true
kaspa-addresses.workspace = true
Expand Down
124 changes: 74 additions & 50 deletions crypto/txscript/src/opcodes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -875,68 +875,92 @@ opcode_list! {
_ => Err(TxScriptError::InvalidSource("LockTimeVerify only applies to transaction inputs".to_string()))
}
}

// Undefined opcodes.
opcode OpInputSPK<0xb2, 1>(self, vm) {
match vm.script_source {
ScriptSource::TxInput{
utxo_entry: kaspa_consensus_core::tx::UtxoEntry{
script_public_key: spk @ kaspa_consensus_core::tx::ScriptPublicKey{
version, ..},
..
},
..
} => {
let version = version.to_be_bytes();
let script = spk.script();
let mut v = Vec::with_capacity(version.len() + script.len());
v.extend_from_slice(&version);
v.extend_from_slice(script);
vm.dstack.push(v);
Ok(())
},
_ => Err(TxScriptError::InvalidSource("OpInputSPK only applies to transaction inputs".to_string()))
cfg_if::cfg_if! {
if #[cfg(feature = "kip-10-mutual-tx")] {
match vm.script_source {
ScriptSource::TxInput{
utxo_entry: kaspa_consensus_core::tx::UtxoEntry{
script_public_key: spk @ kaspa_consensus_core::tx::ScriptPublicKey{
version, ..},
..
},
..
} => {
let version = version.to_be_bytes();
let script = spk.script();
let mut v = Vec::with_capacity(version.len() + script.len());
v.extend_from_slice(&version);
v.extend_from_slice(script);
vm.dstack.push(v);
Ok(())
},
_ => Err(TxScriptError::InvalidSource("OpInputSPK only applies to transaction inputs".to_string()))
}
} else {
Err(TxScriptError::InvalidOpcode(format!("{self:?}")))
}
}
}
opcode OpInputAmount<0xb3, 1>(self, vm) {
match vm.script_source {
ScriptSource::TxInput{
utxo_entry: kaspa_consensus_core::tx::UtxoEntry{
amount,
..
},
..
} => {
push_number(*amount as i64, vm)
},
_ => Err(TxScriptError::InvalidSource("OpInputAmount only applies to transaction inputs".to_string()))
cfg_if::cfg_if! {
if #[cfg(feature = "kip-10-mutual-tx")] {
match vm.script_source {
ScriptSource::TxInput{
utxo_entry: kaspa_consensus_core::tx::UtxoEntry{
amount,
..
},
..
} => {
push_number(*amount as i64, vm)
},
_ => Err(TxScriptError::InvalidSource("OpInputAmount only applies to transaction inputs".to_string()))
}
} else {
Err(TxScriptError::InvalidOpcode(format!("{self:?}")))
}
}
}
opcode OpOutputSpk<0xb4, 1>(self, vm) {
match vm.script_source {
ScriptSource::TxInput{tx, id , ..} => {
let v = tx.outputs().get(id).map(|output| {
let version = output.script_public_key.version.to_be_bytes();
let script = output.script_public_key.script();
let mut v = Vec::with_capacity(version.len() + script.len());
v.extend_from_slice(&version);
v.extend_from_slice(script);
v
});
vm.dstack.push(v.unwrap_or_default());
Ok(())
},
_ => Err(TxScriptError::InvalidSource("OpInputAmount only applies to transaction inputs".to_string()))
cfg_if::cfg_if! {
if #[cfg(feature = "kip-10-mutual-tx")] {
match vm.script_source {
ScriptSource::TxInput{tx, id , ..} => {
let v = tx.outputs().get(id).map(|output| {
let version = output.script_public_key.version.to_be_bytes();
let script = output.script_public_key.script();
let mut v = Vec::with_capacity(version.len() + script.len());
v.extend_from_slice(&version);
v.extend_from_slice(script);
v
});
vm.dstack.push(v.unwrap_or_default());
Ok(())
},
_ => Err(TxScriptError::InvalidSource("OpInputAmount only applies to transaction inputs".to_string()))
}
} else {
Err(TxScriptError::InvalidOpcode(format!("{self:?}")))
}
}
}
opcode OpOutputAmount<0xb5, 1>(self, vm) {
match vm.script_source {
ScriptSource::TxInput{tx, id , ..} => {
push_number(tx.outputs().get(id).map(|output| output.value).unwrap_or_default() as i64, vm)
},
_ => Err(TxScriptError::InvalidSource("OpInputAmount only applies to transaction inputs".to_string()))
cfg_if::cfg_if! {
if #[cfg(feature = "kip-10-mutual-tx")] {
match vm.script_source {
ScriptSource::TxInput{tx, id , ..} => {
push_number(tx.outputs().get(id).map(|output| output.value).unwrap_or_default() as i64, vm)
},
_ => Err(TxScriptError::InvalidSource("OpInputAmount only applies to transaction inputs".to_string()))
}
} else {
Err(TxScriptError::InvalidOpcode(format!("{self:?}")))
}
}
}

// Undefined opcodes.
opcode OpUnknown182<0xb6, 1>(self, vm) Err(TxScriptError::InvalidOpcode(format!("{self:?}")))
opcode OpUnknown183<0xb7, 1>(self, vm) Err(TxScriptError::InvalidOpcode(format!("{self:?}")))
opcode OpUnknown184<0xb8, 1>(self, vm) Err(TxScriptError::InvalidOpcode(format!("{self:?}")))
Expand Down

0 comments on commit 5098caf

Please sign in to comment.