hyperledger-archives / fabric

THIS IS A READ-ONLY historic repository. Current development is at https://gerrit.hyperledger.org/r/#/admin/projects/fabric . pull requests not accepted
https://gerrit.hyperledger.org/
Apache License 2.0
1.17k stars 1.01k forks source link

How to get the transaction detail from payloadHash? #1890

Open huhaiqing opened 8 years ago

huhaiqing commented 8 years ago

Hi,

When I query the transaction by REST API, it returns the below json data. command: curl http://localhost:5000/transactions/a11780d3-0c81-41d2-9cf4-883e6a241cd8 -X GET -i -H "Content-Type:application/json" -H "Accept:application/json"

Response: { "type": 2, "chaincodeID": "EoABNTExNTFhMDM0MjY3Yjk1ZWZlZmRkOGMzNmRkZTAxMjlhMWEzMTA4ZTgzMDUzNzBiYWRhYWJkZjgwYWNjNzYzMDlhZGNkYzU1NDhhZmFmMTFhMGMzNzhhMWNlNjJlN2E0ZTNiYWFhNDMxMDZmOTVhMzZhNDJjNjJhMzc5YzJkMDg=", "payload": "CsgBCAESgwESgAE1MTE1MWEwMzQyNjdiOTVlZmVmZGQ4YzM2ZGRlMDEyOWExYTMxMDhlODMwNTM3MGJhZGFhYmRmODBhY2M3NjMwOWFkY2RjNTU0OGFmYWYxMWEwYzM3OGExY2U2MmU3YTRlM2JhYWE0MzEwNmY5NWEzNmE0MmM2MmEzNzljMmQwOBo+Cg9hZGRfbG9hbl9jcmVkaXQSC2xhb3dhbmcxOTg3Eh4yMDE2LTEyLTAxIGxvYW4gZnJvbSBBQkMgNTAwMDA=", "uuid": "a11780d3-0c81-41d2-9cf4-883e6a241cd8", "timestamp": { "seconds": 1466144965, "nanos": 666092188 }, "nonce": "G3Uw47NsaYSArVIqPdvGoQCXFQJVgUo+", "cert": "MIICPTCCAeOgAwIBAgIQVlb50yJvTx6Sd97JmV+N3DAKBggqhkjOPQQDAzAxMQswCQYDVQQGEwJVUzEUMBIGA1UEChMLSHlwZXJsZWRnZXIxDDAKBgNVBAMTA3RjYTAeFw0xNjA2MTcwNjI2MzhaFw0xNjA5MTUwNjI2MzhaMDExCzAJBgNVBAYTAlVTMRQwEgYDVQQKEwtIeXBlcmxlZGdlcjEMMAoGA1UEAxMDamltMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE7CxVflqb1xQhcV90aawDqd79MANRo1uRtkTZjMZArKhcm2GEUyxt5tlqO3pfPJcqkFepLXH0jewK8TJzTaB+zaOB3DCB2TAOBgNVHQ8BAf8EBAMCB4AwDAYDVR0TAQH/BAIwADANBgNVHQ4EBgQEAQIDBDAPBgNVHSMECDAGgAQBAgMEME0GBioDBAUGBwEB/wRAc7aCZ7cJJKC+tnRWisPTTzCXnXIScFYhgFkqDKYm83sPnNEh1DZIIlGIj+8lVA1+7UYsTCM8yU7DSOiVKEyuNTBKBgYqAwQFBggEQIFuEOC2SabQkY5taiARdhGYprPVvB6fsSZ2aa16lVHvKiwYk6TIz10YV2tRhXx/PpbPnA+sMpWlWWAKRzCucvcwCgYIKoZIzj0EAwMDSAAwRQIhAJVy7224L4P3HIhhw5Ma+0mpz8z0lCxm9Y/u5XrRc3oNAiBjv1PGXCuF+bOCtIxb9d7KLBwZBI8Ec3yF97ONdqdmkQ==", "signature": "MEUCIQDUysHHpfTD9Eiw/LDOBLHnWnUJSSFOSq8wiLae3rCI5QIgcMU8OgED2+2HOCQ8exIbMSfYMIwR2jKxggoysUJChQo=" }

I don't know how to get the transaction data from the payload hash, could you tell me how to get the real value of this paload?

Thanks in advance.

Regards Harry

mastersingh24 commented 8 years ago

@huhaiqing - the chaincodeID and payload are base64 encoded so any base64 decoding library will work

51151a034267b95efefdd8c36dde0129a1a3108e8305370badaabdf80acc76309adcdc5548afaf11a0c378a1ce62e7a4e3baaa43106f95a36a42c62a379c2d08

51151a034267b95efefdd8c36dde0129a1a3108e8305370badaabdf80acc76309adcdc5548afaf11a0c378a1ce62e7a4e3baaa43106f95a36a42c62a379c2d08> add_loan_credit laowang19872016-12-01 loan from ABC 50000

