当前位置: 首页>>代码示例>>PHP>>正文


PHP Buffer::getInt方法代码示例

本文整理汇总了PHP中BitWasp\Buffertools\Buffer::getInt方法的典型用法代码示例。如果您正苦于以下问题:PHP Buffer::getInt方法的具体用法?PHP Buffer::getInt怎么用?PHP Buffer::getInt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BitWasp\Buffertools\Buffer的用法示例。


在下文中一共展示了Buffer::getInt方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testSerialize

 public function testSerialize()
 {
     $hex = '41414141';
     $dec = EccFactory::getAdapter()->hexDec($hex);
     $bin = pack("H*", $hex);
     $this->buffer = Buffer::hex($hex);
     // Check Binary
     $retBinary = $this->buffer->getBinary();
     $this->assertSame($bin, $retBinary);
     // Check Hex
     $this->assertSame($hex, $this->buffer->getHex());
     // Check Decimal
     $this->assertSame($dec, $this->buffer->getInt());
 }
开发者ID:sbwdlihao,项目名称:buffertools-php,代码行数:14,代码来源:BufferTest.php

示例2: twoValueCases

 /**
  * @param $opCode
  * @param ScriptStack $mainStack
  * @throws \BitWasp\Bitcoin\Exceptions\ScriptStackException
  * @throws \Exception
  */
 private function twoValueCases($opCode, ScriptStack $mainStack)
 {
     if ($mainStack->size() < 2) {
         throw new \Exception('Invalid stack operation (greater than)');
     }
     $num1 = $mainStack->top(-2)->getInt();
     // cscriptnum
     $num2 = $mainStack->top(-1)->getInt();
     $opCodes = $this->opCodes;
     $opName = $opCodes->getOp($opCode);
     $math = $this->math;
     $castToBool = $this->castToBool;
     if ($opName == 'OP_ADD') {
         $num = $math->add($num1, $num2);
     } elseif ($opName == 'OP_SUB') {
         // cscriptnum
         $num = $math->sub($num1, $num2);
     } elseif ($opName == 'OP_BOOLAND') {
         // cscriptnum
         $num = $math->cmp($num1, $this->_bn0->getInt()) !== 0 && $math->cmp($num2, $this->_bn0->getInt()) !== 0;
     } elseif ($opName == 'OP_BOOLOR') {
         $num = $math->cmp($num1, $this->_bn0->getInt()) !== 0 || $math->cmp($num2, $this->_bn0->getInt()) !== 0;
     } elseif ($opName == 'OP_NUMEQUAL') {
         // cscriptnum
         $num = $math->cmp($num1, $num2) == 0;
     } elseif ($opName == 'OP_NUMEQUALVERIFY') {
         // cscriptnum
         $num = $math->cmp($num1, $num2) == 0;
     } elseif ($opName == 'OP_NUMNOTEQUAL') {
         $num = $math->cmp($num1, $num2) !== 0;
     } elseif ($opName == 'OP_LESSTHAN') {
         // cscriptnum
         $num = $math->cmp($num1, $num2) < 0;
     } elseif ($opName == 'OP_GREATERTHAN') {
         $num = $math->cmp($num1, $num2) > 0;
     } elseif ($opName == 'OP_LESSTHANOREQUAL') {
         // cscriptnum
         $num = $math->cmp($num1, $num2) <= 0;
     } elseif ($opName == 'OP_GREATERTHANOREQUAL') {
         $num = $math->cmp($num1, $num2) >= 0;
     } elseif ($opName == 'OP_MIN') {
         $num = $math->cmp($num1, $num2) <= 0 ? $num1 : $num2;
     } else {
         // is OP_MAX
         $num = $math->cmp($num1, $num2) >= 0 ? $num1 : $num2;
     }
     $mainStack->pop();
     $mainStack->pop();
     $buffer = Buffer::hex($math->decHex($num));
     $mainStack->push($buffer);
     if ($opCodes->isOp($opCode, 'OP_NUMEQUALVERIFY')) {
         if ($castToBool($mainStack->top(-1))) {
             $mainStack->pop();
         } else {
             throw new \Exception('NUM EQUAL VERIFY error');
         }
     }
 }
开发者ID:rubensayshi,项目名称:bitcoin-php,代码行数:64,代码来源:ArithmeticOperation.php

示例3: check

 /**
  * @param Buffer $hash
  * @param int|string $nBits
  * @return bool
  */
 public function check(Buffer $hash, $nBits)
 {
     $negative = false;
     $overflow = false;
     $target = $this->math->writeCompact($nBits, $negative, $overflow);
     if ($negative || $overflow || $this->math->cmp($target, 0) === 0 || $this->math->cmp($target, $this->getMaxTarget()) > 0) {
         throw new \RuntimeException('nBits below minimum work');
     }
     if ($this->math->cmp($hash->getInt(), $target) > 0) {
         throw new \RuntimeException("Hash doesn't match nBits");
     }
     return true;
 }
开发者ID:sbwdlihao,项目名称:bitcoin-php,代码行数:18,代码来源:ProofOfWork.php

