@@ -20,6 +20,30 @@ pub enum RelationLabel {
20
20
// MiscEntryFunction,
21
21
}
22
22
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
+
23
47
// TODO: deprecate?
24
48
#[ derive( Debug , Clone ) ]
25
49
pub struct TransferTx {
@@ -64,15 +88,13 @@ pub enum EntryFunctionArgs {
64
88
pub struct WarehouseTxMaster {
65
89
pub tx_hash : HashValue , // primary key
66
90
pub relation_label : RelationLabel ,
67
- pub sender : String ,
91
+ pub sender : AccountAddress ,
68
92
pub function : String ,
69
93
pub epoch : u64 ,
70
94
pub round : u64 ,
71
95
pub block_timestamp : u64 ,
72
96
pub block_datetime : DateTime < Utc > ,
73
97
pub expiration_timestamp : u64 ,
74
- // TODO: remove
75
- pub recipient : Option < String > ,
76
98
pub entry_function : Option < EntryFunctionArgs > ,
77
99
pub events : Vec < WarehouseEvent > ,
78
100
}
@@ -82,14 +104,13 @@ impl Default for WarehouseTxMaster {
82
104
Self {
83
105
tx_hash : HashValue :: zero ( ) ,
84
106
relation_label : RelationLabel :: Configuration ,
85
- sender : AccountAddress :: ZERO . short_str_lossless ( ) ,
107
+ sender : AccountAddress :: ZERO ,
86
108
function : "none" . to_owned ( ) ,
87
109
epoch : 0 ,
88
110
round : 0 ,
89
111
block_timestamp : 0 ,
90
112
block_datetime : DateTime :: < Utc > :: from_timestamp_micros ( 0 ) . unwrap ( ) ,
91
113
expiration_timestamp : 0 ,
92
- recipient : None ,
93
114
entry_function : None ,
94
115
// args: json!(""),
95
116
events : vec ! [ ] ,
@@ -104,23 +125,24 @@ impl WarehouseTxMaster {
104
125
/// JSON5 but the last time someone updated
105
126
/// that crate was 3 years ago.
106
127
pub fn to_cypher_object_template ( & self ) -> String {
107
- let recipient = self . recipient . as_ref ( ) . unwrap_or ( & self . sender ) ;
108
-
109
128
let tx_args = match & self . entry_function {
110
129
Some ( ef) => to_cypher_object ( ef, None ) . unwrap_or ( "{test: 0}" . to_string ( ) ) ,
111
130
None => "{test: 1}" . to_owned ( ) ,
112
131
} ;
113
132
114
133
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: "{}"}}"# ,
116
135
self . tx_hash. to_hex_literal( ) ,
117
136
self . block_datetime. to_rfc3339( ) ,
118
137
self . block_timestamp,
119
- self . relation_label,
138
+ self . relation_label. to_cypher_label ( ) ,
120
139
self . function,
121
- self . sender,
140
+ self . sender. to_hex_literal ( ) ,
122
141
tx_args,
123
- recipient,
142
+ self . relation_label
143
+ . get_recipient( )
144
+ . unwrap_or( self . sender)
145
+ . to_hex_literal( ) ,
124
146
)
125
147
}
126
148
@@ -142,8 +164,11 @@ impl WarehouseTxMaster {
142
164
pub fn to_boltmap ( & self ) -> BoltMap {
143
165
let mut map = BoltMap :: new ( ) ;
144
166
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
+ ) ;
147
172
148
173
// TODO
149
174
// map.put("epoch".into(), self.epoch.into());
0 commit comments