Skip to content

Commit cbef6b5

Browse files
committed
Start sketching farcaster verifiers
1 parent 6747f35 commit cbef6b5

File tree

4 files changed

+100
-0
lines changed

4 files changed

+100
-0
lines changed

Cargo.lock

+13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ panic = "unwind"
33

44
[workspace]
55
members = [
6+
"farcaster",
67
"node",
78
"parachain-node",
89
"tuxedo-template-runtime",

farcaster/Cargo.toml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[package]
2+
description = "Farcaster Atomic Swap protocol support for Tuxedo based chains"
3+
edition = "2021"
4+
name = "farcaster-tuxedo"
5+
version = "0.1.0"
6+
7+
# TODO These were copy pasted. Prune them.
8+
[dependencies]
9+
parity-scale-codec = { features = [ "derive" ], workspace = true }
10+
scale-info = { features = [ "derive" ], workspace = true }
11+
serde = { features = [ "derive" ], workspace = true }
12+
sp-core = { default_features = false, workspace = true }
13+
sp-runtime = { default_features = false, workspace = true }
14+
sp-std = { default_features = false, workspace = true }
15+
tuxedo-core = { default-features = false, path = "../tuxedo-core" }
16+
17+
[features]
18+
default = [ "std" ]
19+
std = [
20+
"tuxedo-core/std",
21+
"parity-scale-codec/std",
22+
"sp-runtime/std",
23+
"serde/std",
24+
"sp-core/std",
25+
"sp-std/std",
26+
]

farcaster/src/lib.rs

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
//! The [Farcaster project](https://github.com/farcaster-project) s a cross-chain atomic swap protocol
2+
//! that allows swaps with Monero despite its lack of any on chain logic.
3+
//!
4+
//! This crate contains several Tuxedo `Verifier`s that implement the same logic as Farcaster's
5+
//! original Bitcoin scripts the allowing any Tuxedo chain to act on the arbitrating side of a
6+
//! Farcaster protocol swap.
7+
8+
use parity_scale_codec::{Decode, Encode};
9+
use scale_info::TypeInfo;
10+
use serde::{Deserialize, Serialize};
11+
use sp_core::sr25519::{Public, Signature};
12+
use tuxedo_core::Verifier;
13+
14+
/// Allows coins on the arbitrating Tuxedo chain to be bought or moved into in intermediate
15+
/// utxo that represents the cancellation phase.
16+
#[derive(Serialize, Deserialize, Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
17+
pub struct SwapLock {
18+
recipient: Public,
19+
canceller: Public,
20+
cancelation_timeout: u32,
21+
}
22+
23+
impl Verifier for SwapLock {
24+
type Redeemer = UnlockSwap;
25+
26+
fn verify(&self, simplified_tx: &[u8], block_height: u32, redeemer: &Self::Redeemer) -> bool {
27+
todo!()
28+
}
29+
}
30+
31+
/// Satisfies a `SwapLock` verifier.
32+
#[derive(Serialize, Deserialize, Encode, Decode, Debug, PartialEq, Eq, Clone)]
33+
pub enum UnlockSwap {
34+
///
35+
Buy,
36+
///
37+
Cancel,
38+
}
39+
40+
/// Allows coins in the intermediate cancellation state to be refunded to the original owner
41+
/// or for an alternate punish path. TODO better docs after I fully understand the punish path
42+
#[derive(Serialize, Deserialize, Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
43+
pub struct SwapCancellation {}
44+
45+
impl Verifier for SwapCancellation {
46+
type Redeemer = CompleteCancellation;
47+
48+
fn verify(&self, simplified_tx: &[u8], block_height: u32, redeemer: &Self::Redeemer) -> bool {
49+
todo!()
50+
}
51+
}
52+
53+
///
54+
#[derive(Serialize, Deserialize, Encode, Decode, Debug, PartialEq, Eq, Clone)]
55+
pub enum CompleteCancellation {
56+
///
57+
Refund,
58+
///
59+
Punish,
60+
}

0 commit comments

Comments
 (0)