Skip to content

Conversation

@benalleng
Copy link

@benalleng benalleng commented Jul 16, 2025

This adds the remaining closure in the state check which requires a little more logic as we now need to reference a new db table to see what coins have been seen before.

@benalleng benalleng force-pushed the payjoin-v4-inputs-seen branch 2 times, most recently from dbef86c to 3e51cba Compare July 17, 2025 12:32
@benalleng benalleng force-pushed the payjoin-v4-inputs-seen branch 7 times, most recently from 0c13ead to 7115c71 Compare July 24, 2025 19:12
@benalleng benalleng marked this pull request as ready for review July 24, 2025 19:20
@benalleng benalleng force-pushed the payjoin-v4-inputs-seen branch from 7115c71 to 9b43e61 Compare July 24, 2025 19:22
.expect("Database must be available")
}

pub fn insert_external_coins<'a>(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets keep the function name payjoin specific.
Something like: inserts_outpoint_seen_before

Comment on lines 96 to 97
txid BLOB NOT NULL,
vout INTEGER NOT NULL,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we combine this to just be outpoint (txid:vout)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

outpoint BLOB NOT NULL PRIMARY KEY

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And I think rust-bitcoin outpoint implements consensus encode / decode

.collect()
}

fn insert_input_seen_before(&mut self, outpoints: &[bitcoin::OutPoint]) -> Option<bool> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the return type should just be bool?

&mut self,
outpoints: &[bitcoin::OutPoint],
) -> Vec<DbPayjoinOutpoint> {
// SELECT * FROM payjoinoutpoints WHERE (txid, vout) IN ((txidA, voutA), (txidB, voutB));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we just have one col for outpoint I dont think we need to do an IN condition. We can just do equality on the PK which is more performant.

CREATE TABLE payjoinoutpoints (
txid BLOB NOT NULL,
vout INTEGER NOT NULL,
added_at INTEGER
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this also be not null?

@benalleng benalleng force-pushed the payjoin-v4-inputs-seen branch 4 times, most recently from 5400bed to 418a758 Compare July 28, 2025 21:58
@benalleng benalleng requested a review from arminsabouri July 28, 2025 21:59
Copy link
Collaborator

@arminsabouri arminsabouri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just a few questions and a proposal to use insert or ignore.

) -> HashMap<bitcoin::OutPoint, Option<u32>> {
self.get_seen_payjoin_outpoints(outpoints)
.into_iter()
.map(|db_pjoutpoint| (db_pjoutpoint.outpoint, db_pjoutpoint.added_at))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit. This var is a bit hard to read. I would just go for ot.

Suggested change
.map(|db_pjoutpoint| (db_pjoutpoint.outpoint, db_pjoutpoint.added_at))
.map(|ot| (ot.outpoint, ot.added_at))

Comment on lines 491 to 493
"INSERT INTO payjoinoutpoints (txid, vout, added_at) \
VALUES (?1, ?2, ?3)",
rusqlite::params![outpoint.txid[..].to_vec(), outpoint.vout, curr_timestamp()],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something is not adding up to me. The schema has a single row for outpoint but here we are adding the two components seperatetly? There is probably some magic transformation somewhere?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops I was a little hasty and didn't transition everything over to our new schema format, I'm surprised it actually worked..

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be bc the old db tables still exist with the previous schema?

db_exec(&mut self.conn, |db_tx| {
for outpoint in outpoints {
db_tx.execute(
"INSERT INTO payjoinoutpoints (txid, vout, added_at) \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also should have added this to the prev review. Apologies I just thought of it .
Can we use Insert or ignore here. I think that works since outpoint is the primary key and pk has to be unique.

 let rows_affected = conn.execute(
        "INSERT OR IGNORE INTO  ...",
        params![...],
    )?;

Chat gpt says the execution returns the rows affected which would allow us to remove the get_seen_payjoin_outpoints entirely.

@benalleng benalleng force-pushed the payjoin-v4-inputs-seen branch from 418a758 to 5eb98f0 Compare July 29, 2025 14:37
liana did not have a way to add coins from external wallets to the db,
this adds those coins to the db and forces is_from_self to be false and
sets the wallet_id to 2 which is never the users wallet as it is
hardcoded to 1.
@benalleng benalleng force-pushed the payjoin-v4-inputs-seen branch from 5eb98f0 to 27e0763 Compare July 29, 2025 14:54
Copy link
Collaborator

@arminsabouri arminsabouri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@arminsabouri arminsabouri merged commit 872b1fb into payjoin:payjoin-v4 Jul 29, 2025
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants