Skip to content

Commit 99d2cc7

Browse files
committed
relation labels
1 parent 0b19a9b commit 99d2cc7

File tree

2 files changed

+39
-15
lines changed

2 files changed

+39
-15
lines changed

src/extract_transactions.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,11 @@ pub fn make_master_tx(
124124
let tx = WarehouseTxMaster {
125125
tx_hash,
126126
expiration_timestamp: user_tx.expiration_timestamp_secs(),
127-
sender: user_tx.sender().to_hex_literal(),
127+
sender: user_tx.sender(),
128128
epoch,
129129
round,
130130
block_timestamp,
131131
function,
132-
recipient: None,
133132
entry_function: None,
134133
relation_label,
135134
block_datetime: DateTime::from_timestamp_micros(block_timestamp as i64).unwrap(),

src/table_structs.rs

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,30 @@ pub enum RelationLabel {
2020
// MiscEntryFunction,
2121
}
2222

23+
impl RelationLabel {
24+
pub fn to_cypher_label(&self) -> String {
25+
match self {
26+
RelationLabel::Tx => "Tx".to_owned(),
27+
RelationLabel::Transfer(_) => "Tx".to_owned(),
28+
RelationLabel::Onboarding(_) => "Onboarding".to_owned(),
29+
RelationLabel::Vouch(_) => "Vouch".to_owned(),
30+
RelationLabel::Configuration => "Configuration".to_owned(),
31+
RelationLabel::Miner => "Miner".to_owned(),
32+
}
33+
}
34+
35+
pub fn get_recipient(&self) -> Option<AccountAddress> {
36+
match &self {
37+
RelationLabel::Tx => None,
38+
RelationLabel::Transfer(account_address) => Some(*account_address),
39+
RelationLabel::Onboarding(account_address) => Some(*account_address),
40+
RelationLabel::Vouch(account_address) => Some(*account_address),
41+
RelationLabel::Configuration => None,
42+
RelationLabel::Miner => None,
43+
}
44+
}
45+
}
46+
2347
// TODO: deprecate?
2448
#[derive(Debug, Clone)]
2549
pub struct TransferTx {
@@ -64,15 +88,13 @@ pub enum EntryFunctionArgs {
6488
pub struct WarehouseTxMaster {
6589
pub tx_hash: HashValue, // primary key
6690
pub relation_label: RelationLabel,
67-
pub sender: String,
91+
pub sender: AccountAddress,
6892
pub function: String,
6993
pub epoch: u64,
7094
pub round: u64,
7195
pub block_timestamp: u64,
7296
pub block_datetime: DateTime<Utc>,
7397
pub expiration_timestamp: u64,
74-
// TODO: remove
75-
pub recipient: Option<String>,
7698
pub entry_function: Option<EntryFunctionArgs>,
7799
pub events: Vec<WarehouseEvent>,
78100
}
@@ -82,14 +104,13 @@ impl Default for WarehouseTxMaster {
82104
Self {
83105
tx_hash: HashValue::zero(),
84106
relation_label: RelationLabel::Configuration,
85-
sender: AccountAddress::ZERO.short_str_lossless(),
107+
sender: AccountAddress::ZERO,
86108
function: "none".to_owned(),
87109
epoch: 0,
88110
round: 0,
89111
block_timestamp: 0,
90112
block_datetime: DateTime::<Utc>::from_timestamp_micros(0).unwrap(),
91113
expiration_timestamp: 0,
92-
recipient: None,
93114
entry_function: None,
94115
// args: json!(""),
95116
events: vec![],
@@ -104,23 +125,24 @@ impl WarehouseTxMaster {
104125
/// JSON5 but the last time someone updated
105126
/// that crate was 3 years ago.
106127
pub fn to_cypher_object_template(&self) -> String {
107-
let recipient = self.recipient.as_ref().unwrap_or(&self.sender);
108-
109128
let tx_args = match &self.entry_function {
110129
Some(ef) => to_cypher_object(ef, None).unwrap_or("{test: 0}".to_string()),
111130
None => "{test: 1}".to_owned(),
112131
};
113132

114133
format!(
115-
r#"{{tx_hash: "{}", block_datetime: datetime("{}"), block_timestamp: {}, relation: "{:?}", function: "{}", sender: "{}", args: {}, recipient: "{}"}}"#,
134+
r#"{{tx_hash: "{}", block_datetime: datetime("{}"), block_timestamp: {}, relation: "{}", function: "{}", sender: "{}", args: {}, recipient: "{}"}}"#,
116135
self.tx_hash.to_hex_literal(),
117136
self.block_datetime.to_rfc3339(),
118137
self.block_timestamp,
119-
self.relation_label,
138+
self.relation_label.to_cypher_label(),
120139
self.function,
121-
self.sender,
140+
self.sender.to_hex_literal(),
122141
tx_args,
123-
recipient,
142+
self.relation_label
143+
.get_recipient()
144+
.unwrap_or(self.sender)
145+
.to_hex_literal(),
124146
)
125147
}
126148

@@ -142,8 +164,11 @@ impl WarehouseTxMaster {
142164
pub fn to_boltmap(&self) -> BoltMap {
143165
let mut map = BoltMap::new();
144166
map.put("tx_hash".into(), self.tx_hash.to_string().into());
145-
map.put("sender".into(), self.sender.clone().into());
146-
map.put("recipient".into(), self.sender.clone().into());
167+
map.put("sender".into(), self.sender.clone().to_hex_literal().into());
168+
map.put(
169+
"recipient".into(),
170+
self.sender.clone().to_hex_literal().into(),
171+
);
147172

148173
// TODO
149174
// map.put("epoch".into(), self.epoch.into());

0 commit comments

Comments
 (0)