Search code examples
hyperledger-fabricblockchainhyperledger-composer

Transaction processor function - how can i know when data is commited/endorsed


I have a transaction processor function, for example.

/**
 * creates  transaction
 * @param {org.somenamespace.someMOdel} model
 * @transaction
 */
async function MyTransaction (model) {
    return getAssetRegistry('org.SomeTransaction')
        .then(function (result) {
             var factory = getFactory()
             var newInstruction = factory.newResource(
                 'namespace',
                 'asset',
                 'someId');

             return result.add(newInstruction).then(function() {
                 request.post({ uri : 'www..', json : { ... }});
                  // Added to our ledger here, but could it still fail endorsment ?
             });
     });
}

I need to call a rest API when the data is committed/endorsed and is 100% on the ledger across all peers (ie : it isnt going to be rejected).

Is this possible to do inside a transaction processor function, or any other method ?


Solution

  • Transaction processor functions run a proposal only, they will not know if their results will be successfully committed to the blockchain or not.

    Composer provides a client API (for which the rest server uses) which implements a submit/notify model. When you invoke a composer TP function from either a client (or through the composer rest server), if a success response comes back then you know that the transaction has been successfully committed. However it does NOT guarantee that it has been committed across all peers, it only guarantees that it has been committed to all the peers it is able to communicate with and receive a response to say it has been committed (but you can be sure that all peers will have it on the blockchain eventually)

    Your client application can submit a transaction, wait for a successful response then invoke your rest API.