1. Open Docker pull Mirror, in the https://hub.docker.com/can view the mirror version, in order to cooperate with the completion of We pull 0.6 version, and the tag renamed to latest
Docker Pull Hyperledger/fabric-peer:x86_64-0.6.1-preview
Docker Pull Hyperledger/fabric-membersrvc:latest
Docker images
2. Save the prepared docker-compose.yml to a local c/users/rjy for subsequent runs using
MEMBERSRVC:
image:hyperledger/fabric-membersrvc
ports:
-"7054:7054"
command:membersrvc
vp0 :
image:hyperledger/fabric-peer
ports:
-"7050:7050"
-"7051:7051"
-"7053:7053"
Environment:
-core_peer_addressautodetect=true
-Core_vm_endpoint=unix:///var/run/docker.sock
- Core_logging_level=debug-
core_peer_id=vp0
-core_peer_pki_eca_paddr=membersrvc:7054
-CORE_PEER_ pki_tca_paddr=membersrvc:7054
-core_peer_pki_tlsca_paddr=membersrvc:7054
-Core_security_enabled=true
-core_security_enrollid=test_vp0
-CORE_SECURITY_ENROLLSECRET=MWYPMSRJUPBT
Links:
- MEMBERSRVC
command:sh-c "Sleep 5; Peer node start--peer-chaincodedev "
3. Docker input Docker-compose up
4. Mremoteng Link Docker,
host:192.168.99.100
User Name:docker
Password:tcuser
Agreement: SSHV2
5. Mremoteng Input Docker PS
6. Mremoteng input docker exec-it rjy_vp0_1 bash
7. Return to .../github.com create a new SaveState folder mkdir SaveState
8. Enter SaveState, enter VI savestate2.go create a new Savestate.go file
9. Press i key, copy code from below, click on Mremoteng right button paste over
Package main import ("Errors" "FMT" "Github.com/hyperledger/fabric/core/chaincode/shim") type S Avestate2chaincode struct {} func (T *savestate2chaincode) Init (stub shim. Chaincodestubinterface, function string, args []string] ([]byte, error) {FMT. Printf ("Init called with function%s!\n", function) return nil, nil} func (T *savestate2chaincode) Invoke (stub sh Im. Chaincodestubinterface, function string, args []string] ([]byte, error) {FMT.
Printf ("Invoke called with function%s!\n", function) var key, value string key = Args[0] Value = args[1] The var err error err = stub. Putstate (Key, []byte (value)) If Err!= nil {return nil, err} return nil, nil} func (t *sa Vestate2chaincode) Query (stub shim. Chaincodestubinterface, function string, args []string] ([]byte, error) {FMT. Printf ("Query called with function%s!\n", function) var key string key = Args[0] Valinbytes, err: = STub. GetState (key) If Err!= nil {return nil, errors. New ("Failed to get state for" + key)} message: = ' state for ' + key + ' = ' + string (valinbytes) return []byte (Message), nil} func main () {err: = shim. Start (New (Savestate2chaincode)) If Err!= nil {fmt. Printf ("Error starting Save State Chaincode:%s", err)}}
Ten.: Wq
Go build./Note there is a space behind the build, and a green file appears when you run this sentence
Export CORE_CHAINCODE_ID_NAME=MYCC
Export core_peer_address=0.0.0.0:7051
/savestate &
15. Send the following rest request to the Hyperledger service interface Http://192.168.99.100:7050/registrar using the built-in Jim user login system
{
"Enrollid": "Jim",
"Enrollsecret": "6avzqlwcue9b"
}
16. Send the following rest request to the Hyperledger service interface Http://192.168.99.100:7050/chaincode
{
"Jsonrpc": "2.0",
"Method": "Invoke",
"Params": {
' Type ': 1,
"Chaincodeid": {
' Name ': ' MYCC '
},
"Ctormsg": {
"Function": "Invoke",
"Args": ["TestKey", "Pipixia,let ' s go!"]
},
"Securecontext": "Jim"
},
"ID": 3
}
17.
{
"Jsonrpc": "2.0",
"Method": "Query",
"Params": {
' Type ': 1,
"Chaincodeid": {
' Name ': ' MYCC '
},
"Ctormsg": {
"function": "Query",
"Args": ["TestKey"]
},
"Securecontext": "Jim"
},
"ID": 5
}