Skip to content

Commit

Permalink
Start sketching farcaster verifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshOrndorff committed Feb 11, 2024
1 parent 6747f35 commit cbef6b5
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 0 deletions.
13 changes: 13 additions & 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ panic = "unwind"

[workspace]
members = [
"farcaster",
"node",
"parachain-node",
"tuxedo-template-runtime",
Expand Down
26 changes: 26 additions & 0 deletions farcaster/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[package]
description = "Farcaster Atomic Swap protocol support for Tuxedo based chains"
edition = "2021"
name = "farcaster-tuxedo"
version = "0.1.0"

# TODO These were copy pasted. Prune them.
[dependencies]
parity-scale-codec = { features = [ "derive" ], workspace = true }
scale-info = { features = [ "derive" ], workspace = true }
serde = { features = [ "derive" ], workspace = true }
sp-core = { default_features = false, workspace = true }
sp-runtime = { default_features = false, workspace = true }
sp-std = { default_features = false, workspace = true }
tuxedo-core = { default-features = false, path = "../tuxedo-core" }

[features]
default = [ "std" ]
std = [
"tuxedo-core/std",
"parity-scale-codec/std",
"sp-runtime/std",
"serde/std",
"sp-core/std",
"sp-std/std",
]
60 changes: 60 additions & 0 deletions farcaster/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//! The [Farcaster project](https://github.com/farcaster-project) s a cross-chain atomic swap protocol
//! that allows swaps with Monero despite its lack of any on chain logic.
//!
//! This crate contains several Tuxedo `Verifier`s that implement the same logic as Farcaster's
//! original Bitcoin scripts the allowing any Tuxedo chain to act on the arbitrating side of a
//! Farcaster protocol swap.
use parity_scale_codec::{Decode, Encode};
use scale_info::TypeInfo;
use serde::{Deserialize, Serialize};
use sp_core::sr25519::{Public, Signature};
use tuxedo_core::Verifier;

/// Allows coins on the arbitrating Tuxedo chain to be bought or moved into in intermediate
/// utxo that represents the cancellation phase.
#[derive(Serialize, Deserialize, Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
pub struct SwapLock {
recipient: Public,
canceller: Public,
cancelation_timeout: u32,
}

impl Verifier for SwapLock {
type Redeemer = UnlockSwap;

fn verify(&self, simplified_tx: &[u8], block_height: u32, redeemer: &Self::Redeemer) -> bool {
todo!()
}
}

/// Satisfies a `SwapLock` verifier.
#[derive(Serialize, Deserialize, Encode, Decode, Debug, PartialEq, Eq, Clone)]
pub enum UnlockSwap {
///
Buy,
///
Cancel,
}

/// Allows coins in the intermediate cancellation state to be refunded to the original owner
/// or for an alternate punish path. TODO better docs after I fully understand the punish path
#[derive(Serialize, Deserialize, Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
pub struct SwapCancellation {}

impl Verifier for SwapCancellation {
type Redeemer = CompleteCancellation;

fn verify(&self, simplified_tx: &[u8], block_height: u32, redeemer: &Self::Redeemer) -> bool {
todo!()
}
}

///
#[derive(Serialize, Deserialize, Encode, Decode, Debug, PartialEq, Eq, Clone)]
pub enum CompleteCancellation {
///
Refund,
///
Punish,
}

0 comments on commit cbef6b5

Please sign in to comment.