合约:

package main 

/*
--------------------------------------------------
Author: netkiller <netkiller@msn.com>
Home: http://www.netkiller.cn
Data: 2018-03-20 11:00 PM
-------------------------------------------------- CORE_PEER_ADDRESS=peer:7051 CORE_CHAINCODE_ID_NAME=token3:1.0 chaincode/token/token3 peer chaincode install -n token3 -v 1.0 -p chaincodedev/chaincode/token
peer chaincode instantiate -C myc -n token3 -v 1.0 -c '{"Args":[""]}' -P "OR ('Org1MSP.member','Org2MSP.member')" peer chaincode invoke -C myc -n token3 -c '{"function":"createAccount","Args":["coinbase"]}'
peer chaincode invoke -C myc -n token3 -v 1.0 -c '{"function":"showAccount","Args":["coinbase"]}'
peer chaincode invoke -C myc -n token3 -c '{"function":"balanceAll","Args":["coinbase"]}' peer chaincode invoke -C myc -n token3 -c '{"function":"initCurrency","Args":["Netkiller Token","NKC","1000000","coinbase"]}'
peer chaincode invoke -C myc -n token3 -c '{"function":"initCurrency","Args":["NEO Token","NEC","1000000","coinbase"]}' peer chaincode invoke -C myc -n token3 -c '{"function":"setLock","Args":["true"]}'
peer chaincode invoke -C myc -n token3 -c '{"function":"setLock","Args":["false"]}' peer chaincode invoke -C myc -n token3 -c '{"function":"mintToken","Args":["NKC","5000","coinbase"]}' peer chaincode invoke -C myc -n token3 -c '{"function":"createAccount","Args":["netkiller"]}'
peer chaincode invoke -C myc -n token3 -c '{"function":"transferToken","Args":["coinbase","netkiller","NKC","100"]}'
peer chaincode invoke -C myc -n token3 -c '{"function":"balance","Args":["netkiller","NKC"]}' peer chaincode invoke -C myc -n token3 -c '{"function":"frozenAccount","Args":["netkiller","true"]}' -------------------------------------------------- */ import (
"encoding/json"
"fmt"
"strconv" "github.com/hyperledger/fabric/core/chaincode/shim"
pb "github.com/hyperledger/fabric/protos/peer"
) type Msg struct{
Status bool `json:"Status"`
Code int `json:"Code"`
Message string `json:"Message"`
} type Currency struct{
TokenName string `json:"TokenName"`
TokenSymbol string `json:"TokenSymbol"`
TotalSupply float64 `json:"TotalSupply"`
} type Token struct {
Lock bool `json:"Lock"`
Currency map[string]Currency `json:"Currency"`
} func (token *Token) transfer (_from *Account, _to *Account, _currency string, _value float64) []byte{ var rev []byte
if (token.Lock){
msg := &Msg{Status: false, Code: 0, Message: "锁仓状态,停止一切转账活动"}
rev, _ = json.Marshal(msg)
return rev
}
if(_from.Frozen ) {
msg := &Msg{Status: false, Code: 0, Message: "From 账号冻结"}
rev, _ = json.Marshal(msg)
return rev
}
if( _to.Frozen) {
msg := &Msg{Status: false, Code: 0, Message: "To 账号冻结"}
rev, _ = json.Marshal(msg)
return rev
}
if(!token.isCurrency(_currency)){
msg := &Msg{Status: false, Code: 0, Message: "货币符号不存在"}
rev, _ = json.Marshal(msg)
return rev
}
if(_from.BalanceOf[_currency] >= _value){
_from.BalanceOf[_currency] -= _value;
_to.BalanceOf[_currency] += _value; msg := &Msg{Status: true, Code: 0, Message: "转账成功"}
rev, _ = json.Marshal(msg)
return rev
}else{
msg := &Msg{Status: false, Code: 0, Message: "余额不足"}
rev, _ = json.Marshal(msg)
return rev
} }
func (token *Token) initialSupply(_name string, _symbol string, _supply float64, _account *Account) []byte{
if _,ok := token.Currency[_symbol]; ok {
msg := &Msg{Status: false, Code: 0, Message: "代币已经存在"}
rev, _ := json.Marshal(msg)
return rev
} if _account.BalanceOf[_symbol] > 0 {
msg := &Msg{Status: false, Code: 0, Message: "账号中存在代币"}
rev, _ := json.Marshal(msg)
return rev
}else{
token.Currency[_symbol] = Currency{TokenName: _name, TokenSymbol: _symbol, TotalSupply: _supply}
_account.BalanceOf[_symbol] = _supply msg := &Msg{Status: true, Code: 0, Message: "代币初始化成功"}
rev, _ := json.Marshal(msg)
return rev
} } func (token *Token) mint(_currency string, _amount float64, _account *Account) []byte{
if(!token.isCurrency(_currency)){
msg := &Msg{Status: false, Code: 0, Message: "货币符号不存在"}
rev, _ := json.Marshal(msg)
return rev
}
cur := token.Currency[_currency]
cur.TotalSupply += _amount;
token.Currency[_currency] = cur
_account.BalanceOf[_currency] += _amount; msg := &Msg{Status: true, Code: 0, Message: "代币增发成功"}
rev, _ := json.Marshal(msg)
return rev }
func (token *Token) burn(_currency string, _amount float64, _account *Account) []byte{
if(!token.isCurrency(_currency)){
msg := &Msg{Status: false, Code: 0, Message: "货币符号不存在"}
rev, _ := json.Marshal(msg)
return rev
}
if(token.Currency[_currency].TotalSupply >= _amount){
cur := token.Currency[_currency]
cur.TotalSupply -= _amount;
token.Currency[_currency] = cur
_account.BalanceOf[_currency] -= _amount; msg := &Msg{Status: false, Code: 0, Message: "代币回收成功"}
rev, _ := json.Marshal(msg)
return rev
}else{
msg := &Msg{Status: false, Code: 0, Message: "代币回收失败,回收额度不足"}
rev, _ := json.Marshal(msg)
return rev
} }
func (token *Token) isCurrency(_currency string) bool {
if _, ok := token.Currency[_currency]; ok {
return true
}else{
return false
}
}
func (token *Token) setLock(_look bool) bool {
token.Lock = _look
return token.Lock
}
type Account struct {
Name string `json:"Name"`
Frozen bool `json:"Frozen"`
BalanceOf map[string]float64 `json:"BalanceOf"`
}
func (account *Account) balance (_currency string) map[string]float64{
bal := map[string]float64{_currency:account.BalanceOf[_currency]}
return bal
} func (account *Account) balanceAll() map[string]float64{
return account.BalanceOf
} // -----------
const TokenKey = "Token" // Define the Smart Contract structure
type SmartContract struct { } func (s *SmartContract) Init(stub shim.ChaincodeStubInterface) pb.Response { token := &Token{Currency: map[string]Currency{}} tokenAsBytes, err := json.Marshal(token)
err = stub.PutState(TokenKey, tokenAsBytes)
if err != nil {
return shim.Error(err.Error())
}else{
fmt.Printf("Init Token %s \n", string(tokenAsBytes))
}
return shim.Success(nil)
} func (s *SmartContract) Query(stub shim.ChaincodeStubInterface) pb.Response {
function, args := stub.GetFunctionAndParameters()
if function == "balance" {
return s.balance(stub, args)
} else if function == "balanceAll" {
return s.balanceAll(stub, args)
} else if function == "showAccount" {
return s.showAccount(stub, args)
}
return shim.Error("Invalid Smart Contract function name.")
} func (s *SmartContract) Invoke(stub shim.ChaincodeStubInterface) pb.Response { // Retrieve the requested Smart Contract function and arguments
function, args := stub.GetFunctionAndParameters()
// Route to the appropriate handler function to interact with the ledger appropriately
if function == "initLedger" {
return s.initLedger(stub, args)
} else if function == "createAccount" {
return s.createAccount(stub, args)
} else if function == "initCurrency" {
return s.initCurrency(stub, args)
} else if function == "setLock" {
return s.setLock(stub, args)
} else if function == "transferToken" {
return s.transferToken(stub, args)
} else if function == "frozenAccount" {
return s.frozenAccount(stub, args)
} else if function == "mintToken" {
return s.mintToken(stub, args)
} else if function == "balance" {
return s.balance(stub, args)
} else if function == "balanceAll" {
return s.balanceAll(stub, args)
} else if function == "showAccount" {
return s.showAccount(stub, args)
} else if function == "showToken" {
return s.showToken(stub, args)
} return shim.Error("Invalid Smart Contract function name.")
} func (s *SmartContract) createAccount(stub shim.ChaincodeStubInterface, args []string) pb.Response { if len(args) != 1 {
return shim.Error("Incorrect number of arguments. Expecting 1")
} key := args[0]
name := args[0]
existAsBytes,err := stub.GetState(key)
fmt.Printf("GetState(%s) %s \n", key, string(existAsBytes))
if string(existAsBytes) != "" {
fmt.Println("Failed to create account, Duplicate key.")
return shim.Error("Failed to create account, Duplicate key.")
} account := Account{
Name: name,
Frozen: false,
BalanceOf: map[string]float64{}} accountAsBytes, _ := json.Marshal(account)
err = stub.PutState(key, accountAsBytes)
if err != nil {
return shim.Error(err.Error())
}
fmt.Printf("createAccount %s \n", string(accountAsBytes)) return shim.Success(accountAsBytes)
}
func (s *SmartContract) initLedger(stub shim.ChaincodeStubInterface, args []string) pb.Response {
return shim.Success(nil)
}
func (s *SmartContract) showToken(stub shim.ChaincodeStubInterface, args []string) pb.Response {
tokenAsBytes,err := stub.GetState(TokenKey)
if err != nil {
return shim.Error(err.Error())
}else{
fmt.Printf("GetState(%s)) %s \n", TokenKey, string(tokenAsBytes))
}
return shim.Success(tokenAsBytes)
} func (s *SmartContract) initCurrency(stub shim.ChaincodeStubInterface, args []string) pb.Response {
if len(args) != 4 {
return shim.Error("Incorrect number of arguments. Expecting 4")
} _name := args[0]
_symbol:= args[1]
_supply,_:= strconv.ParseFloat(args[2], 64)
_account := args[3] coinbaseAsBytes,err := stub.GetState(_account)
if err != nil {
return shim.Error(err.Error())
}
fmt.Printf("Coinbase before %s \n", string(coinbaseAsBytes)) coinbase := &Account{} json.Unmarshal(coinbaseAsBytes, &coinbase) token := Token{}
existAsBytes,err := stub.GetState(TokenKey)
if err != nil {
return shim.Error(err.Error())
}else{
fmt.Printf("GetState(%s)) %s \n", TokenKey, string(existAsBytes))
}
json.Unmarshal(existAsBytes, &token) result := token.initialSupply(_name,_symbol,_supply, coinbase) tokenAsBytes, _ := json.Marshal(token)
err = stub.PutState(TokenKey, tokenAsBytes)
if err != nil {
return shim.Error(err.Error())
}else{
fmt.Printf("Init Token %s \n", string(tokenAsBytes))
} coinbaseAsBytes, _ = json.Marshal(coinbase)
err = stub.PutState(_account, coinbaseAsBytes)
if err != nil {
return shim.Error(err.Error())
}
fmt.Printf("Coinbase after %s \n", string(coinbaseAsBytes)) return shim.Success(result)
} func (s *SmartContract) transferToken(stub shim.ChaincodeStubInterface, args []string) pb.Response { if len(args) != 4 {
return shim.Error("Incorrect number of arguments. Expecting 4")
}
_from := args[0]
_to := args[1]
_currency := args[2]
_amount,_ := strconv.ParseFloat(args[3], 32) if(_amount <= 0){
return shim.Error("Incorrect number of amount")
} fromAsBytes,err := stub.GetState(_from)
if err != nil {
return shim.Error(err.Error())
}
fmt.Printf("fromAccount %s \n", string(fromAsBytes))
fromAccount := &Account{}
json.Unmarshal(fromAsBytes, &fromAccount) toAsBytes,err := stub.GetState(_to)
if err != nil {
return shim.Error(err.Error())
}
fmt.Printf("toAccount %s \n", string(toAsBytes))
toAccount := &Account{}
json.Unmarshal(toAsBytes, &toAccount) tokenAsBytes,err := stub.GetState(TokenKey)
if err != nil {
return shim.Error(err.Error())
}
fmt.Printf("Token %s \n", string(toAsBytes))
token := Token{Currency: map[string]Currency{}}
json.Unmarshal(tokenAsBytes, &token) result := token.transfer(fromAccount, toAccount, _currency, _amount)
fmt.Printf("Result %s \n", string(result)) fromAsBytes, err = json.Marshal(fromAccount)
if err != nil {
return shim.Error(err.Error())
}
err = stub.PutState(_from, fromAsBytes)
if err != nil {
return shim.Error(err.Error())
}else{
fmt.Printf("fromAccount %s \n", string(fromAsBytes))
} toAsBytes, err = json.Marshal(toAccount)
if err != nil {
return shim.Error(err.Error())
}
err = stub.PutState(_to, toAsBytes)
if err != nil {
return shim.Error(err.Error())
}else{
fmt.Printf("toAccount %s \n", string(toAsBytes))
} return shim.Success(result)
}
func (s *SmartContract) mintToken(stub shim.ChaincodeStubInterface, args []string) pb.Response { if len(args) != 3 {
return shim.Error("Incorrect number of arguments. Expecting 3")
}
_currency := args[0]
_amount,_ := strconv.ParseFloat(args[1], 32)
_account := args[2] coinbaseAsBytes,err := stub.GetState(_account)
if err != nil {
return shim.Error(err.Error())
}else{
fmt.Printf("Coinbase before %s \n", string(coinbaseAsBytes))
} coinbase := &Account{}
json.Unmarshal(coinbaseAsBytes, &coinbase) tokenAsBytes,err := stub.GetState(TokenKey)
if err != nil {
return shim.Error(err.Error())
}
fmt.Printf("Token before %s \n", string(tokenAsBytes)) token := Token{} json.Unmarshal(tokenAsBytes, &token) result := token.mint(_currency, _amount, coinbase) tokenAsBytes, err = json.Marshal(token)
if err != nil {
return shim.Error(err.Error())
}
err = stub.PutState(TokenKey, tokenAsBytes)
if err != nil {
return shim.Error(err.Error())
}
fmt.Printf("Token after %s \n", string(tokenAsBytes)) coinbaseAsBytes, _ = json.Marshal(coinbase)
err = stub.PutState(_account, coinbaseAsBytes)
if err != nil {
return shim.Error(err.Error())
}else{
fmt.Printf("Coinbase after %s \n", string(coinbaseAsBytes))
} fmt.Printf("mintToken %s \n", string(tokenAsBytes)) return shim.Success(result)
} func (s *SmartContract) setLock(stub shim.ChaincodeStubInterface, args []string) pb.Response { if len(args) != 1 {
return shim.Error("Incorrect number of arguments. Expecting 2")
} _look := args[0] tokenAsBytes,err := stub.GetState(TokenKey)
if err != nil {
return shim.Error(err.Error())
}
// fmt.Printf("setLock - begin %s \n", string(tokenAsBytes)) token := Token{} json.Unmarshal(tokenAsBytes, &token) if(_look == "true"){
token.setLock(true)
}else{
token.setLock(false)
} tokenAsBytes, err = json.Marshal(token)
if err != nil {
return shim.Error(err.Error())
}
err = stub.PutState(TokenKey, tokenAsBytes)
if err != nil {
return shim.Error(err.Error())
}
fmt.Printf("setLock - end %s \n", string(tokenAsBytes)) return shim.Success(nil)
}
func (s *SmartContract) frozenAccount(stub shim.ChaincodeStubInterface, args []string) pb.Response { if len(args) != 2 {
return shim.Error("Incorrect number of arguments. Expecting 2")
} _account := args[0]
_status := args[1] accountAsBytes,err := stub.GetState(_account)
if err != nil {
return shim.Error(err.Error())
}
// fmt.Printf("setLock - begin %s \n", string(tokenAsBytes)) account := Account{} json.Unmarshal(accountAsBytes, &account) var status bool
if(_status == "true"){
status = true;
}else{
status = false
} account.Frozen = status accountAsBytes, err = json.Marshal(account)
if err != nil {
return shim.Error(err.Error())
}
err = stub.PutState(_account, accountAsBytes)
if err != nil {
return shim.Error(err.Error())
}else{
fmt.Printf("frozenAccount - end %s \n", string(accountAsBytes))
} return shim.Success(nil)
} func (s *SmartContract) showAccount(stub shim.ChaincodeStubInterface, args []string) pb.Response { if len(args) != 1 {
return shim.Error("Incorrect number of arguments. Expecting 1")
}
_account := args[0] accountAsBytes,err := stub.GetState(_account)
if err != nil {
return shim.Error(err.Error())
}else{
fmt.Printf("Account balance %s \n", string(accountAsBytes))
}
return shim.Success(accountAsBytes)
} func (s *SmartContract) balance(stub shim.ChaincodeStubInterface, args []string) pb.Response { if len(args) != 2 {
return shim.Error("Incorrect number of arguments. Expecting 1")
}
_account := args[0]
_currency := args[1] accountAsBytes,err := stub.GetState(_account)
if err != nil {
return shim.Error(err.Error())
}else{
fmt.Printf("Account balance %s \n", string(accountAsBytes))
} account := Account{}
json.Unmarshal(accountAsBytes, &account)
result := account.balance(_currency) resultAsBytes, _ := json.Marshal(result)
fmt.Printf("%s balance is %s \n", _account, string(resultAsBytes)) return shim.Success(resultAsBytes)
} func (s *SmartContract) balanceAll(stub shim.ChaincodeStubInterface, args []string) pb.Response { if len(args) != 1 {
return shim.Error("Incorrect number of arguments. Expecting 1")
}
_account := args[0] accountAsBytes,err := stub.GetState(_account)
if err != nil {
return shim.Error(err.Error())
}else{
fmt.Printf("Account balance %s \n", string(accountAsBytes))
} account := Account{}
json.Unmarshal(accountAsBytes, &account)
result := account.balanceAll()
resultAsBytes, _ := json.Marshal(result)
fmt.Printf("%s balance is %s \n", _account, string(resultAsBytes)) return shim.Success(resultAsBytes)
} // The main function is only relevant in unit test mode. Only included here for completeness.
func main() { // Create a new Smart Contract
err := shim.Start(new(SmartContract))
if err != nil {
fmt.Printf("Error creating new Smart Contract: %s", err)
}
}

