Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Satp final #2968

Closed
Closed
Changes from 1 commit
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
dafba95
initial commit
outsidethecode Jun 29, 2023
235e7a4
initial commit
outsidethecode Jun 30, 2023
bfb3d87
initial commit
outsidethecode Jun 30, 2023
6332243
initial commit
outsidethecode Jun 30, 2023
ff66175
initial commit
outsidethecode Jul 1, 2023
c976683
initial commit
outsidethecode Jul 2, 2023
7a99c0d
initial commit
outsidethecode Jul 2, 2023
2dd8ff0
initial commit
outsidethecode Jul 2, 2023
4a0f236
intial commit
outsidethecode Jul 2, 2023
0449cd8
initial commit
outsidethecode Jul 3, 2023
a63d7d6
initial commit
outsidethecode Jul 31, 2023
af47784
initial commit
outsidethecode Jul 31, 2023
98551d2
Implemented the two endpoints TransferProposalClaims and TransferProp…
outsidethecode Aug 1, 2023
3819abc
implemented the lock assertion method
outsidethecode Aug 2, 2023
4aeea5b
Added the lock-assertion-receipt and lock-assertion-broadcast methods
outsidethecode Aug 2, 2023
5fee4cb
Added the request to the driver to lock an asset
outsidethecode Aug 3, 2023
bc6fa77
corrected some variable names
outsidethecode Aug 4, 2023
7ca4476
Merge pull request #1 from outsidethecode/sapt-stage-2
outsidethecode Aug 4, 2023
2ae61f9
Added the endpoints corresponding to the steps 3.1 to 3.9
outsidethecode Aug 9, 2023
2e38595
Implemented the step 2.1B so that the driver call the gateway to upda…
outsidethecode Aug 14, 2023
ee007ad
Implemented the status check functionality required for 2.1B, 3.2B, 3…
outsidethecode Aug 15, 2023
406b6d6
Merge branch 'hyperledger:main' into lock-assertion-lock-assertion-re…
outsidethecode Aug 21, 2023
c537d36
Merge branch 'hyperledger:main' into satp
outsidethecode Aug 21, 2023
d3afbe2
First iteration of switching to real driver (fabric)
outsidethecode Aug 21, 2023
1e53b2d
Added the required functions to call back the gateway after the asset…
outsidethecode Aug 23, 2023
c1fbb46
Colorful log to show different stages and steps
outsidethecode Aug 29, 2023
ae0aa5a
Initial commit for create-asset, extinguish, and assign-asset
outsidethecode Aug 31, 2023
e7b7d38
Added the resources required to assign an asset
outsidethecode Sep 11, 2023
9543ac6
uncommented the perform lock part
outsidethecode Sep 12, 2023
63ea77b
Merge branch 'hyperledger:main' into satp
outsidethecode Sep 19, 2023
4d5f6c2
implemented the lock assertion method
outsidethecode Aug 2, 2023
d25842c
Added the lock-assertion-receipt and lock-assertion-broadcast methods
outsidethecode Aug 2, 2023
d10ef02
Added the request to the driver to lock an asset
outsidethecode Aug 3, 2023
f61d126
corrected some variable names
outsidethecode Aug 4, 2023
a26af14
Added the endpoints corresponding to the steps 3.1 to 3.9
outsidethecode Aug 9, 2023
3c12959
Implemented the step 2.1B so that the driver call the gateway to upda…
outsidethecode Aug 14, 2023
b8c1786
Implemented the status check functionality required for 2.1B, 3.2B, 3…
outsidethecode Aug 15, 2023
5791f2f
First iteration of switching to real driver (fabric)
outsidethecode Aug 21, 2023
7c8dc17
Added the required functions to call back the gateway after the asset…
outsidethecode Aug 23, 2023
92fb3d3
initial commit
outsidethecode Aug 29, 2023
2dfb321
Initial commit for create-asset, extinguish, and assign-asset
outsidethecode Aug 31, 2023
e298f15
Added the resources required to assign an asset
outsidethecode Sep 11, 2023
440c140
uncommented the perform lock part
outsidethecode Sep 12, 2023
0ed12e9
corrected compile error due to merging issue
outsidethecode Sep 19, 2023
099c946
Squashed commit: first implementation version of satp
outsidethecode Aug 2, 2023
16158cb
Merge branch 'satp-version-3' of https://github.com/outsidethecode/ca…
outsidethecode Sep 19, 2023
77a7d1e
Merge pull request #4 from outsidethecode/satp-version-1
outsidethecode Oct 3, 2023
410e843
Initial documentation on how to run the satp gateway and test it
outsidethecode Oct 3, 2023
7345523
Merge pull request #5 from outsidethecode/satp-version-3
outsidethecode Oct 3, 2023
cae117a
feat(weaver): add application logs
RafaelAPB Oct 6, 2023
33703d2
Initial log functionality
outsidethecode Oct 16, 2023
64ce8b3
feat: log statements are stored in sqlite db
outsidethecode Oct 30, 2023
69fac14
feat: updated the .gitignore file
outsidethecode Oct 30, 2023
3c55604
feat: added log entries to all requests
outsidethecode Oct 31, 2023
1b7a268
feat: removed the unnecessary
outsidethecode Nov 2, 2023
9c308aa
feat: removed unnecessary comments
outsidethecode Nov 2, 2023
42e216a
feat: added the missing methods in driver
outsidethecode Nov 3, 2023
7ab00eb
feat: remove the unnecessary log statements
outsidethecode Nov 4, 2023
77ced9e
feat: initial rfcs for satp
outsidethecode Nov 22, 2023
3a23215
Merge branch 'satp' into lock-assertion-lock-assertion-receipt
outsidethecode Nov 27, 2023
b14148c
Merge pull request #2 from outsidethecode/lock-assertion-lock-asserti…
outsidethecode Nov 27, 2023
a3b5f6a
Merge branch 'satp' into satp-version-3
outsidethecode Nov 27, 2023
098ea07
Merge pull request #7 from outsidethecode/satp-version-3
outsidethecode Nov 27, 2023
347d3ec
Merge pull request #8 from outsidethecode/satp-rfcs
outsidethecode Nov 27, 2023
b552f18
initial satp github action script
outsidethecode Nov 27, 2023
55f0af8
corrected the github actions
outsidethecode Nov 28, 2023
3f16312
Merge pull request #9 from outsidethecode/github-actions
outsidethecode Nov 28, 2023
db7ff82
Corrected the protoc version to be 3.17.3 and rebuild
outsidethecode Dec 11, 2023
b890ffc
feat: initial rfcs for satp
outsidethecode Nov 22, 2023
fd80261
initial satp github action script
outsidethecode Nov 27, 2023
cb4dbaf
corrected the github actions
outsidethecode Nov 28, 2023
069a969
Corrected the protoc version to be 3.17.3 and rebuild
outsidethecode Dec 11, 2023
c7a74e2
Merge branch 'satp' of https://github.com/outsidethecode/cacti into satp
outsidethecode Jan 3, 2024
91ba0b8
Merge branch 'satp-final' into satp
outsidethecode Jan 3, 2024
742c1f5
Merge pull request #10 from outsidethecode/satp
outsidethecode Jan 3, 2024
e06737d
refactored the code in satp.ts
outsidethecode Jan 14, 2024
362ddfc
corrected the satpsimpleasset smart contract
outsidethecode Jan 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: added log entries to all requests
outsidethecode committed Oct 31, 2023
commit 3c55604646144ed28f590d27321c82388b78fef9
5 changes: 0 additions & 5 deletions weaver/core/relay/src/services/constants.rs
Original file line number Diff line number Diff line change
@@ -1,5 +0,0 @@
pub static SATP_DB_PATH: &str = "db_satp_path";
pub static SATP_REQUESTS_DB_PATH: &str = "/satp/requests";
pub static SATP_REQUESTS_STATES_DB_PATH: &str = "/satp/requests_states";
pub static SATP_REMOTE_REQUESTS_DB_PATH: &str = "/satp/remote_requests";
pub static SATP_REMOTE_REQUESTS_STATES_DB_PATH: &str = "/satp/remote_requests_states";
63 changes: 4 additions & 59 deletions weaver/core/relay/src/services/network_service.rs
Original file line number Diff line number Diff line change
@@ -28,8 +28,8 @@ use crate::services::helpers::{
};
use crate::services::satp_helper::{
create_transfer_proposal_claims_request, get_relay_from_transfer_proposal_claims,
get_relay_params, get_request_id_from_transfer_proposal_claims, log_request_in_local_satp_db,
log_request_state_in_local_satp_db, spawn_send_transfer_proposal_claims_request,
get_relay_params, get_request_id_from_transfer_proposal_claims,
spawn_send_transfer_proposal_claims_request,
};

