Skip to content

Commit

Permalink
[INIT] initialize docs
Browse files Browse the repository at this point in the history
[INIT] create auth + blockchain algorithm unit test
  • Loading branch information
myth committed May 16, 2024
1 parent 5d4e587 commit b1ef573
Show file tree
Hide file tree
Showing 35 changed files with 2,200 additions and 95 deletions.
9 changes: 7 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ gen-contract:
gen-proto:
docker compose -f ${GEN_COMPOSE} up generate_proto
gen-mock:
docker compose -f ${GEN_COMPOSE} up generate_mock
docker compose -f ${GEN_COMPOSE} up generate_mock_internal
docker compose -f ${GEN_COMPOSE} up generate_mock_pkg
compose:
docker compose -f ${COMPOSE} up -d --build
get-accounts:
Expand All @@ -28,4 +29,8 @@ test-publisher:
test-subscriber:
go run tests/kafka/subscriber/main.go
test-mongo:
go run tests/mongo/main.go
go run tests/mongo/main.go


start-blockchain-algorithm:
go run tests/blockchain/main.go
326 changes: 279 additions & 47 deletions README.md
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

![image](./docs//wiki/blockchain_architechture.png)

#### 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
10 changes: 8 additions & 2 deletions developments/docker-compose.gen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,15 @@ services:
- "../idl/pb:/proto_out/openmyth/blockchain/idl/pb"
entrypoint: sh /app/gen-proto.sh

generate_mock:
image: vektra/mockery
generate_mock_internal:
image: vektra/mockery:latest
working_dir: /code
volumes:
- "../:/code:cached"
command: [ "--all", "--dir", "internal", "--case", "underscore" ]
generate_mock_pkg:
image: vektra/mockery:latest
working_dir: /code
volumes:
- "../:/code:cached"
command: [ "--all", "--dir", "pkg", "--case", "underscore" ]
Binary file added docs/wiki/blockchain_architechture.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ require (
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/status-im/keycard-go v0.2.0 // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/supranational/blst v0.3.11 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,8 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
Expand Down
Loading

0 comments on commit b1ef573

Please sign in to comment.