americanexpress/hyperledger-fabric-sdk-php

Hyperledger Fabric client SDK in PHP

0.1.1 2017-12-09 00:13 UTC

This package is not auto-updated.

Last update: 2024-11-01 04:10:16 UTC


README

Build Status Coverage Status Scrutinizer Code Quality

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.

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.

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.

Channel::queryByChaincode

Query first peer in first organization (default behavior):

$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:

$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:

$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:

$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.

You can clone these projects by going to the Hyperledger repository.

Prerequisites

Docker version ^17.0

Check version of Docker:

docker --version

PHP version ^7.1

Check version of PHP:

php --version

PHP GMP extension

Check PHP-GMP setup in php.ini

Composer tool

Check composer version (it should be 1.5 or plus)

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):

composer fixture:up

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

composer test:integration

After running the tests, feel free to bring down the fabric network:

composer fixture:down

Read more about Docker Compose

Regenerating PHP Class files from .proto files

composer protoc

Read more about compiling PHP code from proto files.

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.

Please feel free to open pull requests and see CONTRIBUTING.md for commit formatting details.

License

Any contributions made under this project will be governed by the Apache License 2.0.

Code of Conduct

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