Skip to content

Commit 08c1e84

Browse files
committed
Address review comments
1 parent 4e7b63e commit 08c1e84

File tree

8 files changed

+39
-32
lines changed

8 files changed

+39
-32
lines changed

api-server/scanner-lib/src/blockchain_state/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,7 +1201,7 @@ async fn update_tables_from_transaction_inputs<T: ApiServerStorageWrite>(
12011201
)
12021202
.await;
12031203
}
1204-
TxOutput::Htlc(_, _) => {} // TODO: support htlc
1204+
TxOutput::Htlc(_, _) => {} // TODO(HTLC)
12051205
TxOutput::LockThenTransfer(output_value, destination, _)
12061206
| TxOutput::Transfer(output_value, destination) => {
12071207
let address = Address::<Destination>::new(&chain_config, destination)
@@ -1616,7 +1616,7 @@ async fn update_tables_from_transaction_outputs<T: ApiServerStorageWrite>(
16161616
.expect("Unable to set locked utxo");
16171617
}
16181618
}
1619-
TxOutput::Htlc(_, _) => {} // TODO: support htlc
1619+
TxOutput::Htlc(_, _) => {} // TODO(HTLC)
16201620
}
16211621
}
16221622

@@ -1816,6 +1816,6 @@ fn get_tx_output_destination(txo: &TxOutput) -> Option<&Destination> {
18161816
| TxOutput::Burn(_)
18171817
| TxOutput::DelegateStaking(_, _)
18181818
| TxOutput::DataDeposit(_) => None,
1819-
TxOutput::Htlc(_, _) => None, // TODO: support htlc
1819+
TxOutput::Htlc(_, _) => None, // TODO(HTLC)
18201820
}
18211821
}

common/src/chain/config/builder.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ const TESTNET_TOKEN_FORK_HEIGHT: BlockHeight = BlockHeight::new(78440);
5050
// The fork, at which we upgrade chainstate to distribute reward to staker proportionally to their balance
5151
// and change various tokens fees
5252
const TESTNET_STAKER_REWARD_AND_TOKENS_FEE_FORK_HEIGHT: BlockHeight = BlockHeight::new(138244);
53-
// The fork, at which txs with htlc outputs become valid
54-
const TESTNET_HTLC_FORK_HEIGHT: BlockHeight = BlockHeight::new(99999999);
55-
const MAINNET_HTLC_FORK_HEIGHT: BlockHeight = BlockHeight::new(99999999);
53+
// The fork, at which txs with htlc and orders outputs become valid
54+
const TESTNET_HTLC_AND_ORDERS_FORK_HEIGHT: BlockHeight = BlockHeight::new(99999999);
55+
const MAINNET_HTLC_AND_ORDERS_FORK_HEIGHT: BlockHeight = BlockHeight::new(99999999);
5656

