class Fabric::Proposal
Proposal
represents a transaction proposal that can be sent to peers for endorsement or evaluated as a query.
Combined ProposalBuilder with Proposal
. Utilizing instance variables and functions in proposal seem adaquate enough to fully create the proposal. ProposalBuilder did not seem like a native ruby design pattern.
Attributes
Public Class Methods
Instantiates a new Proposal
@param [Fabric::ProposedTransaction] proposed_transaction
ProposedTransaction
container class
# File lib/fabric/entities/proposal.rb, line 17 def initialize(proposed_transaction) @proposed_transaction = proposed_transaction end
Public Instance Methods
# File lib/fabric/entities/proposal.rb, line 21 def contract @proposed_transaction.contract end
Proposal
digest which can be utilized for offline signing. If signing offline, call signature= to set signature once computed.
@return [String] raw binary digest of the proposal message.
# File lib/fabric/entities/proposal.rb, line 72 def digest Fabric.crypto_suite.digest(proposal.to_proto) end
Obtain endorsement for the transaction proposal from sufficient peers to allow it to be committed to the ledger.
@param [Hash] options gRPC call options @see www.rubydoc.info/gems/grpc/GRPC%2FClientStub:request_response
@return [Fabric::Transaction] An endorsed transaction that can be submitted to the ledger.
# File lib/fabric/entities/proposal.rb, line 137 def endorse(options = {}) sign endorse_response = client.endorse(new_endorse_request, options) raise Fabric::Error, 'Missing transaction envelope' if endorse_response.prepared_transaction.nil? prepared_transaction = new_prepared_transaction(endorse_response.prepared_transaction) Fabric::Transaction.new(network, prepared_transaction) end
Evaluate the transaction proposal and obtain its result, without updating the ledger. This runs the transaction on a peer to obtain a transaction result, but does not submit the endorsed transaction to the orderer to be committed to the ledger.
@param [Hash] options gRPC call options @see www.rubydoc.info/gems/grpc/GRPC%2FClientStub:request_response
@return [String] The result returned by the transaction function
# File lib/fabric/entities/proposal.rb, line 123 def evaluate(options = {}) sign evaluate_response = client.evaluate(new_evaluate_request, options) evaluate_response.result.payload end
Creates a new endorse request from this proposal.
@return [Gateway::EndorseRequest] EndorseRequest protobuf message
# File lib/fabric/entities/proposal.rb, line 166 def new_endorse_request ::Gateway::EndorseRequest.new( transaction_id: transaction_id, channel_id: network_name, proposed_transaction: signed_proposal, endorsing_organizations: proposed_transaction.endorsing_organizations ) end
Generates an evaluate request from this proposal.
@return [Gateway::EvaluateRequest] evaluation request with the current proposal
# File lib/fabric/entities/proposal.rb, line 153 def new_evaluate_request ::Gateway::EvaluateRequest.new( channel_id: network_name, proposed_transaction: signed_proposal, target_organizations: proposed_transaction.endorsing_organizations ) end
Creates a new prepared transaction from a transaction envelope.
@param [Common::Envelope] envelope transaction envelope
@return [Gateway::PreparedTransaction] prepared transaction protobuf message
# File lib/fabric/entities/proposal.rb, line 182 def new_prepared_transaction(envelope) ::Gateway::PreparedTransaction.new( transaction_id: transaction_id, envelope: envelope ) end
Returns the proposal message as a protobuf Message object.
@return [Protos::Proposal|nil] Proposal
message
# File lib/fabric/entities/proposal.rb, line 36 def proposal proposed_transaction.proposal end
Utilizes the signer to sign the proposal message if it has not been signed yet.
# File lib/fabric/entities/proposal.rb, line 108 def sign return if signed? self.signature = signer.sign proposal.to_proto end
Returns the signed proposal signature
@return [String] Raw byte string signature
# File lib/fabric/entities/proposal.rb, line 91 def signature proposed_transaction.signed_proposal.signature end
Sets the signature of the signed proposal in the proposed transaction
@param [String] signature raw byte string signature of the proposal message
(should be the signature of the proposed message digest)
# File lib/fabric/entities/proposal.rb, line 82 def signature=(signature) proposed_transaction.signed_proposal.signature = signature end
Returns true if the signed proposal has a signature
@return [Boolean] true|false
# File lib/fabric/entities/proposal.rb, line 100 def signed? # signature cannot be nil because google protobuf won't let it !proposed_transaction.signed_proposal.signature.empty? end
Returns the signed proposal
<rant> Fabric
message naming scheme is a mess: ProposedTransaction
has a Proposal
which is a SignedProposal
which has a Proposal which is a Proposal
so.… which proposal do you want to access? Adding this function for clarity </rant>
@return [Protos::SignedProposal|nil] SignedProposal message
# File lib/fabric/entities/proposal.rb, line 52 def signed_proposal proposed_transaction.proposed_transaction.proposal end
Serialized bytes of the proposal message in proto3 format.
@return [String] Binary representation of the proposal message.
# File lib/fabric/entities/proposal.rb, line 61 def to_proto proposed_transaction.to_proto end
# File lib/fabric/entities/proposal.rb, line 27 def transaction_id proposed_transaction.transaction_id end