Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split and cleanup client #9

Merged
merged 44 commits into from
Sep 3, 2024
Merged
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
42c3806
splitting up client
f321x Jul 16, 2024
2a3b524
merge
f321x Jul 21, 2024
b6fc274
separate client logic, cleanup
f321x Jul 21, 2024
3b9d16c
remaining changes
f321x Jul 21, 2024
71efb91
add comments
f321x Jul 21, 2024
29aabb1
put trade mode in metadata
f321x Jul 21, 2024
e181c89
minor improvements
f321x Jul 21, 2024
9d6ad91
Create ecash wallet at the parse input phase, the trade parner needs …
rodant Jul 25, 2024
c9bb1cf
Fix npubs by usong to_bech32.
rodant Jul 26, 2024
b7288cf
rewrite in a more idiomatic form.
rodant Jul 31, 2024
64923f7
Move EscrowClient struct to its module.
rodant Aug 2, 2024
236346c
Inline init_ttrade in main.
rodant Aug 2, 2024
6b10695
Extract wallet creation from RawCliInput
rodant Aug 5, 2024
7e28154
Start introducing the escrow client as state machine for better testa…
rodant Aug 6, 2024
0cf6574
Remove dependency from cli in escrow client.
rodant Aug 6, 2024
7cef1c7
Some clean up.
rodant Aug 6, 2024
d32dc48
Move trade mode to the escrow client.
rodant Aug 6, 2024
3ffe54f
Split escrow metadata in the contract and escrow registration parts.
rodant Aug 9, 2024
7e1b21a
Use PublicKey type in trade contract.
rodant Aug 10, 2024
71af4c2
Replace tuple though the registration message struct.
rodant Aug 13, 2024
af5121c
Remove utils modules.
rodant Aug 13, 2024
2a88dbc
Remove PubkeyMessage and rearrange models.
rodant Aug 14, 2024
7ee5b40
Fix remaining warnings.
rodant Aug 14, 2024
a27ea9a
bump up nostr_sdk version and revert to nip04 direct messages, nip17 …
rodant Aug 15, 2024
85ce4d0
working version with nip17 private direct messages.
rodant Aug 16, 2024
a9714b7
Make func sync after review comment.
rodant Aug 18, 2024
13082e7
Introduce timeout and improvements in receive_escrow_message
rodant Aug 20, 2024
542a2be
Better having a get public key method than a get npub.
rodant Aug 20, 2024
f001e9c
Remove dependency to cli in ClientNostrClient.
rodant Aug 20, 2024
5014664
Hide nostr client in ClientNostrInstance.
rodant Aug 20, 2024
9ae1ba4
Improve the coordinator loop for running forever.
rodant Aug 21, 2024
0d7a2a2
Improvement for error situations.
rodant Aug 21, 2024
645158c
Bumb up nostr_sdk version.
rodant Aug 21, 2024
5e20036
Handle some error cases.
rodant Aug 22, 2024
6a0e061
Avoid unneeded async func.
rodant Aug 22, 2024
5aaa656
Remove nostr instance and clean up escrow client.
rodant Aug 22, 2024
3bcfde4
Fix race condition in receiving registration and introduce escrow cli…
rodant Aug 26, 2024
d038b12
remove unused imports.
rodant Aug 26, 2024
8d79e1c
Deposit enough funds and proceed to a delivery.
rodant Aug 30, 2024
09396a7
Fix typos.
rodant Sep 1, 2024
f4b75cb
Update coordinator/src/escrow_coordinator/mod.rs
rodant Sep 1, 2024
e2e4382
Initialize the notifications receiver at creation and pull events on …
rodant Sep 2, 2024
e1d295e
Define nostr client as field of the escrow client and pass all its fi…
rodant Sep 2, 2024
94d2424
Handle receice errors from a subscription.
rodant Sep 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move EscrowClient struct to its module.
rodant committed Aug 2, 2024
commit 64923f7b6c971d999cd30cf813912298b8e2722c
6 changes: 3 additions & 3 deletions client/src/ecash/mod.rs
Original file line number Diff line number Diff line change
@@ -38,7 +38,7 @@ impl ClientEcashWallet {
fn assemble_escrow_conditions(
&self,
contract: &TradeContract,
escrow_metadata: &ClientEscrowMetadata,
escrow_metadata: &EscrowClientMetadata,
) -> anyhow::Result<SpendingConditions> {
let seller_pubkey = EscrowPubkey::from_str(&contract.seller_ecash_public_key)?;
let buyer_pubkey = EscrowPubkey::from_str(&contract.buyer_ecash_public_key)?;
@@ -67,7 +67,7 @@ impl ClientEcashWallet {
pub async fn create_escrow_token(
&self,
contract: &TradeContract,
escrow_metadata: &ClientEscrowMetadata,
escrow_metadata: &EscrowClientMetadata,
) -> anyhow::Result<String> {
let spending_conditions = self.assemble_escrow_conditions(contract, escrow_metadata)?;
let token = self
@@ -86,7 +86,7 @@ impl ClientEcashWallet {
&self,
escrow_token: &str,
contract: &TradeContract,
escrow_metadata: &ClientEscrowMetadata,
escrow_metadata: &EscrowClientMetadata,
) -> anyhow::Result<Token> {
let spending_conditions = self.assemble_escrow_conditions(contract, escrow_metadata)?;
let token = Token::from_str(escrow_token)?;
15 changes: 11 additions & 4 deletions client/src/escrow_client/mod.rs
Original file line number Diff line number Diff line change
@@ -4,14 +4,14 @@ mod seller_utils;

use super::*;

pub struct ClientEscrowMetadata {
pub struct EscrowClientMetadata {
pub escrow_coordinator_nostr_public_key: NostrPubkey,
pub escrow_coordinator_ecash_public_key: Option<EcashPubkey>,
pub escrow_start_timestamp: Option<Timestamp>,
pub mode: TradeMode,
}

impl ClientEscrowMetadata {
impl EscrowClientMetadata {
pub fn from_client_cli_input(cli_input: &ClientCliInput) -> anyhow::Result<Self> {
Ok(Self {
escrow_coordinator_nostr_public_key: cli_input.coordinator_nostr_pubkey,
@@ -22,10 +22,17 @@ impl ClientEscrowMetadata {
}
}

pub struct EscrowClient {
pub nostr_instance: ClientNostrInstance, // can either be a Nostr Client or Nostr note signer (without networking)
pub ecash_wallet: ClientEcashWallet,
pub escrow_metadata: EscrowClientMetadata, // data relevant for the application but not for the outcome of the trade contract
pub escrow_contract: TradeContract,
}

impl EscrowClient {
pub async fn from_cli_input(cli_input: ClientCliInput) -> anyhow::Result<Self> {
let escrow_contract = TradeContract::from_client_cli_input(&cli_input)?;
let escrow_metadata = ClientEscrowMetadata::from_client_cli_input(&cli_input)?;
let escrow_metadata = EscrowClientMetadata::from_client_cli_input(&cli_input)?;
let nostr_instance = ClientNostrInstance::from_client_cli_input(&cli_input).await?;
let ecash_wallet = cli_input.ecash_wallet;

@@ -38,7 +45,7 @@ impl EscrowClient {
}

pub async fn init_trade(&mut self) -> anyhow::Result<()> {
Self::common_trade_flow(self).await?;
self.common_trade_flow().await?;
debug!("Common trade flow completed");

match self.escrow_metadata.mode {
7 changes: 0 additions & 7 deletions client/src/main.rs
Original file line number Diff line number Diff line change
@@ -18,13 +18,6 @@ use nostr::ClientNostrInstance;
use nostr_sdk::prelude::*;
use nostr_sdk::PublicKey as NostrPubkey;

pub struct EscrowClient {
pub nostr_instance: ClientNostrInstance, // can either be a Nostr Client or Nostr note signer (without networking)
pub ecash_wallet: ClientEcashWallet,
pub escrow_metadata: ClientEscrowMetadata, // data relevant for the application but not for the outcome of the trade contract
pub escrow_contract: TradeContract,
}

#[tokio::main]
async fn main() -> anyhow::Result<()> {
dotenv().ok();
2 changes: 1 addition & 1 deletion client/src/nostr/mod.rs
Original file line number Diff line number Diff line change
@@ -92,7 +92,7 @@ impl ClientNostrInstance {
&self,
wallet: &ClientEcashWallet,
contract: &TradeContract,
metadata: &ClientEscrowMetadata,
metadata: &EscrowClientMetadata,
) -> anyhow::Result<cdk::nuts::Token> {
let filter_note = Filter::new()
.kind(Kind::EncryptedDirectMessage)