-
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.
- Loading branch information
1 parent
8a9779b
commit df1f304
Showing
4 changed files
with
75 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# frozen_string_literal: true | ||
|
||
module CKB | ||
module Serializers | ||
class TransactionSerializer | ||
include TableSerializer | ||
|
||
# @param transaction [CKB::Types::Transaction] | ||
def initialize(transaction) | ||
@raw_serializer = RawTransactionSerializer.new(transaction) | ||
@witnesses_serializer = DynVecSerializer.new(transaction.witnesses, WitnessSerializer) | ||
@items_count = 2 | ||
end | ||
|
||
private | ||
|
||
attr_reader :raw_serializer, :witnesses_serializer, :items_count | ||
|
||
def body | ||
raw_layout + witnesses_layout | ||
end | ||
|
||
def offsets | ||
offset0 = (items_count + 1) * UINT32_CAPACITY | ||
offset1 = offset0 + raw_capacity | ||
|
||
[offset0, offset1] | ||
end | ||
|
||
def raw_layout | ||
raw_serializer.serialize[2..-1] | ||
end | ||
|
||
def raw_capacity | ||
raw_serializer.capacity | ||
end | ||
|
||
def witnesses_layout | ||
witnesses_serializer.serialize[2..-1] | ||
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,25 @@ | ||
# frozen_string_literal: true | ||
|
||
module CKB | ||
module Serializers | ||
class WitnessSerializer | ||
include BaseSerializer | ||
|
||
# @param witness [String] | ||
def initialize(witness) | ||
witness ||= "" | ||
witness = witness.start_with?("0x") ? witness[2..-1] : witness | ||
items = witness.scan(/../) | ||
@bytes_serializer = FixVecSerializer.new(items, ByteSerializer) | ||
end | ||
|
||
private | ||
|
||
attr_reader :bytes_serializer | ||
|
||
def layout | ||
bytes_serializer.serialize[2..-1] | ||
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