Class: Fabric::Proposal

Inherits:
Object
  • Object
show all
Defined in:
lib/fabric/proposal.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(identity, request = {}) ⇒ Proposal

Returns a new instance of Proposal.



5
6
7
8
9
10
# File 'lib/fabric/proposal.rb', line 5

def initialize(identity, request = {})
  @identity = identity
  @request = request

  assign_tx request[:transaction_info] if request[:transaction_info]
end

Instance Attribute Details

#identityObject (readonly)

Returns the value of attribute identity.



3
4
5
# File 'lib/fabric/proposal.rb', line 3

def identity
  @identity
end

#requestObject (readonly)

Returns the value of attribute request.



3
4
5
# File 'lib/fabric/proposal.rb', line 3

def request
  @request
end

Instance Method Details

#argsObject



28
29
30
# File 'lib/fabric/proposal.rb', line 28

def args
  request[:args].compact.map &:to_s
end

#chaincode_idObject



24
25
26
# File 'lib/fabric/proposal.rb', line 24

def chaincode_id
  request[:chaincode_id]
end

#chaincode_proposalObject



85
86
87
88
89
90
91
92
93
94
# File 'lib/fabric/proposal.rb', line 85

def chaincode_proposal
  id = Protos::ChaincodeID.new name: chaincode_id
  chaincode_input = Protos::ChaincodeInput.new args: args
  chaincode_spec = Protos::ChaincodeSpec.new type: Protos::ChaincodeSpec::Type::NODE,
                                             chaincode_id: id,
                                             input: chaincode_input
  input = Protos::ChaincodeInvocationSpec.new chaincode_spec: chaincode_spec

  Protos::ChaincodeProposalPayload.new input: input.to_proto, TransientMap: transient
end

#channel_headerObject



61
62
63
64
65
66
67
# File 'lib/fabric/proposal.rb', line 61

def channel_header
  Common::ChannelHeader.new type: Common::HeaderType::ENDORSER_TRANSACTION,
                            channel_id: channel_id, tx_id: tx_id,
                            extension: channel_header_extension.to_proto,
                            timestamp: tx_timestamp,
                            version: Constants::CHANNEL_HEADER_VERSION
end

#channel_header_extensionObject



69
70
71
72
73
# File 'lib/fabric/proposal.rb', line 69

def channel_header_extension
  id = Protos::ChaincodeID.new name: chaincode_id

  Protos::ChaincodeHeaderExtension.new chaincode_id: id
end

#channel_idObject



20
21
22
# File 'lib/fabric/proposal.rb', line 20

def channel_id
  request[:channel_id]
end

#crypto_suiteObject



12
13
14
# File 'lib/fabric/proposal.rb', line 12

def crypto_suite
  identity.crypto_suite
end

#headerObject



56
57
58
59
# File 'lib/fabric/proposal.rb', line 56

def header
  Common::Header.new channel_header: channel_header.to_proto,
                     signature_header: signature_header.to_proto
end

#nonceObject



16
17
18
# File 'lib/fabric/proposal.rb', line 16

def nonce
  @nonce ||= crypto_suite.generate_nonce
end

#proposalObject



44
45
46
47
# File 'lib/fabric/proposal.rb', line 44

def proposal
  @proposal ||= Protos::Proposal.new header: header.to_proto,
                                     payload: chaincode_proposal.to_proto
end

#signature_headerObject



81
82
83
# File 'lib/fabric/proposal.rb', line 81

def signature_header
  Common::SignatureHeader.new creator: identity.serialize, nonce: nonce
end

#signed_proposalObject



49
50
51
52
53
54
# File 'lib/fabric/proposal.rb', line 49

def signed_proposal
  proposal_bytes = proposal.to_proto
  signature = identity.sign proposal_bytes

  Protos::SignedProposal.new proposal_bytes: proposal_bytes, signature: signature
end

#transaction_idObject



36
37
38
# File 'lib/fabric/proposal.rb', line 36

def transaction_id
  request[:transaction_id]
end

#transientObject



32
33
34
# File 'lib/fabric/proposal.rb', line 32

def transient
  request[:transient] || {}
end

#tx_idObject



40
41
42
# File 'lib/fabric/proposal.rb', line 40

def tx_id
  @tx_id ||= crypto_suite.hexdigest(nonce + identity.serialize)
end

#tx_timestampObject



75
76
77
78
79
# File 'lib/fabric/proposal.rb', line 75

def tx_timestamp
  now = Time.now

  @tx_timestamp ||= Google::Protobuf::Timestamp.new seconds: now.to_i, nanos: now.nsec
end