This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
const fs = require('fs'); | |
const { exec } = require('child_process'); | |
const truffleBuildTemplate = { | |
contract_name: null, | |
abi: null, | |
unlinked_binary: null, | |
networks: {}, | |
schema_version: "0.0.5", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Chaincode interface { | |
// Init is called during Instantiate transaction | |
Init(stub ChaincodeStubInterface) pb.Response | |
// Invoke is called to update or query the ledger | |
Invoke(stub ChaincodeStubInterface) pb.Response | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type ChaincodeStubInterface interface { | |
// GetArgs returns the arguments intended for the chaincode Init and Invoke | |
GetArgs() [][]byte | |
// InvokeChaincode locally calls the specified chaincode | |
InvokeChaincode(chaincodeName string, args [][]byte, channel string) pb.Response | |
// GetState returns the value of the specified `key` from the ledger. | |
GetState(key string) ([]byte, error) | |
// PutState puts the specified `key` and `value` into the transaction's writeset as a data-write proposal. | |
PutState(key string, value []byte) error | |
// DelState records the specified `key` to be deleted in the writeset of the transaction proposal. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (t *SimpleAsset) Invoke(stub shim.ChaincodeStubInterface) peer.Response { | |
fn, args := stub.GetFunctionAndParameters() | |
var result string | |
var err error | |
if fn == "set" { | |
result, err = set(stub, args) | |
} else { // assume 'get' even if fn is nil | |
result, err = get(stub, args) | |
} | |
if err != nil { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Simple CRUD chaincode for store information about cars | |
package cars | |
import ( | |
"errors" | |
"time" | |
"github.com/hyperledger/fabric/core/chaincode/shim" | |
"github.com/hyperledger/fabric/protos/peer" | |
"github.com/s7techlab/cckit/extensions/owner" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"testing" | |
. "github.com/onsi/ginkgo" | |
. "github.com/onsi/gomega" | |
examplecert "github.com/s7techlab/cckit/examples/cert" | |
"github.com/s7techlab/cckit/extensions/owner" | |
"github.com/s7techlab/cckit/identity" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func New() *Chaincode { | |
r := router.New(`cars`) // also initialized logger with "cars" prefix | |
r.Group(`car`). | |
Query(`List`, cars). // chain code method name is carList | |
Query(`Get`, car, p.String(`id`)). // chain code method name is carGet, method has 1 string argument "id" | |
Invoke(`Register`, carRegister, p.Struct(`car`, &CarPayload{}), // 1 struct argument | |
owner.Only) // allow access to method only for chaincode owner (authority) | |
return &Chaincode{r} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Init initializes chain code - sets chaincode "owner" | |
func (cc *Chaincode) Init(stub shim.ChaincodeStubInterface) peer.Response { | |
// set owner of chain code with special permissions , based on tx creator certificate | |
// owner info stored in chaincode state as entry with key "OWNER" and content is serialized "Grant" structure | |
return owner.SetFromCreator(cc.router.Context(`init`, stub)) | |
} | |
// Invoke - entry point for chain code invocations | |
func (cc *Chaincode) Invoke(stub shim.ChaincodeStubInterface) peer.Response { | |
// delegate handling to router |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Car struct for chaincode state | |
type Car struct { | |
Id string | |
Title string | |
Owner string | |
UpdatedAt time.Time // set by chaincode method | |
} | |
// CarPayload chaincode method argument |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Key for car entry in chaincode state | |
func Key(id string) []string { | |
return []string{CarKeyPrefix, id} | |
} | |
// car get info chaincode method handler | |
func car(c router.Context) (interface{}, error) { | |
return c.State().Get( // get state entry | |
Key(c.ArgString(`id`)), // by composite key using CarKeyPrefix and car.Id | |
&Car{}) // and unmarshal from []byte to Car struct |
OlderNewer