From e606a2b1a1c181107423e5e5668fe78e766480ca Mon Sep 17 00:00:00 2001 From: Yigit Sever Date: Wed, 14 Apr 2021 23:08:18 +0300 Subject: Tracking REFERENCE.md --- REFERENCE.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 REFERENCE.md diff --git a/REFERENCE.md b/REFERENCE.md new file mode 100644 index 0000000..ef9e70c --- /dev/null +++ b/REFERENCE.md @@ -0,0 +1,3 @@ +# Reference + +Don't know where to start? Gradecoin uses RESTful API, even simple `curl` commands will work! [This website will help as well](https://curl.trillworks.com/). -- cgit v1.2.3-70-g09d2 From 87e5910ba6dc80b48850d76639960c8e8dc8edd3 Mon Sep 17 00:00:00 2001 From: Yigit Sever Date: Wed, 14 Apr 2021 23:09:02 +0300 Subject: Clarify reference --- REFERENCE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/REFERENCE.md b/REFERENCE.md index ef9e70c..018b0a5 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -1,3 +1,3 @@ # Reference -Don't know where to start? Gradecoin uses RESTful API, even simple `curl` commands will work! [This website will help as well](https://curl.trillworks.com/). +Don't know where to start? Gradecoin uses RESTful API, simple `curl` commands or even your browser will work! [This website will help as well](https://curl.trillworks.com/). -- cgit v1.2.3-70-g09d2 From bc75cf3bf2fcac410c17eaf61e7e54fac5664f84 Mon Sep 17 00:00:00 2001 From: Yigit Sever Date: Wed, 14 Apr 2021 23:16:33 +0300 Subject: Add JWT resources --- REFERENCE.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/REFERENCE.md b/REFERENCE.md index 018b0a5..d57378d 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -1,3 +1,5 @@ # Reference -Don't know where to start? Gradecoin uses RESTful API, simple `curl` commands or even your browser will work! [This website will help as well](https://curl.trillworks.com/). +- Don't know where to start? Gradecoin uses RESTful API, simple `curl` commands or even your browser will work! [This website will help as well](https://curl.trillworks.com/). +- [JWT Debugger](https://jwt.io) and the corresponding [RFC](https://tools.ietf.org/html/rfc7519) + -- cgit v1.2.3-70-g09d2 From 797b0c5a686df7483540f4cb6baaeed6d5147ee8 Mon Sep 17 00:00:00 2001 From: Yigit Sever Date: Wed, 14 Apr 2021 23:27:41 +0300 Subject: Implement the bank account --- src/handlers.rs | 20 ++++++++++++++++---- src/schema.rs | 18 ++++++++++++++++-- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/handlers.rs b/src/handlers.rs index 90cc8c4..a8c9947 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -420,7 +420,6 @@ pub async fn authorized_propose_block( /// * `token` - An Authorization header value such as `Bearer aaa.bbb.ccc` /// * `db` - Global [`Db`] instance /// -/// TODO This method should check if the user has enough balance for the transaction pub async fn authorized_propose_transaction( new_transaction: Transaction, token: String, @@ -459,17 +458,30 @@ pub async fn authorized_propose_transaction( return Ok(warp::reply::with_status( warp::reply::json(&GradeCoinResponse { res: ResponseType::Error, - message: "User does not have enough balance in their account".to_owned(), + message: + "User does not have enough balance in their account for this transaction" + .to_owned(), }), StatusCode::BAD_REQUEST, )); } + } else if new_transaction.by == new_transaction.target + && new_transaction.source + != "31415926535897932384626433832795028841971693993751058209749445923" + { + // Propose to transact with the bank + return Ok(warp::reply::with_status( + warp::reply::json(&GradeCoinResponse { + res: ResponseType::Error, + message: "Transactions cannot extort Gradecoin from unsuspecting users".to_owned(), + }), + StatusCode::BAD_REQUEST, + )); } else { - // TODO: add bank mechanism <14-04-21, keles> // return Ok(warp::reply::with_status( warp::reply::json(&GradeCoinResponse { res: ResponseType::Error, - message: "Invalid by field for the proposed transaction".to_owned(), + message: "Transactions cannot be proposed between two unrelated parties".to_owned(), }), StatusCode::BAD_REQUEST, )); diff --git a/src/schema.rs b/src/schema.rs index 2a9e1db..1002cb8 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -93,15 +93,28 @@ pub struct Claims { pub struct Db { pub blockchain: Arc>, pub pending_transactions: Arc>>, - pub users: Arc>>, + pub users: Arc>>, } impl Db { fn new() -> Self { + let mut users: HashMap = HashMap::new(); + + let bank_acc = MetuId::new("bank".to_owned(), "P7oxDm30g1jeIId".to_owned()).unwrap(); + + users.insert( + "31415926535897932384626433832795028841971693993751058209749445923".to_owned(), + User { + user_id: bank_acc, + public_key: "null".to_owned(), + balance: 27 * 80, + }, + ); + Db { blockchain: Arc::new(RwLock::new(Block::new())), pending_transactions: Arc::new(RwLock::new(HashMap::new())), - users: Arc::new(RwLock::new(HashMap::new())), + users: Arc::new(RwLock::new(users)), } } } @@ -216,6 +229,7 @@ lazy_static! { ("e223786", "UxI6czykJfp9T9N"), ("e231060", "VJgziofQQPCoisH"), ("e223795", "pmcTCKox99NFsqp"), + ("bank", "P7oxDm30g1jeIId"), ] .iter() .cloned() -- cgit v1.2.3-70-g09d2 From 8be38f7f9d52bf95d20fbe440cb9270b035b2cd1 Mon Sep 17 00:00:00 2001 From: Yigit Sever Date: Wed, 14 Apr 2021 23:28:26 +0300 Subject: Update TODOs --- TODO.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/TODO.md b/TODO.md index 1e909cd..b429097 100644 --- a/TODO.md +++ b/TODO.md @@ -1,8 +1,5 @@ # TODO -## Simulation -- [ ] Bank mechanism should be added. - ## Tests - [ ] User Authentication/Authentication Tests - [ ] Route Tests @@ -36,3 +33,4 @@ - [.] POST requests to /block should be authenticated as well (2021-04-13 04:50, they now are but until we make error messages **Verbose** there's not much point in testing because I honestly cannot trace the code) - [X] Blocks should "play out" the transactions and execute transactions (2021-04-14 21:29) - [X] "Coinbase" ("by" of the first transaction of the block) should get rewarded for their efforts (2021-04-14 21:48) +- [X] Implemented Bank Account (2021-04-14 23:28) -- cgit v1.2.3-70-g09d2