-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[INIT] create auth + blockchain algorithm unit test
- Loading branch information
myth
committed
May 16, 2024
1 parent
5d4e587
commit b1ef573
Showing
35 changed files
with
2,200 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,280 @@ | ||
# Prerequisites | ||
Before you start, make sure that you have the following software installed on your computer: | ||
|
||
* Go programming language (version 1.22 or later) | ||
* Git version control system | ||
* Docker version 25.0.2 or later | ||
* Make 3.81 or later | ||
|
||
# Tasks | ||
## Blockchain Consensus Algorithm | ||
Using this command for interact with blockchain algorithm. | ||
|
||
```sh | ||
make start-blockchain-algorithm # for interact with blockchain algorithm | ||
``` | ||
|
||
## Blockchain Interaction | ||
Using this command for start all service that serve for web application. It is also include Blockchain interaction. | ||
|
||
```sh | ||
make start-all # start all services that serve for blockchain interact with algorithm | ||
``` | ||
## Smart Contract Deployment | ||
Using this command for deploy contract (deploy **MyToken** contract). | ||
|
||
```sh | ||
make deploy-contract # deploy contract | ||
``` | ||
## Web Application Development | ||
After you start all services, the frontend UI already serve in http://localhost:9999 by default. | ||
|
||
## Security Considerations: | ||
|
||
- [x] Transfer using signature instead of sending private key through http/https. | ||
- [] Improve web application protocol using SSL (https). | ||
- [] Improve using SSL for grpc protocol for each servers. | ||
- [] Split private key of user into more part and store each part in more place. | ||
|
||
## Optimization and Scalability | ||
|
||
- [x] Split contract service(responsible for contract implementation) into 2 service(contract_reader, contract_writer). | ||
- [x] Implement new watcher service that subscribe to websocket of ethereum chain and publish message to message queue. | ||
- [] Improve send transaction handler with multi-instance can serve. | ||
- [] Improve to multi watcher (currently, only one watcher subscribe to event logs). | ||
|
||
## Documentation | ||
|
||
### Architecture | ||
|
||
 | ||
