Skip to content

Commit 06a01b5

Browse files
authored
Merge pull request #6476 from jferrant/chore/aac-rename-alias-to-vmexecutionresult
Rename ambiguous Result alias to VmExecutionResult
2 parents f0e6042 + 1198aea commit 06a01b5

File tree

2 files changed

+51
-38
lines changed

2 files changed

+51
-38
lines changed

clarity/src/vm/database/structures.rs

Lines changed: 50 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub trait ClaritySerializable {
3030
}
3131

3232
pub trait ClarityDeserializable<T> {
33-
fn deserialize(json: &str) -> Result<T>;
33+
fn deserialize(json: &str) -> Result<T, Error>;
3434
}
3535

3636
impl ClaritySerializable for String {
@@ -40,7 +40,7 @@ impl ClaritySerializable for String {
4040
}
4141

4242
impl ClarityDeserializable<String> for String {
43-
fn deserialize(serialized: &str) -> Result<String> {
43+
fn deserialize(serialized: &str) -> Result<String, Error> {
4444
Ok(serialized.into())
4545
}
4646
}
@@ -54,7 +54,7 @@ macro_rules! clarity_serializable {
5454
}
5555
impl ClarityDeserializable<$Name> for $Name {
5656
#[cfg(not(target_family = "wasm"))]
57-
fn deserialize(json: &str) -> Result<Self> {
57+
fn deserialize(json: &str) -> Result<Self, Error> {
5858
let mut deserializer = serde_json::Deserializer::from_str(&json);
5959
// serde's default 128 depth limit can be exhausted
6060
// by a 64-stack-depth AST, so disable the recursion limit
@@ -67,7 +67,7 @@ macro_rules! clarity_serializable {
6767
})
6868
}
6969
#[cfg(target_family = "wasm")]
70-
fn deserialize(json: &str) -> Result<Self> {
70+
fn deserialize(json: &str) -> Result<Self, Error> {
7171
serde_json::from_str(json).map_err(|_| {
7272
InterpreterError::Expect("Failed to deserialize vm.Value".into()).into()
7373
})
@@ -166,8 +166,6 @@ pub struct STXBalanceSnapshot<'db, 'conn> {
166166
db_ref: &'conn mut ClarityDatabase<'db>,
167167
}
168168

169-
type Result<T> = std::result::Result<T, Error>;
170-
171169
impl ClaritySerializable for STXBalance {
172170
#[allow(clippy::expect_used)]
173171
fn serialize(&self) -> String {
@@ -259,7 +257,7 @@ impl ClaritySerializable for STXBalance {
259257
}
260258

261259
impl ClarityDeserializable<STXBalance> for STXBalance {
262-
fn deserialize(input: &str) -> Result<Self> {
260+
fn deserialize(input: &str) -> Result<Self, Error> {
263261
let bytes = hex_bytes(input).map_err(|_| {
264262
InterpreterError::Expect("STXBalance deserialization: failed decoding bytes.".into())
265263
})?;
@@ -376,12 +374,12 @@ impl<'db, 'conn> STXBalanceSnapshot<'db, 'conn> {
376374
&self.balance
377375
}
378376

379-
pub fn save(self) -> Result<()> {
377+
pub fn save(self) -> Result<(), Error> {
380378
let key = ClarityDatabase::make_key_for_account_balance(&self.principal);
381379
self.db_ref.put_data(&key, &self.balance)
382380
}
383381

384-
pub fn transfer_to(mut self, recipient: &PrincipalData, amount: u128) -> Result<()> {
382+
pub fn transfer_to(mut self, recipient: &PrincipalData, amount: u128) -> Result<(), Error> {
385383
if !self.can_transfer(amount)? {
386384
return Err(InterpreterError::InsufficientBalance.into());
387385
}
@@ -402,7 +400,7 @@ impl<'db, 'conn> STXBalanceSnapshot<'db, 'conn> {
402400
Ok(())
403401
}
404402

405-
pub fn get_available_balance(&mut self) -> Result<u128> {
403+
pub fn get_available_balance(&mut self) -> Result<u128, Error> {
406404
let v1_unlock_height = self.db_ref.get_v1_unlock_height();
407405
let v2_unlock_height = self.db_ref.get_v2_unlock_height()?;
408406
let v3_unlock_height = self.db_ref.get_v3_unlock_height()?;
@@ -414,7 +412,7 @@ impl<'db, 'conn> STXBalanceSnapshot<'db, 'conn> {
414412
)
415413
}
416414

417-
pub fn canonical_balance_repr(&mut self) -> Result<STXBalance> {
415+
pub fn canonical_balance_repr(&mut self) -> Result<STXBalance, Error> {
418416
let v1_unlock_height = self.db_ref.get_v1_unlock_height();
419417
let v2_unlock_height = self.db_ref.get_v2_unlock_height()?;
420418
let v3_unlock_height = self.db_ref.get_v3_unlock_height()?;
@@ -429,7 +427,7 @@ impl<'db, 'conn> STXBalanceSnapshot<'db, 'conn> {
429427
.0)
430428
}
431429

432-
pub fn has_locked_tokens(&mut self) -> Result<bool> {
430+
pub fn has_locked_tokens(&mut self) -> Result<bool, Error> {
433431
let v1_unlock_height = self.db_ref.get_v1_unlock_height();
434432
let v2_unlock_height = self.db_ref.get_v2_unlock_height()?;
435433
let v3_unlock_height = self.db_ref.get_v3_unlock_height()?;
@@ -441,7 +439,7 @@ impl<'db, 'conn> STXBalanceSnapshot<'db, 'conn> {
441439
))
442440
}
443441

444-
pub fn has_unlockable_tokens(&mut self) -> Result<bool> {
442+
pub fn has_unlockable_tokens(&mut self) -> Result<bool, Error> {
445443
let v1_unlock_height = self.db_ref.get_v1_unlock_height();
446444
let v2_unlock_height = self.db_ref.get_v2_unlock_height()?;
447445
let v3_unlock_height = self.db_ref.get_v3_unlock_height()?;
@@ -453,11 +451,11 @@ impl<'db, 'conn> STXBalanceSnapshot<'db, 'conn> {
453451
))
454452
}
455453

456-
pub fn can_transfer(&mut self, amount: u128) -> Result<bool> {
454+
pub fn can_transfer(&mut self, amount: u128) -> Result<bool, Error> {
457455
Ok(self.get_available_balance()? >= amount)
458456
}
459457

460-
pub fn debit(&mut self, amount: u128) -> Result<()> {
458+
pub fn debit(&mut self, amount: u128) -> Result<(), Error> {
461459
let unlocked = self.unlock_available_tokens_if_any()?;
462460
if unlocked > 0 {
463461
debug!("Consolidated after account-debit");
@@ -466,7 +464,7 @@ impl<'db, 'conn> STXBalanceSnapshot<'db, 'conn> {
466464
self.balance.debit_unlocked_amount(amount)
467465
}
468466

469-
pub fn credit(&mut self, amount: u128) -> Result<()> {
467+
pub fn credit(&mut self, amount: u128) -> Result<(), Error> {
470468
let unlocked = self.unlock_available_tokens_if_any()?;
471469
if unlocked > 0 {
472470
debug!("Consolidated after account-credit");
@@ -482,7 +480,11 @@ impl<'db, 'conn> STXBalanceSnapshot<'db, 'conn> {
482480
self.balance = balance;
483481
}
484482

485-
pub fn lock_tokens_v1(&mut self, amount_to_lock: u128, unlock_burn_height: u64) -> Result<()> {
483+
pub fn lock_tokens_v1(
484+
&mut self,
485+
amount_to_lock: u128,
486+
unlock_burn_height: u64,
487+
) -> Result<(), Error> {
486488
let unlocked = self.unlock_available_tokens_if_any()?;
487489
if unlocked > 0 {
488490
debug!("Consolidated after account-token-lock");
@@ -528,7 +530,7 @@ impl<'db, 'conn> STXBalanceSnapshot<'db, 'conn> {
528530

529531
/// Return true iff `self` represents a snapshot that has a lock
530532
/// created by PoX v2.
531-
pub fn is_v2_locked(&mut self) -> Result<bool> {
533+
pub fn is_v2_locked(&mut self) -> Result<bool, Error> {
532534
match self.canonical_balance_repr()? {
533535
STXBalance::LockedPoxTwo { .. } => Ok(true),
534536
_ => Ok(false),
@@ -537,7 +539,7 @@ impl<'db, 'conn> STXBalanceSnapshot<'db, 'conn> {
537539

538540
/// Increase the account's current lock to `new_total_locked`.
539541
/// Panics if `self` was not locked by V2 PoX.
540-
pub fn increase_lock_v2(&mut self, new_total_locked: u128) -> Result<()> {
542+
pub fn increase_lock_v2(&mut self, new_total_locked: u128) -> Result<(), Error> {
541543
let unlocked = self.unlock_available_tokens_if_any()?;
542544
if unlocked > 0 {
543545
debug!("Consolidated after extend-token-lock");
@@ -586,7 +588,7 @@ impl<'db, 'conn> STXBalanceSnapshot<'db, 'conn> {
586588
/// Extend this account's current lock to `unlock_burn_height`.
587589
/// After calling, this method will set the balance to a "LockedPoxTwo" balance,
588590
/// because this method is only invoked as a result of PoX2 interactions
589-
pub fn extend_lock_v2(&mut self, unlock_burn_height: u64) -> Result<()> {
591+
pub fn extend_lock_v2(&mut self, unlock_burn_height: u64) -> Result<(), Error> {
590592
let unlocked = self.unlock_available_tokens_if_any()?;
591593
if unlocked > 0 {
592594
debug!("Consolidated after extend-token-lock");
@@ -619,7 +621,11 @@ impl<'db, 'conn> STXBalanceSnapshot<'db, 'conn> {
619621
/// Lock `amount_to_lock` tokens on this account until `unlock_burn_height`.
620622
/// After calling, this method will set the balance to a "LockedPoxTwo" balance,
621623
/// because this method is only invoked as a result of PoX2 interactions
622-
pub fn lock_tokens_v2(&mut self, amount_to_lock: u128, unlock_burn_height: u64) -> Result<()> {
624+
pub fn lock_tokens_v2(
625+
&mut self,
626+
amount_to_lock: u128,
627+
unlock_burn_height: u64,
628+
) -> Result<(), Error> {
623629
let unlocked = self.unlock_available_tokens_if_any()?;
624630
if unlocked > 0 {
625631
debug!("Consolidated after account-token-lock");
@@ -668,7 +674,11 @@ impl<'db, 'conn> STXBalanceSnapshot<'db, 'conn> {
668674
/// Lock `amount_to_lock` tokens on this account until `unlock_burn_height`.
669675
/// After calling, this method will set the balance to a "LockedPoxThree" balance,
670676
/// because this method is only invoked as a result of PoX3 interactions
671-
pub fn lock_tokens_v3(&mut self, amount_to_lock: u128, unlock_burn_height: u64) -> Result<()> {
677+
pub fn lock_tokens_v3(
678+
&mut self,
679+
amount_to_lock: u128,
680+
unlock_burn_height: u64,
681+
) -> Result<(), Error> {
672682
let unlocked = self.unlock_available_tokens_if_any()?;
673683
if unlocked > 0 {
674684
debug!("Consolidated after account-token-lock");
@@ -718,7 +728,7 @@ impl<'db, 'conn> STXBalanceSnapshot<'db, 'conn> {
718728
/// Extend this account's current lock to `unlock_burn_height`.
719729
/// After calling, this method will set the balance to a "LockedPoxThree" balance,
720730
/// because this method is only invoked as a result of PoX3 interactions
721-
pub fn extend_lock_v3(&mut self, unlock_burn_height: u64) -> Result<()> {
731+
pub fn extend_lock_v3(&mut self, unlock_burn_height: u64) -> Result<(), Error> {
722732
let unlocked = self.unlock_available_tokens_if_any()?;
723733
if unlocked > 0 {
724734
debug!("Consolidated after extend-token-lock");
@@ -750,7 +760,7 @@ impl<'db, 'conn> STXBalanceSnapshot<'db, 'conn> {
750760

751761
/// Increase the account's current lock to `new_total_locked`.
752762
/// Panics if `self` was not locked by V3 PoX.
753-
pub fn increase_lock_v3(&mut self, new_total_locked: u128) -> Result<()> {
763+
pub fn increase_lock_v3(&mut self, new_total_locked: u128) -> Result<(), Error> {
754764
let unlocked = self.unlock_available_tokens_if_any()?;
755765
if unlocked > 0 {
756766
debug!("Consolidated after extend-token-lock");
@@ -795,7 +805,7 @@ impl<'db, 'conn> STXBalanceSnapshot<'db, 'conn> {
795805

796806
/// Return true iff `self` represents a snapshot that has a lock
797807
/// created by PoX v3.
798-
pub fn is_v3_locked(&mut self) -> Result<bool> {
808+
pub fn is_v3_locked(&mut self) -> Result<bool, Error> {
799809
match self.canonical_balance_repr()? {
800810
STXBalance::LockedPoxThree { .. } => Ok(true),
801811
_ => Ok(false),
@@ -807,7 +817,11 @@ impl<'db, 'conn> STXBalanceSnapshot<'db, 'conn> {
807817
/// Lock `amount_to_lock` tokens on this account until `unlock_burn_height`.
808818
/// After calling, this method will set the balance to a "LockedPoxFour" balance,
809819
/// because this method is only invoked as a result of PoX4 interactions
810-
pub fn lock_tokens_v4(&mut self, amount_to_lock: u128, unlock_burn_height: u64) -> Result<()> {
820+
pub fn lock_tokens_v4(
821+
&mut self,
822+
amount_to_lock: u128,
823+
unlock_burn_height: u64,
824+
) -> Result<(), Error> {
811825
let unlocked = self.unlock_available_tokens_if_any()?;
812826
if unlocked > 0 {
813827
debug!("Consolidated after account-token-lock");
@@ -846,7 +860,7 @@ impl<'db, 'conn> STXBalanceSnapshot<'db, 'conn> {
846860
/// Extend this account's current lock to `unlock_burn_height`.
847861
/// After calling, this method will set the balance to a "LockedPoxFour" balance,
848862
/// because this method is only invoked as a result of PoX3 interactions
849-
pub fn extend_lock_v4(&mut self, unlock_burn_height: u64) -> Result<()> {
863+
pub fn extend_lock_v4(&mut self, unlock_burn_height: u64) -> Result<(), Error> {
850864
let unlocked = self.unlock_available_tokens_if_any()?;
851865
if unlocked > 0 {
852866
debug!("Consolidated after extend-token-lock");
@@ -872,7 +886,7 @@ impl<'db, 'conn> STXBalanceSnapshot<'db, 'conn> {
872886

873887
/// Increase the account's current lock to `new_total_locked`.
874888
/// Panics if `self` was not locked by V3 PoX.
875-
pub fn increase_lock_v4(&mut self, new_total_locked: u128) -> Result<()> {
889+
pub fn increase_lock_v4(&mut self, new_total_locked: u128) -> Result<(), Error> {
876890
let unlocked = self.unlock_available_tokens_if_any()?;
877891
if unlocked > 0 {
878892
debug!("Consolidated after extend-token-lock");
@@ -912,7 +926,7 @@ impl<'db, 'conn> STXBalanceSnapshot<'db, 'conn> {
912926

913927
/// Return true iff `self` represents a snapshot that has a lock
914928
/// created by PoX v3.
915-
pub fn is_v4_locked(&mut self) -> Result<bool> {
929+
pub fn is_v4_locked(&mut self) -> Result<bool, Error> {
916930
match self.canonical_balance_repr()? {
917931
STXBalance::LockedPoxFour { .. } => Ok(true),
918932
_ => Ok(false),
@@ -923,7 +937,7 @@ impl<'db, 'conn> STXBalanceSnapshot<'db, 'conn> {
923937

924938
/// If this snapshot is locked, then alter the lock height to be
925939
/// the next burn block (i.e., `self.burn_block_height + 1`)
926-
pub fn accelerate_unlock(&mut self) -> Result<()> {
940+
pub fn accelerate_unlock(&mut self) -> Result<(), Error> {
927941
let unlocked = self.unlock_available_tokens_if_any()?;
928942
if unlocked > 0 {
929943
debug!("Consolidated after account-token-lock");
@@ -971,7 +985,7 @@ impl<'db, 'conn> STXBalanceSnapshot<'db, 'conn> {
971985

972986
/// Unlock any tokens that are unlockable at the current
973987
/// burn block height, and return the amount newly unlocked
974-
fn unlock_available_tokens_if_any(&mut self) -> Result<u128> {
988+
fn unlock_available_tokens_if_any(&mut self) -> Result<u128, Error> {
975989
let (new_balance, unlocked) = self.balance.canonical_repr_at_block(
976990
self.burn_block_height,
977991
self.db_ref.get_v1_unlock_height(),
@@ -1088,7 +1102,7 @@ impl STXBalance {
10881102
}
10891103
}
10901104

1091-
fn debit_unlocked_amount(&mut self, delta: u128) -> Result<()> {
1105+
fn debit_unlocked_amount(&mut self, delta: u128) -> Result<(), Error> {
10921106
match self {
10931107
STXBalance::Unlocked {
10941108
amount: amount_unlocked,
@@ -1150,7 +1164,7 @@ impl STXBalance {
11501164
v1_unlock_height: u32,
11511165
v2_unlock_height: u32,
11521166
v3_unlock_height: u32,
1153-
) -> Result<(STXBalance, u128)> {
1167+
) -> Result<(STXBalance, u128), Error> {
11541168
if self.has_unlockable_tokens_at_burn_block(
11551169
burn_block_height,
11561170
v1_unlock_height,
@@ -1174,7 +1188,7 @@ impl STXBalance {
11741188
v1_unlock_height: u32,
11751189
v2_unlock_height: u32,
11761190
v3_unlock_height: u32,
1177-
) -> Result<u128> {
1191+
) -> Result<u128, Error> {
11781192
if self.has_unlockable_tokens_at_burn_block(
11791193
burn_block_height,
11801194
v1_unlock_height,
@@ -1243,7 +1257,7 @@ impl STXBalance {
12431257
}
12441258
}
12451259

1246-
pub fn get_total_balance(&self) -> Result<u128> {
1260+
pub fn get_total_balance(&self) -> Result<u128, Error> {
12471261
let (unlocked, locked) = match self {
12481262
STXBalance::Unlocked { amount } => (*amount, 0),
12491263
STXBalance::LockedPoxOne {
@@ -1448,7 +1462,7 @@ impl STXBalance {
14481462
v1_unlock_height: u32,
14491463
v2_unlock_height: u32,
14501464
v3_unlock_height: u32,
1451-
) -> Result<bool> {
1465+
) -> Result<bool, Error> {
14521466
Ok(self.get_available_balance_at_burn_block(
14531467
burn_block_height,
14541468
v1_unlock_height,

stackslib/src/clarity_vm/clarity.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1745,8 +1745,7 @@ impl<'a> ClarityBlockConnection<'a, '_> {
17451745
stx_balance: STXBalance::zero(),
17461746
};
17471747

1748-
let costs_4_contract_tx =
1749-
StacksTransaction::new(tx_version.clone(), boot_code_auth, payload);
1748+
let costs_4_contract_tx = StacksTransaction::new(tx_version, boot_code_auth, payload);
17501749

17511750
let costs_4_initialization_receipt = self.as_transaction(|tx_conn| {
17521751
// bump the epoch in the Clarity DB

0 commit comments

Comments
 (0)