Class: Fabric::Proposal
- Inherits:
-
Object
- Object
- Fabric::Proposal
- Defined in:
- lib/fabric/proposal.rb
Instance Attribute Summary collapse
-
#identity ⇒ Object
readonly
Returns the value of attribute identity.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
Instance Method Summary collapse
- #args ⇒ Object
- #chaincode_id ⇒ Object
- #chaincode_proposal ⇒ Object
- #channel_header ⇒ Object
- #channel_header_extension ⇒ Object
- #channel_id ⇒ Object
- #crypto_suite ⇒ Object
- #header ⇒ Object
-
#initialize(identity, request = {}) ⇒ Proposal
constructor
A new instance of Proposal.
- #nonce ⇒ Object
- #proposal ⇒ Object
- #signature_header ⇒ Object
- #signed_proposal ⇒ Object
- #transaction_id ⇒ Object
- #transient ⇒ Object
- #tx_id ⇒ Object
- #tx_timestamp ⇒ Object
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
#identity ⇒ Object (readonly)
Returns the value of attribute identity.
3 4 5 |
# File 'lib/fabric/proposal.rb', line 3 def identity @identity end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
3 4 5 |
# File 'lib/fabric/proposal.rb', line 3 def request @request end |
Instance Method Details
#args ⇒ Object
28 29 30 |
# File 'lib/fabric/proposal.rb', line 28 def args request[:args].compact.map &:to_s end |
#chaincode_id ⇒ Object
24 25 26 |
# File 'lib/fabric/proposal.rb', line 24 def chaincode_id request[:chaincode_id] end |
#chaincode_proposal ⇒ Object
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_header ⇒ Object
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: , version: Constants::CHANNEL_HEADER_VERSION end |
#channel_header_extension ⇒ Object
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_id ⇒ Object
20 21 22 |
# File 'lib/fabric/proposal.rb', line 20 def channel_id request[:channel_id] end |
#crypto_suite ⇒ Object
12 13 14 |
# File 'lib/fabric/proposal.rb', line 12 def crypto_suite identity.crypto_suite end |
#header ⇒ Object
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 |
#nonce ⇒ Object
16 17 18 |
# File 'lib/fabric/proposal.rb', line 16 def nonce @nonce ||= crypto_suite.generate_nonce end |
#proposal ⇒ Object
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_header ⇒ Object
81 82 83 |
# File 'lib/fabric/proposal.rb', line 81 def signature_header Common::SignatureHeader.new creator: identity.serialize, nonce: nonce end |
#signed_proposal ⇒ Object
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_id ⇒ Object
36 37 38 |
# File 'lib/fabric/proposal.rb', line 36 def transaction_id request[:transaction_id] end |
#transient ⇒ Object
32 33 34 |
# File 'lib/fabric/proposal.rb', line 32 def transient request[:transient] || {} end |
#tx_id ⇒ Object
40 41 42 |
# File 'lib/fabric/proposal.rb', line 40 def tx_id @tx_id ||= crypto_suite.hexdigest(nonce + identity.serialize) end |
#tx_timestamp ⇒ Object
75 76 77 78 79 |
# File 'lib/fabric/proposal.rb', line 75 def now = Time.now @tx_timestamp ||= Google::Protobuf::Timestamp.new seconds: now.to_i, nanos: now.nsec end |