Skip to content

Commit

Permalink
Merge pull request #61 from cryptape/develop
Browse files Browse the repository at this point in the history
Using appchain.rb and sidekiq to process transactions
  • Loading branch information
ashchan committed Nov 28, 2018
2 parents 834b401 + edf17bf commit 9d023d4
Show file tree
Hide file tree
Showing 34 changed files with 262 additions and 453 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
.github
tmp
docker/data
docker/redis
12 changes: 12 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,24 @@
# "db" for docker inside database, "host.docker.internal" for host database(only work for mac and windows for docker 18.03+)
DB_HOST="db"
DB_PORT=5432
DB_POOL=64
DB_USERNAME="postgres"
DB_PASSWORD="postgres"
DB_NAME_DEV="re-birth_development"
DB_NAME_TEST="re-birth_test"
DB_NAME_PRO="re-birth_production"

# Redis config for docker inside redis, rewrite it in `.env.local` if you don't use docker.
# Set redis default namespace to nil.
REDIS_URL="redis://redis:6379/8"
# set password if have
# REDIS_PASSWORD=""
REDIS_NAMESPACE=""

# Sidekiq Username and Password, default is `sidekiq`
SIDEKIQ_USERNAME="sidekiq"
SIDEKIQ_PASSWORD="sidekiq"

# secret
# run `rails secret` to generate one and rewrite in .env.local
SECRET_KEY_BASE="dee66a8ef3281bc6bd74a5637ede4d846c455df93ca0d6c098da1d52b65dda8f87933c421a077643b903d8d3c5328178e39f729dda0a06e96d268c5c81530df5"
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ doc

# docker database
docker/data
docker/redis

