github.com/adnan-c/fabric_e2e_couchdb@v0.6.1-preview.0.20170228180935-21ce6b23cf91/examples/chaincode/go/asset_management_interactive/app1/app1.go (about)

     1  /*
     2  Copyright IBM Corp. 2016 All Rights Reserved.
     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  package main
    18  
    19  import (
    20  	"os"
    21  	"time"
    22  
    23  	"github.com/hyperledger/fabric/core/crypto"
    24  	pb "github.com/hyperledger/fabric/protos"
    25  	"github.com/op/go-logging"
    26  	"google.golang.org/grpc"
    27  )
    28  
    29  var (
    30  	// Logging
    31  	appLogger = logging.MustGetLogger("app")
    32  
    33  	// NVP related objects
    34  	peerClientConn *grpc.ClientConn
    35  	serverClient   pb.PeerClient
    36  
    37  	// Alice is the deployer
    38  	alice crypto.Client
    39  
    40  	// Bob is the administrator
    41  	bob     crypto.Client
    42  	bobCert crypto.CertificateHandler
    43  )
    44  
    45  func deploy() (err error) {
    46  	appLogger.Debug("------------- Alice wants to assign the administrator role to Bob;")
    47  	// Deploy:
    48  	// 1. Alice is the deployer of the chaincode;
    49  	// 2. Alice wants to assign the administrator role to Bob;
    50  	// 3. Alice obtains, via an out-of-band channel, the ECert of Bob, let us call this certificate *BobCert*;
    51  	// 4. Alice constructs a deploy transaction, as described in *application-ACL.md*,  setting the transaction
    52  	// metadata to *DER(CharlieCert)*.
    53  	// 5. Alice submits th	e transaction to the fabric network.
    54  
    55  	resp, err := deployInternal(alice, bobCert)
    56  	if err != nil {
    57  		appLogger.Errorf("Failed deploying [%s]", err)
    58  		return
    59  	}
    60  	appLogger.Debugf("Resp [%s]", resp.String())
    61  	appLogger.Debugf("Chaincode NAME: [%s]-[%s]", chaincodeName, string(resp.Msg))
    62  
    63  	appLogger.Debug("Wait 60 seconds")
    64  	time.Sleep(60 * time.Second)
    65  
    66  	appLogger.Debug("------------- Done!")
    67  	return
    68  }
    69  
    70  func testAssetManagementChaincode() (err error) {
    71  	// Deploy
    72  	err = deploy()
    73  	if err != nil {
    74  		appLogger.Errorf("Failed deploying [%s]", err)
    75  		return
    76  	}
    77  
    78  	appLogger.Debug("Deployed!")
    79  
    80  	closeCryptoClient(alice)
    81  	closeCryptoClient(bob)
    82  
    83  	return
    84  }
    85  
    86  func main() {
    87  	// Initialize a non-validating peer whose role is to submit
    88  	// transactions to the fabric network.
    89  	// A 'core.yaml' file is assumed to be available in the working directory.
    90  	if err := initNVP(); err != nil {
    91  		appLogger.Debugf("Failed initiliazing NVP [%s]", err)
    92  		os.Exit(-1)
    93  	}
    94  
    95  	// Enable fabric 'confidentiality'
    96  	confidentiality(true)
    97  
    98  	// Exercise the 'asset_management' chaincode
    99  	if err := testAssetManagementChaincode(); err != nil {
   100  		appLogger.Debugf("Failed testing asset management chaincode [%s]", err)
   101  		os.Exit(-2)
   102  	}
   103  }