Skip to content

Commit fbace0f

Browse files
committed
Clean up tx event types
1 parent d2f029e commit fbace0f

File tree

3 files changed

+52
-52
lines changed

3 files changed

+52
-52
lines changed

node/src/wallets.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ impl RpcWallet {
182182
let (_, fullspaceout) = SpacesWallet::verify_listing::<Sha256>(state, &listing)?;
183183

184184
let space = fullspaceout.spaceout.space.as_ref().expect("space").name.to_string();
185-
let foreign_input = fullspaceout.outpoint();
185+
let previous_spaceout = fullspaceout.outpoint();
186186
let tx = wallet.buy::<Sha256>(state, &listing, fee_rate)?;
187187

188188
if !skip_tx_check {
@@ -197,7 +197,7 @@ impl RpcWallet {
197197
let tx_record = TxRecord::new_with_events(tx, vec![TxEvent {
198198
kind: TxEventKind::Buy,
199199
space: Some(space),
200-
foreign_input: Some(foreign_input),
200+
previous_spaceout: Some(previous_spaceout),
201201
details: None,
202202
}]);
203203

@@ -599,7 +599,7 @@ impl RpcWallet {
599599
continue;
600600
}
601601

602-
if event.foreign_input.is_some_and(|input| input == space.outpoint()) {
602+
if event.previous_spaceout.is_some_and(|input| input == space.outpoint()) {
603603
continue;
604604
}
605605
res.outbid.push(space);

wallet/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ impl SpacesWallet {
551551
txid,
552552
event.kind,
553553
event.space,
554-
event.foreign_input,
554+
event.previous_spaceout,
555555
event.details,
556556
).context("could not insert tx event into wallet db")?;
557557
}

wallet/src/tx_event.rs

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,20 @@ pub struct TxEvent {
2626
#[serde(skip_serializing_if = "Option::is_none")]
2727
pub space: Option<String>,
2828
#[serde(skip_serializing_if = "Option::is_none")]
29-
pub foreign_input: Option<OutPoint>,
29+
pub previous_spaceout: Option<OutPoint>,
3030
#[serde(skip_serializing_if = "Option::is_none", flatten)]
3131
pub details: Option<serde_json::Value>,
3232
}
3333

3434
#[derive(Debug, Serialize, Deserialize)]
3535
pub struct BidEventDetails {
36-
pub bid_current: Amount,
37-
pub bid_previous: Amount,
36+
pub current_bid: Amount,
37+
pub previous_bid: Amount,
3838
}
3939

4040
#[derive(Debug, Serialize, Deserialize)]
4141
pub struct TransferEventDetails {
42-
pub to: ScriptBuf,
42+
pub script_pubkey: ScriptBuf,
4343
}
4444

4545
#[derive(Debug, Serialize, Deserialize)]
@@ -50,21 +50,21 @@ pub struct BidoutEventDetails {
5050
#[derive(Debug, Serialize, Deserialize)]
5151
pub struct SendEventDetails {
5252
#[serde(skip_serializing_if = "Option::is_none")]
53-
pub to_space: Option<String>,
54-
pub script_pubkey: ScriptBuf,
53+
pub recipient_space: Option<String>,
54+
pub recipient_script_pubkey: ScriptBuf,
5555
pub amount: Amount,
5656
}
5757

5858
#[derive(Debug, Serialize, Deserialize)]
5959
pub struct OpenEventDetails {
60-
pub bid_initial: Amount,
60+
pub initial_bid: Amount,
6161
}
6262

6363
#[derive(Debug, Serialize, Deserialize)]
6464
pub struct CommitEventDetails {
65-
pub commit_script_pubkey: protocol::Bytes,
65+
pub script_pubkey: protocol::Bytes,
6666
/// [SpaceScriptSigningInfo] in raw format
67-
pub commit_signing_info: protocol::Bytes,
67+
pub signing_info: protocol::Bytes,
6868
}
6969

7070
#[derive(Debug, Serialize, Deserialize)]
@@ -100,7 +100,7 @@ impl TxEvent {
100100
txid TEXT NOT NULL, \
101101
type TEXT NOT NULL, \
102102
space TEXT, \
103-
foreign_input TEXT, \
103+
previous_spaceout TEXT, \
104104
details TEXT, \
105105
created_at INTEGER NOT NULL DEFAULT (strftime('%s','now'))
106106
) STRICT;",
@@ -112,7 +112,7 @@ impl TxEvent {
112112

113113
pub fn all(db_tx: &rusqlite::Transaction, txid: Txid) -> rusqlite::Result<Vec<Self>> {
114114
let stmt = db_tx.prepare(&format!(
115-
"SELECT type, space, foreign_input, details
115+
"SELECT type, space, previous_spaceout, details
116116
FROM {} WHERE txid = ?1",
117117
Self::TX_EVENTS_TABLE_NAME,
118118
))?;
@@ -121,7 +121,7 @@ impl TxEvent {
121121

122122
pub fn bids(db_tx: &rusqlite::Transaction, space: String) -> rusqlite::Result<Vec<Self>> {
123123
let stmt = db_tx.prepare(&format!(
124-
"SELECT type, space, foreign_input, details
124+
"SELECT type, space, previous_spaceout, details
125125
FROM {} WHERE type = 'bid' AND space = ?1",
126126
Self::TX_EVENTS_TABLE_NAME,
127127
))?;
@@ -138,9 +138,9 @@ impl TxEvent {
138138
let query_placeholders = txids.iter().map(|_| "?").collect::<Vec<_>>().join(",");
139139

140140
let mut stmt = db_tx.prepare(&format!(
141-
"SELECT txid, foreign_input
141+
"SELECT txid, previous_spaceout
142142
FROM {}
143-
WHERE foreign_input IS NOT NULL AND type = 'bid' AND txid IN ({})",
143+
WHERE previous_spaceout IS NOT NULL AND type = 'bid' AND txid IN ({})",
144144
Self::TX_EVENTS_TABLE_NAME,
145145
query_placeholders
146146
))?;
@@ -149,8 +149,8 @@ impl TxEvent {
149149
rusqlite::params_from_iter(txids.into_iter().map(|t| Impl(t))),
150150
|row| {
151151
let txid: Impl<Txid> = row.get(0)?;
152-
let foreign_input: Option<Impl<OutPoint>> = row.get(1)?;
153-
Ok((txid, foreign_input.map(|x| x.0).unwrap()))
152+
let previous_spaceout: Option<Impl<OutPoint>> = row.get(1)?;
153+
Ok((txid, previous_spaceout.map(|x| x.0).unwrap()))
154154
},
155155
)?;
156156
let mut results = Vec::new();
@@ -164,7 +164,7 @@ impl TxEvent {
164164

165165
pub fn all_bid_txs(db_tx: &rusqlite::Transaction, txid: Txid) -> rusqlite::Result<Option<Self>> {
166166
let stmt = db_tx.prepare(&format!(
167-
"SELECT type, space, foreign_input, details
167+
"SELECT type, space, previous_spaceout, details
168168
FROM {} WHERE type = 'bid' AND txid = ?1",
169169
Self::TX_EVENTS_TABLE_NAME,
170170
))?;
@@ -174,7 +174,7 @@ impl TxEvent {
174174

175175
pub fn get_signing_info(db_tx: &rusqlite::Transaction, txid: Txid, script_pubkey: &ScriptBuf) -> rusqlite::Result<Option<SpaceScriptSigningInfo>> {
176176
let stmt = db_tx.prepare(&format!(
177-
"SELECT type, space, foreign_input, details
177+
"SELECT type, space, previous_spaceout, details
178178
FROM {} WHERE type = 'commit' AND txid = ?1",
179179
Self::TX_EVENTS_TABLE_NAME,
180180
))?;
@@ -185,8 +185,8 @@ impl TxEvent {
185185
let details = result.details.expect("signing details in tx event");
186186
let details: CommitEventDetails = serde_json::from_value(details)
187187
.expect("signing details");
188-
if details.commit_script_pubkey.as_slice() == script_pubkey.as_bytes() {
189-
let raw = details.commit_signing_info.to_vec();
188+
if details.script_pubkey.as_slice() == script_pubkey.as_bytes() {
189+
let raw = details.signing_info.to_vec();
190190
let info =
191191
SpaceScriptSigningInfo::from_slice(raw.as_slice()).expect("valid signing info");
192192
return Ok(Some(info))
@@ -200,7 +200,7 @@ impl TxEvent {
200200
db_tx: &rusqlite::Transaction,
201201
) -> rusqlite::Result<Vec<(Txid, TxEvent)>> {
202202
let query = format!(
203-
"SELECT txid, type, space, foreign_input, details
203+
"SELECT txid, type, space, previous_spaceout, details
204204
FROM {table}
205205
WHERE id IN (
206206
SELECT MAX(id)
@@ -221,7 +221,7 @@ impl TxEvent {
221221
TxEvent {
222222
kind: row.get("type")?,
223223
space: row.get("space")?,
224-
foreign_input: row.get::<_, Option<Impl<OutPoint>>>("foreign_input")?.map(|x| x.0),
224+
previous_spaceout: row.get::<_, Option<Impl<OutPoint>>>("previous_spaceout")?.map(|x| x.0),
225225
details: row.get::<_, Option<Impl<serde_json::Value>>>("details")?.map(|x| x.0),
226226
},
227227
))
@@ -243,18 +243,18 @@ impl TxEvent {
243243
Ok((
244244
row.get::<_, TxEventKind>("type")?,
245245
row.get::<_, Option<String>>("space")?,
246-
row.get::<_, Option<Impl<OutPoint>>>("foreign_input")?,
246+
row.get::<_, Option<Impl<OutPoint>>>("previous_spaceout")?,
247247
row.get::<_, Option<Impl<serde_json::Value>>>("details")?,
248248
))
249249
})?;
250250

251251
let mut events = Vec::new();
252252
for row in row_iter {
253-
let (event_type, space, foreign_input, details) = row?;
253+
let (event_type, space, previous_spaceout, details) = row?;
254254
events.push(TxEvent {
255255
kind: event_type,
256256
space,
257-
foreign_input: foreign_input.map(|x| x.0),
257+
previous_spaceout: previous_spaceout.map(|x| x.0),
258258
details: details.map(|x| x.0),
259259
})
260260
}
@@ -267,11 +267,11 @@ impl TxEvent {
267267
txid: Txid,
268268
kind: TxEventKind,
269269
space: Option<String>,
270-
foreign_input: Option<OutPoint>,
270+
previous_spaceout: Option<OutPoint>,
271271
details: Option<serde_json::Value>,
272272
) -> rusqlite::Result<usize> {
273273
let query = format!(
274-
"INSERT INTO {} (txid, type, space, foreign_input, details)
274+
"INSERT INTO {} (txid, type, space, previous_spaceout, details)
275275
VALUES (?1, ?2, ?3, ?4, ?5)",
276276
Self::TX_EVENTS_TABLE_NAME,
277277
);
@@ -282,7 +282,7 @@ impl TxEvent {
282282
txid.to_string(),
283283
kind,
284284
space,
285-
foreign_input.map(|b| b.to_string()),
285+
previous_spaceout.map(|b| b.to_string()),
286286
details.map(|d| d.to_string())
287287
],
288288
)?;
@@ -309,7 +309,7 @@ impl TxRecord {
309309
self.events.push(TxEvent {
310310
kind: TxEventKind::FeeBump,
311311
space: None,
312-
foreign_input: None,
312+
previous_spaceout: None,
313313
details: None,
314314
});
315315
}
@@ -318,25 +318,25 @@ impl TxRecord {
318318
self.events.push(TxEvent {
319319
kind: TxEventKind::Transfer,
320320
space: Some(space),
321-
foreign_input: None,
322-
details: Some(serde_json::to_value(TransferEventDetails { to }).expect("json value")),
321+
previous_spaceout: None,
322+
details: Some(serde_json::to_value(TransferEventDetails { script_pubkey: to }).expect("json value")),
323323
});
324324
}
325325

326326
pub fn add_renew(&mut self, space: String, to: ScriptBuf) {
327327
self.events.push(TxEvent {
328328
kind: TxEventKind::Renew,
329329
space: Some(space),
330-
foreign_input: None,
331-
details: Some(serde_json::to_value(TransferEventDetails { to }).expect("json value")),
330+
previous_spaceout: None,
331+
details: Some(serde_json::to_value(TransferEventDetails { script_pubkey: to }).expect("json value")),
332332
});
333333
}
334334

335335
pub fn add_bidout(&mut self, count: usize) {
336336
self.events.push(TxEvent {
337337
kind: TxEventKind::Bidout,
338338
space: None,
339-
foreign_input: None,
339+
previous_spaceout: None,
340340
details: Some(serde_json::to_value(BidoutEventDetails { count }).expect("json value")),
341341
});
342342
}
@@ -350,11 +350,11 @@ impl TxRecord {
350350
self.events.push(TxEvent {
351351
kind: TxEventKind::Send,
352352
space: None,
353-
foreign_input: None,
353+
previous_spaceout: None,
354354
details: Some(
355355
serde_json::to_value(SendEventDetails {
356-
to_space,
357-
script_pubkey: resolved_address,
356+
recipient_space: to_space,
357+
recipient_script_pubkey: resolved_address,
358358
amount,
359359
})
360360
.expect("json value"),
@@ -372,11 +372,11 @@ impl TxRecord {
372372
self.events.push(TxEvent {
373373
kind: TxEventKind::Commit,
374374
space: Some(space),
375-
foreign_input: None,
375+
previous_spaceout: None,
376376
details: Some(
377377
serde_json::to_value(CommitEventDetails {
378-
commit_script_pubkey: protocol::Bytes::new(reveal_address.to_bytes()),
379-
commit_signing_info: protocol::Bytes::new(signing_info),
378+
script_pubkey: protocol::Bytes::new(reveal_address.to_bytes()),
379+
signing_info: protocol::Bytes::new(signing_info),
380380
})
381381
.expect("json value"),
382382
),
@@ -387,10 +387,10 @@ impl TxRecord {
387387
self.events.push(TxEvent {
388388
kind: TxEventKind::Open,
389389
space: Some(space),
390-
foreign_input: None,
390+
previous_spaceout: None,
391391
details: Some(
392392
serde_json::to_value(OpenEventDetails {
393-
bid_initial: initial_bid,
393+
initial_bid: initial_bid,
394394
})
395395
.expect("json value"),
396396
),
@@ -402,7 +402,7 @@ impl TxRecord {
402402
self.events.push(TxEvent {
403403
kind: TxEventKind::Script,
404404
space: Some(space),
405-
foreign_input: None,
405+
previous_spaceout: None,
406406
details: Some(
407407
serde_json::to_value(ExecuteEventDetails {
408408
n: reveal_input_index,
@@ -418,12 +418,12 @@ impl TxRecord {
418418
Covenant::Bid { total_burned, .. } => total_burned,
419419
_ => panic!("expected a bid"),
420420
};
421-
let foreign_input = match wallet.is_mine(previous.spaceout.script_pubkey.clone()) {
421+
let previous_spaceout = match wallet.is_mine(previous.spaceout.script_pubkey.clone()) {
422422
false => Some(previous.outpoint()),
423423
true => None
424424
};
425425

426-
if foreign_input.is_some() {
426+
if previous_spaceout.is_some() {
427427
self.txouts.push((previous.outpoint(), TxOut {
428428
value: previous.spaceout.value,
429429
script_pubkey: previous.spaceout.script_pubkey.clone(),
@@ -433,11 +433,11 @@ impl TxRecord {
433433
self.events.push(TxEvent {
434434
kind: TxEventKind::Bid,
435435
space: Some(space.name.to_string()),
436-
foreign_input,
436+
previous_spaceout: previous_spaceout,
437437
details: Some(
438438
serde_json::to_value(BidEventDetails {
439-
bid_current: amount,
440-
bid_previous: previous_bid,
439+
current_bid: amount,
440+
previous_bid: previous_bid,
441441
})
442442
.expect("json value"),
443443
),

0 commit comments

Comments
 (0)