Class: Fabric::Transaction
- Inherits:
-
Object
- Object
- Fabric::Transaction
- Includes:
- Accessors::Network
- Defined in:
- lib/fabric/entities/transaction.rb
Overview
Represents an endorsed transaction that can be submitted to the orderer for commit to the ledger, query the transaction results and its commit status.
Instance Attribute Summary collapse
- #envelope ⇒ Fabric::Envelope readonly
-
#network ⇒ Object
readonly
Returns the value of attribute network.
-
#prepared_transaction ⇒ Gateway::PreparedTransaction
readonly
Prepared Transaction.
Attributes included from Accessors::Network
Attributes included from Accessors::Gateway
Instance Method Summary collapse
-
#initialize(network, prepared_transaction) ⇒ Transaction
constructor
Creates a new Transaction instance.
-
#result(check_status: true) ⇒ String
Get the transaction result.
-
#sign_status_request ⇒ Fabric::Transaction
Sign the signed commit status request.
-
#sign_submit_request ⇒ void
Sign the transaction envelope.
-
#signed_commit_status_request ⇒ Gateway::SignedCommitStatusRequest
Returns the current instance of the signed commit status request.
-
#status(options = {}) ⇒ Fabric::Status
Get status of the committed transaction.
-
#status_request_digest ⇒ String
Digest to be signed to support offline signing of the commit status request.
-
#status_request_signature=(signature) ⇒ void
Sets the status request signature.
-
#status_request_signed? ⇒ Boolean
Returns true if the signed commit status request has been signed.
-
#submit(options = {}) ⇒ Fabric::Transaction
Submit the transaction to the orderer to be committed to the ledger.
-
#submit_request_digest ⇒ String
Digest to be signed to support offline signing of the submit request.
-
#submit_request_signature=(signature) ⇒ void
Sets the submit request signature.
-
#submit_request_signed? ⇒ Boolean
Returns true if the transaction envelope has been signed.
-
#transaction_id ⇒ String
Returns the transaction ID from the prepared transaction.
Constructor Details
#initialize(network, prepared_transaction) ⇒ Transaction
Creates a new Transaction instance.
25 26 27 28 29 |
# File 'lib/fabric/entities/transaction.rb', line 25 def initialize(network, prepared_transaction) @network = network @prepared_transaction = prepared_transaction @envelope = Envelope.new(prepared_transaction.envelope) end |
Instance Attribute Details
#envelope ⇒ Fabric::Envelope (readonly)
17 18 19 |
# File 'lib/fabric/entities/transaction.rb', line 17 def envelope @envelope end |
#network ⇒ Object (readonly)
Returns the value of attribute network.
9 10 11 |
# File 'lib/fabric/entities/transaction.rb', line 9 def network @network end |
#prepared_transaction ⇒ Gateway::PreparedTransaction (readonly)
Returns Prepared Transaction.
14 15 16 |
# File 'lib/fabric/entities/transaction.rb', line 14 def prepared_transaction @prepared_transaction end |
Instance Method Details
#result(check_status: true) ⇒ String
Get the transaction result. This is obtained during the endorsement process when the transaction proposal is run on endorsing peers.
39 40 41 42 43 |
# File 'lib/fabric/entities/transaction.rb', line 39 def result(check_status: true) raise Fabric::CommitError, status if check_status && !status.successful envelope.result end |
#sign_status_request ⇒ Fabric::Transaction
Sign the signed commit status request
158 159 160 161 162 163 164 165 |
# File 'lib/fabric/entities/transaction.rb', line 158 def sign_status_request return if status_request_signed? signature = signer.sign(signed_commit_status_request.request) signed_commit_status_request.signature = signature self end |
#sign_submit_request ⇒ void
This method returns an undefined value.
Sign the transaction envelope.
74 75 76 77 78 79 |
# File 'lib/fabric/entities/transaction.rb', line 74 def sign_submit_request return if submit_request_signed? signature = signer.sign(envelope.payload_bytes) self.submit_request_signature = signature end |
#signed_commit_status_request ⇒ Gateway::SignedCommitStatusRequest
Returns the current instance of the signed commit status request. Necessary so we can keep the state of the signature in the transaction object.
173 174 175 |
# File 'lib/fabric/entities/transaction.rb', line 173 def signed_commit_status_request @signed_commit_status_request ||= new_signed_commit_status_request end |
#status(options = {}) ⇒ Fabric::Status
Get status of the committed transaction. If the transaction has not yet committed, this method blocks until the commit occurs. If status is already queried, this returns status from cache and does not make additional queries.
120 121 122 |
# File 'lib/fabric/entities/transaction.rb', line 120 def status( = {}) @status ||= query_status() end |
#status_request_digest ⇒ String
Digest to be signed to support offline signing of the commit status request
129 130 131 |
# File 'lib/fabric/entities/transaction.rb', line 129 def status_request_digest Fabric.crypto_suite.digest(signed_commit_status_request.request) end |
#status_request_signature=(signature) ⇒ void
This method returns an undefined value.
Sets the status request signature. This is used to support offline signing of the commit status request.
140 141 142 |
# File 'lib/fabric/entities/transaction.rb', line 140 def status_request_signature=(signature) signed_commit_status_request.signature = signature end |
#status_request_signed? ⇒ Boolean
Returns true if the signed commit status request has been signed.
149 150 151 |
# File 'lib/fabric/entities/transaction.rb', line 149 def status_request_signed? !signed_commit_status_request.signature.empty? end |
#submit(options = {}) ⇒ Fabric::Transaction
Submit the transaction to the orderer to be committed to the ledger.
62 63 64 65 66 67 68 |
# File 'lib/fabric/entities/transaction.rb', line 62 def submit( = {}) sign_submit_request client.submit(new_submit_request, ) self end |
#submit_request_digest ⇒ String
Digest to be signed to support offline signing of the submit request
95 96 97 |
# File 'lib/fabric/entities/transaction.rb', line 95 def submit_request_digest envelope.payload_digest end |
#submit_request_signature=(signature) ⇒ void
This method returns an undefined value.
Sets the submit request signature. This is used to support offline signing of the submit request.
106 107 108 |
# File 'lib/fabric/entities/transaction.rb', line 106 def submit_request_signature=(signature) envelope.signature = signature end |
#submit_request_signed? ⇒ Boolean
Returns true if the transaction envelope has been signed.
86 87 88 |
# File 'lib/fabric/entities/transaction.rb', line 86 def submit_request_signed? @envelope.signed? end |
#transaction_id ⇒ String
Returns the transaction ID from the prepared transaction.
50 51 52 |
# File 'lib/fabric/entities/transaction.rb', line 50 def transaction_id prepared_transaction.transaction_id end |