Skip to content

Commit

Permalink
Updates in anticipation of #493
Browse files Browse the repository at this point in the history
  • Loading branch information
djordon committed Sep 15, 2024
1 parent 2f85b54 commit cf0b1da
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
19 changes: 15 additions & 4 deletions signer/src/stacks/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,15 @@ pub struct CompleteDepositV1 {
pub recipient: PrincipalData,
/// The address that deployed the contract.
pub deployer: StacksAddress,
/// The block hash of the bitcoin block that contains a sweep
/// transaction with the above outpoint as one of its inputs. This
/// field, with the `sweep_block_height` field, is used by the
/// `complete-deposit-wrapper` clarity function to ensure that we do
/// not mint in case of a bitcoin reorg affects the sweep transaction
/// that is included in this block.
pub sweep_block_hash: BitcoinBlockHash,
/// The block height associated with the above bitcoin block hash.
pub sweep_block_height: u64,
}

impl AsContractCall for CompleteDepositV1 {
Expand Down Expand Up @@ -236,7 +245,7 @@ impl AsContractCall for CompleteDepositV1 {
///
pub struct DepositContext {
/// The block hash on the bitcoin blockchain with the greatest height.
/// On ties we sort by the block_hash descending and take the first
/// On ties, we sort by the block_hash descending and take the first
/// one.
pub chain_tip: BitcoinBlockHash,
/// How many bitcoin blocks back from the chain tip the signer will
Expand Down Expand Up @@ -273,10 +282,10 @@ impl CompleteDepositV1 {
// The `complete-deposit-wrapper` public function will not mint to
// the user again if we mistakenly submit two transactions for the
// same deposit outpoint. This means we do not need to do a check
// for existance of a similar transaction in the stacks mempool. This is
// for existence of a similar transaction in the stacks mempool. This is
// fortunate, because even if we wanted to, the only view into the
// stacks-core mempool is through the `POST /new_mempool_tx`
// webhooks, which we do not currently injest and could be
// webhooks, which we do not currently ingest and could be
// incomplete.

// Check that this is actually a pending and accepted deposit
Expand All @@ -303,7 +312,7 @@ impl CompleteDepositV1 {
};

if deposit_request.outpoint() != self.outpoint {
// Seriously, how did we messed this one up?
// Seriously, how did we mess this one up?
return Ok(false);
}

Expand Down Expand Up @@ -569,6 +578,8 @@ mod tests {
amount: 15000,
recipient: PrincipalData::from(StacksAddress::burn_address(true)),
deployer: StacksAddress::burn_address(false),
sweep_block_hash: BitcoinBlockHash::from([0; 32]),
sweep_block_height: 7,
};

let _ = call.as_contract_call();
Expand Down
7 changes: 7 additions & 0 deletions signer/tests/integration/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use signer::stacks::contracts::AsContractCall;
use signer::stacks::contracts::RejectWithdrawalV1;
use signer::stacks::contracts::RotateKeysV1;
use signer::stacks::wallet::SignerWallet;
use signer::storage::model::BitcoinBlockHash;
use signer::testing::wallet::ContractCallWrapper;
use tokio::sync::OnceCell;

Expand Down Expand Up @@ -204,12 +205,16 @@ pub async fn deploy_smart_contracts() -> &'static SignerStxState {
amount: 123654789,
recipient: PrincipalData::parse("SN2V7WTJ7BHR03MPHZ1C9A9ZR6NZGR4WM8HT4V67Y").unwrap(),
deployer: testing::wallet::WALLET.0.address(),
sweep_block_hash: signer::storage::model::BitcoinBlockHash::from([0; 32]),
sweep_block_height: 7,
}); "complete-deposit standard recipient")]
#[test_case(ContractCallWrapper(CompleteDepositV1 {
outpoint: bitcoin::OutPoint::null(),
amount: 123654,
recipient: PrincipalData::parse("ST1RQHF4VE5CZ6EK3MZPZVQBA0JVSMM9H5PMHMS1Y.my-contract-name").unwrap(),
deployer: testing::wallet::WALLET.0.address(),
sweep_block_hash: BitcoinBlockHash::from([0; 32]),
sweep_block_height: 7,
}); "complete-deposit contract recipient")]
#[test_case(ContractCallWrapper(AcceptWithdrawalV1 {
request_id: 1,
Expand Down Expand Up @@ -300,6 +305,8 @@ async fn estimate_tx_fees() {
amount: 123654,
recipient: PrincipalData::parse("ST1RQHF4VE5CZ6EK3MZPZVQBA0JVSMM9H5PMHMS1Y").unwrap(),
deployer: StacksAddress::burn_address(false),
sweep_block_hash: BitcoinBlockHash::from([0; 32]),
sweep_block_height: 7,
};
let payload = ContractCallWrapper(contract_call);

Expand Down
5 changes: 5 additions & 0 deletions signer/tests/integration/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use signer::stacks::events::WithdrawalCreateEvent;
use signer::stacks::events::WithdrawalRejectEvent;
use signer::storage;
use signer::storage::model;
use signer::storage::model::BitcoinBlockHash;
use signer::storage::model::BitcoinTxId;
use signer::storage::model::QualifiedRequestId;
use signer::storage::model::RotateKeysTransaction;
Expand Down Expand Up @@ -138,12 +139,16 @@ impl AsContractCall for InitiateWithdrawalRequest {
amount: 123654,
recipient: PrincipalData::parse("ST1RQHF4VE5CZ6EK3MZPZVQBA0JVSMM9H5PMHMS1Y").unwrap(),
deployer: testing::wallet::WALLET.0.address(),
sweep_block_hash: BitcoinBlockHash::from([0; 32]),
sweep_block_height: 7,
}); "complete-deposit standard recipient")]
#[test_case(ContractCallWrapper(CompleteDepositV1 {
outpoint: bitcoin::OutPoint::null(),
amount: 123654,
recipient: PrincipalData::parse("ST1RQHF4VE5CZ6EK3MZPZVQBA0JVSMM9H5PMHMS1Y.my-contract-name").unwrap(),
deployer: testing::wallet::WALLET.0.address(),
sweep_block_hash: BitcoinBlockHash::from([0; 32]),
sweep_block_height: 7,
}); "complete-deposit contract recipient")]
#[test_case(ContractCallWrapper(AcceptWithdrawalV1 {
request_id: 0,
Expand Down

0 comments on commit cf0b1da

Please sign in to comment.