Skip to content

Commit

Permalink
feat: add new apis
Browse files Browse the repository at this point in the history
1. get_header
2. get_header_by_number
3. get_cellbase_output_capacity_details
  • Loading branch information
shaojunda committed Jul 26, 2019
1 parent 32ee77e commit 75d7a81
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lib/ckb/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,30 @@ def index_lock_hash(lock_hash, index_from: "0")
Types::LockHashIndexState.from_h(state)
end

# @param block_hash [String] 0x...
#
# @return [CKB::Types::BlockHeader]
def get_header(block_hash)
block_header_h = rpc.get_header(block_hash)
Types::BlockHeader.from_h(block_header_h)
end

# @param block_number [String | Integer]
#
# @return [CKB::Types::BlockHeader]
def get_header_by_number(block_number)
block_header_h = rpc.get_header_by_number(block_number.to_s)
Types::BlockHeader.from_h(block_header_h)
end

# @param block_hash [String] 0x...
#
# @return [CKB::Types::BlockReward]
def get_cellbase_output_capacity_details(block_hash)
block_reward_h = rpc.get_cellbase_output_capacity_details(block_hash)
Types::BlockReward.from_h(block_reward_h)
end

def inspect
"\#<API@#{rpc.uri}>"
end
Expand Down
12 changes: 12 additions & 0 deletions lib/ckb/rpc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,18 @@ def index_lock_hash(lock_hash, index_from: '0')
rpc_request("index_lock_hash", params: [lock_hash, index_from.to_s])
end

def get_header(block_hash)
rpc_request("get_header", params: [block_hash])
end

def get_header_by_number(block_number)
rpc_request("get_header_by_number", params: [block_number.to_s])
end

def get_cellbase_output_capacity_details(block_hash)
rpc_request("get_cellbase_output_capacity_details", params: [block_hash])
end

def inspect
"\#<RPC@#{uri}>"
end
Expand Down

0 comments on commit 75d7a81

Please sign in to comment.