Intelligent Contract Demo Analysis of digital currency development tutorial
Source: Internet
Author: User
Blockchain Enthusiast (qq:53016353)
Code slices
/* Copyright IBM Corp All rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); You are not a use of this file except in compliance with the License. Obtain a copy of the License at http://www.apache.org/licenses/lic ENSE-2.0 unless required by applicable law or agreed to in writing, software distributed under the License I s distributed on a "as is" BASIS, without warranties or CONDITIONS of any KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. * * package main //warning-this Chaincode ' s ID was hard-coded in Chaincode_ Example04 to illustrate one by //calling Chaincode from a chaincode. If This example is modified, chaincode_example04.go have //to be modified as well with the new ID of Chaincode_examp Le02. //CHAINCODE_EXAMPLE05 Show ' s how Chaincode ID can is passed in as a parameter instead of //hard-coding. Import ( "errors" "FMT" "StrConv"   ; "Github.com/hyperledger/fabric/core/chaincode/shim" ) // Simplechaincode Example Simple Chaincode implementation type Simplechaincode struct { } Func (t *simplechaincode) Init (stub *shim). Chaincodestub, function string, args []string] ([]byte, error) { var A, B string //Enti Ties var aval, Bval Int//Asset Holdings VAR err error &nbs P If Len (args)! = 4 { return nil, errors. New ("Incorrect number of arguments. Expecting 4 ") } //Initialize the Chaincode &NBSP A = args[0] Aval, err = StrConv. Atoi (Args[1]) If err! = Nil { return nil, errors. New ("Expecting integer value for asset holding") } B = args[2] &NB Sp Bval, err = StrConv. Atoi (Args[3]) If err! = Nil { return nil, errors. New ("Expecting integer value for asset holding") } FMT. Printf ("Aval =%d, Bval =%d\n", Aval, Bval) //Write the state to the ledger &NB Sp Err = stub. Putstate (A, []byte (StrConv). Itoa (Aval)) If err! = Nil { return nil, err } err = stub. Putstate (B, []byte (StrConv). Itoa (Bval)) If err! = Nil { return nil, err } return nil, nil } //Transaction makes payment of X units fro M A to B func (t *simplechaincode) Invoke (stub *shim. Chaincodestub, function string, args []string] ([]byte, error) { if function = = "Delete" { &NB Sp //Deletes an entity from it state return t.delete (stub, args) &n Bsp var A, B string //entities VAR aval, Bval INT//Asset Holdings var X int //Transaction value
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service