github.com/muhammedhassanm/blockchain@v0.0.0-20200120143007-697261defd4d/sawtooth-core-master/sdk/javascript/processor/handler.js (about)

     1  /**
     2   * Copyright 2017 Intel Corporation
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   * ------------------------------------------------------------------------------
    16   */
    17  
    18  'use strict'
    19  
    20  /**
    21   * TransactionHandler is the interface that defines the business logic
    22   * for a new transaction family. This is the only interface that needs
    23   * to be implemented to create a new transaction family.
    24   *
    25   * The transactionFamilyName, versions, and namespaces properties are
    26   * used by the processor to route processing requests to the handler.
    27   */
    28  class TransactionHandler {
    29    /**
    30     * @param {string} transactionFamilyName - the name of the
    31     * transaction family that this handler can process, e.g. "intkey"
    32     * @param {string[]} versions - the versions of the transaction
    33     * family that this handler can process, e.g. ["1.0", "1.5"]
    34     * @param {string[]} namespaces - a list containing all of the
    35     * handler's namespaces, e.g. ["abcdef"]
    36     */
    37    constructor (transactionFamilyName, versions, namespaces) {
    38      _readOnlyProperty(this, 'transactionFamilyName', transactionFamilyName)
    39      _readOnlyProperty(this, 'versions', versions)
    40      _readOnlyProperty(this, 'namespaces', namespaces)
    41    }
    42  
    43    /**
    44     * Apply is the single method where all the business logic for a
    45     * transaction family is defined. The method will be called by the
    46     * transaction processor upon receiving a TpProcessRequest that the
    47     * handler understands and will pass in the TpProcessRequest and an
    48     * initialized instance of the Context type.
    49     *
    50     * @param {TpProcessRequest} transactionProcessRequest - the
    51     * transaction to be processed
    52     * @param {Context} context - the context the handler can use to
    53     * access state
    54     */
    55    apply (transactionProcessRequest, context) {
    56      throw new Error('apply(TpProcessRequest, context) not implemented')
    57    }
    58  }
    59  
    60  const _readOnlyProperty = (instance, propertyName, value) =>
    61    Object.defineProperty(instance, propertyName, {
    62      writeable: false,
    63      enumerable: true,
    64      congigurable: true,
    65      value
    66    })
    67  
    68  module.exports = {
    69    TransactionHandler
    70  }