|
||
#### Description ✍️: | ||
⭐ **Gateway service**: Responsible to deliver all apis to services using reverse proxy. \ | ||
⭐ **User management service**: Responsible to auth/user management. \ | ||
⭐ **Contract writer service**: Responsible to write command for contract or ethereum chain information. \ | ||
⭐ **Contract reader service**: Responsible to read command for contract or ethereum chain information. \ | ||
⭐ **Watcher service**: Responsible to watch event logs from ethereum chain. | ||
|
||
### Structure folder: | ||
``` | ||
. | ||
├── LICENSE | ||
├── Makefile | ||
├── README.md | ||
├── api | ||
│ ├── protos | ||
│ │ ├── common | ||
│ │ │ └── common.proto | ||
│ │ ├── contract | ||
│ │ │ └── contract_reader.proto | ||
│ │ └── user | ||
│ │ ├── auth.proto | ||
│ │ └── user.proto | ||
│ └── sols | ||
│ ├── ERC20.sol | ||
│ ├── IERC20.sol | ||
│ └── MyToken.sol | ||
├── cmd | ||
│ ├── contractReader.go | ||
│ ├── contractWriter.go | ||
│ ├── deployContract.go | ||
│ ├── frontend.go | ||
│ ├── gateway.go | ||
│ ├── root.go | ||
│ ├── srv | ||
│ │ ├── contract_reader | ||
│ │ │ └── srv.go | ||
│ │ ├── contract_writer | ||
│ │ │ └── srv.go | ||
│ │ ├── deploy_contract | ||
│ │ │ └── srv.go | ||
│ │ ├── frontend | ||
│ │ │ └── srv.go | ||
│ │ ├── gateway | ||
│ │ │ └── srv.go | ||
│ │ ├── user | ||
│ │ │ └── srv.go | ||
│ │ └── watcher | ||
│ │ └── srv.go | ||
│ ├── user.go | ||
│ └── watcher.go | ||
├── config | ||
│ ├── address.go | ||
│ ├── common | ||
│ │ └── config.yaml | ||
│ ├── config.go | ||
│ ├── contract_reader | ||
│ │ └── config.yaml | ||
│ ├── contract_writer | ||
│ │ └── config.yaml | ||
│ ├── database.go | ||
│ ├── deploy_contract | ||
│ │ └── config.yaml | ||
│ ├── frontend | ||
│ │ └── config.yaml | ||
│ ├── gateway | ||
│ │ └── config.yaml | ||
│ ├── user | ||
│ │ └── config.yaml | ||
│ └── watcher | ||
│ └── config.yaml | ||
├── developments | ||
│ ├── Dockerfile | ||
│ ├── docker-compose.all.yml | ||
│ ├── docker-compose.gen.yml | ||
│ ├── docker-compose.yml | ||
│ ├── ganache_data | ||
│ ├── gen-proto.sh | ||
│ ├── gen-sol.sh | ||
│ ├── proto.Dockerfile | ||
│ └── sol.Dockerfile | ||
├── docs | ||
│ ├── swagger | ||
│ │ ├── blockchain | ||
│ │ │ └── blockchain.swagger.json | ||
│ │ ├── common | ||
│ │ │ └── common.swagger.json | ||
│ │ ├── contract | ||
│ │ │ └── contract_reader.swagger.json | ||
│ │ └── user | ||
│ │ ├── auth.swagger.json | ||
│ │ └── user.swagger.json | ||
│ └── wiki | ||
│ └── blockchain_architechture.png | ||
├── go.mod | ||
├── go.sum | ||
├── html # presentation for UI. | ||
├── idl | ||
│ ├── contracts | ||
│ │ ├── ERC20.abi | ||
│ │ ├── ERC20.bin | ||
│ │ ├── ERC20.go | ||
│ │ ├── IERC20.abi | ||
│ │ ├── IERC20.bin | ||
│ │ ├── IERC20.go | ||
│ │ ├── MyToken.abi | ||
│ │ ├── MyToken.bin | ||
│ │ └── MyToken.go | ||
│ └── pb | ||
│ ├── common | ||
│ │ ├── common.pb.go | ||
│ │ └── common.pb.validate.go | ||
│ ├── contract | ||
│ │ ├── contract_reader.pb.go | ||
│ │ ├── contract_reader.pb.gw.go | ||
│ │ ├── contract_reader.pb.validate.go | ||
│ │ └── contract_reader_grpc.pb.go | ||
│ └── user | ||
│ ├── auth.pb.go | ||
│ ├── auth.pb.gw.go | ||
│ ├── auth.pb.validate.go | ||
│ ├── auth_grpc.pb.go | ||
│ ├── user.pb.go | ||
│ ├── user.pb.gw.go | ||
│ ├── user.pb.validate.go | ||
│ └── user_grpc.pb.go | ||
├── internal | ||
│ ├── blockchain | ||
│ │ └── watcher | ||
│ │ └── watcher.go | ||
│ ├── contract | ||
│ │ ├── entities | ||
│ │ │ ├── approval.go | ||
│ │ │ └── transfer.go | ||
│ │ ├── repositories | ||
│ │ │ ├── approval.go | ||
│ │ │ ├── blockchain.go | ||
│ │ │ ├── eth | ||
│ │ │ │ ├── blockchain.go | ||
│ │ │ │ └── my_token.go | ||
│ │ │ ├── mongo | ||
│ │ │ │ ├── approval.go | ||
│ │ │ │ └── transfer.go | ||
│ │ │ ├── my_token.go | ||
│ │ │ └── transfer.go | ||
│ │ └── services | ||
│ │ ├── contract_reader.go | ||
│ │ ├── contract_writer.go | ||
│ │ └── deploy.go | ||
│ └── user-mgnt | ||
│ ├── entities | ||
│ │ └── user.go | ||
│ ├── repositories | ||
│ │ ├── mongo | ||
│ │ │ └── user.go | ||
│ │ └── user.go | ||
│ └── services | ||
│ ├── auth.go | ||
│ ├── auth_test.go | ||
│ └── user.go | ||
├── main.go | ||
├── pkg | ||
│ ├── blockchain | ||
│ │ ├── block | ||
│ │ │ └── block.go | ||
│ │ ├── blockchain.go | ||
│ │ ├── miner | ||
│ │ │ └── miner.go | ||
│ │ └── pow | ||
│ │ ├── pow.go | ||
│ │ └── pow_test.go | ||
│ ├── constants | ||
│ │ └── constants.go | ||
│ ├── eth_client | ||
│ │ ├── client.go | ||
│ │ ├── dial_client.go | ||
│ │ └── simulated_client.go | ||
│ ├── grpc_client | ||
│ │ └── client.go | ||
│ ├── grpc_server | ||
│ │ ├── grpc.go | ||
│ │ └── health_check.go | ||
│ ├── http_server | ||
│ │ ├── http.go | ||
│ │ ├── middleware.go | ||
│ │ └── utils.go | ||
│ ├── iface | ||
│ │ ├── processor | ||
│ │ │ ├── processor.go | ||
│ │ │ └── service.go | ||
│ │ └── pubsub | ||
│ │ ├── model.go | ||
│ │ ├── publisher.go | ||
│ │ └── subscriber.go | ||
│ ├── kafka | ||
│ │ ├── handler.go | ||
│ │ ├── publisher.go | ||
│ │ └── subscriber.go | ||
│ ├── metadata | ||
│ │ └── metadata.go | ||
│ ├── mongo_client | ||
│ │ └── client.go | ||
│ └── xerror | ||
│ └── xerror.go | ||
├── tests | ||
│ ├── blockchain | ||
│ │ └── main.go | ||
│ ├── kafka | ||
│ │ ├── publisher | ||
│ │ │ └── main.go | ||
│ │ └── subscriber | ||
│ │ └── main.go | ||
│ ├── layer1 | ||
│ │ └── ganache | ||
│ │ └── main.go | ||
│ └── mongo | ||
│ └── main.go | ||
└── util | ||
├── convert.go | ||
├── crypto.go | ||
├── eth_util | ||
│ ├── util.go | ||
│ └── util_test.go | ||
├── hash_sha256.go | ||
├── jwt.go | ||
└── password.go | ||
89 directories, 180 files | ||
``` | ||
|
||
Available Accounts | ||
================== | ||
(0) 0xBa3Fa2e3AbA0602E62471BdCBbdD2ADD0c43962c (1000 ETH) | ||
(1) 0x00825D455C1CC59De50C172FcEB2663f50f00b51 (1000 ETH) | ||
(2) 0xEF4473b802F813C7e6542257781e465E03D81BCC (1000 ETH) | ||
(3) 0xD0Cf52FFEd4cdb46e35bB1B46eaFfdCF9efc3185 (1000 ETH) | ||
(4) 0x862B76D59bFEE86510Beea68f13B0563f7C40cd2 (1000 ETH) | ||
(5) 0xf780B9c3C757657F9d208d773eC00C6a9499Bf6f (1000 ETH) | ||
(6) 0xEd1fa5FBDE427d6B86150d85787e90741a5d1C35 (1000 ETH) | ||
(7) 0xD2409E5c7BcFc07985b296AA86bEDb650FA4690E (1000 ETH) | ||
(8) 0xf6170516D3199e70c63983A4B3f5E105d578F278 (1000 ETH) | ||
(9) 0xB67480568CF5193e13FB55FB1185444c72545650 (1000 ETH) | ||
|
||
Private Keys | ||
================== | ||
(0) 0x8378c4e4383b0ae04a815eb57208e4512aba0e5a9d0badcded84efef05dd98d7 | ||
(1) 0xac740835e22cc66664fc9f3c0b75876e21b416f027e775197db09c8d3d1dddf9 | ||
(2) 0xb4d3ad5324429e7c38776980447b6aaf694861b066d04d232e447f65900dac60 | ||
(3) 0x35dccaa632da5d6a7d6f14c75d771ba3f2fe5dbbedc33527bce144f48d969bd7 | ||
(4) 0x7cf185c7c698c52d5dbf292919d1a06311aa01bcf8dcdf36a50978d144cf53db | ||
(5) 0xddff8d02d582c62d5ca09a6e179459b6088fa667ce765523983fc7f94184e7c1 | ||
(6) 0x06757123c6a6ba7a4a3cb5a7860c5d72dbcb3e73c9a4eaa10dcdfa84d3c89bd6 | ||
(7) 0x8994c3b1a70a9d66320b7bc02eb27e856c01ed45a986c6e524468243a1327dc1 | ||
(8) 0xcfead2bc58d41ed402229282a274266be07ef567555518934cfd51b7404eba29 | ||
(9) 0x7c3315ee8d88bdf965258b630b15a2041d9cf624340f6061de164a82b66429d7 | ||
|
||
HD Wallet | ||
================== | ||
Mnemonic: orient tourist lottery extend cover black forget dry stomach quit fabric indoor | ||
Base HD Path: m/44'/60'/0'/0/{account_index} | ||
|
||
Default Gas Price | ||
================== | ||
2000000000 | ||
|
||
BlockGas Limit | ||
================== | ||
30000000 | ||
|
||
Call Gas Limit | ||
================== | ||
50000000 | ||
|
||
Chain | ||
================== | ||
Hardfork: shanghai | ||
Id: 1337 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.