# custom configs
config/customs/*.yml
Expand Down
13 changes: 13 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,23 @@ gem 'ethereum.rb', '~> 2.2'

gem 'health_check', '~> 3.0'

# appchain sdk
gem "appchain.rb", github: "cryptape/appchain.rb"

# Redis
gem 'hiredis', '~> 0.6.1'
gem 'redis', '~> 4.0', '>= 4.0.3'
gem 'redis-namespace', '~> 1.6'
gem 'redis-objects', '~> 1.4', '>= 1.4.3'

# Sidekiq
gem 'sidekiq', '~> 5.2', '>= 5.2.3'

# Deployment
gem 'mina', require: false
gem 'mina-puma', require: false
gem 'mina-multistage', require: false
gem 'mina-sidekiq', '~> 1.0', '>= 1.0.3', require: false

group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
Expand Down
37 changes: 37 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
GIT
remote: https://github.com/cryptape/appchain.rb.git
revision: 3a7e2288b57a5d2ef2bf850ab548e79fc3a8a6b7
specs:
appchain.rb (0.2.0)
activesupport (~> 5.2.1)
ciri-crypto (= 0.1.1)
faraday (~> 0.15.3)
google-protobuf (~> 3.6)
web3-eth (~> 0.2.16)

GEM
remote: https://rubygems.org/
specs:
Expand Down Expand Up @@ -71,6 +82,7 @@ GEM
url
coderay (1.1.2)
concurrent-ruby (1.1.1)
connection_pool (2.2.2)
crack (0.4.3)
safe_yaml (~> 1.0.0)
crass (1.0.4)
Expand Down Expand Up @@ -101,6 +113,7 @@ GEM
hashdiff (0.3.7)
health_check (3.0.0)
railties (>= 5.0)
hiredis (0.6.1)
i18n (1.1.1)
concurrent-ruby (~> 1.0)
jaro_winkler (1.5.1)
Expand Down Expand Up @@ -139,6 +152,8 @@ GEM
mina-puma (1.1.0)
mina (~> 1.2.0)
puma (>= 2.13)
mina-sidekiq (1.0.3)
mina (>= 1.0.2)
mini_mime (1.0.1)
mini_portile2 (2.3.0)
minitest (5.11.3)
Expand All @@ -163,6 +178,8 @@ GEM
puma (3.12.0)
rack (2.0.6)
rack-cors (1.0.2)
rack-protection (2.0.4)
rack
rack-test (1.1.0)
rack (>= 1.0, < 3)
rails (5.2.1)
Expand Down Expand Up @@ -199,6 +216,12 @@ GEM
rb-fsevent (0.10.3)
rb-inotify (0.9.10)
ffi (>= 0.5.0, < 2)
redis (4.0.3)
redis-namespace (1.6.0)
redis (>= 3.0.4)
redis-objects (1.4.3)
redis (~> 4.0)
rlp (0.7.3)
rspec-core (3.8.0)
rspec-support (~> 3.8.0)
rspec-expectations (3.8.2)
Expand Down Expand Up @@ -227,6 +250,10 @@ GEM
ruby-progressbar (1.10.0)
ruby_dep (1.5.0)
safe_yaml (1.0.4)
sidekiq (5.2.3)
connection_pool (~> 2.2, >= 2.2.2)
rack-protection (>= 1.5.0)
redis (>= 3.3.5, < 5)
simplecov (0.16.1)
docile (~> 1.1)
json (>= 1.8, < 3)
Expand All @@ -250,6 +277,9 @@ GEM
thread_safe (~> 0.1)
unicode-display_width (1.4.0)
url (0.3.2)
web3-eth (0.2.16)
digest-sha3 (~> 1.1.0)
rlp (~> 0.7.3)
webmock (3.4.2)
addressable (>= 2.3.6)
crack (>= 0.3.2)
Expand All @@ -266,6 +296,7 @@ PLATFORMS

DEPENDENCIES
active_model_serializers (~> 0.10.7)
appchain.rb!
awesome_print
bootsnap (>= 1.1.0)
byebug
Expand All @@ -279,11 +310,13 @@ DEPENDENCIES
faraday (~> 0.15.2)
google-protobuf (~> 3.6)
health_check (~> 3.0)
hiredis (~> 0.6.1)
kaminari (~> 1.1, >= 1.1.1)
listen (>= 3.0.5, < 3.2)
mina
mina-multistage
mina-puma
mina-sidekiq (~> 1.0, >= 1.0.3)
oj (~> 3.6, >= 3.6.2)
pg (>= 0.18, < 2.0)
pry (= 0.11.3)
Expand All @@ -292,8 +325,12 @@ DEPENDENCIES
rack-cors
rails (~> 5.2.0)
ransack (~> 2.0, >= 2.0.1)
redis (~> 4.0, >= 4.0.3)
redis-namespace (~> 1.6)
redis-objects (~> 1.4, >= 1.4.3)
rspec-rails (~> 3.7)
rubocop (~> 0.59)
sidekiq (~> 5.2, >= 5.2.3)
simplecov
spring
spring-watcher-listen (~> 2.0.0)
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ Now upgrade to work with CITA v0.20

If you just want to run this, just use [docker 🐳](https://docs.docker.com/install)

Remember to run `rails secret` to generate secret key and write in .env.local (read .env for more info)
Remember to run `rails secret` to generate secret key and write in `.env.local` (read `.env` for more info)
Remember to change your sidekiq username and password in `.env.local`

⚠️ IMPORTANT: your database data will save at docker/data

⚠️ IMPORTANT: your redis data will save at docker/redis

App will run at http://localhost:8888

```shell
Expand All @@ -37,7 +40,7 @@ you can get more info from Makefile
## Packages

- [postgresql](https://www.postgresql.org/) 9.4 and above
- install secp256k1 (see [secp256k1](https://github.com/bitcoin-core/secp256k1.git) for more info)
- install [secp256k1](https://github.com/bitcoin-core/secp256k1.git)

```shell
$ cd re-birth/tmp && git clone https://github.com/bitcoin-core/secp256k1.git && cd secp256k1 && ./autogen.sh && ./configure --enable-module-recovery --enable-experimental --enable-module-ecdh && make && sudo make install && cd ../..
Expand Down
2 changes: 0 additions & 2 deletions app/controllers/concerns/split_requests_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ module SplitRequestsConcern

# real time sync methods
SYNC_METHODS = %w(
getBlockByNumber
getBlockByHash
getTransaction
).freeze

Expand Down
2 changes: 1 addition & 1 deletion app/models/block.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Block < ApplicationRecord
has_many :erc20_transfers

# store_accessor :header, :number
store_accessor :body, :transactions
# store_accessor :body, :transactions

validates :cita_hash, presence: true, uniqueness: true
validates :block_number, presence: true, uniqueness: true
Expand Down
36 changes: 7 additions & 29 deletions app/models/cita_sync/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,11 @@

module CitaSync
class Api
class << self
# New methods without prefix since CITA v0.16
# now upgrade to CITA v0.18
METHOD_NAMES = %w(
peerCount
blockNumber
sendRawTransaction
getBlockByHash
getBlockByNumber
getTransaction
getTransactionReceipt
getLogs
call
getTransactionCount
getCode
getAbi
getBalance
newFilter
newBlockFilter
uninstallFilter
getFilterChanges
getFilterLogs
getTransactionProof
getMetaData
getBlockHeader
getStateProof
).freeze
# New methods without prefix since CITA v0.16
# now upgrade to CITA v0.20
METHOD_NAMES = AppChain::RPC::METHOD_NAMES

class << self
METHOD_NAMES.each do |name|
define_method name.underscore do |*params|
call_rpc(name, params: params)
Expand All @@ -44,8 +21,9 @@ class << self
# @param id [Integer] id number
# @return [Hash, String, Array] json decode to hash
def call_rpc(method, params: [], jsonrpc: "2.0", id: 83)
resp = CitaSync::Http.post(method, params: params, jsonrpc: jsonrpc, id: id)
Oj.load(resp.body)
cita_url = ENV["CITA_URL"]
client = AppChain::Client.new(cita_url)
client.rpc.call_rpc(method, jsonrpc: jsonrpc, params: params, id: id)
end
end
end
Expand Down
51 changes: 0 additions & 51 deletions app/models/cita_sync/http.rb

This file was deleted.

Loading

0 comments on commit 9d023d4

Please sign in to comment.