Skip to content

Exchange lite node integration #51

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

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
59 changes: 35 additions & 24 deletions src/api/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,38 +516,45 @@ pub async fn post_import_keypairs(
pub async fn post_make_payment(
db: WalletDb,
peer: Node,
encapsulated_data: EncapsulatedPayment,
encapsulated_data: Vec<EncapsulatedPayment>,
route: &'static str,
call_id: String,
) -> Result<JsonReply, JsonReply> {
let EncapsulatedPayment {
address,
amount,
passphrase,
locktime,
} = encapsulated_data;

let r = CallResponse::new(route, &call_id);
let mut addresses = Vec::new();
let mut amounts = Vec::new();

let request = match db.test_passphrase(passphrase).await {
Ok(_) => UserRequest::UserApi(UserApiRequest::MakePayment {
address: address.clone(),
for ed in encapsulated_data {
let EncapsulatedPayment {
address,
amount,
passphrase,
locktime,
}),
Err(e) => {
return wallet_db_error(e, r);
}
};
} = ed;

let request = match db.test_passphrase(passphrase).await {
Ok(_) => UserRequest::UserApi(UserApiRequest::MakePayment {
address: address.clone(),
amount,
locktime,
}),
Err(e) => {
return wallet_db_error(e, r);
}
};

if let Err(e) = peer.inject_next_event(peer.local_address(), request) {
error!("route:make_payment error: {:?}", e);
return r.into_err_internal(ApiErrorType::CannotAccessUserNode);
addresses.push(address);
amounts.push(amount);

if let Err(e) = peer.inject_next_event(peer.local_address(), request) {
error!("route:make_payment error: {:?}", e);
return r.into_err_internal(ApiErrorType::CannotAccessUserNode);
}
}

r.into_ok(
"Payment processing",
json_serialize_embed(construct_make_payment_map(address, amount)),
json_serialize_embed(construct_make_payment_map(&addresses, &amounts)),
)
}

Expand Down Expand Up @@ -593,7 +600,7 @@ pub async fn post_make_ip_payment(

r.into_ok(
"IP payment processing",
json_serialize_embed(construct_make_payment_map(address.clone(), amount)),
json_serialize_embed(construct_make_payment_map(&vec![address.clone()], &vec![amount])),
)
}

Expand Down Expand Up @@ -1148,10 +1155,14 @@ pub fn construct_ctx_map(transactions: &[Transaction]) -> BTreeMap<String, (Stri

/// Constructs the mapping of output address to asset for `make_payment`
pub fn construct_make_payment_map(
to_address: String,
amount: TokenAmount,
to_address: &[String],
amount: &[TokenAmount],
) -> BTreeMap<String, APIAsset> {
let mut tx_info = BTreeMap::new();
tx_info.insert(to_address, APIAsset::new(Asset::Token(amount), None));

for (to_address, amount) in to_address.iter().zip(amount.iter()) {
tx_info.insert(to_address.clone(), APIAsset::new(Asset::Token(amount.clone()), None));
}

tx_info
}
38 changes: 27 additions & 11 deletions src/bin/node_settings_aws.toml
Original file line number Diff line number Diff line change
@@ -1,29 +1,45 @@
mempool_db_mode = {Live = 0}
storage_db_mode = {Live = 0}
miner_db_mode = {Live = 0}
user_db_mode = {Live = 0}
api_port = 3000
mempool_db_mode = { Test = 0 }
storage_db_mode = { Test = 0 }
miner_db_mode = { Live = 0 }
user_db_mode = { Live = 1000 }
user_api_port = 3000
storage_api_port = 3001
mempool_api_port = 3003
miner_api_port = 3004
mempool_raft = 1
storage_raft = 1
storage_block_timeout = 60000
mempool_partition_full_size = 1
mempool_minimum_miner_pool_len = 1
jurisdiction = "US"
backup_block_modulo = 4
peer_limit = 1000
mempool_mining_event_timeout= 30000
storage_block_timeout = 30000
#backup_restore = true
enable_trigger_messages_pipeline_reset = true

[mempool_unicorn_fixed_param]
modulus = "6864797660130609714981900799081393217269435300143305409394463459185543183397656052122559640661454554977296311391480858037121987999716643812574028291115057151"
iterations = 1_000
iterations = 2
security = 1

[user_test_auto_gen_setup]
user_setup_tx_chunk_size = 5
user_setup_tx_in_per_tx = 3
user_setup_tx_max_count = 100000

#first node is leader
[[mempool_nodes]]
address = "44.239.251.56:12300"
address = "34.65.95.17:8116"

[[storage_nodes]]
address = "52.40.82.170:8080"
address = "https://storage.aiblock.dev"

[[miner_nodes]]
address = "52.27.248.13:12340"
address = "127.0.0.1:12390"

[[user_nodes]]
address = "35.155.18.122:12342"
address = "127.0.0.1:12370"

#[[user_nodes]]
#"address"="127.0.0.1:12361"
Loading