测试日志:

2018-03-20 14:46:11.957 UTC [shim] SetupChaincodeLogging -> INFO 001 Chaincode log level not provided; defaulting to: INFO
2018-03-20 14:46:11.957 UTC [shim] SetupChaincodeLogging -> INFO 002 Chaincode (build level: ) starting up ...
Coinbase before {"Name":"jam","Frozen":false,"BalanceOf":{"BBC":10000,"CCE":10000,"EJB":4000,"NBA":999900}}
Token before {"Lock":false,"Currency":{"BBC":{"TokenName":"NEO Token","TokenSymbol":"BBC","TotalSupply":10000},"CCE":{"TokenName":"NEO Token","TokenSymbol":"CCE","TotalSupply":10000},"EJB":{"TokenName":"NEO Token","TokenSymbol":"EJB","TotalSupply":20000},"K8":{"TokenName":"888","TokenSymbol":"K8","TotalSupply":1000000},"NBA":{"TokenName":"NEO Token","TokenSymbol":"NBA","TotalSupply":1000000},"NEC":{"TokenName":"NEO Token","TokenSymbol":"NEC","TotalSupply":1000000},"NKC":{"TokenName":"Netkiller Token","TokenSymbol":"NKC","TotalSupply":1005000},"NKCKK":{"TokenName":"Netkillersss","TokenSymbol":"NKCKK","TotalSupply":1000000},"TTC":{"TokenName":"NEO Token","TokenSymbol":"TTC","TotalSupply":1000000}}}
Token after {"Lock":false,"Currency":{"BBC":{"TokenName":"NEO Token","TokenSymbol":"BBC","TotalSupply":10000},"CCE":{"TokenName":"NEO Token","TokenSymbol":"CCE","TotalSupply":10000},"EJB":{"TokenName":"NEO Token","TokenSymbol":"EJB","TotalSupply":24000},"K8":{"TokenName":"888","TokenSymbol":"K8","TotalSupply":1000000},"NBA":{"TokenName":"NEO Token","TokenSymbol":"NBA","TotalSupply":1000000},"NEC":{"TokenName":"NEO Token","TokenSymbol":"NEC","TotalSupply":1000000},"NKC":{"TokenName":"Netkiller Token","TokenSymbol":"NKC","TotalSupply":1005000},"NKCKK":{"TokenName":"Netkillersss","TokenSymbol":"NKCKK","TotalSupply":1000000},"TTC":{"TokenName":"NEO Token","TokenSymbol":"TTC","TotalSupply":1000000}}}
Coinbase after {"Name":"jam","Frozen":false,"BalanceOf":{"BBC":10000,"CCE":10000,"EJB":8000,"NBA":999900}}
mintToken {"Lock":false,"Currency":{"BBC":{"TokenName":"NEO Token","TokenSymbol":"BBC","TotalSupply":10000},"CCE":{"TokenName":"NEO Token","TokenSymbol":"CCE","TotalSupply":10000},"EJB":{"TokenName":"NEO Token","TokenSymbol":"EJB","TotalSupply":24000},"K8":{"TokenName":"888","TokenSymbol":"K8","TotalSupply":1000000},"NBA":{"TokenName":"NEO Token","TokenSymbol":"NBA","TotalSupply":1000000},"NEC":{"TokenName":"NEO Token","TokenSymbol":"NEC","TotalSupply":1000000},"NKC":{"TokenName":"Netkiller Token","TokenSymbol":"NKC","TotalSupply":1005000},"NKCKK":{"TokenName":"Netkillersss","TokenSymbol":"NKCKK","TotalSupply":1000000},"TTC":{"TokenName":"NEO Token","TokenSymbol":"TTC","TotalSupply":1000000}}}
Account balance {"Name":"jam","Frozen":false,"BalanceOf":{"BBC":10000,"CCE":10000,"EJB":8000,"NBA":999900}}
jam balance is {"BBC":10000,"CCE":10000,"EJB":8000,"NBA":999900}
Coinbase before {"Name":"jam","Frozen":false,"BalanceOf":{"BBC":10000,"CCE":10000,"EJB":8000,"NBA":999900}}
Token before {"Lock":false,"Currency":{"BBC":{"TokenName":"NEO Token","TokenSymbol":"BBC","TotalSupply":10000},"CCE":{"TokenName":"NEO Token","TokenSymbol":"CCE","TotalSupply":10000},"EJB":{"TokenName":"NEO Token","TokenSymbol":"EJB","TotalSupply":24000},"K8":{"TokenName":"888","TokenSymbol":"K8","TotalSupply":1000000},"NBA":{"TokenName":"NEO Token","TokenSymbol":"NBA","TotalSupply":1000000},"NEC":{"TokenName":"NEO Token","TokenSymbol":"NEC","TotalSupply":1000000},"NKC":{"TokenName":"Netkiller Token","TokenSymbol":"NKC","TotalSupply":1005000},"NKCKK":{"TokenName":"Netkillersss","TokenSymbol":"NKCKK","TotalSupply":1000000},"TTC":{"TokenName":"NEO Token","TokenSymbol":"TTC","TotalSupply":1000000}}}
Token after {"Lock":false,"Currency":{"BBC":{"TokenName":"NEO Token","TokenSymbol":"BBC","TotalSupply":10000},"CCE":{"TokenName":"NEO Token","TokenSymbol":"CCE","TotalSupply":10000},"EJB":{"TokenName":"NEO Token","TokenSymbol":"EJB","TotalSupply":28000},"K8":{"TokenName":"888","TokenSymbol":"K8","TotalSupply":1000000},"NBA":{"TokenName":"NEO Token","TokenSymbol":"NBA","TotalSupply":1000000},"NEC":{"TokenName":"NEO Token","TokenSymbol":"NEC","TotalSupply":1000000},"NKC":{"TokenName":"Netkiller Token","TokenSymbol":"NKC","TotalSupply":1005000},"NKCKK":{"TokenName":"Netkillersss","TokenSymbol":"NKCKK","TotalSupply":1000000},"TTC":{"TokenName":"NEO Token","TokenSymbol":"TTC","TotalSupply":1000000}}}
Coinbase after {"Name":"jam","Frozen":false,"BalanceOf":{"BBC":10000,"CCE":10000,"EJB":12000,"NBA":999900}}
mintToken {"Lock":false,"Currency":{"BBC":{"TokenName":"NEO Token","TokenSymbol":"BBC","TotalSupply":10000},"CCE":{"TokenName":"NEO Token","TokenSymbol":"CCE","TotalSupply":10000},"EJB":{"TokenName":"NEO Token","TokenSymbol":"EJB","TotalSupply":28000},"K8":{"TokenName":"888","TokenSymbol":"K8","TotalSupply":1000000},"NBA":{"TokenName":"NEO Token","TokenSymbol":"NBA","TotalSupply":1000000},"NEC":{"TokenName":"NEO Token","TokenSymbol":"NEC","TotalSupply":1000000},"NKC":{"TokenName":"Netkiller Token","TokenSymbol":"NKC","TotalSupply":1005000},"NKCKK":{"TokenName":"Netkillersss","TokenSymbol":"NKCKK","TotalSupply":1000000},"TTC":{"TokenName":"NEO Token","TokenSymbol":"TTC","TotalSupply":1000000}}}
Account balance {"Name":"jam","Frozen":false,"BalanceOf":{"BBC":10000,"CCE":10000,"EJB":8000,"NBA":999900}}
jam balance is {"BBC":10000,"CCE":10000,"EJB":8000,"NBA":999900} Coinbase before {"Name":"jam","Frozen":false,"BalanceOf":{"BBC":10000,"CCE":10000,"EJB":12000,"NBA":999900}}
Token before {"Lock":false,"Currency":{"BBC":{"TokenName":"NEO Token","TokenSymbol":"BBC","TotalSupply":10000},"CCE":{"TokenName":"NEO Token","TokenSymbol":"CCE","TotalSupply":10000},"EJB":{"TokenName":"NEO Token","TokenSymbol":"EJB","TotalSupply":28000},"K8":{"TokenName":"888","TokenSymbol":"K8","TotalSupply":1000000},"NBA":{"TokenName":"NEO Token","TokenSymbol":"NBA","TotalSupply":1000000},"NEC":{"TokenName":"NEO Token","TokenSymbol":"NEC","TotalSupply":1000000},"NKC":{"TokenName":"Netkiller Token","TokenSymbol":"NKC","TotalSupply":1005000},"NKCKK":{"TokenName":"Netkillersss","TokenSymbol":"NKCKK","TotalSupply":1000000},"TTC":{"TokenName":"NEO Token","TokenSymbol":"TTC","TotalSupply":1000000}}}
Token after {"Lock":false,"Currency":{"BBC":{"TokenName":"NEO Token","TokenSymbol":"BBC","TotalSupply":10000},"CCE":{"TokenName":"NEO Token","TokenSymbol":"CCE","TotalSupply":10000},"EJB":{"TokenName":"NEO Token","TokenSymbol":"EJB","TotalSupply":30000},"K8":{"TokenName":"888","TokenSymbol":"K8","TotalSupply":1000000},"NBA":{"TokenName":"NEO Token","TokenSymbol":"NBA","TotalSupply":1000000},"NEC":{"TokenName":"NEO Token","TokenSymbol":"NEC","TotalSupply":1000000},"NKC":{"TokenName":"Netkiller Token","TokenSymbol":"NKC","TotalSupply":1005000},"NKCKK":{"TokenName":"Netkillersss","TokenSymbol":"NKCKK","TotalSupply":1000000},"TTC":{"TokenName":"NEO Token","TokenSymbol":"TTC","TotalSupply":1000000}}}
Coinbase after {"Name":"jam","Frozen":false,"BalanceOf":{"BBC":10000,"CCE":10000,"EJB":14000,"NBA":999900}}
mintToken {"Lock":false,"Currency":{"BBC":{"TokenName":"NEO Token","TokenSymbol":"BBC","TotalSupply":10000},"CCE":{"TokenName":"NEO Token","TokenSymbol":"CCE","TotalSupply":10000},"EJB":{"TokenName":"NEO Token","TokenSymbol":"EJB","TotalSupply":30000},"K8":{"TokenName":"888","TokenSymbol":"K8","TotalSupply":1000000},"NBA":{"TokenName":"NEO Token","TokenSymbol":"NBA","TotalSupply":1000000},"NEC":{"TokenName":"NEO Token","TokenSymbol":"NEC","TotalSupply":1000000},"NKC":{"TokenName":"Netkiller Token","TokenSymbol":"NKC","TotalSupply":1005000},"NKCKK":{"TokenName":"Netkillersss","TokenSymbol":"NKCKK","TotalSupply":1000000},"TTC":{"TokenName":"NEO Token","TokenSymbol":"TTC","TotalSupply":1000000}}} Account balance {"Name":"jam","Frozen":false,"BalanceOf":{"BBC":10000,"CCE":10000,"EJB":14000,"NBA":999900}}
jam balance is {"BBC":10000,"CCE":10000,"EJB":14000,"NBA":999900}
Coinbase before {"Name":"jam","Frozen":false,"BalanceOf":{"BBC":10000,"CCE":10000,"EJB":14000,"NBA":999900}}
Token before {"Lock":false,"Currency":{"BBC":{"TokenName":"NEO Token","TokenSymbol":"BBC","TotalSupply":10000},"CCE":{"TokenName":"NEO Token","TokenSymbol":"CCE","TotalSupply":10000},"EJB":{"TokenName":"NEO Token","TokenSymbol":"EJB","TotalSupply":30000},"K8":{"TokenName":"888","TokenSymbol":"K8","TotalSupply":1000000},"NBA":{"TokenName":"NEO Token","TokenSymbol":"NBA","TotalSupply":1000000},"NEC":{"TokenName":"NEO Token","TokenSymbol":"NEC","TotalSupply":1000000},"NKC":{"TokenName":"Netkiller Token","TokenSymbol":"NKC","TotalSupply":1005000},"NKCKK":{"TokenName":"Netkillersss","TokenSymbol":"NKCKK","TotalSupply":1000000},"TTC":{"TokenName":"NEO Token","TokenSymbol":"TTC","TotalSupply":1000000}}}
Token after {"Lock":false,"Currency":{"BBC":{"TokenName":"NEO Token","TokenSymbol":"BBC","TotalSupply":10000},"CCE":{"TokenName":"NEO Token","TokenSymbol":"CCE","TotalSupply":10000},"EJB":{"TokenName":"NEO Token","TokenSymbol":"EJB","TotalSupply":36000},"K8":{"TokenName":"888","TokenSymbol":"K8","TotalSupply":1000000},"NBA":{"TokenName":"NEO Token","TokenSymbol":"NBA","TotalSupply":1000000},"NEC":{"TokenName":"NEO Token","TokenSymbol":"NEC","TotalSupply":1000000},"NKC":{"TokenName":"Netkiller Token","TokenSymbol":"NKC","TotalSupply":1005000},"NKCKK":{"TokenName":"Netkillersss","TokenSymbol":"NKCKK","TotalSupply":1000000},"TTC":{"TokenName":"NEO Token","TokenSymbol":"TTC","TotalSupply":1000000}}}
Coinbase after {"Name":"jam","Frozen":false,"BalanceOf":{"BBC":10000,"CCE":10000,"EJB":20000,"NBA":999900}}
mintToken {"Lock":false,"Currency":{"BBC":{"TokenName":"NEO Token","TokenSymbol":"BBC","TotalSupply":10000},"CCE":{"TokenName":"NEO Token","TokenSymbol":"CCE","TotalSupply":10000},"EJB":{"TokenName":"NEO Token","TokenSymbol":"EJB","TotalSupply":36000},"K8":{"TokenName":"888","TokenSymbol":"K8","TotalSupply":1000000},"NBA":{"TokenName":"NEO Token","TokenSymbol":"NBA","TotalSupply":1000000},"NEC":{"TokenName":"NEO Token","TokenSymbol":"NEC","TotalSupply":1000000},"NKC":{"TokenName":"Netkiller Token","TokenSymbol":"NKC","TotalSupply":1005000},"NKCKK":{"TokenName":"Netkillersss","TokenSymbol":"NKCKK","TotalSupply":1000000},"TTC":{"TokenName":"NEO Token","TokenSymbol":"TTC","TotalSupply":1000000}}}
Account balance {"Name":"jam","Frozen":false,"BalanceOf":{"BBC":10000,"CCE":10000,"EJB":14000,"NBA":999900}}
jam balance is {"BBC":10000,"CCE":10000,"EJB":14000,"NBA":999900} frozenAccount - end {"Name":"netkiller","Frozen":true,"BalanceOf":{"NKC":300}}
fromAccount {"Name":"jam","Frozen":false,"BalanceOf":{"BBC":10000,"CCE":10000,"EJB":20000,"NBA":999900}}
toAccount {"Name":"netkiller","Frozen":true,"BalanceOf":{"NKC":300}}
Token {"Name":"netkiller","Frozen":true,"BalanceOf":{"NKC":300}}
Result {"Status":false,"Code":0,"Message":"To 账号冻结"}
fromAccount {"Name":"jam","Frozen":false,"BalanceOf":{"BBC":10000,"CCE":10000,"EJB":20000,"NBA":999900}}
toAccount {"Name":"netkiller","Frozen":true,"BalanceOf":{"NKC":300}}
frozenAccount - end {"Name":"netkiller","Frozen":false,"BalanceOf":{"NKC":300}}
fromAccount {"Name":"jam","Frozen":false,"BalanceOf":{"BBC":10000,"CCE":10000,"EJB":20000,"NBA":999900}}
toAccount {"Name":"netkiller","Frozen":false,"BalanceOf":{"NKC":300}}
Token {"Name":"netkiller","Frozen":false,"BalanceOf":{"NKC":300}}
Result {"Status":true,"Code":0,"Message":"转账成功"}
fromAccount {"Name":"jam","Frozen":false,"BalanceOf":{"BBC":10000,"CCE":10000,"EJB":19900,"NBA":999900}}
toAccount {"Name":"netkiller","Frozen":false,"BalanceOf":{"EJB":100,"NKC":300}} Account balance {"Name":"netkiller","Frozen":false,"BalanceOf":{"EJB":100,"NKC":300}}
netkiller balance is {"NKC":300}
Account balance {"Name":"netkiller","Frozen":false,"BalanceOf":{"EJB":100,"NKC":300}}
netkiller balance is {"NKCs":0}
Account balance {"Name":"netkiller","Frozen":false,"BalanceOf":{"EJB":100,"NKC":300}}
netkiller balance is {"NKC":300}
Coinbase before {"Name":"coinbase","Frozen":false,"BalanceOf":{"NKC":4600}}
GetState(Token)) {"Lock":false,"Currency":{"BBC":{"TokenName":"NEO Token","TokenSymbol":"BBC","TotalSupply":10000},"CCE":{"TokenName":"NEO Token","TokenSymbol":"CCE","TotalSupply":10000},"EJB":{"TokenName":"NEO Token","TokenSymbol":"EJB","TotalSupply":36400},"K8":{"TokenName":"888","TokenSymbol":"K8","TotalSupply":1000000},"NAS":{"TokenName":"NAS Token","TokenSymbol":"NAS","TotalSupply":2000},"NBA":{"TokenName":"NEO Token","TokenSymbol":"NBA","TotalSupply":1000000},"NEC":{"TokenName":"NEO Token","TokenSymbol":"NEC","TotalSupply":1000000},"NKC":{"TokenName":"Netkiller Token","TokenSymbol":"NKC","TotalSupply":1005000},"NKCKK":{"TokenName":"Netkillersss","TokenSymbol":"NKCKK","TotalSupply":1000000},"TTC":{"TokenName":"NEO Token","TokenSymbol":"TTC","TotalSupply":1000000}}}
Init Token {"Lock":false,"Currency":{"BBC":{"TokenName":"NEO Token","TokenSymbol":"BBC","TotalSupply":10000},"CCE":{"TokenName":"NEO Token","TokenSymbol":"CCE","TotalSupply":10000},"EJB":{"TokenName":"NEO Token","TokenSymbol":"EJB","TotalSupply":36400},"K8":{"TokenName":"888","TokenSymbol":"K8","TotalSupply":1000000},"NAS":{"TokenName":"NAS Token","TokenSymbol":"NAS","TotalSupply":2000},"NBA":{"TokenName":"NEO Token","TokenSymbol":"NBA","TotalSupply":1000000},"NEC":{"TokenName":"NEO Token","TokenSymbol":"NEC","TotalSupply":1000000},"NKC":{"TokenName":"Netkiller Token","TokenSymbol":"NKC","TotalSupply":1005000},"NKCKK":{"TokenName":"Netkillersss","TokenSymbol":"NKCKK","TotalSupply":1000000},"TTC":{"TokenName":"NEO Token","TokenSymbol":"TTC","TotalSupply":1000000}}}
Coinbase after {"Name":"coinbase","Frozen":false,"BalanceOf":{"NKC":4600}} Coinbase before {"Name":"coinbase","Frozen":false,"BalanceOf":{"NKC":4600}}
GetState(Token)) {"Lock":false,"Currency":{"BBC":{"TokenName":"NEO Token","TokenSymbol":"BBC","TotalSupply":10000},"CCE":{"TokenName":"NEO Token","TokenSymbol":"CCE","TotalSupply":10000},"EJB":{"TokenName":"NEO Token","TokenSymbol":"EJB","TotalSupply":36400},"K8":{"TokenName":"888","TokenSymbol":"K8","TotalSupply":1000000},"NAS":{"TokenName":"NAS Token","TokenSymbol":"NAS","TotalSupply":2000},"NBA":{"TokenName":"NEO Token","TokenSymbol":"NBA","TotalSupply":1000000},"NEC":{"TokenName":"NEO Token","TokenSymbol":"NEC","TotalSupply":1000000},"NKC":{"TokenName":"Netkiller Token","TokenSymbol":"NKC","TotalSupply":1005000},"NKCKK":{"TokenName":"Netkillersss","TokenSymbol":"NKCKK","TotalSupply":1000000},"TTC":{"TokenName":"NEO Token","TokenSymbol":"TTC","TotalSupply":1000000}}}
Init Token {"Lock":false,"Currency":{"BBC":{"TokenName":"NEO Token","TokenSymbol":"BBC","TotalSupply":10000},"CCE":{"TokenName":"NEO Token","TokenSymbol":"CCE","TotalSupply":10000},"EJB":{"TokenName":"NEO Token","TokenSymbol":"EJB","TotalSupply":36400},"K8":{"TokenName":"888","TokenSymbol":"K8","TotalSupply":1000000},"NAS":{"TokenName":"NAS Token","TokenSymbol":"NAS","TotalSupply":2000},"NBA":{"TokenName":"NEO Token","TokenSymbol":"NBA","TotalSupply":1000000},"NEC":{"TokenName":"NEO Token","TokenSymbol":"NEC","TotalSupply":1000000},"NKC":{"TokenName":"Netkiller Token","TokenSymbol":"NKC","TotalSupply":1005000},"NKCKK":{"TokenName":"Netkillersss","TokenSymbol":"NKCKK","TotalSupply":1000000},"TTC":{"TokenName":"NEO Token","TokenSymbol":"TTC","TotalSupply":1000000}}}
Coinbase after {"Name":"coinbase","Frozen":false,"BalanceOf":{"NKC":4600}}