JiZiJian commented 8 years ago

@mastersingh24 This sample is OK for just using base64 decoding, but if you set CORE_SECURITY_PRIVACY=true, then the payload will be encrypted like below, can't just use base64 decoding, do you know how to decrypt it? "transactions": [ { "type": 2, "chaincodeID": "BOT0Gws+NQrhIV9bsAz1j9Ae+mePggCxY/jypT7kOV1s+FtQ74WkW59bzSDHNmY5lmizcHhCLzaNj7fkD4xQ8Rdj2vKU0h4XqnrYpDIWyDSMVmsuQLiJD3JV0fTkBRM3ng+99xUBk5uVP7FFiRYKI0QxW0/Z5lQ=", "payload": "BBFFhuRoDtlNvU0SI0YKwPH+gpQXHAVE/AJ4Xn8BYZwN6NsN49uwytrMMM3u+O9Wk4G36XKqjUBgXeL9uyFxTnXNmzTkB4GUGRB51Mn9QI0GvXUDFFsq9KEMGjsCNaQzWe/TxoMoIWAY5CiNcxISv87QX+Fgi17LW5BQUdt5xnLnDZrj6X+WRMyAu/KyDtTa+9Fr", "uuid": "e0a8029c-61b9-492a-a1b6-2ccaceb3aa40", "timestamp": { "seconds": 1469425541, "nanos": 461776071 }, "confidentialityLevel": 1, "confidentialityProtocolVersion": "1.2", "nonce": "PysQ3yVJadZgpr9XOE022RcFO9b/RJBE", "toValidators": "BPiR/rQbaD43Lxqz13v4GLsOpzcCxrMBIrUvvu19ZO3XK/nD7B87NDpov+HU+p4Ac6xKDuu3tHsH3KOYZypRnsNL+eMO9fTbsQdRpydUxJXlrWrt2nwNGVPpw+o3IZG7fF/ne+OAlVkkmh48/J13lBel9JWThA/4tZVUvg3ZsEXagv1yX4/pNrw8zYubyftjnUJ30167lRGoB6wytzYKkHcskg4dhT5xegqR33wIh/lGUulj81D+4H9a5QYNKSEUngq0aOC1Yku4BOtIQn/NqGlm2mAlAgxOt674mxRS7+/g+kxxOOTbcVDHEeQ6iavA", "cert": "MIICRDCCAeqgAwIBAgIQGK8NCAEzRMaAztnjb12SFDAKBggqhkjOPQQDAzAxMQswCQYDVQQGEwJVUzEUMBIGA1UEChMLSHlwZXJsZWRnZXIxDDAKBgNVBAMTA3RjYTAeFw0xNjA3MTIwOTI1NDJaFw0xNjEwMTAwOTI1NDJaMDgxCzAJBgNVBAYTAlVTMRQwEgYDVQQKEwtIeXBlcmxlZGdlcjETMBEGA1UEAwwKdGVzdF91c2VyMTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABNXvrugSNKLdYMAPi3nhmnVF0Y5b6znU0As99kVLTt8HYv1FLq3+2I6H/FQ2N8kxbL7s6rxiNjoNQYdcg0mdsx+jgdwwgdkwDgYDVR0PAQH/BAQDAgeAMAwGA1UdEwEB/wQCMAAwDQYDVR0OBAYEBAECAwQwDwYDVR0jBAgwBoAEAQIDBDBNBgYqAwQFBgcBAf8EQGnMbXwKJHDbfEV84iMgPSdtmZrlh0vW+73HWYP9YpeIPnzYXaEWYpNU2bWM89Gl29EuvTC5MdtVOQzyjfNIcMYwSgYGKgMEBQYIBEAbeTqm1n8th2JRszPDRvLr3/VqA3gUnKeuRxoYxHe2SZ9CmPvsS+1xdCpPvluCwl9h6mbYESDPU78iibwMjJnlMAoGCCqGSM49BAMDA0gAMEUCIQCcPtDzIyhr+4JvvYPN36ynoI7WbifZ3rxKhu0lsCljkQIgOuZ9oKLNLu6ncdFYLQKUe3tL/Xp2svpY8U2700qED1Y=", "signature": "MEQCIBR0TQxubzRBjc2WTih2eyTWGHOlkd4g8dIsYZHUaVKOAiA32VWdkwvTPTtc5GG6jKau+ZtNXyg0L9+GOtPJ7ZdY3Q==" } ],

iiiLiQuiDiii commented 8 years ago

I also have a question about decoding the payload : there are some characters which don't get decoded properly. ������� what are those?

JiZiJian commented 8 years ago

@iiiLiQuiDiii the payload message is firstly encoded by protobuf and then encoded by base64 , so after decoded by base64, you need to decode it using protobuf to get the original payload message, here is the protobuf definition file https://github.com/hyperledger/fabric/blob/232346ba60a3b0d3a4022c8da9e6d07a870f4441/protos/fabric.proto