Module: Fabric::Helper

Defined in:
lib/fabric/helper.rb

Class Method Summary collapse

Class Method Details

.build_channel_header(opts) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/fabric/helper.rb', line 3

def self.build_channel_header(opts)
  header = Common::ChannelHeader.new type: opts[:type],
                                     channel_id: opts[:channel_id],
                                     tx_id: opts[:tx_id],
                                     timestamp: opts[:timestamp] || build_timestamp,
                                     version: 1

  header.extension = build_channel_header_extension(opts) if opts[:chaincode_id]

  header
end

.build_channel_header_extension(opts) ⇒ Object



15
16
17
18
19
# File 'lib/fabric/helper.rb', line 15

def self.build_channel_header_extension(opts)
  id = Protos::ChaincodeID.new name: opts[:chaincode_id]

  Protos::ChaincodeHeaderExtension.new chaincode_id: id
end

.build_timestampObject



21
22
23
24
25
# File 'lib/fabric/helper.rb', line 21

def self.build_timestamp
  now = Time.now

  Google::Protobuf::Timestamp.new seconds: now.to_i, nanos: now.nsec
end

.timestamp_to_time(timestamp) ⇒ Object



27
28
29
# File 'lib/fabric/helper.rb', line 27

def self.timestamp_to_time(timestamp)
  (timestamp.seconds * 1000 + timestamp.nanos / 10**6).to_i
end