class Fabric::ProposedTransaction
Manages the instantiation and creation of the Gateway::ProposedTransaction Protobuf Message.
Adapted from official fabric-gateway SDK ProposalBuilder and hyperledger-fabric-sdk: github.com/hyperledger/fabric-gateway/blob/1518e03ed3d6db1b6809e23e61a92744fd18e724/node/src/proposalbuilder.ts github.com/kirshin/hyperledger-fabric-sdk/blob/95a5a1a37001852312df25946e960a9ff149207e/lib/fabric/proposal.rb
Attributes
Specifies the set of organizations that will attempt to endorse the proposal. No other organizations’ peers will be sent this proposal. This is usually used in conjunction with transientData for private data scenarios.
Public Class Methods
# File lib/fabric/entities/proposed_transaction.rb, line 26 def initialize(contract, transaction_name, arguments: [], transient_data: {}, endorsing_organizations: []) @contract = contract @transaction_name = transaction_name @arguments = arguments @transient_data = transient_data @endorsing_organizations = endorsing_organizations generate_proposed_transaction end
Public Instance Methods
Returns the protobuf message instance
@return [Gateway::ProposedTransaction] protobuf message instance
# File lib/fabric/entities/proposed_transaction.rb, line 139 def as_proto proposed_transaction end
# File lib/fabric/entities/proposed_transaction.rb, line 77 def chaincode_id Protos::ChaincodeID.new name: chaincode_name end
# File lib/fabric/entities/proposed_transaction.rb, line 81 def chaincode_proposal_payload chaincode_input = Protos::ChaincodeInput.new args: [transaction_name] + arguments chaincode_spec = Protos::ChaincodeSpec.new type: Protos::ChaincodeSpec::Type::NODE, chaincode_id: chaincode_id, input: chaincode_input input = Protos::ChaincodeInvocationSpec.new chaincode_spec: chaincode_spec Protos::ChaincodeProposalPayload.new input: input.to_proto, TransientMap: transient_data end
# File lib/fabric/entities/proposed_transaction.rb, line 65 def channel_header Common::ChannelHeader.new type: Common::HeaderType::ENDORSER_TRANSACTION, channel_id: network_name, tx_id: transaction_id, extension: channel_header_extension.to_proto, timestamp: timestamp, epoch: 0 # version: Constants::CHANNEL_HEADER_VERSION # official SDK does not send this. end
# File lib/fabric/entities/proposed_transaction.rb, line 73 def channel_header_extension Protos::ChaincodeHeaderExtension.new chaincode_id: chaincode_id end
Builds the proposed transaction protobuf message
@return [Gateway::ProposedTransaction]
# File lib/fabric/entities/proposed_transaction.rb, line 41 def generate_proposed_transaction @proposed_transaction = ::Gateway::ProposedTransaction.new( transaction_id: transaction_id, proposal: signed_proposal, endorsing_organizations: endorsing_organizations ) end
# File lib/fabric/entities/proposed_transaction.rb, line 60 def header Common::Header.new channel_header: channel_header.to_proto, signature_header: signature_header.to_proto end
Generates a random nonce
@return [String] random nonce
# File lib/fabric/entities/proposed_transaction.rb, line 107 def nonce @nonce ||= signer.crypto_suite.generate_nonce end
# File lib/fabric/entities/proposed_transaction.rb, line 55 def proposal @proposal ||= Protos::Proposal.new header: header.to_proto, payload: chaincode_proposal_payload.to_proto end
Generates a SignatureHeader protobuf message from the signer and nonce
@return [Common::SignatureHeader] signature header protobuf message instance
# File lib/fabric/entities/proposed_transaction.rb, line 126 def signature_header Common::SignatureHeader.new creator: signer.to_proto, nonce: nonce end
# File lib/fabric/entities/proposed_transaction.rb, line 49 def signed_proposal @signed_proposal ||= Protos::SignedProposal.new( proposal_bytes: proposal.to_proto ) end
Returns the current timestamp
@return [Google::Protobuf::Timestamp] gRPC timestamp
# File lib/fabric/entities/proposed_transaction.rb, line 96 def timestamp now = Time.now @timestamp ||= Google::Protobuf::Timestamp.new seconds: now.to_i, nanos: now.nsec end
Returns the serialized JSON form of the proposed transaction
@param [Hash] options JSON serialization options @see ruby-doc.org/stdlib-2.6.3/libdoc/json/rdoc/JSON.html#method-i-generate
@return [String] serialized JSON form of the proposed transaction
# File lib/fabric/entities/proposed_transaction.rb, line 159 def to_json(options = {}) proposed_transaction.to_json(options) end
Returns the serialized Protobuf binary form of the proposed transaction
@return [String] serialized Protobuf binary form of the proposed transaction
# File lib/fabric/entities/proposed_transaction.rb, line 148 def to_proto proposed_transaction.to_proto end
Generates a unique transaction ID for the transaction based on a random number and the signer or returns the existing transaction ID if it has already been generated.
@return [String] transaction ID
# File lib/fabric/entities/proposed_transaction.rb, line 117 def transaction_id @transaction_id ||= signer.crypto_suite.hexdigest(nonce + signer.to_proto) end