2017 © Pedro Peláez
 

library hyperledger-fabric-sdk-php

Hyperledger Fabric client SDK in PHP

image

americanexpress/hyperledger-fabric-sdk-php

Hyperledger Fabric client SDK in PHP

  • Saturday, December 9, 2017
  • by tklever
  • Repository
  • 12 Watchers
  • 19 Stars
  • 8 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 9 Forks
  • 2 Open issues
  • 3 Versions
  • 14 % Grown

The README.md

Build Status Coverage Status Scrutinizer Code Quality, (*1)

Hyperledger Fabric Client SDK for PHP


Welcome to PHP SDK for Hyperledger project. The main objective of this SDK is to facilitate a client to perform basic chaincode related operations like: creating a channel, installing and accessing a chaincode etc., (*2)

Note, the fabric-sdk-php is a standalone client side interface to access the network information and ledger data over running blockchain network, it cannot be used as a persistence medium for application defined channels data., (*3)

Installation

composer require americanexpress/hyperledger-fabric-sdk-php

Usage

Below, you will find high-level and concise snippets of code demonstrating how to interact with this SDK., (*4)

Channel::queryByChaincode

Query first peer in first organization (default behavior):, (*5)

$config = new \AmericanExpress\HyperledgerFabricClient\Config\ClientConfig([
    // See `test/integration/config.php` for an example.
]);
$response = \AmericanExpress\HyperledgerFabricClient\Client\ClientFactory::fromConfig($config)
    ->getChannel('foo')
    ->getChaincode('example_cc')
    ->invoke('query', 'a');

Query specific organization:, (*6)

$config = new \AmericanExpress\HyperledgerFabricClient\Config\ClientConfig([
    // See `test/integration/config.php` for an example.
]);
$response = \AmericanExpress\HyperledgerFabricClient\Client\ClientFactory::fromConfig($config, 'peerOrg1')
    ->getChannel('foo')
    ->getChaincode('example_cc')
    ->invoke('query', 'a');

Query specific organization and peer:, (*7)

$config = new \AmericanExpress\HyperledgerFabricClient\Config\ClientConfig([
    // See `test/integration/config.php` for an example.
]);
$options = new \AmericanExpress\HyperledgerFabricClient\Transaction\TransactionOptions([
    'peer' => 'peer1',
]);
$response = \AmericanExpress\HyperledgerFabricClient\Client\ClientFactory::fromConfig($config, 'peerOrg1')
    ->getChannel('foo')
    ->getChaincode('example_cc')
    ->invoke('query', 'a', $options);

Query chaincode by path and version:, (*8)

$config = new \AmericanExpress\HyperledgerFabricClient\Config\ClientConfig([
    // See `test/integration/config.php` for an example.
]);
$response = \AmericanExpress\HyperledgerFabricClient\Client\ClientFactory::fromConfig($config)
    ->getChannel('foo')
    ->getChaincode(['name' => 'example_cc', 'version' => '1', 'path' => 'github.com/example_cc'])
    ->invoke('query', 'a');

Phase 1

  • For phase 1, we are providing client access for basic chaincode operations like query by chain code.
  • It’s assumed that we have a running blockchain network, with a predefined channel and an installed chaincode.
  • A predefined script is provided to bring up the test network as per the test cases.

Phase 2 (Upcoming)

  • In next release we are targeting to add more chaincode operations like create channel, invoke & install etc

Latest builds of Fabric and Fabric-ca v1.1.0

Hyperledger Fabric v1.1.0 is currently under active development., (*9)

You can clone these projects by going to the Hyperledger repository., (*10)


Prerequisites

Docker version ^17.0

Check version of Docker:, (*11)

docker --version

PHP version ^7.1

Check version of PHP:, (*12)

php --version

PHP GMP extension

Check PHP-GMP setup in php.ini, (*13)

Composer tool

Check composer version (it should be 1.5 or plus), (*14)

composer --version

Installing SDK (for development)

git clone https://github.com/americanexpress/hyperledger-fabric-sdk-php && cd $_
composer update

Generating SDK API Documentation

composer docs
open build/docs/index.html

Running the End2End test case

Before running the tests, we need to bring up the fabric network and fixture(s):, (*15)

composer fixture:up

At present, we are providing example test case for Querying a chaincode, which can be run as below:, (*16)

composer test:integration

After running the tests, feel free to bring down the fabric network:, (*17)

composer fixture:down

Read more about Docker Compose, (*18)

Regenerating PHP Class files from .proto files

composer protoc

Read more about compiling PHP code from proto files., (*19)

Contributing

We welcome Your interest in the American Express Open Source Community on Github. Any Contributor to any Open Source Project managed by the American Express Open Source Community must accept and sign an Agreement indicating agreement to the terms below. Except for the rights granted in this Agreement to American Express and to recipients of software distributed by American Express, You reserve all right, title, and interest, if any, in and to Your Contributions. Please fill out the Agreement., (*20)

Please feel free to open pull requests and see CONTRIBUTING.md for commit formatting details., (*21)

License

Any contributions made under this project will be governed by the Apache License 2.0., (*22)

Code of Conduct

This project adheres to the American Express Community Guidelines. By participating, you are expected to honor these guidelines., (*23)

The Versions

09/12 2017