Skip to content

Commit

Permalink
Merge pull request #102 from cryptape/recover-false
Browse files Browse the repository at this point in the history
Disable recover mode and only support v0.22 and above
  • Loading branch information
classicalliu committed May 24, 2019
2 parents b43760e + 6cec7ca commit 558f418
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 22 deletions.
5 changes: 3 additions & 2 deletions Gemfile
Expand Up @@ -45,7 +45,7 @@ gem 'ransack', '~> 2.0', '>= 2.0.1'
# paginate
gem 'kaminari', '~> 1.1', '>= 1.1.1'

gem 'google-protobuf', '~> 3.6'
gem 'google-protobuf', '~> 3.7'

gem 'ciri-crypto', '0.1.1'

Expand All @@ -54,7 +54,8 @@ gem 'ethereum.rb', '~> 2.2'
gem 'health_check', '~> 3.0'

# CITA sdk
gem 'cita-sdk-ruby', '~> 0.20.0', require: 'cita'
gem 'cita-sdk-ruby', '~> 0.23.0', require: 'cita'
gem 'web3-eth', '0.2.18'

# Redis
gem 'hiredis', '~> 0.6.1'
Expand Down
11 changes: 6 additions & 5 deletions Gemfile.lock
Expand Up @@ -65,11 +65,11 @@ GEM
ciri-utils (~> 0.2.0)
ciri-utils (0.2.2)
digest-sha3 (~> 1.1.0)
cita-sdk-ruby (0.20.0)
cita-sdk-ruby (0.23.0)
activesupport (~> 5.2.1)
ciri-crypto (= 0.1.1)
faraday (~> 0.15.3)
google-protobuf (~> 3.6)
google-protobuf (~> 3.7)
web3-eth (~> 0.2.16)
codecov (0.1.13)
json
Expand Down Expand Up @@ -106,7 +106,7 @@ GEM
ffi (1.9.25)
globalid (0.4.2)
activesupport (>= 4.2.0)
google-protobuf (3.6.1)
google-protobuf (3.7.1-universal-darwin)
hashdiff (0.3.7)
health_check (3.0.0)
railties (>= 5.0)
Expand Down Expand Up @@ -299,7 +299,7 @@ DEPENDENCIES
bootsnap (>= 1.1.0)
byebug
ciri-crypto (= 0.1.1)
cita-sdk-ruby (~> 0.20.0)
cita-sdk-ruby (~> 0.23.0)
codecov
composite_primary_keys (~> 11.1)
daemons (~> 1.2, >= 1.2.6)
Expand All @@ -308,7 +308,7 @@ DEPENDENCIES
ethereum.rb (~> 2.2)
factory_bot_rails
faraday (~> 0.15.2)
google-protobuf (~> 3.6)
google-protobuf (~> 3.7)
health_check (~> 3.0)
hiredis (~> 0.6.1)
kaminari (~> 1.1, >= 1.1.1)
Expand Down Expand Up @@ -336,6 +336,7 @@ DEPENDENCIES
spring
spring-watcher-listen (~> 2.0.0)
tzinfo-data
web3-eth (= 0.2.18)
webmock (~> 3.4, >= 3.4.2)
yard (~> 0.9.14)
yard-activesupport-concern
Expand Down
2 changes: 1 addition & 1 deletion README-CN.md
Expand Up @@ -8,7 +8,7 @@

