Skip to content

Commit

Permalink
perf: byte32 serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
shaojunda committed Jan 25, 2021
1 parent 73c03c0 commit 9574a5e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
10 changes: 7 additions & 3 deletions lib/ckb/serializers/code_hash_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,23 @@ class CodeHashSerializer

# @param code_hash [String]
def initialize(code_hash)
@byte32_serializer = Byte32Serializer.new(code_hash)
@item = if code_hash
code_hash.start_with?("0x") ? code_hash[2..-1] : code_hash
else
""
end
end

private

attr_reader :byte32_serializer
attr_reader :item

def layout
body
end

def body
byte32_serializer.serialize[2..-1]
item
end
end
end
Expand Down
10 changes: 7 additions & 3 deletions lib/ckb/serializers/header_dep_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,23 @@ class HeaderDepSerializer

# @param header_dep [String]
def initialize(header_dep)
@byte32_serializer = Byte32Serializer.new(header_dep)
@item = if header_dep
header_dep.start_with?("0x") ? header_dep[2..-1] : header_dep
else
""
end
end

private

attr_reader :byte32_serializer
attr_reader :item

def layout
body
end

def body
byte32_serializer.serialize[2..-1]
item
end
end
end
Expand Down
10 changes: 7 additions & 3 deletions lib/ckb/serializers/out_point_tx_hash_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,23 @@ class OutPointTxHashSerializer

# @param tx_hash [String]
def initialize(tx_hash)
@byte32_serializer = Byte32Serializer.new(tx_hash)
@item = if tx_hash
tx_hash.start_with?("0x") ? tx_hash[2..-1] : tx_hash
else
""
end
end

private

attr_reader :byte32_serializer
attr_reader :item

def layout
body
end

def body
byte32_serializer.serialize[2..-1]
item
end
end
end
Expand Down

0 comments on commit 9574a5e

Please sign in to comment.