@@ -8,58 +8,57 @@ var hfc = require('fabric-client');
8
8
var path = require ( 'path' ) ;
9
9
10
10
var options = {
11
- wallet_path : path . join ( __dirname , './network/creds' ) ,
12
- user_id : 'PeerAdmin' ,
13
- channel_id : 'mychannel' ,
14
- chaincode_id : 'fabcar' ,
15
- network_url : 'grpc://localhost:7051' ,
16
- } ;
11
+ wallet_path : path . join ( __dirname , './network/creds' ) ,
12
+ user_id : 'PeerAdmin' ,
13
+ channel_id : 'mychannel' ,
14
+ chaincode_id : 'fabcar' ,
15
+ network_url : 'grpc://localhost:7051' ,
16
+ } ;
17
17
18
18
var channel = { } ;
19
19
var client = null ;
20
20
21
- Promise . resolve ( ) . then ( ( ) => {
22
- console . log ( "Create a client and set the wallet location" ) ;
23
- client = new hfc ( ) ;
24
- return hfc . newDefaultKeyValueStore ( { path : options . wallet_path } ) ;
21
+ Promise . resolve ( ) . then ( ( ) => {
22
+ console . log ( "Create a client and set the wallet location" ) ;
23
+ client = new hfc ( ) ;
24
+ return hfc . newDefaultKeyValueStore ( { path : options . wallet_path } ) ;
25
25
} ) . then ( ( wallet ) => {
26
- console . log ( "Set wallet path, and associate user " , options . user_id , " with application" ) ;
27
- client . setStateStore ( wallet ) ;
28
- return client . getUserContext ( options . user_id , true ) ;
29
- } ) . then ( ( user ) => {
30
- console . log ( "Check user is enrolled, and set a query URL in the network" ) ;
31
- if ( user === undefined || user . isEnrolled ( ) === false ) {
32
- console . error ( "User not defined, or not enrolled - error" ) ;
33
- }
34
- channel = client . newChannel ( options . channel_id ) ;
35
- channel . addPeer ( client . newPeer ( options . network_url ) ) ;
36
- return ;
37
- } ) . then ( ( ) => {
38
- console . log ( "Make query" ) ;
39
- var transaction_id = client . newTransactionID ( ) ;
40
- console . log ( "Assigning transaction_id: " , transaction_id . _transaction_id ) ;
26
+ console . log ( "Set wallet path, and associate user " , options . user_id , " with application" ) ;
27
+ client . setStateStore ( wallet ) ;
28
+ return client . getUserContext ( options . user_id , true ) ;
29
+ } ) . then ( ( user ) => {
30
+ console . log ( "Check user is enrolled, and set a query URL in the network" ) ;
31
+ if ( user === undefined || user . isEnrolled ( ) === false ) {
32
+ console . error ( "User not defined, or not enrolled - error" ) ;
33
+ }
34
+ channel = client . newChannel ( options . channel_id ) ;
35
+ channel . addPeer ( client . newPeer ( options . network_url ) ) ;
36
+ return ;
37
+ } ) . then ( ( ) => {
38
+ console . log ( "Make query" ) ;
39
+ var transaction_id = client . newTransactionID ( ) ;
40
+ console . log ( "Assigning transaction_id: " , transaction_id . _transaction_id ) ;
41
41
42
- // queryCar - requires 1 argument, ex: args: ['CAR4'],
43
- // queryAllCars - requires no arguments , ex: args: [''],
44
- const request = {
45
- chaincodeId : options . chaincode_id ,
46
- txId : transaction_id ,
47
- fcn : 'queryAllCars' ,
48
- args : [ '' ]
49
- } ;
50
- return channel . queryByChaincode ( request ) ;
51
- } ) . then ( ( query_responses ) => {
52
- console . log ( "returned from query" ) ;
53
- if ( ! query_responses . length ) {
54
- console . log ( "No payloads were returned from query" ) ;
55
- } else {
56
- console . log ( "Query result count = " , query_responses . length )
57
- }
58
- if ( query_responses [ 0 ] instanceof Error ) {
59
- console . error ( "error from query = " , query_responses [ 0 ] ) ;
60
- }
61
- console . log ( "Response is " , query_responses [ 0 ] . toString ( ) ) ;
62
- } )
63
- . catch ( ( err ) => {
64
- console . error ( "Caught Error" , err ) ;
42
+ // queryCar - requires 1 argument, ex: args: ['CAR4'],
43
+ // queryAllCars - requires no arguments , ex: args: [''],
44
+ const request = {
45
+ chaincodeId : options . chaincode_id ,
46
+ txId : transaction_id ,
47
+ fcn : 'queryAllCars' ,
48
+ args : [ '' ]
49
+ } ;
50
+ return channel . queryByChaincode ( request ) ;
51
+ } ) . then ( ( query_responses ) => {
52
+ console . log ( "returned from query" ) ;
53
+ if ( ! query_responses . length ) {
54
+ console . log ( "No payloads were returned from query" ) ;
55
+ } else {
56
+ console . log ( "Query result count = " , query_responses . length )
57
+ }
58
+ if ( query_responses [ 0 ] instanceof Error ) {
59
+ console . error ( "error from query = " , query_responses [ 0 ] ) ;
60
+ }
61
+ console . log ( "Response is " , query_responses [ 0 ] . toString ( ) ) ;
62
+ } ) . catch ( ( err ) => {
63
+ console . error ( "Caught Error" , err ) ;
65
64
} ) ;
0 commit comments