Bug Of spec256k1-php Was Fixed With PHP-hack And UPDs[php-graphene-node-client v3.1.0]

in #utopian-io7 years ago (edited)

php-graphene-node-client

It is PHP API client for Steem/GOLOS blockchain

Github or packagist with MIT license. Author @t3ran13 and active helper @semasping

In Release v3.1.0

  • spec256k1-php bug fix
  • upd Transaction:init()
  • brodcast operations classes Op*.php were updated
  • readme was updated

spec256k1-php bug fix

Transactions are signing with spec256k1-php with function secp256k1_ecdsa_sign_recoverable($context, $signatureRec, $msg32, $privateKey) and if it is not canonical from first time, you have to make transaction for other block. For searching canonical sign function have to implement two more parameters, but spec256k1-php library does not have it.

It is was solved with php-hack in Transaction::sign() - we will add 1 sec to tx expiration time and try to get canonical signing for new msg. Up to 200 tries.

...
//becouse spec256k1-php canonical sign trouble will use php hack.
//If sign is not canonical, we have to chang msg () and try to sign again
$nTries = 0;
while (true) {
    $nTries++;
    $msg = self::getTxMsg($chainName, $trxData);
    echo '<pre>' . print_r($trxData->getParams(), true) . '<pre>'; //FIXME delete it

    try {
        foreach ($privateWIFs as $keyName => $privateWif) {
            $index = count($trxData->getParams()[0]['signatures']);

            /** @var CommandQueryData $trxData */
            $trxData->setParamByKey('0:signatures:' . $index, self::signOperation($msg, $privateWif));
        }
        break;
    } catch (TransactionSignException $e) {
        if ($nTries > 200) {
            //stop tries to find canonical sign
            throw $e;
            break;
        } else {
            /** @var CommandQueryData $trxData */
            $params = $trxData->getParams();
            foreach ($params as $key => $tx) {
                $tx['expiration'] = (new \DateTime($tx['expiration']))
                    ->add(new \DateInterval('PT0M1S'))
                    ->format('Y-m-d\TH:i:s\.000');
                $params[$key] = $tx;
            }
            $trxData->setParams($params);
        }
    }
...

Transaction:init()

We have to transfer connector(it have to implements ConnectorInterface) instead ChainName param to function now like in example below

<?php

use GrapheneNodeClient\Tools\Transaction;
use GrapheneNodeClient\Connectors\Http\SteemitHttpConnector;
use GrapheneNodeClient\Connectors\WebSocket\GolosWSConnector;

$connector = new SteemitHttpConnector();
//$connector = new GolosWSConnector();

/** @var CommandQueryData $tx */
$tx = Transaction::init($connector);
$tx->setParamByKey(
    '0:operations:0',
    [
        'vote',
        [
            'voter'    => $voter,
            'author'   => $author,
            'permlink' => $permlink,
            'weight'   => $weight
        ]
    ]
);

$command = new BroadcastTransactionSynchronousCommand($connector);
Transaction::sign($chainName, $tx, ['posting' => $publicWif]);

$answer = $command->execute(
    $tx
);

brodcast operations classes Op*.php were updated

We have to transfer connector(it have to implements ConnectorInterface) instead ChainName param to function now like in example below

<?php

use GrapheneNodeClient\Tools\ChainOperations\OpVote;
use GrapheneNodeClient\Connectors\Http\SteemitHttpConnector;
use GrapheneNodeClient\Connectors\WebSocket\GolosWSConnector;

$connector = new SteemitHttpConnector();
//$connector = new GolosWSConnector();

$answer = OpVote::doSynchronous(
    $connector,
    'guest123',
    '5JRaypasxMx1L97ZUX7YuC5Psb5EAbF821kkAGtBj7xCJFQcbLg',
    'firepower',
    'steemit-veni-vidi-vici-steemfest-2016-together-we-made-it-happen-thank-you-steemians',
    10000
);

// example of answer
//Array
//(
//    [id] => 5
//    [result] => Array
//        (
//            [id] => a2c52988ea870e446480782ff046994de2666e0d
//            [block_num] => 17852337
//            [trx_num] => 1
//            [expired] =>
//        )
//
//)

Do not forget to make pull request and post about it on utopian


It is better with each commit

Commits were done by me for release v3.1.0

  • TransactionSignException.php was added
  • Transaction.php php hack for fix bug of spec256k1-php and tx init upd
  • OpComment.php was updated
  • OpTransfer.php was updated
  • OpVote.php was updated
  • README.md was updated
  • clear staff



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Thank you for the contribution. It has been approved.

You can contact us on Discord.
[utopian-moderator]

thx you too!)

Вот НИФИГА не понял, но на вский случай апнул , вдруг пригодится))

нужно хрундель окунуть в пхп, а потом начать делать что-то полезное для стима или голоса) почти тоже самое что готовка, только не так вкусно, но проще)

Я пока только слегка готовлю в хтмл, в пхп не умею готовить)

Я тоже с хтмл начинал)

Ну, все.Лет через ..дцать я стану гуру пхп)

Hey @t3ran13 I am @utopian-io. I have just upvoted you!

Achievements

  • Seems like you contribute quite often. AMAZING!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x

thank you!