-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from bmrlab/dev
Dev
- Loading branch information
Showing
41 changed files
with
1,675 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
target | ||
dockerfile | ||
.dockerignore | ||
.git | ||
.gitignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
// 使用 IntelliSense 了解相关属性。 | ||
// 悬停以查看现有属性的描述。 | ||
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"type": "lldb", | ||
"request": "launch", | ||
"name": "Debug", | ||
"program": "${workspaceFolder}/<executable file>", | ||
"args": [], | ||
"cwd": "${workspaceFolder}" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# Loco configuration file documentation | ||
|
||
# Application logging configuration | ||
logger: | ||
# Enable or disable logging. | ||
enable: true | ||
# Enable pretty backtrace (sets RUST_BACKTRACE=1) | ||
pretty_backtrace: true | ||
# Log level, options: trace, debug, info, warn or error. | ||
level: debug | ||
# Define the logging format. options: compact, pretty or Json | ||
format: pretty | ||
# By default the logger has filtering only logs that came from your code or logs that came from `loco` framework. to see all third party libraries | ||
# Uncomment the line below to override to see all third party libraries you can enable this config and override the logger filters. | ||
# override_filter: trace | ||
|
||
# Web server configuration | ||
server: | ||
# Port on which the server will listen. the server binding is 0.0.0.0:{PORT} | ||
port: 8081 | ||
# The UI hostname or IP address that mailers will point to. | ||
host: http://localhost | ||
# Out of the box middleware configuration. to disable middleware you can changed the `enable` field to `false` of comment the middleware block | ||
middlewares: | ||
# Enable Etag cache header middleware | ||
etag: | ||
enable: true | ||
# Allows to limit the payload size request. payload that bigger than this file will blocked the request. | ||
limit_payload: | ||
# Enable/Disable the middleware. | ||
enable: true | ||
# the limit size. can be b,kb,kib,mb,mib,gb,gib | ||
body_limit: 5mb | ||
# Generating a unique request ID and enhancing logging with additional information such as the start and completion of request processing, latency, status code, and other request details. | ||
logger: | ||
# Enable/Disable the middleware. | ||
enable: true | ||
# when your code is panicked, the request still returns 500 status code. | ||
catch_panic: | ||
# Enable/Disable the middleware. | ||
enable: true | ||
# Timeout for incoming requests middleware. requests that take more time from the configuration will cute and 408 status code will returned. | ||
timeout_request: | ||
# Enable/Disable the middleware. | ||
enable: false | ||
# Duration time in milliseconds. | ||
timeout: 5000 | ||
cors: | ||
enable: true | ||
# Set the value of the [`Access-Control-Allow-Origin`][mdn] header | ||
# allow_origins: | ||
# - https://loco.rs | ||
# Set the value of the [`Access-Control-Allow-Headers`][mdn] header | ||
# allow_headers: | ||
# - Content-Type | ||
# Set the value of the [`Access-Control-Allow-Methods`][mdn] header | ||
# allow_methods: | ||
# - POST | ||
# Set the value of the [`Access-Control-Max-Age`][mdn] header in seconds | ||
# max_age: 3600 | ||
|
||
# Database Configuration | ||
database: | ||
# Database connection URI | ||
uri: {{ get_env(name="DATABASE_URL", default="mysql://root:123456@localhost:3306/muse_integrator") }} | ||
# When enabled, the sql query will be logged. | ||
enable_logging: false | ||
# Set the timeout duration when acquiring a connection. | ||
connect_timeout: 500 | ||
# Set the idle duration before closing a connection. | ||
idle_timeout: 500 | ||
# Minimum number of connections for a pool. | ||
min_connections: 1 | ||
# Maximum number of connections for a pool. | ||
max_connections: 1 | ||
# Run migration up when application loaded | ||
auto_migrate: true | ||
# Truncate database when application loaded. This is a dangerous operation, make sure that you using this flag only on dev environments or test mode | ||
dangerously_truncate: false | ||
# Recreating schema when application loaded. This is a dangerous operation, make sure that you using this flag only on dev environments or test mode | ||
dangerously_recreate: false | ||
|
||
# Redis Configuration | ||
redis: | ||
# Redis connection URI | ||
uri: {{ get_env(name="REDIS_URL", default="redis://127.0.0.1") }} | ||
# Dangerously flush all data in Redis on startup. dangerous operation, make sure that you using this flag only on dev environments or test mode | ||
dangerously_flush: false | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
FROM rust:1.74-slim as builder | ||
|
||
WORKDIR /usr/src/ | ||
|
||
COPY . . | ||
|
||
RUN cargo build --release | ||
|
||
FROM debian:bookworm-slim | ||
|
||
RUN apt-get update && apt-get install -y libc6 | ||
|
||
WORKDIR /usr/app | ||
|
||
COPY --from=builder /usr/src/config /usr/app/config | ||
COPY --from=builder /usr/src/target/release/credits-cli /usr/app/credits-cli | ||
|
||
ENTRYPOINT ["/usr/app/credits-cli"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,143 @@ | ||
use chrono::{TimeZone, Utc}; | ||
use credits::{ | ||
app::App, | ||
models::_entities::transaction_events::{self}, | ||
}; | ||
use eyre::Context; | ||
#[allow(unused_imports)] | ||
use loco_rs::{cli::playground, prelude::*}; | ||
use muse_integrator::{ | ||
app::App, | ||
models::_entities::wallets::{self, ActiveModel}, | ||
use mongodb::{ | ||
bson::{Bson, Document}, | ||
Client, Collection, | ||
}; | ||
use sea_orm::prelude::Decimal; | ||
use serde_json::Value as Json; | ||
use std::env; | ||
|
||
#[tokio::main] | ||
async fn main() -> eyre::Result<()> { | ||
let ctx = playground::<App>().await.context("playground")?; | ||
|
||
let active_model = ActiveModel { | ||
addr: Set("0xadsfasdf".to_string()), | ||
balance: Set(Decimal::new(2000, 2)), | ||
status: Set(1), | ||
..Default::default() | ||
}; | ||
active_model.insert(&ctx.db).await.unwrap(); | ||
// ctx,. | ||
|
||
let uri = env::var("url")?; | ||
|
||
let client = Client::with_uri_str(uri).await?; | ||
// Get a handle on the movies collection | ||
let database = client.database("damaigc-credits-billing"); | ||
let my_coll: Collection<Document> = database.collection("transaction_event"); | ||
|
||
let mut cursor = my_coll.find(None, None).await?; | ||
while cursor.advance().await? { | ||
let mut tran = transaction_events::ActiveModel { | ||
..Default::default() | ||
}; | ||
|
||
let doc = &cursor.deserialize_current()?; | ||
|
||
println!("{:?}", doc); | ||
let mut id = 0; | ||
|
||
let event_exec_id_opt = doc.get("event_exec_id"); | ||
if let Some(v) = event_exec_id_opt { | ||
if let Bson::Int32(r) = v { | ||
id = r.clone(); | ||
tran.id = Set(r.to_owned()); | ||
} | ||
} | ||
let temp = transaction_events::Entity::find_by_id(id) | ||
.one(&ctx.db) | ||
.await | ||
.unwrap(); | ||
if let None = temp { | ||
let event_type_opt = doc.get("event_type"); | ||
if let Some(event_type) = event_type_opt { | ||
if let Bson::String(v) = event_type { | ||
tran.event_type = Set(v.to_string()); | ||
} | ||
} | ||
|
||
let from_addr_opt = doc.get("from_addr"); | ||
if let Some(from_addr) = from_addr_opt { | ||
if let Bson::String(v) = from_addr { | ||
tran.from_addr = Set(Some(v.to_string())); | ||
} | ||
} | ||
|
||
let to_addr_opt = doc.get("to_addr"); | ||
if let Some(to_addr) = to_addr_opt { | ||
if let Bson::String(v) = to_addr { | ||
tran.to_addr = Set(Some(v.to_string())); | ||
} | ||
} | ||
|
||
let amount_opt = doc.get("amount"); | ||
if let Some(amount) = amount_opt { | ||
if let Bson::Double(v) = amount { | ||
tran.amount = Set(Decimal::new((v * 100.0).round() as i64, 2)); | ||
} | ||
} | ||
|
||
let info_opt = doc.get("info"); | ||
if let Some(info) = info_opt { | ||
if let Bson::Document(v) = info { | ||
tran.info = Set(Some(Json::from_iter(v.clone()))); | ||
} | ||
} | ||
|
||
let account_event_id_opt = doc.get("_id"); | ||
if let Some(v) = account_event_id_opt { | ||
if let Bson::String(r) = v { | ||
tran.event_id = Set(r.to_string()); | ||
} | ||
} | ||
|
||
let trace_id_id_opt: Option<&Bson> = doc.get("trace_id"); | ||
if let Some(v) = trace_id_id_opt { | ||
if let Bson::String(r) = v { | ||
tran.trace_id = Set(r.to_string()); | ||
} | ||
} | ||
|
||
let status_opt = doc.get("status"); | ||
if let Some(v) = status_opt { | ||
if let Bson::Int32(r) = v { | ||
tran.state = Set(r.to_owned() as i16); | ||
} | ||
} | ||
|
||
let callback_url_opt = doc.get("callback_url"); | ||
if let Some(v) = callback_url_opt { | ||
if let Bson::String(r) = v { | ||
tran.callback_url = Set(Some(r.to_string())); | ||
} | ||
} | ||
|
||
let status_msg_opt = doc.get("status_msg"); | ||
if let Some(v) = status_msg_opt { | ||
if let Bson::String(r) = v { | ||
tran.status_msg = Set(Some(r.to_string())); | ||
} | ||
} | ||
|
||
let res = wallets::Entity::find().all(&ctx.db).await.unwrap(); | ||
println!("{:?}", res); | ||
let created_at_opt = doc.get("created_at"); | ||
if let Some(v) = created_at_opt { | ||
if let Bson::DateTime(r) = v { | ||
tran.created_at = Set(Utc.timestamp_millis_opt(r.timestamp_millis()).unwrap()); | ||
} | ||
} | ||
let updated_at_opt = doc.get("updated_at"); | ||
if let Some(v) = updated_at_opt { | ||
if let Bson::DateTime(r) = v { | ||
tran.updated_at = Set(Utc.timestamp_millis_opt(r.timestamp_millis()).unwrap()); | ||
} | ||
} | ||
println!("{:?}", &tran); | ||
println!("开始转储------"); | ||
tran.insert(&ctx.db).await.unwrap(); | ||
} | ||
} | ||
println!("转储完成------"); | ||
|
||
Ok(()) | ||
} |
Oops, something went wrong.