Hyperledger Fabric SDK例fabric-samples-「balance-transfer」の9「指定された取引情報の照会」


本文はすでに私の公衆番号Fabric技術でオリジナルの先発を分かち合った.転載は出典を明記してください.https://blog.csdn.net/qq_27818541/article/details/78517110出典:【BigManingのブログ】

前言


取引idに基づいて取引詳細を照会します.次のパラメータが必要です.
  • 取引id
  • peerノード
  • channel

  • 6番目の記事の取引id eb058850e7247ad0bc25ec57ced1cd1255666c390ca0c9300858ce6e57175221を多重化することができます.

    ルート


    指定したpeerおよびトランザクションidを受信し、パラメータを検証して特定の実装に転送します.app.js
    // id    Query Get Transaction by Transaction ID
    app.get('/channels/:channelName/transactions/:trxnId', function(req, res) {
        logger.debug(
            '================ GET TRANSACTION BY TRANSACTION_ID ======================'
        );
        logger.debug('channelName : ' + req.params.channelName);
        let trxnId = req.params.trxnId;
        let peer = req.query.peer;
        if (!trxnId) {
            res.json(getErrorMessage('\'trxnId\''));
            return;
        }
        //  
        query.getTransactionByID(peer, trxnId, req.username, req.orgname)
            .then(function(message) {
                res.send(message);
            });
    });

    具体的な実装

    query.js
    var getTransactionByID = function(peer, trxnID, username, org) {
        //1  peer 
        var target = buildTarget(peer, org);
        //2  channel
        var channel = helper.getChannelForOrg(org);
        //3  
        return helper.getRegisteredUsers(username, org).then((member) => {
            //4  
            return channel.queryTransaction(trxnID, target);
        }, (err) => {
            logger.info('Failed to get submitter "' + username + '"');
            return 'Failed to get submitter "' + username + '". Error: ' + err.stack ?
                err.stack : err;
        }).then((response_payloads) => {
            //5  
            if (response_payloads) {
                logger.debug(response_payloads);
                return response_payloads;
            } else {
                logger.error('response_payloads is null');
                return 'response_payloads is null';
            }
        }, (err) => {
            logger.error('Failed to send query due to error: ' + err.stack ? err.stack :
                err);
            return 'Failed to send query due to error: ' + err.stack ? err.stack : err;
        }).catch((err) => {
            logger.error('Failed to query with error:' + err.stack ? err.stack : err);
            return 'Failed to query with error:' + err.stack ? err.stack : err;
        });
    };

    基本プロセス


    Created with Raphal2.1.2 Start現在のユーザーがchannelを通じて取引情報を照会する処理結果Endを取得

    APIアクセス

    echo "GET query Transaction by TransactionID"
    echo
    curl -s -X GET http://localhost:4000/channels/mychannel/transactions/eb058850e7247ad0bc25ec57ced1cd1255666c390ca0c9300858ce6e57175221?peer=peer1 \
      -H "authorization: Bearer $ORG1_TOKEN" \
      -H "content-type: application/json"
    echo
    echo

    コンソール印刷:
    
    GET query Transaction by TransactionID
    
    {"validationCode":0,"transactionEnvelope":{"signature":{"type":"Buffer","data":[48,69,2,33,0,177,26,37,152,112,224,187,240,114,88,79,53,58,177,81,95,71,89,200,84,235,71,91,237,204,186,56,181,195,98,164,215,2,32,102,121,110,5,234,233,1,94,99,238,162,8,112,138,154,142,145,133,56,33,199,34,26,132,60,75,208,125,235,250,233,124]},"payload":{"header":{"channel_header":{"type":"ENDORSER_TRANSACTION","version":3,"timestamp":"Mon Oct 16 2017 11:07:40 GMT+0800 (CST)","channel_id":"mychannel","tx_id":"eb058850e7247ad0bc25ec57ced1cd1255666c390ca0c9300858ce6e57175221","epoch":0,"extension":{"type":"Buffer","data":[18,6,18,4,109,121,99,99]}},"signature_header":{"creator":{"Mspid":"Org1MSP","IdBytes":"-----BEGIN CERTIFICATE-----
    MIIB7zCCAZWgAwIBAgIUTQ2LENWmI4cRoknmGQFqZ6a+8uswCgYIKoZIzj0EAwIw
    czELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNh
    biBGcmFuY2lzY28xGTAXBgNVBAoTEG9yZzEuZXhhbXBsZS5jb20xHDAaBgNVBAMT
    E2NhLm9yZzEuZXhhbXBsZS5jb20wHhcNMTcxMDE2MDMwMjAwWhcNMTgxMDE2MDMw
    MjAwWjAOMQwwCgYDVQQDEwNKaW0wWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAASz
    4qdbmk/SsIFYmxxFveSfWDrqnX1GZ5jHt2XEypaXPcWIIOWp23WrF4QawVjpOJrQ
    0TCmgn3AaC3LLSxdzLNJo2wwajAOBgNVHQ8BAf8EBAMCB4AwDAYDVR0TAQH/BAIw
    ADAdBgNVHQ4EFgQU42nR4T+yFtzFUcCWx06codR4rU8wKwYDVR0jBCQwIoAgDnKS
    JOiz8xeEyKk8W4729MHJHZ5uV3xFwzFjYJ/kABEwCgYIKoZIzj0EAwIDSAAwRQIh
    ANpJucU0QfIApR7BrR2wzqU22Oq1Mv2slupaSSEhqUcuAiAK0iN+dkb8qsJPbUHp
    sX26SgxX8YIiKWpL0t+OYEqjsw==
    -----END CERTIFICATE-----
    "
    },"nonce":{"type":"Buffer","data":[169,122,192,203,43,77,68,42,128,240,8,81,90,35,63,156,13,236,81,59,126,148,200,17]}}},"data":{"actions":[{"header":{"creator":{"Mspid":"Org1MSP","IdBytes":"-----BEGIN CERTIFICATE-----
    MIIB7zCCAZWgAwIBAgIUTQ2LENWmI4cRoknmGQFqZ6a+8uswCgYIKoZIzj0EAwIw
    czELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNh
    biBGcmFuY2lzY28xGTAXBgNVBAoTEG9yZzEuZXhhbXBsZS5jb20xHDAaBgNVBAMT
    E2NhLm9yZzEuZXhhbXBsZS5jb20wHhcNMTcxMDE2MDMwMjAwWhcNMTgxMDE2MDMw
    MjAwWjAOMQwwCgYDVQQDEwNKaW0wWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAASz
    4qdbmk/SsIFYmxxFveSfWDrqnX1GZ5jHt2XEypaXPcWIIOWp23WrF4QawVjpOJrQ
    0TCmgn3AaC3LLSxdzLNJo2wwajAOBgNVHQ8BAf8EBAMCB4AwDAYDVR0TAQH/BAIw
    ADAdBgNVHQ4EFgQU42nR4T+yFtzFUcCWx06codR4rU8wKwYDVR0jBCQwIoAgDnKS
    JOiz8xeEyKk8W4729MHJHZ5uV3xFwzFjYJ/kABEwCgYIKoZIzj0EAwIDSAAwRQIh
    ANpJucU0QfIApR7BrR2wzqU22Oq1Mv2slupaSSEhqUcuAiAK0iN+dkb8qsJPbUHp
    sX26SgxX8YIiKWpL0t+OYEqjsw==
    -----END CERTIFICATE-----
    "
    },"nonce":{"type":"Buffer","data":[169,122,192,203,43,77,68,42,128,240,8,81,90,35,63,156,13,236,81,59,126,148,200,17]}},"payload":{"chaincode_proposal_payload":{"input":{"type":"Buffer","data":[10,28,8,1,18,6,18,4,109,121,99,99,26,16,10,4,109,111,118,101,10,1,97,10,1,98,10,2,49,48]}},"action":{"proposal_response_payload":{"proposal_hash":"36c833a60246db1941e7c403e1e3d3cf2f240bdc40c210da80278d463fb094c6","extension":{"results":{"data_model":0,"ns_rwset":[{"namespace":"lscc","rwset":{"reads":[{"key":"mycc","version":{"block_num":{"low":1,"high":0,"unsigned":true},"tx_num":{"low":0,"high":0,"unsigned":true}}}],"range_queries_info":[],"writes":[]}},{"namespace":"mycc","rwset":{"reads":[{"key":"a","version":{"block_num":{"low":1,"high":0,"unsigned":true},"tx_num":{"low":0,"high":0,"unsigned":true}}},{"key":"b","version":{"block_num":{"low":1,"high":0,"unsigned":true},"tx_num":{"low":0,"high":0,"unsigned":true}}}],"range_queries_info":[],"writes":[{"key":"a","is_delete":false,"value":"90"},{"key":"b","is_delete":false,"value":"210"}]}}]},"events":{"chaincode_id":"","tx_id":"","event_name":"","payload":{"type":"Buffer","data":[]}},"response":{"status":200,"message":"","payload":""}}},"endorsements":[{"endorser":{"Mspid":"Org1MSP","IdBytes":"-----BEGIN -----
    MIICGDCCAb+gAwIBAgIQPcMFFEB/vq6mEL6vXV7aUTAKBggqhkjOPQQDAjBzMQsw
    CQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZy
    YW5jaXNjbzEZMBcGA1UEChMQb3JnMS5leGFtcGxlLmNvbTEcMBoGA1UEAxMTY2Eu
    b3JnMS5leGFtcGxlLmNvbTAeFw0xNzA2MjMxMjMzMTlaFw0yNzA2MjExMjMzMTla
    MFsxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1T
    YW4gRnJhbmNpc2NvMR8wHQYDVQQDExZwZWVyMC5vcmcxLmV4YW1wbGUuY29tMFkw
    EwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEzS9k2gCKHcat8Wj4T2nB1uyC8R2zg3um
    xdTL7nmgFWp0uyCCbQQxD/VS+8R/3DNvEFkvzhcjc9NU/nRqMirpLqNNMEswDgYD
    VR0PAQH/BAQDAgeAMAwGA1UdEwEB/wQCMAAwKwYDVR0jBCQwIoAgDnKSJOiz8xeE
    yKk8W4729MHJHZ5uV3xFwzFjYJ/kABEwCgYIKoZIzj0EAwIDRwAwRAIgHBdxbHUG
    rFUzKPX9UmmN3SwigWcRUREUy/GTb3hDIAsCIEF1BxTqv8ilQYE8ql0wJL4mTber
    HE6DFYvvBCUnicUh
    -----END -----
    "
    },"signature":{"type":"Buffer","data":[48,68,2,32,63,184,99,69,87,244,62,157,237,78,167,227,25,195,112,215,214,197,244,114,183,91,98,30,135,103,97,82,53,102,214,64,2,32,96,34,207,210,245,68,136,213,125,235,146,198,246,248,179,48,130,115,48,159,54,172,212,58,1,142,37,211,118,47,195,173]}},{"endorser":{"Mspid":"Org1MSP","IdBytes":"-----BEGIN -----
    MIICGjCCAcCgAwIBAgIRAI+BBtEBvpOqhfRZZH7eV/YwCgYIKoZIzj0EAwIwczEL
    MAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNhbiBG
    cmFuY2lzY28xGTAXBgNVBAoTEG9yZzEuZXhhbXBsZS5jb20xHDAaBgNVBAMTE2Nh
    Lm9yZzEuZXhhbXBsZS5jb20wHhcNMTcwNjIzMTIzMzE5WhcNMjcwNjIxMTIzMzE5
    WjBbMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMN
    U2FuIEZyYW5jaXNjbzEfMB0GA1UEAxMWcGVlcjEub3JnMS5leGFtcGxlLmNvbTBZ
    MBMGByqGSM49AgEGCCqGSM49AwEHA0IABCnT04ltvjsgiZVuCGLsRYzEiCTJZlZw
    h3HT/273B3NkWA7wrlyK7FfAanIyexuR1UI9m4+YKNqFG6cgYnf8MsejTTBLMA4G
    A1UdDwEB/wQEAwIHgDAMBgNVHRMBAf8EAjAAMCsGA1UdIwQkMCKAIA5ykiTos/MX
    hMipPFuO9vTByR2ebld8RcMxY2Cf5AARMAoGCCqGSM49BAMCA0gAMEUCIQCSRdWm
    i4IgVUajvzWVxyE/wi7n617pVqS4+nJ7gbTRjQIgefzBwS+bkNhPc3/rktySFLRC
    WMnq87KyqMLc6iRaJx0=
    -----END -----
    "
    },"signature":{"type":"Buffer","data":[48,68,2,32,76,217,173,123,31,20,202,218,178,182,34,209,106,247,120,120,18,17,185,185,79,107,181,134,40,40,117,89,215,41,176,186,2,32,1,76,239,78,145,183,212,170,26,111,86,80,140,178,212,198,166,201,33,28,86,181,198,25,15,79,227,97,43,56,101,216]}}]}}}]}}}}

    バックグラウンド印刷:
    [2017-10-16 11:07:43.140] [DEBUG] SampleWebApp - Decoded from JWT token: username - Jim, orgname - org1
    [2017-10-16 11:07:43.140] [DEBUG] SampleWebApp - ================ GET TRANSACTION BY TRANSACTION_ID ======================
    [2017-10-16 11:07:43.141] [DEBUG] SampleWebApp - channelName : mychannel
    [2017-10-16 11:07:43.142] [DEBUG] Helper - [FileKeyValueStore.js]: FileKeyValueStore.js - constructor
    [2017-10-16 11:07:43.144] [DEBUG] Helper - [FileKeyValueStore.js]: FileKeyValueStore -- getValue
    [2017-10-16 11:07:43.145] [DEBUG] Helper - [crypto_ecdsa_aes]: importKey - start
    [2017-10-16 11:07:43.146] [DEBUG] Helper - [crypto_ecdsa_aes]: importKey - have the key [Circular]
    [2017-10-16 11:07:43.146] [DEBUG] Helper - [utils.CryptoKeyStore]: _getKeyStore resolving store
    [2017-10-16 11:07:43.146] [DEBUG] Helper - [ecdsa/key.js]: ECDSA curve param X: b3e2a75b9a4fd2b081589b1c45bde49f583aea9d7d466798c7b765c4ca96973d
    [2017-10-16 11:07:43.146] [DEBUG] Helper - [ecdsa/key.js]: ECDSA curve param Y: c58820e5a9db75ab17841ac158e9389ad0d130a6827dc0682dcb2d2c5dccb349
    [2017-10-16 11:07:43.146] [DEBUG] Helper - [FileKeyValueStore.js]: FileKeyValueStore -- setValue
    [2017-10-16 11:07:43.147] [DEBUG] Helper - [utils.CryptoKeyStore]: _getKeyStore resolving store
    [2017-10-16 11:07:43.147] [DEBUG] Helper - [FileKeyValueStore.js]: FileKeyValueStore -- getValue
    [2017-10-16 11:07:43.147] [DEBUG] Helper - [ecdsa/key.js]: ECDSA curve param X: b3e2a75b9a4fd2b081589b1c45bde49f583aea9d7d466798c7b765c4ca96973d
    [2017-10-16 11:07:43.147] [DEBUG] Helper - [ecdsa/key.js]: ECDSA curve param Y: c58820e5a9db75ab17841ac158e9389ad0d130a6827dc0682dcb2d2c5dccb349
    [2017-10-16 11:07:43.148] [DEBUG] Helper - [ecdsa/key.js]: ECDSA curve param X: b3e2a75b9a4fd2b081589b1c45bde49f583aea9d7d466798c7b765c4ca96973d
    [2017-10-16 11:07:43.148] [DEBUG] Helper - [ecdsa/key.js]: ECDSA curve param Y: c58820e5a9db75ab17841ac158e9389ad0d130a6827dc0682dcb2d2c5dccb349
    [2017-10-16 11:07:43.148] [DEBUG] Helper - [ecdsa/key.js]: ECDSA curve param X: b3e2a75b9a4fd2b081589b1c45bde49f583aea9d7d466798c7b765c4ca96973d
    [2017-10-16 11:07:43.148] [DEBUG] Helper - [ecdsa/key.js]: ECDSA curve param Y: c58820e5a9db75ab17841ac158e9389ad0d130a6827dc0682dcb2d2c5dccb349
    [2017-10-16 11:07:43.148] [DEBUG] Helper - [FileKeyValueStore.js]: FileKeyValueStore -- setValue
    [2017-10-16 11:07:43.148] [INFO] Helper - Successfully loaded member from persistence
    [2017-10-16 11:07:43.155] [DEBUG] Helper - [crypto_ecdsa_aes]: ecdsa signature:  Signature {
      r: 6d0ae79a06d8b5d9d593d8a22f9667e41ef41d7005f635e071d61730e4519868>,
      s: 2aa650cffd0dcf227f76add8a490a94eae4717a572576e2f56105d58cb21d292>,
      recoveryParam: 1 }
    [2017-10-16 11:07:43.167] [DEBUG] Query - { validationCode: 0,
      transactionEnvelope: 
       { signature: 30 45 02 21 00 b1 1a 25 98 70 e0 bb f0 72 58 4f 35 3a b1 51 5f 47 59 c8 54 eb 47 5b ed cc ba 38 b5 c3 62 a4 d7 02 20 66 79 6e 05 ea e9 01 5e 63 ee a2 ... >,
         payload: { header: [Object], data: [Object] } } }