This document summarizes a presentation on developing blockchain applications using Hyperledger Fabric. It discusses key Hyperledger Fabric concepts like chaincode, which defines the business logic of a blockchain application. Chaincode is written in languages like Go and JavaScript. It also discusses the Hyperledger Fabric architecture, including components like peers, orderers, and how channels isolate ledgers in the network. The presentation provides examples of querying and updating state databases using chaincode. It demonstrates typical workflows for deploying chaincode to networks like Oracle Autonomous Blockchain Cloud Service.
1. überraschend mehr Möglichkeiten!
DOAG 2018 Konferenz, 22.11.2018
Andreas Chatziantoniou, Matthias Fuchs, Borys Neselovskyi
Eine Reise durch die Blockchain
Applikationsentwicklung
2. Eine Reise durch die Blockchain Applikationsentwicklung
Über uns…
Andreas Chatziantoniou
@MagicChatzi
DevTops, Nürnberg
OCA 10
AS, EM Certified
Middleware
Matthias Fuchs
@hias222
DevTops, Nürnberg
OCP 12
Exadata, RAC, Java Cloud
Certified
Database, Middleware
Borys Neselovskyi
@bneselov
OPITZ CONSULTING, Essen
OCP 8, 10, 12
Database, Middleware,
Engineered Systems
Cloud Technology
BMA
5. Eine Reise durch die Blockchain Applikationsentwicklung
The current world
Shop Bank
Insurance Regulator Manufacturer
Customer
A
6. The current world – with Hyperledger Fabric
Shop Bank
Insurance Regulator
Customer
Blockchain Ledger
shared, replicated, permissioned
A
Eine Reise durch die Blockchain Applikationsentwicklung
Manufacturer
7. What the business wants
Privacy
All transactions have security embedded
Authentication and access controls are
enabled for granular access
Shared Ledger
Database is immutable (append only)
Shared across the business network
Trust
All the transactions are verified and
endorsed by the trusted relevant parties
Smart contract
Business logic is embedded within the
database and executed to validate and
store the transactions
A
Eine Reise durch die Blockchain Applikationsentwicklung
8. Properties of a Distributed Ledger
Decentralized, replicated across many participants, each of whom
collaborate in its maintenance
Information recorded is append-only
Immutability makes it simple to determine the provenance of the
information
These properties makes it called as “Systems of Proof”
A
Eine Reise durch die Blockchain Applikationsentwicklung
9. HyperLedger Fabric Key Features
Private and permission based
Members of HyperLedger Fabric enrolls thru MSP - Membership Service
Provider
Different MSPs are supported
Ledger data can be stored in multiple formats.
Consensus mechanisms can be switched in and out
Ability to create channels - Allowing a group of participants to create a
separate ledger of transactions.
A
Eine Reise durch die Blockchain Applikationsentwicklung
11. Hyperledger Fabric – Assets/Smart Contract
Assets
Real world physical/financial assets
Represented as a collection of key-value
pairs
state changes recorded as transactions on
a Channel ledger
Assets can be represented in binary
and/or JSON form
Smart Contracts
Defining an asset and the transaction
instructions for modifying it
Enforces rules for reading or altering key
value pairs
Executes against the ledger’s current state
database & are initiated through a
transaction proposaI
Execution results in a set of key value
writes (write set) that can be submitted to
the network and applied to the ledger on
all peers
A
Eine Reise durch die Blockchain Applikationsentwicklung
12. Hyperledger Fabric – Ledger/Channels
Ledger
Ledger is the sequenced, tamper-resistant
record of all state transitions in the fabric
State transitions are a result of Chaincode
invocations (‘transactions’) submitted by
participating parties
Each transaction results in a set of asset
key-value pairs that are committed to the
ledger as creates, updates, or deletes
The ledger is comprised of a Blockchain
(‘chain’) to store the immutable,
sequenced record in blocks
Channels
There is one ledger per channel
Each peer maintains a copy of the ledger
for each channel of which they are a
member
Private “subnet” of communication
between two or more specific network
members, for the purpose of conducting
private and confidential transactions
Channel is a completely separate instance
of HyperLedger Fabric. Every Channel is
completely isolated and will never talk to
each other
A
Eine Reise durch die Blockchain Applikationsentwicklung
13. Hyperledger vs Bitcoin A
Eine Reise durch die Blockchain Applikationsentwicklung
Hyperledger Fabric Bitcoin
Provides Identity Anonymity
Practical Byzantine Fault Tolerance Proof of work
Assets Cryptocurrency
Selective Endorsement Zero Trust
15. Eine Reise durch die Blockchain Applikationsentwicklung
What is Chaincode?
Chaincode is software defining the business logic
Chaincode is a piece of code that is written in Javascript / Go / Node.js
Chaincode enforces the rules for reading or altering key-value pairs or
other state database information.
Chaincode functions execute against the ledger’s current state database
and are initiated through a transaction proposal.
Chaincode execution results in a set of key-value writes (write set) that can
be submitted to the network and applied to the ledger on all peers.
Source: https://hyperledger-fabric.readthedocs.io/en/release-1.3/fabric_model.html
B
16. Eine Reise durch die Blockchain Applikationsentwicklung
Chaincode: two perspectives
Chaincode for Developers
Developing a blockchain
application
Chaincode for Operator
Managing blockchain network
Maintenance chaincode by:
Install
Instantiate
upgrade
B
17. Eine Reise durch die Blockchain Applikationsentwicklung
Chaincode Interface
Methods:
B
18. Eine Reise durch die Blockchain Applikationsentwicklung
Chaincode Interface
Dependencies:
Package shim provides APIs for the chaincode
to access its state variables, transaction context
and call other chaincodes:
Can be generated:
import
"github.com/hyperledger/fabric/core/chain
code/shim"
Functions:
* fmt: contains PrintIn for debugging/logging
* error: standard go error format
B
Source: https://fabrictestdocs.readthedocs.io/en/latest/chaincode.html
19. Eine Reise durch die Blockchain Applikationsentwicklung
Package shim: Logging Control
Create a logging object for use by a chaincode:
NewLogger(name string) *ChaincodeLogger
Set the logging level of the logger:
(c *ChaincodeLogger) SetLevel(level LoggingLevel)
Return true if logs will be generated at the given level:
(c *ChaincodeLogger) IsEnabledFor(level LoggingLevel) bool
A LoggingLevel is a member of the enumeration:
LogDebug, LogInfo, LogNotice, LogWarning, LogError, LogCritical
which can be used directly, or generated by passing a case-insensitive version of the strings:
DEBUG, INFO, NOTICE, WARNING, ERROR, CRITICAL
B
Source: https://hyperledger-fabric.readthedocs.io/en/release-1.2/logging-control.html
20. Eine Reise durch die Blockchain Applikationsentwicklung
Package shim: Type Response
A response with a representation similar to an HTTP response that can be used within another
message
B
21. Eine Reise durch die Blockchain Applikationsentwicklung
Package shim: Type ServerStatus_StatusCode
type ServerStatus_StatusCode int32
B
22. Eine Reise durch die Blockchain Applikationsentwicklung
Oracle Autonomous Blockchain Cloud Service (OABCS)
Chaincode is written in Go or node.js and packaged into a ZIP file
Create the package.json file with two sections:
The scripts section declares how to launch the chaincode
The dependencies section specifies the dependencies
Source: https://docs.oracle.com/en/cloud/paas/blockchain-cloud/user/write-chaincode.html#GUID-64153568-41D2-40E6-9F66-EF384AFEC8E9
B
23. Eine Reise durch die Blockchain Applikationsentwicklung
Oracle Autonomous Blockchain Cloud Service (OABCS)
Source: https://docs.oracle.com/en/cloud/paas/blockchain-cloud/user/typical-workflow-deploy-chaincodes.html
B
24. Eine Reise durch die Blockchain Applikationsentwicklung
REST API for Oracle Autonomous Blockchain Cloud Service
Administer Chaincode:
Get Chaincode Information:
Method: GET
Path: /console/admin/api/v1.1/chaincodes/{chaincodeName}
Install a Chaincode:
Method: POST
Path: /console/admin/api/v1.1/chaincodes
Instantiate a Chaincode:
Method: POST
Path: /console/admin/api/v1.1/chaincodes/{chaincodeName}/instantiate
List of all REST Endpoints:
https://docs.oracle.com/en/cloud/paas/blockchain-cloud/rest-api/rest-endpoints.html
B
27. Access (hyperledger)
Query State DB (CouchDB)
versioned key-value store (KVS)
blobs
Fabric Core
Rest
Cli
Hyperledger Fabric SDKs Document Store
schema-free
RESTful HTTP/JSON API
M
28. Eine Reise durch die Blockchain Applikationsentwicklung
Access Path (hyperledger)
Rest
EndpointsRest
Endpoints
Micro-
services
Micro-
services
Micro-
services
Rest Connects
IoT Devices
Integration
CLI (peer cmds)
Rest
SDK (java, node
..)
M
29. Events
event hub
This service sent events any time a new
block was added to the peer’s ledger,
regardless of the channel to which that
block pertained
New since 1.1
Event services
Deliver
DeliverFiltered
SDK with
Integratio
n
SDK (java, node
..)
M
33. Development 1 – Basic Tasks
Query
Most queries against the state
DB
Chaincode shim interface
Updates
channel.SendTransactionPropos
al
The ordering service bundles
the transaction into a block and
delivers it to all peers on a
channel for validation
34. Development – 2 Example Swagger
Using hyperledger
composer
Yeoman generates a
template
Some examples from
fabric
Start rest server