From 92f18242376253b008dcfa40be6963d5c8d79751 Mon Sep 17 00:00:00 2001 From: boston Date: Sat, 29 Jun 2019 21:57:47 +0300 Subject: [PATCH] php example --- README.md | 15 +++++++++++++++ examples/cli.php | 1 - src/MetaHashCrypto.php | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7280942..2e8402d 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,21 @@ PHP library for [#MetaHash](https://metahash.org ) blockchain ### Usage +### PHP examples +```php +setNetwork('main'); + +$balance = $metaHash->fetchBalance('0x00fa2a5279f8f0fd2f0f9d3280ad70403f01f9d62f52373833'); +print_r($balance); +``` + +### Console examples ```shell git clone git@github.com:xboston/php-metahash.git cd php-metahash diff --git a/examples/cli.php b/examples/cli.php index 4d11a5e..9e03a5b 100644 --- a/examples/cli.php +++ b/examples/cli.php @@ -21,7 +21,6 @@ $metaHash = new MetaHash(); $metaHash->setNetwork($args['net']); - switch ($args['method']) { case 'generate': $metaHash->setEcdsa(new MetaHashCrypto()); diff --git a/src/MetaHashCrypto.php b/src/MetaHashCrypto.php index 389718f..63b4b95 100644 --- a/src/MetaHashCrypto.php +++ b/src/MetaHashCrypto.php @@ -6,6 +6,8 @@ use Mdanter\Ecc\Crypto\Signature\Signer; use Mdanter\Ecc\Crypto\Signature\SignHasher; use Mdanter\Ecc\EccFactory; +use Mdanter\Ecc\Math\GmpMathInterface; +use Mdanter\Ecc\Primitives\GeneratorPoint; use Mdanter\Ecc\Random\RandomGeneratorFactory; use Mdanter\Ecc\Serializer\PrivateKey\DerPrivateKeySerializer; use Mdanter\Ecc\Serializer\PublicKey\DerPublicKeySerializer; @@ -18,7 +20,13 @@ */ class MetaHashCrypto { + /** + * @var GmpMathInterface + */ private $adapter; + /** + * @var GeneratorPoint + */ private $generator; /** @@ -286,4 +294,36 @@ public function hex2str(string $hex): string { return \pack('H*', $hex); } + + /** + * @return GmpMathInterface + */ + public function getAdapter(): GmpMathInterface + { + return $this->adapter; + } + + /** + * @param GmpMathInterface $adapter + */ + public function setAdapter(GmpMathInterface $adapter): void + { + $this->adapter = $adapter; + } + + /** + * @return GeneratorPoint + */ + public function getGenerator(): GeneratorPoint + { + return $this->generator; + } + + /** + * @param GeneratorPoint $generator + */ + public function setGenerator(GeneratorPoint $generator): void + { + $this->generator = $generator; + } }