github.com/kchristidis/fabric@v1.0.4-0.20171028114726-837acd08cde1/examples/chaincode/go/utxo/README.md (about) 1 ### UTXO Chaincode 2 3 The UTXO example chaincode contains a single invocation function named `execute`. This function accepts BASE64 encoded transactions from the Bitcoin network. This chaincode will parse the transactions and pass the transaction components to the Bitcoin libconsensus C library for script verification. 4 5 The purpose of this chaincode is to 6 7 1. Demonstrate how the world state can be used to store and process unspent transaction outputs (UTXO). 8 9 2. Demonstrate how to include and use a C library from within a chaincode. 10 11 A client for exercising this chaincode is avilable at https://github.com/srderson/hyperledger-fabric-utxo-client-java. 12 13 14 The following are instructions for building and deploying the UTXO chaincode in Hypereledger Fabric. All commands should be run with vagrant. 15 16 First, build the Docker image for the UTXO chaincode. 17 18 ``` 19 cd $GOPATH/src/github.com/hyperledger/fabric/examples/chaincode/go/utxo/ 20 docker build -t utxo:0.1.0 . 21 ``` 22 23 Next, modify the `core.yaml` file in the Hyperledger Fabric project to point to the local Docker image that was built in the previous step. In the core.yaml file find `chaincode.golang.Dockerfile` and change it from from `hyperledger/fabric-baseimage` to `utxo:0.1.0` 24 25 Start the peer using the following commands 26 ``` 27 peer node start 28 ``` 29 30 In a second window, deploy the example UTXO chaincode 31 ``` 32 CORE_PEER_ADDRESS=localhost:7051 peer chaincode deploy -p github.com/hyperledger/fabric/examples/chaincode/go/utxo -c '{"Function":"init", "Args": []}' 33 ``` 34 Wait about 30 seconds for the chaincode to be deployed. Output from the window where the peer is running will indicate that this is successful. 35 36 Next, find the `image ID` for the deployed chaincode. Run 37 ``` 38 docker images 39 ``` 40 and look for the image ID of the most recently deployed chaincode. The image ID will likely be similar to 41 ``` 42 dev-jdoe-cbe6be7ed67931b9be2ce31dd833e523702378bef91b29917005f0eaa316b57e268e19696093d48b91076f1134cbf4b06afd78e6afd947133f43cb51bf40b0a4 43 ``` 44 Make a note of this as we'll be using it later. 45 46 Stop the running peer. 47 48 Build a peer docker image by running the following test. This will allow for easy testing of the chaincode by giving us the ability to reset the database to a clean state. 49 ``` 50 go test github.com/hyperledger/fabric/core/container -run=BuildImage_Peer 51 ``` 52 53 Using the Docker image that we just built, start a peer within a container in `chaincodedev` mode. 54 ``` 55 docker run -it -p 7051:7051 -p 7053:7053 hyperledger/fabric-peer peer node start --peer-chaincodedev 56 ``` 57 58 59 In another window, start UTXO chaincode in a container. The <image ID> refers to the UTXO image ID noted in a prior step. 60 ``` 61 docker run -it <image ID> /bin/bash 62 ``` 63 64 Build the UTXO chaincode. 65 ``` 66 cd $GOPATH/src/github.com/hyperledger/fabric/examples/chaincode/go/utxo/ 67 go build 68 CORE_PEER_ADDRESS=172.17.0.2:7051 CORE_CHAINCODE_ID_NAME=utxo ./utxo 69 ``` 70 71 In another window, deploy the chaincode 72 ``` 73 peer chaincode deploy -n utxo -c '{"Function":"init", "Args": []}' 74 ``` 75 76 The chaincode is now deployed and ready to accept transactions. 77 78 <a rel="license" href="http://creativecommons.org/licenses/by/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by/4.0/88x31.png" /></a><br />This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by/4.0/">Creative Commons Attribution 4.0 International License</a>. 79 s