Skip to content

Commit

Permalink
feat: add serialized_size_without_uncle_proposals
Browse files Browse the repository at this point in the history
  • Loading branch information
shaojunda committed Mar 10, 2021
1 parent 92e0dd6 commit 43f5077
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/ckb/types/block.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ def initialize(uncles:, proposals:, transactions:, header:)
@header = header
end

# https://github.com/nervosnetwork/ckb/blob/develop/util/types/src/extension/serialized_size.rs#L22-L30
def serialized_size_without_uncle_proposals
block_size = CKB::Serializers::BlockSerializer.new(self).capacity
uncles_proposals_size = self.uncles.map { |uncle| uncle.proposals.map { |proposal| CKB::Serializers::ProposalShortIdSerializer.new(proposal).capacity - CKB::Serializers::TableSerializer::UINT32_CAPACITY }.sum }.sum

block_size - uncles_proposals_size
end

def to_h
{
uncles: @uncles.map(&:to_h),
Expand Down

0 comments on commit 43f5077

Please sign in to comment.