Class: Fabric::Contract
- Inherits:
-
Object
- Object
- Fabric::Contract
- Includes:
- Accessors::Network
- Defined in:
- lib/fabric/contract.rb
Overview
Contract represents a smart contract, and allows applications to:
Evaluate transactions that query state from the ledger using the EvaluateTransaction() method.
Submit transactions that store state to the ledger using the SubmitTransaction() method.
For more complex transaction invocations, such as including transient data, transactions can be evaluated or submitted using the Evaluate() or Submit() methods respectively. The result of a submitted transaction can be accessed prior to its commit to the ledger using SubmitAsync().
By default, proposal, transaction and commit status messages will be signed using the signing implementation specified when connecting the Gateway. In cases where an external client holds the signing credentials, a signing implementation can be omitted when connecting the Gateway and off-line signing can be carried out by:
Returning the serialized proposal, transaction or commit status along with its digest to the client for them to generate a signature.
With the serialized message and signature received from the client to create a signed proposal, transaction or commit using the Gateway's NewSignedProposal(), NewSignedTransaction() or NewSignedCommit() methods respectively.
Instance Attribute Summary collapse
-
#chaincode_name ⇒ Object
readonly
Returns the value of attribute chaincode_name.
-
#contract_name ⇒ Object
readonly
Returns the value of attribute contract_name.
-
#network ⇒ Object
readonly
Returns the value of attribute network.
Attributes included from Accessors::Network
Attributes included from Accessors::Gateway
Instance Method Summary collapse
-
#chaincode_events(start_block: nil, call_options: {}) {|chaincode_event| ... } ⇒ Enumerator|GRPC::ActiveCall::Operation|nil
Get chaincode events emitted by transaction functions of the chaincode.
-
#evaluate(transaction_name, proposal_options = {}) ⇒ String
Evaluate a transaction function and return its result.
-
#evaluate_transaction(transaction_name, arguments = []) ⇒ String
Evaluate a transaction function and return its results.
-
#initialize(network, chaincode_name, contract_name = '') ⇒ Contract
constructor
A new instance of Contract.
-
#new_proposal(transaction_name, arguments: [], transient_data: {}, endorsing_organizations: []) ⇒ Fabric::Proposal
Creates a transaction proposal that can be evaluated or endorsed.
-
#qualified_transaction_name(transaction_name) ⇒ string
Generates the qualified transaction name for the contract.
-
#submit(transaction_name, proposal_options = {}) ⇒ String
Submit a transaction to the ledger and return its result only after it is committed to the ledger.
-
#submit_async ⇒ Object
not 100% sure if grpc support is necessary for this.
-
#submit_transaction(transaction_name, arguments = []) ⇒ String
Submit a transaction to the ledger and return its result only after it is committed to the ledger.
Constructor Details
#initialize(network, chaincode_name, contract_name = '') ⇒ Contract
Returns a new instance of Contract.
32 33 34 35 36 |
# File 'lib/fabric/contract.rb', line 32 def initialize(network, chaincode_name, contract_name = '') @network = network @chaincode_name = chaincode_name @contract_name = contract_name end |
Instance Attribute Details
#chaincode_name ⇒ Object (readonly)
Returns the value of attribute chaincode_name.
26 27 28 |
# File 'lib/fabric/contract.rb', line 26 def chaincode_name @chaincode_name end |
#contract_name ⇒ Object (readonly)
Returns the value of attribute contract_name.
26 27 28 |
# File 'lib/fabric/contract.rb', line 26 def contract_name @contract_name end |
#network ⇒ Object (readonly)
Returns the value of attribute network.
26 27 28 |
# File 'lib/fabric/contract.rb', line 26 def network @network end |
Instance Method Details
#chaincode_events(start_block: nil, call_options: {}) {|chaincode_event| ... } ⇒ Enumerator|GRPC::ActiveCall::Operation|nil
Get chaincode events emitted by transaction functions of the chaincode.
135 136 137 138 139 140 141 142 |
# File 'lib/fabric/contract.rb', line 135 def chaincode_events(start_block: nil, call_options: {}, &block) network.chaincode_events( self, start_block: start_block, call_options: , &block ) end |
#evaluate(transaction_name, proposal_options = {}) ⇒ String
Evaluate a transaction function and return its result. This method provides greater control over the transaction proposal content and the endorsing peers on which it is evaluated. This allows transaction functions to be evaluated where the proposal must include transient data, or that will access ledger data with key-based endorsement policies.
83 84 85 |
# File 'lib/fabric/contract.rb', line 83 def evaluate(transaction_name, = {}) new_proposal(transaction_name, **).evaluate end |
#evaluate_transaction(transaction_name, arguments = []) ⇒ String
Evaluate a transaction function and return its results. A transaction proposal will be evaluated on endorsing peers but the transaction will not be sent to the ordering service and so will not be committed to the ledger. This can be used for querying the world state.
48 49 50 |
# File 'lib/fabric/contract.rb', line 48 def evaluate_transaction(transaction_name, arguments = []) evaluate(transaction_name, { arguments: arguments }) end |
#new_proposal(transaction_name, arguments: [], transient_data: {}, endorsing_organizations: []) ⇒ Fabric::Proposal
Creates a transaction proposal that can be evaluated or endorsed. Supports off-line signing flow.
155 156 157 158 159 160 161 162 163 164 |
# File 'lib/fabric/contract.rb', line 155 def new_proposal(transaction_name, arguments: [], transient_data: {}, endorsing_organizations: []) proposed_transaction = ProposedTransaction.new( self, qualified_transaction_name(transaction_name), arguments: arguments, transient_data: transient_data, endorsing_organizations: endorsing_organizations ) Proposal.new(proposed_transaction) end |
#qualified_transaction_name(transaction_name) ⇒ string
Generates the qualified transaction name for the contract. (prepends the contract name to the transaction name if contract name is set)
174 175 176 |
# File 'lib/fabric/contract.rb', line 174 def qualified_transaction_name(transaction_name) contract_name.nil? || contract_name.empty? ? transaction_name : "#{contract_name}:#{transaction_name}" end |
#submit(transaction_name, proposal_options = {}) ⇒ String
Submit a transaction to the ledger and return its result only after it is committed to the ledger. The transaction function will be evaluated on endorsing peers and then submitted to the ordering service to be committed to the ledger.
102 103 104 105 106 107 |
# File 'lib/fabric/contract.rb', line 102 def submit(transaction_name, = {}) transaction = new_proposal(transaction_name, **).endorse transaction.submit transaction.result end |
#submit_async ⇒ Object
unimplemented, not sure if this can be implemented because the official grpc ruby client does not support non-blocking async calls (https://github.com/grpc/grpc/issues/10973)
not 100% sure if grpc support is necessary for this.
116 117 118 |
# File 'lib/fabric/contract.rb', line 116 def submit_async raise NotYetImplemented end |
#submit_transaction(transaction_name, arguments = []) ⇒ String
Submit a transaction to the ledger and return its result only after it is committed to the ledger. The transaction function will be evaluated on endorsing peers and then submitted to the ordering service to be committed to the ledger.
63 64 65 |
# File 'lib/fabric/contract.rb', line 63 def submit_transaction(transaction_name, arguments = []) submit(transaction_name, { arguments: arguments }) end |