Skip to content

Commit

Permalink
fix: token init for tnc acceptance
Browse files Browse the repository at this point in the history
  • Loading branch information
DhananjayPurohit committed Sep 4, 2024
1 parent 955e083 commit 7b836e7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 25 deletions.
6 changes: 3 additions & 3 deletions docker-compose-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 17 additions & 22 deletions token-server/src/endpoints/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,22 +99,29 @@ pub struct PODStatus {
}


#[get("/token/token_init")]
pub async fn token_init(token_server: &State<TokenServer>) -> status::Custom<Json<Value>> {
#[get("/token/token_init/<token_id>")]
pub async fn token_init(token_server: &State<TokenServer>, token_id: String) -> status::Custom<Json<Value>> {

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));
Expand Down Expand Up @@ -147,18 +154,6 @@ pub async fn token_gen(token_server: &State<TokenServer>) -> status::Custom<Json
return status::Custom(Status::Ok, Json(response_body));
}

#[get("/token/token_accept/<token_id>")]
pub async fn token_accept(token_server: &State<TokenServer>, token_id: String) -> status::Custom<Json<Value>> {

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/<token_id>")]
pub async fn token_verify(token_server: &State<TokenServer>, token_id: String) -> status::Custom<Json<Value>> {

Expand Down

0 comments on commit 7b836e7

Please sign in to comment.