Class: Filecoin::Types::DataRef

Inherits:
Object
  • Object
show all
Defined in:
lib/filecoin/types/data_ref.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(transfer_type: nil, root:, piece_cid: nil, piece_size: nil) ⇒ DataRef

Returns a new instance of DataRef.



8
9
10
11
12
13
# File 'lib/filecoin/types/data_ref.rb', line 8

def initialize(transfer_type: nil, root:, piece_cid: nil, piece_size: nil)
  @transfer_type = transfer_type
  @root = Cid.new(root)
  @piece_cid = Cid.new(piece_cid)
  @piece_size = piece_size
end

Instance Attribute Details

#piece_cidObject (readonly)

Returns the value of attribute piece_cid.



6
7
8
# File 'lib/filecoin/types/data_ref.rb', line 6

def piece_cid
  @piece_cid
end

#piece_sizeObject (readonly)

Returns the value of attribute piece_size.



6
7
8
# File 'lib/filecoin/types/data_ref.rb', line 6

def piece_size
  @piece_size
end

#rootObject (readonly)

Returns the value of attribute root.



6
7
8
# File 'lib/filecoin/types/data_ref.rb', line 6

def root
  @root
end

#transfer_typeObject (readonly)

Returns the value of attribute transfer_type.



6
7
8
# File 'lib/filecoin/types/data_ref.rb', line 6

def transfer_type
  @transfer_type
end

Instance Method Details

#as_jsonObject



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/filecoin/types/data_ref.rb', line 15

def as_json
  hash = {
    "Root" => root.as_json,
  }

  hash["TransferType"] = transfer_type unless transfer_type.nil?
  hash["PieceCID"] = piece_cid.as_json unless piece_cid.nil?
  hash["PieceSize"] = piece_size unless piece_size.nil?

  hash
end