Skip to content

Commit fa9ff32

Browse files
committed
feat: added a route to display info of a wallet (balance)
1 parent 1312b70 commit fa9ff32

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

1-simple-transactional-blockchain/README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Simple Blockchain implementation
2-
2+
Above is a function to automatically generate rsa key pair to be used as transaction wallets
3+
`wallet_id` should be a `base64_encoded_public_key` instead of a plain string like `Lucas`
34
```bash
45
# Generate key pairs for testing in transactions and mining
56
genkeypair(){
@@ -10,13 +11,13 @@ genkeypair(){
1011
mkdir -p $KEY_DIR && openssl genpkey -algorithm RSA -out $PVT_KEY -pkeyopt rsa_keygen_bits:1024 && openssl rsa -pubout -in $PVT_KEY -out $PUB_KEY && echo "$1: $(base64 -w0 $PUB_KEY)" >> $WALLETS
1112
}
1213
```
13-
1414
## Routes
15+
- GET /info?wallet=**wallet_id**
1516
- GET /chain
1617
- GET /memorypool
17-
- GET /mine?wallet=base64_encoded_public_key
18+
- GET /mine?wallet=**wallet_id**
1819
- POST /data/new
19-
> body: `{ "from": "Lucas", "to": "Filipe", "amount": 10 }`
20+
- body: `{ "from": "Lucas", "to": "Filipe", "amount": 10 }`
2021

2122
## Lacks of
2223
- Persistence

1-simple-transactional-blockchain/blockchain.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,5 +216,15 @@ func main() {
216216
return c.Status(fiber.StatusOK).JSON(response)
217217
})
218218

219+
// Get information of a wallet
220+
app.Get("/info", func(c *fiber.Ctx) error {
221+
blockchain := c.Locals("blockchain").(*Blockchain)
222+
wallet := c.Query("wallet")
223+
response := fiber.Map{
224+
"balance": blockchain.getBalance(wallet),
225+
}
226+
return c.Status(fiber.StatusOK).JSON(response)
227+
})
228+
219229
app.Listen(":7000")
220230
}

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,19 @@ classDiagram
9090
Block3 <|-- Block4 : PreviousHash
9191
```
9292
#### Routes
93+
- GET /info?wallet=**wallet_id**
9394
- GET /chain
9495
- GET /memorypool
95-
- GET /mine?wallet=**base64_encoded_public_key**
96+
- GET /mine?wallet=**wallet_id**
9697
- POST /data/new
9798
- body: `{ "from": "Lucas", "to": "Filipe", "amount": 10 }`
9899

100+
## Lacks of
101+
- Persistence
102+
- Descentralization
103+
- P2P Network
104+
- Node discovery
105+
99106
#### Lacks of
100107
- Persistence
101108
- Descentralization

0 commit comments

Comments
 (0)