模仿以太坊 ERC20 规范的 Hyperledger Fabric 实现 Token 通证的更多相关文章

  1. 以太坊ERC20代币开发

    以太坊ERC20代币开发首先需要对以太坊,代币,ERC20,智能合约等以太坊代币开发中的基本概念有了解.根据我们的示例代码就可以发行自己的以太坊代币. 什么是ERC20 可以把ERC20简单理解成以太 ...

  2. 零门槛,包教会。让你在5分钟内使用以太坊ERC20智能合约发行属于自己的空气币

    前言 目前区块链是互联网中最最火的风口,没有之一.我周围的很多朋友也加入了“炒币”行列,但很不幸,几乎都被“割韭菜”了.而经过我的几天研究,发现,如果自己要发行一种空气币,简直太简单了.只需要下面几个 ...

  3. 以太坊erc20转账失败的情况和原因

    以太坊erc20转账失败的情况和原因 eth转账失败有多种情况,除了手续费过低以外(Out of gas),众筹额度满了(Bad instruction)也会失败链上转账有可能失败,转账失败转账的币退 ...

  4. 一键创建以太坊ERC20代币教程

    30秒极速创建以太坊ERC20代币 傻瓜式创建,界面化创建,自动创建代币,简单好用 合约采用新版 5.10 新版合约编译器,合约代码100%安全无任何漏洞 下面是详细的使用和创建教程 1.点击创建ER ...

  5. 以太坊 ERC20 与 ERC721 深度解密

    去年11月份的一段时间,Ethereum网络突然变的特别拥堵,原因是兴起了一款以太坊养猫的Dapp游戏,超级可爱的猫形象,再加上配种,繁殖和拍卖等丰富的玩法,风靡了币圈. 一时间币圈大大小小的人都在撸 ...

  6. 以太坊ERC20代币合约案例

    一.ERC20代币合约与web3调用 ERC20代币合约在小白看来觉得很高大上,但其实就是一个代币的定义标准,方便其他dapp统一调用各种代币的方法.如图: 二.ERC20合约标准 [官方链接] co ...

  7. 10分钟 5步 发布以太坊 ERC20 代币

    1.安装 METAMASK Brings Ethereum to your browser 一个可以浏览器上进行操作的以太坊钱包,推荐 Chrome. Chrome 插件安装地址: https://c ...

  8. 【Ethereum】以太坊ERC20 Token标准完整说明

    什么是ERC20 token 市面上出现了大量的用ETH做的代币,他们都遵守REC20协议,那么我们需要知道什么是REC20协议. 概述 token代表数字资产,具有价值,但是并不是都符合特定的规范. ...

  9. Hyperledger Fabric、Corda和以太坊对比

     Hyperledger Fabric . Corda 和以太坊的对比 三种不同的框架 我们从 Hyperledger Fabric.R3 Corda和以太坊的白皮书中可以看到,三种框架在可能的应用领 ...