// External modules
@@ -535,65 +535,11 @@ impl Network for NetworkService {
create_transfer_proposal_claims_request(network_asset_transfer.clone());
let request_id =
get_request_id_from_transfer_proposal_claims(transfer_proposal_claims_request.clone());
// TODO refactor
let request_logged: Result<Option<sled::IVec>, crate::error::Error> =
log_request_in_local_satp_db(&request_id, &network_asset_transfer, conf.clone());
match request_logged {
Ok(_) => println!(
"Successfully stored NetworkAssetTransfer in local satp_db with request_id: {}",
request_id
),
Err(e) => {
// Internal failure of sled. Send Error response
println!(
"Error storing NetworkAssetTransfer in local satp_db for request_id: {}",
request_id
);
let reply = Ok(Response::new(Ack {
status: ack::Status::Error as i32,
request_id: request_id,
message: format!(
"Error storing NetworkAssetTransfer in local satp_db {:?}",
e
),
}));
println!("Sending Ack back with an error to network of the asset transfer request: {:?}\n", reply);
return reply;
}
}

// Initial request state stored in DB.
let target: RequestState = RequestState {
status: request_state::Status::PendingAck as i32,
request_id: request_id.clone(),
state: None,
};
let request_state_logged: Result<Option<sled::IVec>, crate::error::Error> =
log_request_state_in_local_satp_db(&request_id, &target, conf.clone());
match request_state_logged {
Ok(_) => println!(
"Successfully stored RequestState in local satp_db with request_id: {}",
request_id
),
Err(e) => {
// Internal failure of sled. Send Error response
println!(
"Error storing RequestState in local satp_db for request_id: {}",
request_id
);
let reply = Ok(Response::new(Ack {
status: ack::Status::Error as i32,
request_id: request_id,
message: format!("Error storing RequestState in local satp_db {:?}", e),
}));
println!("Sending Ack back with an error to network of the asset transfer request: {:?}\n", reply);
return reply;
}
}
// TODO refactor / add log entry

let parsed_address = parse_address(network_asset_transfer.address.to_string());
match parsed_address {
Ok(address) => {
Ok(_address) => {
let (relay_host, relay_port) = get_relay_from_transfer_proposal_claims(
transfer_proposal_claims_request.clone(),
);
@@ -608,7 +554,6 @@ impl Network for NetworkService {
relay_port,
use_tls,
tlsca_cert_path,
conf,
);
// Send Ack back to network while request is happening in a thread
let reply = Ack {
252 changes: 31 additions & 221 deletions weaver/core/relay/src/services/satp_helper.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
use crate::db::Database;
use crate::error::{self, Error};
use crate::error::Error;
use crate::relay_proto::LocationSegment;
use crate::services::helpers::get_driver_client;
use crate::services::logger::Operation;
use chrono::Utc;
use config::Config;
use dotenv::dotenv;
use serde::de::DeserializeOwned;
use serde::{Deserialize, Serialize};
use sled::IVec;
use tonic::transport::{Certificate, Channel, ClientTlsConfig};
use tonic::Response;
use weaverpb::common::ack::{ack, Ack};
use weaverpb::common::state::{request_state, RequestState};
use weaverpb::driver::driver::{
AssignAssetRequest, CreateAssetRequest, ExtinguishRequest, PerformLockRequest,
};
@@ -24,27 +17,16 @@ use weaverpb::relay::satp::{
TransferCommenceRequest, TransferCompletedRequest, TransferProposalClaimsRequest,
TransferProposalReceiptRequest,
};

use super::constants::{
SATP_DB_PATH, SATP_REMOTE_REQUESTS_DB_PATH, SATP_REMOTE_REQUESTS_STATES_DB_PATH,
SATP_REQUESTS_DB_PATH, SATP_REQUESTS_STATES_DB_PATH,
};
use super::logger::LogEntry;
use super::types::Driver;

pub fn log_request(log_entry: LogEntry) {
dotenv().ok();
log::debug!("{}", log_entry);
}

// Sends a request to the receiving gateway
pub fn spawn_send_transfer_proposal_claims_request(
transfer_proposal_claims_request: TransferProposalClaimsRequest,
relay_host: String,
relay_port: String,
use_tls: bool,
tlsca_cert_path: String,
conf: Config,
) {
println!(
"Sending transfer proposal claims request to receiver gateway: {:?}:{:?}",
@@ -80,7 +62,6 @@ pub fn spawn_send_transfer_commence_request(
relay_port: String,
use_tls: bool,
tlsca_cert_path: String,
conf: Config,
) {
println!(
"Sending transfer commence request to receiver gateway: {:?}:{:?}",
@@ -159,7 +140,6 @@ pub fn spawn_send_ack_commence_request(
relay_port: String,
use_tls: bool,
tlsca_cert_path: String,
conf: Config,
) {
tokio::spawn(async move {
let request_id = ack_commence_request.session_id.to_string();
@@ -247,7 +227,6 @@ pub fn spawn_send_lock_assertion_request(
relay_port: String,
use_tls: bool,
tlsca_cert_path: String,
conf: Config,
) {
tokio::spawn(async move {
let request_id = lock_assertion_request.session_id.to_string();
@@ -275,7 +254,6 @@ pub fn spawn_send_commit_prepare_request(
relay_port: String,
use_tls: bool,
tlsca_cert_path: String,
conf: Config,
) {
println!(
"Sending commit prepare request to receiver gateway: {:?}:{:?}",
@@ -331,10 +309,8 @@ pub fn spawn_send_commit_ready_request(
relay_port: String,
use_tls: bool,
tlsca_cert_path: String,
conf: Config,
) {
tokio::spawn(async move {
let request_id = commit_ready_request.session_id.to_string();
let result = call_commit_ready(
relay_host,
relay_port,
@@ -383,10 +359,8 @@ pub fn spawn_send_ack_final_receipt_request(
relay_port: String,
use_tls: bool,
tlsca_cert_path: String,
conf: Config,
) {
tokio::spawn(async move {
let request_id = ack_final_receipt_request.session_id.to_string();
let result = call_ack_final_receipt(
relay_host,
relay_port,
@@ -409,7 +383,6 @@ pub fn spawn_send_ack_final_receipt_broadcast_request(
relay_port: String,
use_tls: bool,
tlsca_cert_path: String,
conf: Config,
) {
tokio::spawn(async move {
let request_id = ack_final_receipt_request.session_id.to_string();
@@ -472,7 +445,6 @@ pub fn spawn_send_commit_final_assertion_request(
relay_port: String,
use_tls: bool,
tlsca_cert_path: String,
conf: Config,
) {
tokio::spawn(async move {
let request_id = commit_final_assertion_request.session_id.to_string();
@@ -885,9 +857,8 @@ pub fn create_ack_error_message(
}

pub fn create_transfer_proposal_claims_request(
network_asset_transfer: NetworkAssetTransfer,
_network_asset_transfer: NetworkAssetTransfer,
) -> TransferProposalClaimsRequest {
let session_id = "to_be_calculated_session_id";
let transfer_proposal_claims_request = TransferProposalClaimsRequest {
message_type: "message_type1".to_string(),
client_identity_pubkey: "client_identity_pubkey1".to_string(),
@@ -907,7 +878,7 @@ pub fn create_transfer_proposal_claims_request(
}

pub fn create_transfer_commence_request(
transfer_proposal_receipt_request: TransferProposalReceiptRequest,
_transfer_proposal_receipt_request: TransferProposalReceiptRequest,
) -> TransferCommenceRequest {
let session_id = "to_be_calculated_session_id";
let transfer_commence_request = TransferCommenceRequest {
@@ -925,7 +896,7 @@ pub fn create_transfer_commence_request(
}

pub fn create_transfer_proposal_receipt_request(
transfer_proposal_claims_request: TransferProposalClaimsRequest,
_transfer_proposal_claims_request: TransferProposalClaimsRequest,
) -> TransferProposalReceiptRequest {
// TODO: remove hard coded values
let transfer_proposal_receipt_request = TransferProposalReceiptRequest {
@@ -947,7 +918,7 @@ pub fn create_transfer_proposal_receipt_request(
}

pub fn create_ack_commence_request(
transfer_commence_request: TransferCommenceRequest,
_transfer_commence_request: TransferCommenceRequest,
) -> AckCommenceRequest {
// TODO: remove hard coded values
let ack_commence_request = AckCommenceRequest {
@@ -964,7 +935,7 @@ pub fn create_ack_commence_request(
}

pub fn create_lock_assertion_request(
send_asset_status_request: SendAssetStatusRequest,
_send_asset_status_request: SendAssetStatusRequest,
) -> LockAssertionRequest {
// TODO: remove hard coded values
let lock_assertion_request = LockAssertionRequest {
@@ -984,7 +955,7 @@ pub fn create_lock_assertion_request(
}

pub fn create_lock_assertion_receipt_request(
lock_assertion_request: LockAssertionRequest,
_lock_assertion_request: LockAssertionRequest,
) -> LockAssertionReceiptRequest {
// TODO: remove hard coded values
let lock_assertion_receipt_request = LockAssertionReceiptRequest {
@@ -1001,7 +972,7 @@ pub fn create_lock_assertion_receipt_request(
}

pub fn create_commit_prepare_request(
lock_assertion_receipt_request: LockAssertionReceiptRequest,
_lock_assertion_receipt_request: LockAssertionReceiptRequest,
) -> CommitPrepareRequest {
// TODO: remove hard coded values
let commit_prepare_request = CommitPrepareRequest {
@@ -1013,7 +984,7 @@ pub fn create_commit_prepare_request(
}

pub fn create_commit_ready_request(
send_asset_status_request: SendAssetStatusRequest,
_send_asset_status_request: SendAssetStatusRequest,
) -> CommitReadyRequest {
// TODO: remove hard coded values
let commit_ready_request = CommitReadyRequest {
@@ -1025,7 +996,7 @@ pub fn create_commit_ready_request(
}

pub fn create_commit_final_assertion_request(
send_asset_status_request: SendAssetStatusRequest,
_send_asset_status_request: SendAssetStatusRequest,
) -> CommitFinalAssertionRequest {
// TODO: remove hard coded values
let commit_final_assertion_request = CommitFinalAssertionRequest {
@@ -1037,7 +1008,7 @@ pub fn create_commit_final_assertion_request(
}

pub fn create_ack_final_receipt_request(
send_asset_status_request: SendAssetStatusRequest,
_send_asset_status_request: SendAssetStatusRequest,
) -> AckFinalReceiptRequest {
// TODO: remove hard coded values
let ack_final_receipt_request = AckFinalReceiptRequest {
@@ -1049,7 +1020,7 @@ pub fn create_ack_final_receipt_request(
}

pub fn create_transfer_completed_request(
ack_final_receipt_request: AckFinalReceiptRequest,
_ack_final_receipt_request: AckFinalReceiptRequest,
) -> TransferCompletedRequest {
// TODO: remove hard coded values
let transfer_completed_request = TransferCompletedRequest {
@@ -1060,7 +1031,7 @@ pub fn create_transfer_completed_request(
return transfer_completed_request;
}

pub fn create_perform_lock_request(ack_commence_request: AckCommenceRequest) -> PerformLockRequest {
pub fn create_perform_lock_request(_ack_commence_request: AckCommenceRequest) -> PerformLockRequest {
// TODO: remove hard coded values
let perform_lock_request = PerformLockRequest {
session_id: "session_id1".to_string(),
@@ -1069,7 +1040,7 @@ pub fn create_perform_lock_request(ack_commence_request: AckCommenceRequest) ->
}

pub fn create_create_asset_request(
commit_prepare_request: CommitPrepareRequest,
_commit_prepare_request: CommitPrepareRequest,
) -> CreateAssetRequest {
// TODO: remove hard coded values
let create_asset_request = CreateAssetRequest {
@@ -1078,7 +1049,7 @@ pub fn create_create_asset_request(
return create_asset_request;
}

pub fn create_extinguish_request(commit_ready_request: CommitReadyRequest) -> ExtinguishRequest {
pub fn create_extinguish_request(_commit_ready_request: CommitReadyRequest) -> ExtinguishRequest {
// TODO: remove hard coded values
let extinguish_request = ExtinguishRequest {
session_id: "session_id1".to_string(),
@@ -1087,7 +1058,7 @@ pub fn create_extinguish_request(commit_ready_request: CommitReadyRequest) -> Ex
}

pub fn create_assign_asset_request(
commit_final_assertion_request: CommitFinalAssertionRequest,
_commit_final_assertion_request: CommitFinalAssertionRequest,
) -> AssignAssetRequest {
// TODO: remove hard coded values
let assign_asset_request = AssignAssetRequest {
@@ -1096,242 +1067,81 @@ pub fn create_assign_asset_request(
return assign_asset_request;
}

pub fn generate_commit_final_assertion_request(
commit_ready_request: CommitReadyRequest,
) -> CommitFinalAssertionRequest {
// TODO Get the corresponding send_asset_status_request from db
// TODO: remove hard coded values
let commit_final_assertion_request = CommitFinalAssertionRequest {
message_type: "message_type1".to_string(),
session_id: "session_id1".to_string(),
transfer_context_id: "transfer_context_id1".to_string(),
};
return commit_final_assertion_request;
}

pub fn generate_commit_ready_request(
commit_prepare_request: CommitPrepareRequest,
) -> CommitReadyRequest {
// TODO Get the corresponding send_asset_status_request from db
// TODO: remove hard coded values
let commit_ready_request = CommitReadyRequest {
message_type: "message_type1".to_string(),
session_id: "session_id1".to_string(),
transfer_context_id: "transfer_context_id1".to_string(),
};
return commit_ready_request;
}

pub fn generate_ack_final_receipt_request(
commit_final_assertion_request: CommitFinalAssertionRequest,
) -> AckFinalReceiptRequest {
// TODO Get the corresponding send_asset_status_request from db
// TODO: remove hard coded values
let ack_final_receipt_request = AckFinalReceiptRequest {
message_type: "message_type1".to_string(),
session_id: "session_id1".to_string(),
transfer_context_id: "transfer_context_id1".to_string(),
};
return ack_final_receipt_request;
}

pub fn get_satp_requests_local_db(conf: Config) -> Database {
let db = Database {
db_path: format!(
"{}{}",
conf.get_str(SATP_DB_PATH).unwrap(),
SATP_REQUESTS_DB_PATH
),
db_open_max_retries: conf.get_int("db_open_max_retries").unwrap_or(500) as u32,
db_open_retry_backoff_msec: conf.get_int("db_open_retry_backoff_msec").unwrap_or(10) as u32,
};
return db;
}

pub fn get_satp_requests_remote_db(conf: Config) -> Database {
let db = Database {
db_path: format!(
"{}{}",
conf.get_str(SATP_DB_PATH).unwrap(),
SATP_REMOTE_REQUESTS_DB_PATH
),
db_open_max_retries: conf.get_int("db_open_max_retries").unwrap_or(500) as u32,
db_open_retry_backoff_msec: conf.get_int("db_open_retry_backoff_msec").unwrap_or(10) as u32,
};
return db;
}

pub fn get_satp_requests_states_local_db(conf: Config) -> Database {
let db = Database {
db_path: format!(
"{}{}",
conf.get_str(SATP_DB_PATH).unwrap(),
SATP_REQUESTS_STATES_DB_PATH
),
db_open_max_retries: conf.get_int("db_open_max_retries").unwrap_or(500) as u32,
db_open_retry_backoff_msec: conf.get_int("db_open_retry_backoff_msec").unwrap_or(10) as u32,
};
return db;
}

pub fn get_satp_requests_states_remote_db(conf: Config) -> Database {
let db = Database {
db_path: format!(
"{}{}",
conf.get_str(SATP_DB_PATH).unwrap(),
SATP_REMOTE_REQUESTS_STATES_DB_PATH
),
db_open_max_retries: conf.get_int("db_open_max_retries").unwrap_or(500) as u32,
db_open_retry_backoff_msec: conf.get_int("db_open_retry_backoff_msec").unwrap_or(10) as u32,
};
return db;
}

pub fn log_request_state_in_local_satp_db(
request_id: &String,
target: &RequestState,
conf: Config,
) -> Result<std::option::Option<IVec>, error::Error> {
let db = get_satp_requests_states_local_db(conf);
return db.set(&request_id, &target);
}

pub fn log_request_in_local_satp_db<T: Serialize>(
request_id: &String,
value: T,
conf: Config,
) -> Result<std::option::Option<IVec>, error::Error> {
let db = get_satp_requests_local_db(conf);
return db.set(&request_id, &value);
}

pub fn log_request_in_remote_satp_db<T: Serialize>(
request_id: &String,
value: T,
conf: Config,
) -> Result<std::option::Option<IVec>, error::Error> {
let db = get_satp_requests_remote_db(conf);
return db.set(&request_id, &value);
}

pub fn get_request_from_remote_satp_db<T: DeserializeOwned>(
request_id: &String,
conf: Config,
) -> Result<T, error::Error> {
let db = get_satp_requests_remote_db(conf);
let query: Result<T, error::Error> = db
.get::<T>(request_id.to_string())
.map_err(|e| Error::GetQuery(format!("Failed to get query from db. Error: {:?}", e)));
return query;
}

pub fn update_request_state_in_local_satp_db(
request_id: String,
new_status: request_state::Status,
state: Option<request_state::State>,
conf: Config,
) {
let db = get_satp_requests_states_local_db(conf);
let target: RequestState = RequestState {
status: new_status as i32,
request_id: request_id.clone(),
state,
};
db.set(&request_id, &target)
.expect("Failed to insert into DB");
println!("Successfully written RequestState to database");
println!("{:?}\n", db.get::<RequestState>(request_id).unwrap())
}

pub fn get_relay_from_transfer_proposal_claims(
transfer_proposal_claims_request: TransferProposalClaimsRequest,
_transfer_proposal_claims_request: TransferProposalClaimsRequest,
) -> (String, String) {
// TODO
return ("localhost".to_string(), "9085".to_string());
}

pub fn get_relay_from_transfer_proposal_receipt(
transfer_proposal_receipt_request: TransferProposalReceiptRequest,
_transfer_proposal_receipt_request: TransferProposalReceiptRequest,
) -> (String, String) {
// TODO
return ("localhost".to_string(), "9085".to_string());
}

pub fn get_relay_from_transfer_commence(
transfer_commence_request: TransferCommenceRequest,
_transfer_commence_request: TransferCommenceRequest,
) -> (String, String) {
// TODO
return ("localhost".to_string(), "9085".to_string());
}

pub fn get_relay_from_ack_commence(ack_commence_request: AckCommenceRequest) -> (String, String) {
pub fn get_relay_from_ack_commence(_ack_commence_request: AckCommenceRequest) -> (String, String) {
// TODO
return ("localhost".to_string(), "9085".to_string());
}

pub fn get_relay_from_lock_assertion(
lock_assertion_request: LockAssertionRequest,
) -> (String, String) {
// TODO
return ("localhost".to_string(), "9085".to_string());
}

pub fn get_relay_from_lock_assertion_receipt(
lock_assertion_receipt_request: LockAssertionReceiptRequest,
_lock_assertion_request: LockAssertionRequest,
) -> (String, String) {
// TODO
return ("localhost".to_string(), "9085".to_string());
}

pub fn get_relay_from_commit_prepare(
commit_prepare_request: CommitPrepareRequest,
_commit_prepare_request: CommitPrepareRequest,
) -> (String, String) {
// TODO
return ("localhost".to_string(), "9085".to_string());
}

pub fn get_relay_from_commit_ready(commit_ready_request: CommitReadyRequest) -> (String, String) {
pub fn get_relay_from_commit_ready(_commit_ready_request: CommitReadyRequest) -> (String, String) {
// TODO
return ("localhost".to_string(), "9085".to_string());
}

pub fn get_relay_from_commit_final_assertion(
commit_final_assertion_request: CommitFinalAssertionRequest,
_commit_final_assertion_request: CommitFinalAssertionRequest,
) -> (String, String) {
// TODO
return ("localhost".to_string(), "9085".to_string());
}

pub fn get_relay_from_ack_final_receipt(
ack_final_receipt_request: AckFinalReceiptRequest,
) -> (String, String) {
// TODO
return ("localhost".to_string(), "9085".to_string());
}

pub fn get_relay_from_send_asset_status(
send_asset_status_request: SendAssetStatusRequest,
_ack_final_receipt_request: AckFinalReceiptRequest,
) -> (String, String) {
// TODO
return ("localhost".to_string(), "9085".to_string());
}

pub fn get_driver_address_from_perform_lock(perform_lock_request: PerformLockRequest) -> String {
pub fn get_driver_address_from_perform_lock(_perform_lock_request: PerformLockRequest) -> String {
// TODO
return "localhost:9085/Dummy_Network/abc:abc:abc:abc".to_string();
}

pub fn get_driver_address_from_create_asset(create_asset_request: CreateAssetRequest) -> String {
pub fn get_driver_address_from_create_asset(_create_asset_request: CreateAssetRequest) -> String {
// TODO
return "localhost:9085/Dummy_Network/abc:abc:abc:abc".to_string();
}

pub fn get_driver_address_from_extinguish(extinguish_request: ExtinguishRequest) -> String {
pub fn get_driver_address_from_extinguish(_extinguish_request: ExtinguishRequest) -> String {
// TODO
return "localhost:9085/Dummy_Network/abc:abc:abc:abc".to_string();
}

pub fn get_driver_address_from_assign_asset(assign_asset_request: AssignAssetRequest) -> String {
pub fn get_driver_address_from_assign_asset(_assign_asset_request: AssignAssetRequest) -> String {
// TODO
return "localhost:9085/Dummy_Network/abc:abc:abc:abc".to_string();
}
@@ -1383,14 +1193,14 @@ pub async fn create_satp_client(
}

pub fn get_request_id_from_transfer_proposal_claims(
request: TransferProposalClaimsRequest,
_request: TransferProposalClaimsRequest,
) -> String {
// TODO
return "hard_coded_transfer_proposal_claims_request_id".to_string();
}

pub fn get_request_id_from_transfer_proposal_receipt(
request: TransferProposalReceiptRequest,
_request: TransferProposalReceiptRequest,
) -> String {
// TODO
return "hard_coded_transfer_proposal_receipt_request_id".to_string();
800 changes: 522 additions & 278 deletions weaver/core/relay/src/services/satp_service.rs

Large diffs are not rendered by default.