更新賬本資訊在APP側和查詢相似,就是通過智能合約提供的介面更新資料。當前提供的功能包括建立CAR,以及修改CAR的owner屬性。我們可以通過修改invoke.js代碼實現對不同介面的調用。
var request = { //targets: let default to the peer assigned to the client chaincodeId: 'fabcar', fcn: 'createCar', args: ['CAR12', 'Honda', 'Accord', 'Black', 'Tom'], chainId: 'mychannel', txId: tx_id };執行結果:lydeiMac:fabcar ly$ node invoke.js Store path:/Users/ly/go/src/github.com/hyperledger/fabric-samples/fabcar/hfc-key-storeSuccessfully loaded user1 from persistenceAssigning transaction_id: a5b684603b1f2a0296851409cecb143c3109220014182721165ef8fe5c326b2eTransaction proposal was goodSuccessfully sent Proposal and received ProposalResponse: Status - 200, message - "OK"The transaction has been committed on peer localhost:7053Send transaction promise and event listener promise have completedSuccessfully sent transaction to the orderer.Successfully committed the change to the ledger by the peer
建立後查詢所有CAR資訊,可以看到增加了CAR12資訊
[{"Key":"CAR0", "Record":{"colour":"blue","make":"Toyota","model":"Prius","owner":"Tomoko"}},{"Key":"CAR1", "Record":{"colour":"red","make":"Ford","model":"Mustang","owner":"Brad"}},{"Key":"CAR12", "Record":{"colour":"Black","make":"Honda","model":"Accord","owner":"Tom"}},{"Key":"CAR2", "Record":{"colour":"green","make":"Hyundai","model":"Tucson","owner":"Jin Soo"}},{"Key":"CAR3", "Record":{"colour":"yellow","make":"Volkswagen","model":"Passat","owner":"Max"}},{"Key":"CAR4", "Record":{"colour":"black","make":"Tesla","model":"S","owner":"Adriana"}},{"Key":"CAR5", "Record":{"colour":"purple","make":"Peugeot","model":"205","owner":"Michel"}},{"Key":"CAR6", "Record":{"colour":"white","make":"Chery","model":"S22L","owner":"Aarav"}},{"Key":"CAR7", "Record":{"colour":"violet","make":"Fiat","model":"Punto","owner":"Pari"}},{"Key":"CAR8", "Record":{"colour":"indigo","make":"Tata","model":"Nano","owner":"Valeria"}},{"Key":"CAR9", "Record":{"colour":"brown","make":"Holden","model":"Barina","owner":"Shotaro"}}]