随机推荐

  1. nuxt项目中vue报错The client-side rendered virtual ...

    报错: 翻译过来是: [Vue警告]:客户端呈现的虚拟DOM树与服务器呈现的内容不匹配.这可能是由不正确的HTML标记引起的,例如在其中嵌套块级元素或丢失.Bailing水化和执行完整的客户端渲染. ...

  2. 10.15仿admin开发stark组件(一)

    2018-10-15 12:28:50 越努力,越幸运!永远不要高估自己! 低调做人,高调做事! 明天开stark项目!! admin 参考连接: http://www.cnblogs.com/yua ...

  3. day_5.12 py 老王开枪demo

    ps:2018-7-24 21:00:04 其实这部分主要是面向对象的复习!而不是面向过程 #!/usr/bin/env/python #-*-coding:utf-8-*- ''' 2018-5-1 ...

  4. 使用ASP.NET Core的User Secrets特性

    昨天在一个集成测试项目中实际使用 ASP.NET Core 的 user secrets 保存敏感配置信息,避免了直接保存在 appsettings.json 中,在这篇随笔中记录一下. 使用 use ...

  5. c++基本函数

    std::abs 求绝对值函数 double abs (double x); float abs (float x); long double abs (long double x); std::sw ...

  6. TF模型训练中注意Loss和F1的变化情况

    之前训练模型,认为网络图构建完成,Loss肯定是呈现下降的,就没有太留心,知识关注F1的变化情况,找到最优的F1训练就停止了,认为模型就ok. 但实际中发现,我们要时刻关注网络的损失变化情况,batc ...

  7. 运维监控篇(2)_Zabbix简单的性能调优

    Zabbix是一款高性能的分布式监控报警系统.比如现在常见的家用台式机配置处理器I5-3470.内存4GB1600MHz.硬盘7200rpm就能够监控1000台左右的HOST,是的没错Zabbix就是 ...

  8. Page10:Lyapunov稳定概念及判定定理[Linear System Theory]

    内容包含连续和离散系统的Lyapunov稳定概念及其各种判别定理

  9. 流计算技术实战 - CEP

    CEP,Complex event processing Wiki定义 "Complex event processing, or CEP, is event processing that ...

  10. 转:cookie.setPath()用法

    原文地址:cookie.setPath()的用法 正常的cookie只能在一个应用中共享,即一个cookie只能由创建它的应用获得. 1.可在同一应用服务器内共享方法:设置cookie.setPath ...