示例4: generateMasterKey

 /**
  * Generate a master private key given a
  * @param Buffer $seed
  * @param EcAdapterInterface $ecAdapter
  * @return ElectrumKey
  */
 public static function generateMasterKey(Buffer $seed, EcAdapterInterface $ecAdapter = null)
 {
     // Really weird, did electrum actually hash hex string seeds?
     $seed = $oldseed = $seed->getHex();
     // Perform sha256 hash 5 times per iteration
     for ($i = 0; $i < 5 * 20000; $i++) {
         // Hash should return binary data
         $seed = hash('sha256', $seed . $oldseed, true);
     }
     // Convert binary data to hex.
     $str = new Buffer($seed);
     return self::fromSecretExponent($str->getInt(), $ecAdapter ?: Bitcoin::getEcAdapter());
 }
开发者ID:rubensayshi,项目名称:bitcoin-php,代码行数:19,代码来源:ElectrumKeyFactory.php

示例5: encode

 /**
  * Encode a given hex string in base58
  *
  * @param Buffer $binary
  * @return string
  * @throws \Exception
  */
 public static function encode(Buffer $binary)
 {
     $size = $binary->getSize();
     if ($size == 0) {
         return '';
     }
     $math = Bitcoin::getMath();
     $orig = $binary->getBinary();
     $decimal = $binary->getInt();
     $return = "";
     while ($math->cmp($decimal, 0) > 0) {
         list($decimal, $rem) = $math->divQr($decimal, 58);
         $return = $return . self::$base58chars[$rem];
     }
     $return = strrev($return);
     //leading zeros
     for ($i = 0; $i < $size && $orig[$i] == ""; $i++) {
         $return = "1" . $return;
     }
     return $return;
 }
开发者ID:rubensayshi,项目名称:bitcoin-php,代码行数:28,代码来源:Base58.php

示例6: __construct

 /**
  * @param EcAdapterInterface $ecAdapter
  * @param PrivateKeyInterface $privateKey
  * @param Buffer $messageHash
  * @param string $algo
  */
 public function __construct(EcAdapterInterface $ecAdapter, PrivateKeyInterface $privateKey, Buffer $messageHash, $algo = 'sha256')
 {
     $mdPk = new MdPrivateKey($ecAdapter->getMath(), $ecAdapter->getGenerator(), $privateKey->getSecretMultiplier());
     $this->ecAdapter = $ecAdapter;
     $this->hmac = new HmacRandomNumberGenerator($ecAdapter->getMath(), $mdPk, $messageHash->getInt(), $algo);
 }
开发者ID:rubensayshi,项目名称:bitcoin-php,代码行数:12,代码来源:Rfc6979.php

示例7: hasBlockchain

 public function hasBlockchain()
 {
     $math = Bitcoin::getMath();
     return $math->cmp($math->bitwiseAnd($this->services->getInt(), self::NODE_NETWORK), self::NODE_NETWORK) == 0;
 }
开发者ID:tokenly,项目名称:bitcoin-p2p-php,代码行数:5,代码来源:Version.php

示例8: validatePrivateKey

 /**
  * @param Buffer $privateKey
  * @return bool
  */
 public function validatePrivateKey(Buffer $privateKey)
 {
     $math = $this->math;
     $scalar = $privateKey->getInt();
     return $math->cmp($scalar, 0) > 0 && $math->cmp($scalar, $this->getGenerator()->getOrder()) < 0;
 }
开发者ID:sbwdlihao,项目名称:bitcoin-php,代码行数:10,代码来源:EcAdapter.php

示例9: castToBool

 /**
  * Cast the value to a boolean
  *
  * @param $value
  * @return bool
  */
 public function castToBool(Buffer $value)
 {
     if ($value->getSize() === 0) {
         return true;
     }
     // Since we're using buffers, lets try ensuring the contents are not 0.
     return $this->math->cmp($value->getInt(), 0) > 0;
 }
开发者ID:sbwdlihao,项目名称:bitcoin-php,代码行数:14,代码来源:Interpreter.php

示例10: validatePrivateKey

 /**
  * @param Buffer $privateKey
  * @return bool
  */
 public function validatePrivateKey(Buffer $privateKey)
 {
     return $this->checkInt($privateKey->getInt(), $this->getGenerator()->getOrder());
 }
开发者ID:rubensayshi,项目名称:bitcoin-php,代码行数:8,代码来源:PhpEcc.php

示例11: castToBool

 /**
  * Cast the value to a boolean
  *
  * @param $value
  * @return bool
  */
 public function castToBool(Buffer $value)
 {
     // Since we're using buffers, lets try ensuring the contents are not 0.
     return $this->ecAdapter->getMath()->cmp($value->getInt(), 0) > 0;
     // cscriptNum or edge case.
 }
开发者ID:rubensayshi,项目名称:bitcoin-php,代码行数:12,代码来源:Interpreter.php


注:本文中的BitWasp\Buffertools\Buffer::getInt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。