diff --git a/docker-compose-test.yml b/docker-compose-test.yml index 63bcd5ac..f7b8e847 100644 --- a/docker-compose-test.yml +++ b/docker-compose-test.yml @@ -75,9 +75,9 @@ services: context: . dockerfile: ./token-server/Dockerfile environment: - PROCESSOR_URL: http://mercurylayer-enclave-sgx-1:18080" - API_KEY: aaaaa - FEE: 10000 + PROCESSOR_URL: https://api.swiss-bitcoin-pay.ch + API_KEY: aaaa + FEE: 0.0001 UNIT: BTC DELAY: 3600 CONNECTION_STRING: postgres://postgres:pgpassword@postgres:5432/postgres diff --git a/token-server/src/endpoints/token.rs b/token-server/src/endpoints/token.rs index 95f5a61f..7544b0b4 100644 --- a/token-server/src/endpoints/token.rs +++ b/token-server/src/endpoints/token.rs @@ -99,22 +99,29 @@ pub struct PODStatus { } -#[get("/token/token_init")] -pub async fn token_init(token_server: &State) -> status::Custom> { +#[get("/token/token_init/")] +pub async fn token_init(token_server: &State, token_id: String) -> status::Custom> { - let token_id = uuid::Uuid::new_v4().to_string(); + set_tnc_accepted(&token_server.pool, &token_id).await; + + let row = sqlx::query( + "SELECT token_id, invoice, onchain_address, processor_id \ + FROM public.tokens \ + WHERE token_id = $1") + .bind(&token_id) + .fetch_one(&token_server.pool) + .await; + + let row = row.unwrap(); - let invoice: Invoice = get_lightning_invoice(token_server, token_id.clone()).await; let pod_info = PODInfo { - token_id: token_id.clone(), + token_id: row.get(0), fee: token_server.config.fee.clone(), - lightning_invoice: invoice.pr.clone(), - btc_payment_address: invoice.onChainAddr.clone(), - processor_id: invoice.id.clone(), + lightning_invoice: row.get(1), + btc_payment_address: row.get(2), + processor_id: row.get(3), }; - insert_new_token(&token_server.pool, &token_id, &invoice.pr.clone(), &invoice.onChainAddr, &invoice.id).await; - let response_body = json!(pod_info); return status::Custom(Status::Ok, Json(response_body)); @@ -147,18 +154,6 @@ pub async fn token_gen(token_server: &State) -> status::Custom")] -pub async fn token_accept(token_server: &State, token_id: String) -> status::Custom> { - - set_tnc_accepted(&token_server.pool, &token_id).await; - - let response_body = json!({ - "accepted": true, - }); - - return status::Custom(Status::Ok, Json(response_body)); -} - #[get("/token/token_verify/")] pub async fn token_verify(token_server: &State, token_id: String) -> status::Custom> {