|
1 | 1 | use std::str::FromStr; |
2 | 2 |
|
3 | 3 | use bytes::BytesMut; |
| 4 | +use chrono::{DateTime, Utc}; |
4 | 5 | use ethers::{ |
5 | 6 | abi::{Int, LogParam, Token}, |
6 | 7 | addressbook::Address, |
@@ -79,6 +80,8 @@ pub enum EthereumSqlTypeWrapper { |
79 | 80 | VecString(Vec<String>), |
80 | 81 | Bytes(Bytes), |
81 | 82 | VecBytes(Vec<Bytes>), |
| 83 | + |
| 84 | + DateTime(DateTime<Utc>), |
82 | 85 | } |
83 | 86 |
|
84 | 87 | impl EthereumSqlTypeWrapper { |
@@ -147,6 +150,8 @@ impl EthereumSqlTypeWrapper { |
147 | 150 | EthereumSqlTypeWrapper::VecString(_) => "VecString", |
148 | 151 | EthereumSqlTypeWrapper::Bytes(_) => "Bytes", |
149 | 152 | EthereumSqlTypeWrapper::VecBytes(_) => "VecBytes", |
| 153 | + |
| 154 | + EthereumSqlTypeWrapper::DateTime(_) => "DateTime", |
150 | 155 | } |
151 | 156 | } |
152 | 157 |
|
@@ -215,6 +220,9 @@ impl EthereumSqlTypeWrapper { |
215 | 220 | EthereumSqlTypeWrapper::VecString(_) => PgType::TEXT_ARRAY, |
216 | 221 | EthereumSqlTypeWrapper::Bytes(_) => PgType::BYTEA, |
217 | 222 | EthereumSqlTypeWrapper::VecBytes(_) => PgType::BYTEA_ARRAY, |
| 223 | + |
| 224 | + // DateTime |
| 225 | + EthereumSqlTypeWrapper::DateTime(_) => PgType::TIMESTAMPTZ, |
218 | 226 | } |
219 | 227 | } |
220 | 228 | } |
@@ -472,6 +480,7 @@ impl ToSql for EthereumSqlTypeWrapper { |
472 | 480 | int_values.to_sql(ty, out) |
473 | 481 | } |
474 | 482 | } |
| 483 | + EthereumSqlTypeWrapper::DateTime(value) => value.to_sql(ty, out), |
475 | 484 | } |
476 | 485 | } |
477 | 486 |
|
@@ -1133,6 +1142,9 @@ pub fn map_ethereum_wrapper_to_json( |
1133 | 1142 | EthereumSqlTypeWrapper::VecBytes(bytes) => { |
1134 | 1143 | json!(bytes.iter().map(hex::encode).collect::<Vec<_>>()) |
1135 | 1144 | } |
| 1145 | + EthereumSqlTypeWrapper::DateTime(date_time) => { |
| 1146 | + json!(date_time.to_rfc3339()) |
| 1147 | + } |
1136 | 1148 | }; |
1137 | 1149 | result.insert(abi_input.name.clone(), value); |
1138 | 1150 | wrappers_index_processed.push(current_wrapper_index); |
|
0 commit comments