ServiceHub.DefaultImpls
Keywords: net.corda.core.node.ServiceHub.DefaultImpls class
Date: 2023-09-18

net.corda.core.node

## Class ServiceHub.DefaultImpls

- net.corda.core.node.ServiceHub.DefaultImpls

- Enclosing interface:
    ServiceHub

      public static class ServiceHub.DefaultImpls

  A service hub is the starting point for most operations you can do inside the node. You are provided with one when a class annotated with `annotationclass CordaService` is constructed, and you have access to one inside flows. Most RPCs simply forward to the services found here after some access checking.

  The APIs are organised roughly by category, with a few very important top level APIs available on the ServiceHub itself. Inside a flow, it's safe to keep a reference to services found here on the stack: checkpointing will do the right thing (it won't try to serialise the internals of the service).

  In unit test environments, some of those services may be missing or mocked out.

  See Also:
    `annotationclass CordaService`

- - ### Constructor Detail

    - #### DefaultImpls

          public DefaultImpls()

  - ### Method Detail

    - #### recordTransactions

          public static void recordTransactions(ServiceHub $this,
                                                boolean notifyVault,
                                                @NotNull
                                                java.lang.Iterable<net.corda.core.transactions.SignedTransaction> txs)

      Stores the given `class SignedTransaction`s in the local transaction storage and then sends them to the vault for further processing if `notifyVault` is true. This is expected to be run within a database transaction.

      Parameters:
        `$this` - indicate if the vault should be notified for the update.
        `notifyVault` - The transactions to record.
        `txs` - The transactions to record.
      See Also:
        `class SignedTransaction`, `notifyVault`

    - #### recordTransactions

          public static void recordTransactions(ServiceHub $this,
                                                boolean notifyVault,
                                                @NotNull
                                                SignedTransaction first,
                                                @NotNull
                                                net.corda.core.transactions.SignedTransaction... remaining)

      Stores the given `class SignedTransaction`s in the local transaction storage and then sends them to the vault for further processing if `notifyVault` is true. This is expected to be run within a database transaction.

      See Also:
        `class SignedTransaction`, `notifyVault`

    - #### recordTransactions

          public static void recordTransactions(ServiceHub $this,
                                                @NotNull
                                                SignedTransaction first,
                                                @NotNull
                                                net.corda.core.transactions.SignedTransaction... remaining)

      Stores the given `class SignedTransaction`s in the local transaction storage and then sends them to the vault for further processing. This is expected to be run within a database transaction.

      See Also:
        `class SignedTransaction`

    - #### recordTransactions

          public static void recordTransactions(ServiceHub $this,
                                                @NotNull
                                                java.lang.Iterable<net.corda.core.transactions.SignedTransaction> txs)

      Stores the given `class SignedTransaction`s in the local transaction storage and then sends them to the vault for further processing. This is expected to be run within a database transaction.

      See Also:
        `class SignedTransaction`

    - #### toStateAndRef

          @NotNull
          public static <T extends ContractState> StateAndRef<T> toStateAndRef(ServiceHub $this,
                                                                                        @NotNull
                                                                                        StateRef stateRef)

      Converts the given `class StateRef` into a `class StateAndRef` object.

      Throws:
        `TransactionResolutionException` - if `stateRef` points to a non-existent transaction.
      See Also:
        `class StateRef`, `class StateAndRef`

    - #### signInitialTransaction

          @NotNull
          public static SignedTransaction signInitialTransaction(ServiceHub $this,
                                                                          @NotNull
                                                                          TransactionBuilder builder,
                                                                          @NotNull
                                                                          java.security.PublicKey publicKey)

      Helper method to construct an initial partially signed transaction from a `class TransactionBuilder` using keys stored inside the node. Signature metadata is added automatically.

      Parameters:
        `$this` - The `class TransactionBuilder` to seal with the node's signature.Any existing signatures on the builder will be preserved.
        `builder` - The PublicKey matched to the internal java.security.PrivateKey to use in signing this transaction.If the passed in key is actually a CompositeKey the code searches for the first child key hosted within this nodeto sign with.
        `publicKey` - The PublicKey matched to the internal java.security.PrivateKey to use in signing this transaction. If the passed in key is actually a CompositeKey the code searches for the first child key hosted within this node to sign with.
      Returns:
        Returns a SignedTransaction with the new node signature attached.
      See Also:
        `class TransactionBuilder`

    - #### signInitialTransaction

          @NotNull
          public static SignedTransaction signInitialTransaction(ServiceHub $this,
                                                                          @NotNull
                                                                          TransactionBuilder builder)

      Helper method to construct an initial partially signed transaction from a TransactionBuilder using the default identity key contained in the node. The legal identity key is used to sign.

      Parameters:
        `$this` - The TransactionBuilder to seal with the node's signature.Any existing signatures on the builder will be preserved.
        `builder` - The TransactionBuilder to seal with the node's signature. Any existing signatures on the builder will be preserved.
      Returns:
        Returns a SignedTransaction with the new node signature attached.

    - #### signInitialTransaction

          @NotNull
          public static SignedTransaction signInitialTransaction(ServiceHub $this,
                                                                          @NotNull
                                                                          TransactionBuilder builder,
                                                                          @NotNull
                                                                          java.lang.Iterable<? extends java.security.PublicKey> signingPubKeys)

      Helper method to construct an initial partially signed transaction from a `class TransactionBuilder` using a set of keys all held in this node.

      Parameters:
        `$this` - The `class TransactionBuilder` to seal with the node's signature.Any existing signatures on the builder will be preserved.
        `builder` - A list of PublicKeys used to lookup the matching java.security.PrivateKey and sign.
        `signingPubKeys` - A list of PublicKeys used to lookup the matching java.security.PrivateKey and sign.
      Returns:
        Returns a `class SignedTransaction` with the new node signature attached.
      Throws:
        `IllegalArgumentException` - is thrown if any keys are unavailable locally.
      See Also:
        `class TransactionBuilder`

    - #### createSignature

          @NotNull
          public static TransactionSignature createSignature(ServiceHub $this,
                                                                      @NotNull
                                                                      SignedTransaction signedTransaction,
                                                                      @NotNull
                                                                      java.security.PublicKey publicKey)

      Helper method to create an additional signature for an existing (partially) `class SignedTransaction`. Additional `class SignatureMetadata`, including the platform version used during signing and the cryptographic signature scheme use, is added to the signature.

      Parameters:
        `$this` - The `class SignedTransaction` to which the signature will apply.
        `signedTransaction` - The PublicKey matching to a signing java.security.PrivateKey hosted in the node.If the PublicKey is actually a `class CompositeKey` the first leaf key found locally will be usedfor signing.
        `publicKey` - The PublicKey matching to a signing java.security.PrivateKey hosted in the node. If the PublicKey is actually a `class CompositeKey` the first leaf key found locally will be used for signing.
      Returns:
        The `class TransactionSignature` generated by signing with the internally held java.security.PrivateKey.
      See Also:
        `class SignedTransaction`, `class SignatureMetadata`

    - #### createSignature

          @NotNull
          public static TransactionSignature createSignature(ServiceHub $this,
                                                                      @NotNull
                                                                      SignedTransaction signedTransaction)

      Helper method to create a signature for an existing (partially) `class SignedTransaction` using the default identity signing key of the node. The legal identity key is used to sign. Additional `class SignatureMetadata`, including the platform version used during signing and the cryptographic signature scheme use, is added to the signature.

      Parameters:
        `$this` - The SignedTransaction to which the signature will apply.
        `signedTransaction` - The SignedTransaction to which the signature will apply.
      Returns:
        the TransactionSignature generated by signing with the internally held identity PrivateKey.
      See Also:
        `class SignedTransaction`, `class SignatureMetadata`

    - #### addSignature

          @NotNull
          public static SignedTransaction addSignature(ServiceHub $this,
                                                                @NotNull
                                                                SignedTransaction signedTransaction,
                                                                @NotNull
                                                                java.security.PublicKey publicKey)

      Helper method to append an additional signature to an existing (partially) `class SignedTransaction`.

      Parameters:
        `$this` - The `class SignedTransaction` to which the signature will be added.
        `signedTransaction` - The PublicKey matching to a signing java.security.PrivateKey hosted in the node.If the PublicKey is actually a `class CompositeKey` the first leaf key found locally will be usedfor signing.
        `publicKey` - The PublicKey matching to a signing java.security.PrivateKey hosted in the node. If the PublicKey is actually a `class CompositeKey` the first leaf key found locally will be used for signing.
      Returns:
        A new `class SignedTransaction` with the addition of the new signature.
      See Also:
        `class SignedTransaction`

    - #### addSignature

          @NotNull
          public static SignedTransaction addSignature(ServiceHub $this,
                                                                @NotNull
                                                                SignedTransaction signedTransaction)

      Helper method to append an additional signature for an existing (partially) `class SignedTransaction` using the default identity signing key of the node.

      Parameters:
        `$this` - The `class SignedTransaction` to which the signature will be added.
        `signedTransaction` - The `class SignedTransaction` to which the signature will be added.
      Returns:
        A new `class SignedTransaction` with the addition of the new signature.
      See Also:
        `class SignedTransaction`

    - #### createSignature

          @NotNull
          public static TransactionSignature createSignature(ServiceHub $this,
                                                                      @NotNull
                                                                      FilteredTransaction filteredTransaction,
                                                                      @NotNull
                                                                      java.security.PublicKey publicKey)

      Helper method to create a signature for a FilteredTransaction. Additional `class SignatureMetadata`, including the platform version used during signing and the cryptographic signature scheme use, is added to the signature.

      Parameters:
        `$this` - the `class FilteredTransaction` to which the signature will apply.
        `filteredTransaction` - The PublicKey matching to a signing java.security.PrivateKey hosted in the node.If the PublicKey is actually a `class CompositeKey` the first leaf key found locally will be usedfor signing.
        `publicKey` - The PublicKey matching to a signing java.security.PrivateKey hosted in the node. If the PublicKey is actually a `class CompositeKey` the first leaf key found locally will be used for signing.
      Returns:
        The `class TransactionSignature` generated by signing with the internally held java.security.PrivateKey.
      See Also:
        `class SignatureMetadata`

    - #### createSignature

          @NotNull
          public static TransactionSignature createSignature(ServiceHub $this,
                                                                      @NotNull
                                                                      FilteredTransaction filteredTransaction)

      Helper method to create a signature for a FilteredTransaction using the default identity signing key of the node. The legal identity key is used to sign. Additional `class SignatureMetadata`, including the platform version used during signing and the cryptographic signature scheme use, is added to the signature.

      Parameters:
        `$this` - the FilteredTransaction to which the signature will apply.
        `filteredTransaction` - the FilteredTransaction to which the signature will apply.
      Returns:
        the `class TransactionSignature` generated by signing with the internally held identity java.security.PrivateKey.
      See Also:
        `class SignatureMetadata`

    - #### getAppContext

          @NotNull
          public static CordappContext getAppContext(ServiceHub $this)

      See `CordappProvider.getAppContext`

      See Also:
        `CordappProvider.getAppContext`