5757
impl ChainType {
5858
fn default_genesis_init(&self) -> GenesisBlockInit {
@@ -170,7 +170,7 @@ impl ChainType {
170170
),
171171
),
172172
(
173-
MAINNET_HTLC_FORK_HEIGHT,
173+
MAINNET_HTLC_AND_ORDERS_FORK_HEIGHT,
174174
ChainstateUpgrade::new(
175175
TokenIssuanceVersion::V1,
176176
RewardDistributionVersion::V1,
@@ -223,7 +223,7 @@ impl ChainType {
223223
),
224224
),
225225
(
226-
TESTNET_HTLC_FORK_HEIGHT,
226+
TESTNET_HTLC_AND_ORDERS_FORK_HEIGHT,
227227
ChainstateUpgrade::new(
228228
TokenIssuanceVersion::V1,
229229
RewardDistributionVersion::V1,

common/src/chain/transaction/output/htlc.rs

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ use serialization::{Decode, Encode};
2121

2222
use super::{timelock::OutputTimeLock, Destination};
2323

24+
fixed_hash::construct_fixed_hash! {
25+
#[derive(Encode, Decode, serde::Serialize, serde::Deserialize)]
26+
pub struct SecretHash(20);
27+
}
28+
29+
impl rpc_description::HasValueHint for SecretHash {
30+
const HINT_SER: rpc_description::ValueHint = rpc_description::ValueHint::HEX_STRING;
31+
}
32+
2433
#[derive(Debug, Clone, PartialEq, Eq, Encode, Decode, serde::Serialize, serde::Deserialize)]
2534
pub struct HashedTimelockContract {
2635
// can be spent either by a specific address that knows the secret
@@ -108,19 +117,24 @@ mod tests {
108117
}
109118

110119
#[rstest]
111-
#[case("\"0000000000000000000000000000000000000000\"")]
112-
#[case("\"0000000000000000000000000000000000000001\"")]
113-
#[case("\"ac7b960a8d03705d1ace08b1a19da3fdcc99ddbd\"")]
114-
#[case("\"e4732fe6f1ed1cddc2ed4b328fff5224276e3f6f\"")]
115-
#[case("\"0103b9683e51e5aba83b8a34c9b98ce67d66136c\"")]
116-
fn deserialize_valid(#[case] s: String) {
117-
serde_json::from_str::<HtlcSecretHash>(&s).unwrap();
120+
#[case("\"0000000000000000000000000000000000000000\"", [0;20])]
121+
#[case("\"0000000000000000000000000000000000000001\"", [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1])]
122+
#[case("\"ac7b960a8d03705d1ace08b1a19da3fdcc99ddbd\"", [0xac,0x7b,0x96,0x0a,0x8d,0x03,0x70,0x5d,0x1a,0xce,0x08,0xb1,0xa1,0x9d,0xa3,0xfd,0xcc,0x99,0xdd,0xbd])]
123+
#[case("\"e4732fe6f1ed1cddc2ed4b328fff5224276e3f6f\"", [0xe4,0x73,0x2f,0xe6,0xf1,0xed,0x1c,0xdd,0xc2,0xed,0x4b,0x32,0x8f,0xff,0x52,0x24,0x27,0x6e,0x3f,0x6f])]
124+
#[case("\"0103b9683e51e5aba83b8a34c9b98ce67d66136c\"", [0x01,0x03,0xb9,0x68,0x3e,0x51,0xe5,0xab,0xa8,0x3b,0x8a,0x34,0xc9,0xb9,0x8c,0xe6,0x7d,0x66,0x13,0x6c])]
125+
fn deserialize_valid(#[case] str: String, #[case] expected: [u8; 20]) {
126+
let result = serde_json::from_str::<HtlcSecretHash>(&str).unwrap();
127+
assert_eq!(result, HtlcSecretHash::from_slice(&expected));
118128
}
119129

120130
#[rstest]
121-
#[case("\"00000000000000000000000000000000000000000000000000000000000000\"")]
122-
#[case("\"000000000000000000000000000000000invalid\"")]
123-
fn deserialize_invalid(#[case] s: String) {
124-
serde_json::from_str::<HtlcSecretHash>(&s).unwrap_err();
131+
#[case(
132+
"\"00000000000000000000000000000000000000000000000000000000000000\"",
133+
"Invalid input length"
134+
)]
135+
#[case("\"000000000000000000000000000000000invalid\"", "Invalid character")]
136+
fn deserialize_invalid(#[case] s: String, #[case] expected_msg: String) {
137+
let err = serde_json::from_str::<HtlcSecretHash>(&s).unwrap_err();
138+
assert!(err.to_string().contains(&expected_msg));
125139
}
126140
}

common/src/chain/transaction/output/mod.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,6 @@ pub mod output_value;
4242
pub mod stakelock;
4343
pub mod timelock;
4444

45-
fixed_hash::construct_fixed_hash! {
46-
#[derive(Encode, Decode, serde::Serialize, serde::Deserialize)]
47-
pub struct SecretHash(20);
48-
}
49-
50-
impl rpc_description::HasValueHint for SecretHash {
51-
const HINT_SER: rpc_description::ValueHint = rpc_description::ValueHint::HEX_STRING;
52-
}
53-
5445
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Encode, Decode, VariantCount)]
5546
pub enum Destination {
5647
#[codec(index = 0)]

mintscript/src/translate.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,9 @@ impl<C: InputInfoProvider> TranslateInput<C> for TimelockOnly {
258258
Ok(WitnessScript::timelock(*timelock))
259259
}
260260
TxOutput::Htlc(_, htlc) => match ctx.witness() {
261-
InputWitness::NoSignature(_) => Ok(WitnessScript::TRUE),
261+
InputWitness::NoSignature(_) => Err(TranslationError::SignatureError(
262+
DestinationSigError::SignatureNotFound,
263+
)),
262264
InputWitness::Standard(sig) => {
263265
let htlc_spend =
264266
AuthorizedHashedTimelockContractSpend::from_data(sig.raw_signature())?;

wallet/src/account/transaction_list/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ fn own_output(key_chain: &AccountKeyChainImpl, output: &TxOutput) -> bool {
113113
TxOutput::Transfer(_, dest) | TxOutput::LockThenTransfer(_, dest, _) => KeyPurpose::ALL
114114
.iter()
115115
.any(|purpose| key_chain.get_leaf_key_chain(*purpose).is_destination_mine(dest)),
116-
TxOutput::Htlc(_, _) => false, // TODO: support htlc
116+
TxOutput::Htlc(_, _) => false, // TODO(HTLC)
117117
TxOutput::Burn(_)
118118
| TxOutput::CreateStakePool(_, _)
119119
| TxOutput::ProduceBlockFromStake(_, _)

wallet/src/send_request/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ where
307307
| TxOutput::Burn(_)
308308
| TxOutput::DelegateStaking(_, _)
309309
| TxOutput::DataDeposit(_) => None,
310-
TxOutput::Htlc(_, _) => None, // TODO: support htlc
310+
TxOutput::Htlc(_, _) => None, // TODO(HTLC)
311311
}
312312
}
313313

wallet/types/src/utxo_types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub fn get_utxo_type(output: &TxOutput) -> Option<UtxoType> {
5353
| TxOutput::DelegateStaking(_, _)
5454
| TxOutput::IssueFungibleToken(_)
5555
| TxOutput::DataDeposit(_) => None,
56-
TxOutput::Htlc(_, _) => None, // TODO: support htlc
56+
TxOutput::Htlc(_, _) => None, // TODO(HTLC)
5757
}
5858
}
5959
pub fn get_utxo_state(output: &TxState) -> UtxoState {

0 commit comments

Comments
 (0)