-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add `get_blockchain_info` and `get_peers_state` RPCs
- Loading branch information
1 parent
d71e3f5
commit 2ec5580
Showing
10 changed files
with
156 additions
and
1 deletion.
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
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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# frozen_string_literal: true | ||
|
||
module CKB | ||
module Types | ||
class ChainInfo | ||
attr_reader :is_initial_block_download, :epoch, :difficulty, :median_time, :chain, :warnings | ||
|
||
# @param is_initialize_block_download [Boolean] | ||
# @param epoch [String] number | ||
# @param difficulty [String] 0x... | ||
# @param median_time [String] timestamp | ||
# @param chain [String] | ||
# @param warnings [String] | ||
def initialize( | ||
is_initial_block_download:, | ||
epoch:, | ||
difficulty:, | ||
median_time:, | ||
chain:, | ||
warnings: | ||
) | ||
@is_initial_block_download = is_initial_block_download | ||
@epoch = epoch | ||
@difficulty = difficulty | ||
@median_time = median_time | ||
@chain = chain | ||
@warnings = warnings | ||
end | ||
|
||
def to_h | ||
{ | ||
is_initial_block_download: @is_initial_block_download, | ||
epoch: @epoch, | ||
difficulty: @difficulty, | ||
median_time: @median_time, | ||
chain: @chain, | ||
warnings: @warnings | ||
} | ||
end | ||
|
||
def self.from_h(hash) | ||
return if hash.nil? | ||
|
||
new( | ||
is_initial_block_download: hash[:is_initial_block_download], | ||
epoch: hash[:epoch], | ||
difficulty: hash[:difficulty], | ||
median_time: hash[:median_time], | ||
chain: hash[:chain], | ||
warnings: hash[:warnings] | ||
) | ||
end | ||
end | ||
end | ||
end |
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# frozen_string_literal: true | ||
|
||
module CKB | ||
module Types | ||
class PeerState | ||
attr_reader :last_updated, :blocks_in_flight, :peer | ||
|
||
# @param last_updated [String] | ||
# @param block_in_flight [String] number | ||
# @param peer [String] number | ||
def initialize(last_updated:, blocks_in_flight:, peer:) | ||
@last_updated = last_updated | ||
@blocks_in_flight = blocks_in_flight | ||
@peer = peer | ||
end | ||
|
||
def to_h | ||
{ | ||
last_updated: @last_updated, | ||
blocks_in_flight: @blocks_in_flight, | ||
peer: peer | ||
} | ||
end | ||
|
||
def self.from_h(hash) | ||
return if hash.nil? | ||
|
||
new( | ||
last_updated: hash[:last_updated], | ||
blocks_in_flight: hash[:blocks_in_flight], | ||
peer: hash[:peer] | ||
) | ||
end | ||
end | ||
end | ||
end |
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
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
RSpec.describe CKB::Types::ChainInfo do | ||
let(:chain_info_h) do | ||
{ | ||
"is_initial_block_download": false, | ||
"epoch": "0", | ||
"difficulty": "0x100", | ||
"median_time": "1557287480008", | ||
"chain": "ckb_dev", | ||
"warnings": "" | ||
} | ||
end | ||
|
||
it "from h" do | ||
chain_info = CKB::Types::ChainInfo::from_h(chain_info_h) | ||
expect(chain_info).to be_a(CKB::Types::ChainInfo) | ||
end | ||
end |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
RSpec.describe CKB::Types::PeerState do | ||
let(:peer_state_h) do | ||
{ | ||
"last_updated": "1557289448237", | ||
"blocks_in_flight": "86", | ||
"peer": "1" | ||
} | ||
end | ||
|
||
it "from h" do | ||
peer_state = CKB::Types::PeerState.from_h(peer_state_h) | ||
expect(peer_state).to be_a(CKB::Types::PeerState) | ||
end | ||
end |
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 |
---|---|---|
|
@@ -16,7 +16,7 @@ | |
|
||
it "to_hash" do | ||
expect( | ||
lock.to_hash | ||
always_success.to_hash | ||
).to eq always_success_type_hash | ||
end | ||
end |