[CITA](http://docs.citahub.com) 缓存服务器

适配 CITA v0.20
适配 CITA v0.22 及以上

⚠️ NOTE: 如果从 CITA 0.17 更新到 0.18,更新完成之后执行 `rake daemons:sync:stop`,再执行 `rake zero18:update` 来更新数据,然后执行 `rake daemons:sync:start`,完成后重启 server 即可 😄

Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -8,7 +8,7 @@ English | [简体中文](./README-CN.md)

A blockchain explorer cache server for [CITA](http://docs.citahub.com).

Now upgrade to work with CITA v0.20
Now only support CITA v0.22 and above.

⚠️ NOTE: If you upgrade your chain to 0.18 from 0.17, after upgrade, you should stop sync task(`rake daemons:sync:stop`) and run `rake zero18:update` to update your old data, and start your sync task (`rake daemons:sync:start`), then restart your server 😄

Expand Down
3 changes: 2 additions & 1 deletion app/models/cita_sync/persist.rb
Expand Up @@ -69,6 +69,7 @@ def save_block(hex_num_str)
def save_transaction(tx_data, index, block_number, block_hash, timestamp)
hash = tx_data["hash"]
content = tx_data["content"]
from = tx_data["from"]
receipt_data = CitaSync::Api.get_transaction_receipt(hash)

receipt_result = receipt_data["result"]
Expand All @@ -86,7 +87,7 @@ def save_transaction(tx_data, index, block_number, block_hash, timestamp)
block_number: block_number,
block_hash: block_hash,
index: index,
from: message.from,
from: from,
to: message.to,
data: message.data,
value: HexUtils.to_decimal(message.value),
Expand Down
5 changes: 2 additions & 3 deletions app/models/message.rb
@@ -1,17 +1,16 @@
# frozen_string_literal: true

class Message
attr_reader :unverified_transaction, :data, :signature, :value, :to, :from, :version, :chain_id
attr_reader :unverified_transaction, :data, :signature, :value, :to, :version, :chain_id

# initialize the object and values...
#
# @param content [String] hex number string of transaction content
# @return [void]
def initialize(content)
@data = CITA::TransactionSigner.decode(content)
@data = CITA::TransactionSigner.decode(content, recover: false)
@unverified_transaction = @data[:unverified_transaction]
@transaction = @unverified_transaction[:transaction]
@from = @data.dig(:sender, :address)
@to = @transaction[:to]
@data = @transaction[:data]
@value = @transaction[:value]
Expand Down
6 changes: 0 additions & 6 deletions spec/models/message_spec.rb
Expand Up @@ -2,8 +2,6 @@

RSpec.describe Message do
let(:content) { "0x0a770a28636235313466303134313761626366626431663632393961306434313961326430656165613362361220323066613965333731663531343062613862656533333632313735396338343718e80720db8512322000000000000000000000000000000000000000000000000000000000000010003801124113ec0f1aba3247937c069d250faa708f53162b2a8059597f3df4d1a74ff1c2214eb6251e4bb336a2cc3b6c432fe1e0c79ba9d464fdd8ab8eb525cb2ac93c8a7500" }
let(:from) { "0xee01b9ba97671e8a1891e85b206b499f106822a1" }
let(:from_pubkey) { "0x502c3fcf093f3f14d34d1eea42d8740d5caa793ede97fea257306530cb0ecd032d5abcdc96dc198c1eebe4e55bbba059e338671b603160a30ca34fe361917f71" }
let(:to) { "0xcb514f01417abcfbd1f6299a0d419a2d0eaea3b6" }
let(:quota) { 1000 }
let(:value) { "0x0000000000000000000000000000000000000000000000000000000000001000" }
Expand All @@ -19,10 +17,6 @@
expect(message.value).to eq value
end

it "from should be eq" do
expect(message.from).to eq from
end

it "to should be eq" do
expect(message.to).to eq to
end
Expand Down
12 changes: 9 additions & 3 deletions spec/supports/block_mock_support.rb
Expand Up @@ -101,7 +101,8 @@ def stub_request_error_wrapper(method, params, error, status: 200, json_rpc: "2.
"transactions" => [
{
"hash": "0x4b364ce2e607c57200995ee39ecdd98f5749107752125383c2df5058e53be2f7",
"content": "0x0a770a28636235313466303134313761626366626431663632393961306434313961326430656165613362361220323066613965333731663531343062613862656533333632313735396338343718e80720db8512322000000000000000000000000000000000000000000000000000000000000010003801124113ec0f1aba3247937c069d250faa708f53162b2a8059597f3df4d1a74ff1c2214eb6251e4bb336a2cc3b6c432fe1e0c79ba9d464fdd8ab8eb525cb2ac93c8a7500"
"content": "0x0a770a28636235313466303134313761626366626431663632393961306434313961326430656165613362361220323066613965333731663531343062613862656533333632313735396338343718e80720db8512322000000000000000000000000000000000000000000000000000000000000010003801124113ec0f1aba3247937c069d250faa708f53162b2a8059597f3df4d1a74ff1c2214eb6251e4bb336a2cc3b6c432fe1e0c79ba9d464fdd8ab8eb525cb2ac93c8a7500",
"from": "0xee01b9ba97671e8a1891e85b206b499f106822a1"
}
]
}
Expand Down Expand Up @@ -148,7 +149,8 @@ def stub_request_error_wrapper(method, params, error, status: 200, json_rpc: "2.
"transactions" => [
{
"hash" => "0x5ddd3cac30321f03ca660054449601b096090445b3fa77f1504c4464eb358bbb",
"content" => "0x0a780a28363564643732376436353332316530343263346131306666643264356339326234373334353431351220376161373438343630653836343037623931363632363765626438346633636418b0ea0120a7eb03322000000000000000000000000000000000000000000000000000000000000003e838011241f8691d76e72c26a589d617aaa5da51445174fedfbeb4c9517abd7629d0f1fdbe49b784cc762f3656db9ae89f5ac44618bc96d490bacf9f8239f67761fb8b9f9700"
"content" => "0x0a780a28363564643732376436353332316530343263346131306666643264356339326234373334353431351220376161373438343630653836343037623931363632363765626438346633636418b0ea0120a7eb03322000000000000000000000000000000000000000000000000000000000000003e838011241f8691d76e72c26a589d617aaa5da51445174fedfbeb4c9517abd7629d0f1fdbe49b784cc762f3656db9ae89f5ac44618bc96d490bacf9f8239f67761fb8b9f9700",
"from": "0x4b5ae4567ad5d9fb92bc9afd6a657e6fa13a2523"
}
]
}
Expand All @@ -166,7 +168,8 @@ def stub_request_error_wrapper(method, params, error, status: 200, json_rpc: "2.
"transactions": [
{
"content": "0x0a86011220336635633630373433643131346437373965313032373432356534353163343618b0ea0120e7f203322000000000000000000000000000000000000000000000000000000000000003e840014a14d22b603d6abd259699c8b048f55c757f6387f286522000000000000000000000000000000000000000000000000000000000000000011241f3e9e358f507db55f3e7fc996c879d87d3cb70254c73885b7292d0b5217924f83656f0741081048b0027c71738e6c9b98b20717711a91bdba1e44176aa71cf7501",
"hash": "0x0b607a613e9c95113145ae5221ff30963823bb6914d9d8f6eb3a6b37c8fdfbc4"
"hash": "0x0b607a613e9c95113145ae5221ff30963823bb6914d9d8f6eb3a6b37c8fdfbc4",
"from": "0x4b5ae4567ad5d9fb92bc9afd6a657e6fa13a2523"
}
]
},
Expand Down Expand Up @@ -207,6 +210,7 @@ def stub_request_error_wrapper(method, params, error, status: 200, json_rpc: "2.
{
"hash": transaction_hash,
"content": transaction_content,
"from": "0xee01b9ba97671e8a1891e85b206b499f106822a1",
"blockNumber": "0x1",
"blockHash": block_one_hash,
"index": "0x0"
Expand All @@ -222,6 +226,7 @@ def stub_request_error_wrapper(method, params, error, status: 200, json_rpc: "2.
{
hash: transaction_hash_two,
content: "0x0a780a28363564643732376436353332316530343263346131306666643264356339326234373334353431351220376161373438343630653836343037623931363632363765626438346633636418b0ea0120a7eb03322000000000000000000000000000000000000000000000000000000000000003e838011241f8691d76e72c26a589d617aaa5da51445174fedfbeb4c9517abd7629d0f1fdbe49b784cc762f3656db9ae89f5ac44618bc96d490bacf9f8239f67761fb8b9f9700",
"from": "0x4b5ae4567ad5d9fb92bc9afd6a657e6fa13a2523",
blockNumber: "0x2",
blockHash: block_two_hash,
index: "0x0"
Expand All @@ -238,6 +243,7 @@ def stub_request_error_wrapper(method, params, error, status: 200, json_rpc: "2.
"blockHash": "0x7137d7989519127f76667948edb14cec9c7427c4ce6667a63aeeebcb4dcff0cf",
"blockNumber": "0x3",
"content": "0x0a86011220336635633630373433643131346437373965313032373432356534353163343618b0ea0120e7f203322000000000000000000000000000000000000000000000000000000000000003e840014a14d22b603d6abd259699c8b048f55c757f6387f286522000000000000000000000000000000000000000000000000000000000000000011241f3e9e358f507db55f3e7fc996c879d87d3cb70254c73885b7292d0b5217924f83656f0741081048b0027c71738e6c9b98b20717711a91bdba1e44176aa71cf7501",
"from": "0x4b5ae4567ad5d9fb92bc9afd6a657e6fa13a2523",
"hash": transaction_hash_version1,
"index": "0x0"
}
Expand Down

0 comments on commit 558f418

Please sign in to comment.