-
Notifications
You must be signed in to change notification settings - Fork 33
Refactor State Machine and Events have correct types for Alice AND Bob #427
Changes from 9 commits
c437c88
14fe1b9
13970b1
d99200e
52b013d
da6c204
cc1e5fd
33ef1c7
f0f80cb
bd22a72
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,39 @@ | ||
use bitcoin_support::{Address, BitcoinQuantity, Blocks, OutPoint}; | ||
use secp256k1_support::KeyPair; | ||
use swap_protocols::{ledger::Bitcoin, rfc003::Ledger}; | ||
use swap_protocols::{ | ||
ledger::Bitcoin, | ||
rfc003::{state_machine::HtlcParams, Ledger}, | ||
}; | ||
|
||
mod extract_secret; | ||
mod htlc; | ||
mod queries; | ||
mod validation; | ||
|
||
pub use self::{ | ||
htlc::{Htlc, UnlockingError}, | ||
queries::*, | ||
}; | ||
use swap_protocols::{ | ||
asset::Asset, | ||
rfc003::{state_machine::OngoingSwap, IntoSecretHash}, | ||
}; | ||
|
||
impl Ledger for Bitcoin { | ||
type LockDuration = Blocks; | ||
type HtlcLocation = OutPoint; | ||
type HtlcIdentity = KeyPair; | ||
} | ||
|
||
pub fn bitcoin_htlc<TL: Ledger, TA: Asset, S: IntoSecretHash>( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NICE! 👍 |
||
swap: &OngoingSwap<Bitcoin, TL, BitcoinQuantity, TA, S>, | ||
) -> Htlc { | ||
Htlc::new( | ||
swap.source_ledger_success_identity, | ||
swap.source_ledger_refund_identity, | ||
swap.secret.clone().into(), | ||
swap.source_ledger_lock_duration.into(), | ||
) | ||
impl From<HtlcParams<Bitcoin, BitcoinQuantity>> for Htlc { | ||
fn from(htlc_params: HtlcParams<Bitcoin, BitcoinQuantity>) -> Self { | ||
Htlc::new( | ||
htlc_params.success_identity, | ||
htlc_params.refund_identity, | ||
htlc_params.secret_hash, | ||
htlc_params.lock_duration.into(), | ||
) | ||
} | ||
} | ||
|
||
pub fn bitcoin_htlc_address<TL: Ledger, TA: Asset, S: IntoSecretHash>( | ||
swap: &OngoingSwap<Bitcoin, TL, BitcoinQuantity, TA, S>, | ||
) -> Address { | ||
bitcoin_htlc(swap).compute_address(swap.source_ledger.network) | ||
impl HtlcParams<Bitcoin, BitcoinQuantity> { | ||
pub fn compute_address(&self) -> Address { | ||
Htlc::from(self.clone()).compute_address(self.ledger.network) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔧 It would be nice if we could avoid this clone. Either re-instantiate the Htlc here or create a private fn to reduce the duplication between this and the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't really know what you mean as a the solution. My preferred solution would be to replace HtlcParams with the actual HTLCs. Lucas and I tried this at some point and it's tricker than adding an associated type on ledger bound to an HTLC trait because the ethereum HTLC depends on the asset. Now that we have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah we can optimize later. |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❌ Can we have this test or a similar one back please? One that proofs that we don't need type arguments?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You do need the type arguments :^)
There is no way to infer the role from the arguments (unless you made the role an argument but I don't even know if this will fix it as I doubt it will be able to infer the type parameters to Alice or Bob).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please read the test name again!
I was talking about the "type" arguments that are now associated types on the
StateActions
. Since they are associated, you shouldn't need to specify them when calling theactions
method.The test would ensure that we can use this API in the way we intend. (similar to how a test that instantiates the state machine for Alice and Bob verifies that we can actually do that.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wups. Fixed. Sorry I was lazy.