Skip to content

Commit

Permalink
feat: add endpoint for tnc acceptance
Browse files Browse the repository at this point in the history
  • Loading branch information
DhananjayPurohit committed Aug 30, 2024
1 parent 8e6138b commit 955e083
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
16 changes: 16 additions & 0 deletions docker-compose-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,22 @@ services:
depends_on:
- postgres

token-server:
build:
context: .
dockerfile: ./token-server/Dockerfile
environment:
PROCESSOR_URL: http://mercurylayer-enclave-sgx-1:18080"
API_KEY: aaaaa
FEE: 10000
UNIT: BTC
DELAY: 3600
CONNECTION_STRING: postgres://postgres:pgpassword@postgres:5432/postgres
ports:
- "8001:8001"
depends_on:
- postgres

alice:
image: lightninglabs/lndinit:v0.1.21-beta-lnd-v0.18.0-beta
container_name: mercurylayer-alice-1
Expand Down
29 changes: 29 additions & 0 deletions token-server/src/endpoints/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,18 @@ 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 Expand Up @@ -291,3 +303,20 @@ pub async fn set_token_confirmed(pool: &sqlx::PgPool, token_id: &str) {

transaction.commit().await.unwrap();
}

pub async fn set_tnc_accepted(pool: &sqlx::PgPool, token_id: &str) {

let mut transaction = pool.begin().await.unwrap();

let query = "UPDATE tokens \
SET accepted = true \
WHERE token_id = $1";

let _ = sqlx::query(query)
.bind(token_id)
.execute(&mut *transaction)
.await
.unwrap();

transaction.commit().await.unwrap();
}
1 change: 1 addition & 0 deletions token-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ async fn main() {
endpoints::token::token_init,
endpoints::token::token_verify,
endpoints::token::token_gen,
endpoints::token::token_accept,
])
.register("/", catchers![
not_found,
Expand Down

0 comments on commit 955e083

Please sign in to comment.