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


PHP Buffer::int方法代码示例

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


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

示例1: serialize

 /**
  * @param TransactionSignature $txSig
  * @return \BitWasp\Buffertools\Buffer
  */
 public function serialize(TransactionSignature $txSig)
 {
     $sig = $this->sigSerializer->serialize($txSig->getSignature());
     $parser = new Parser($sig->getHex());
     $parser->writeBytes(1, Buffer::int($txSig->getHashType(), 1));
     $buffer = $parser->getBuffer();
     return $buffer;
 }
开发者ID:sbwdlihao,项目名称:bitcoin-php,代码行数:12,代码来源:TransactionSignatureSerializer.php

示例2: getGenesisBlock

 /**
  * @return \BitWasp\Bitcoin\Block\BlockInterface
  */
 public function getGenesisBlock()
 {
     $timestamp = new Buffer('The Times 03/Jan/2009 Chancellor on brink of second bailout for banks', null, $this->math);
     $publicKey = Buffer::hex('04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f', null, $this->math);
     $inputScript = ScriptFactory::sequence([Buffer::int('486604799', 4, $this->math)->flip(), Buffer::int('4', null, $this->math), $timestamp]);
     $outputScript = ScriptFactory::sequence([$publicKey, Opcodes::OP_CHECKSIG]);
     return new Block($this->math, $this->getGenesisBlockHeader(), new TransactionCollection([(new TxBuilder())->version('1')->input(new Buffer('', 32), 4294967295.0, $inputScript)->output(5000000000.0, $outputScript)->locktime(0)->get()]));
 }
开发者ID:Bit-Wasp,项目名称:node-php,代码行数:11,代码来源:RegtestParams.php

示例3: serialize

 /**
  * @param BloomFilter $filter
  * @return BufferInterface
  */
 public function serialize(BloomFilter $filter)
 {
     $math = new Math();
     $vBuf = [];
     foreach ($filter->getData() as $i) {
         $vBuf[] = Buffer::int($i, 1, $math);
     }
     return $this->getTemplate()->write([$vBuf, $filter->getNumHashFuncs(), $filter->getTweak(), (string) $filter->getFlags()]);
 }
开发者ID:nmarley,项目名称:bitcoin-php,代码行数:13,代码来源:BloomFilterSerializer.php

示例4: doSerialize

 /**
  * @param PublicKey $publicKey
  * @return Buffer
  */
 private function doSerialize(PublicKey $publicKey)
 {
     $math = $this->ecAdapter->getMath();
     $point = $publicKey->getPoint();
     $compressed = $publicKey->isCompressed();
     $parser = new Parser('', $math);
     $parser->writeBytes(1, $this->getPrefix($compressed, $point));
     $compressed ? $parser->writeBytes(32, Buffer::int($point->getX(), null, $math)) : $parser->writeBytes(32, Buffer::int($point->getX(), null, $math))->writeBytes(32, Buffer::int($point->getY(), null, $math));
     return $parser->getBuffer();
 }
开发者ID:sbwdlihao,项目名称:bitcoin-php,代码行数:14,代码来源:PublicKeySerializer.php

示例5: __construct

 /**
  * @param EcAdapter $ecAdapter
  * @param $int
  * @param bool $compressed
  * @throws InvalidPrivateKey
  */
 public function __construct(EcAdapter $ecAdapter, $int, $compressed = false)
 {
     if (false === $ecAdapter->validatePrivateKey(Buffer::int($int, 32, $ecAdapter->getMath()))) {
         throw new InvalidPrivateKey('Invalid private key - must be less than curve order.');
     }
     if (false === is_bool($compressed)) {
         throw new \InvalidArgumentException('PrivateKey: Compressed argument must be a boolean');
     }
     $this->ecAdapter = $ecAdapter;
     $this->secretMultiplier = $int;
     $this->compressed = $compressed;
 }
开发者ID:nmarley,项目名称:bitcoin-php,代码行数:18,代码来源:PrivateKey.php

示例6: serialize

 /**
  * @param AlertDetail $detail
  * @return \BitWasp\Buffertools\Buffer
  */
 public function serialize(AlertDetail $detail)
 {
     $setCancels = [];
     foreach ($detail->getSetCancel() as $toCancel) {
         $t = new Parser();
         $setCancels[] = $t->writeBytes(4, Buffer::int($toCancel), true)->getBuffer();
     }
     $setSubVers = [];
     foreach ($detail->getSetSubVer() as $subVer) {
         $t = new Parser();
         $setSubVers[] = $t->writeBytes(4, Buffer::int($subVer), true)->getBuffer();
     }
     return $this->getTemplate()->write([$detail->getVersion(), $detail->getRelayUntil(), $detail->getExpiration(), $detail->getId(), $detail->getCancel(), $setCancels, $detail->getMinVer(), $detail->getMaxVer(), $setSubVers, $detail->getPriority(), $detail->getComment(), $detail->getStatusBar()]);
 }
开发者ID:tokenly,项目名称:bitcoin-p2p-php,代码行数:18,代码来源:AlertDetailSerializer.php

示例7: bitsToBuffers

 /**
  * @param array $bits
  * @return array
  */
 private function bitsToBuffers(array $bits)
 {
     $math = Bitcoin::getMath();
     $vBuffers = str_split(str_pad('', (count($bits) + 7) / 8, '0', STR_PAD_LEFT));
     $nBits = count($bits);
     for ($p = 0; $p < $nBits; $p++) {
         $index = (int) floor($p / 8);
         $vBuffers[$index] |= $bits[$p] << $p % 8;
     }
     foreach ($vBuffers as &$value) {
         $value = Buffer::int($value, null, $math);
     }
     unset($value);
     return $vBuffers;
 }
开发者ID:nmarley,项目名称:bitcoin-php,代码行数:19,代码来源:PartialMerkleTreeSerializer.php

示例8: push

 /**
  * Push data into the stack.
  *
  * @param $data
  * @return $this
  * @throws \Exception
  */
 public function push(Buffer $data)
 {
     $length = $data->getSize();
     $parsed = new Parser('', $this->math);
     /** Note that larger integers are serialized without flipping bits - Big endian */
     if ($length < $this->opcodes->getOpByName('OP_PUSHDATA1')) {
         $varInt = Buffertools::numToVarInt($length);
         $data = new Buffer($varInt->getBinary() . $data->getBinary(), null, $this->math);
         $parsed->writeBytes($data->getSize(), $data);
     } else {
         if ($length <= 0xff) {
             $lengthSize = 1;
         } elseif ($length <= 0xffff) {
             $lengthSize = 2;
         } else {
             $lengthSize = 4;
         }
         $op = $this->opcodes->getOpByName('OP_PUSHDATA' . $lengthSize);
         $parsed->writeBytes(1, Buffer::int($op))->writeBytes($lengthSize, Buffer::int($length), true)->writeBytes($length, $data);
     }
     $this->script .= $parsed->getBuffer()->getBinary();
     return $this;
 }
开发者ID:sbwdlihao,项目名称:bitcoin-php,代码行数:30,代码来源:ScriptCreator.php

示例9: testIntConstruct

 /**
  * @dataProvider IntVectors
  */
 public function testIntConstruct($int, $size, $expectedHex, $math)
 {
     $buffer = Buffer::int($int, $size, $math);
     $this->assertEquals($expectedHex, $buffer->getHex());
 }
开发者ID:sbwdlihao,项目名称:buffertools-php,代码行数:8,代码来源:BufferTest.php

示例10: calculate

 /**
  * Calculate the hash of the current transaction, when you are looking to
  * spend $txOut, and are signing $inputToSign. The SigHashType defaults to
  * SIGHASH_ALL, though SIGHASH_SINGLE, SIGHASH_NONE, SIGHASH_ANYONECANPAY
  * can be used.
  *
  * @param ScriptInterface $txOutScript
  * @param int $inputToSign
  * @param int $sighashType
  * @return BufferInterface
  * @throws \Exception
  */
 public function calculate(ScriptInterface $txOutScript, $inputToSign, $sighashType = SigHash::ALL)
 {
     $math = Bitcoin::getMath();
     $tx = new TxMutator($this->transaction);
     $inputs = $tx->inputsMutator();
     $outputs = $tx->outputsMutator();
     // Default SIGHASH_ALL procedure: null all input scripts
     foreach ($inputs as $input) {
         $input->script(new Script());
     }
     $inputs[$inputToSign]->script($txOutScript);
     if ($math->cmp($math->bitwiseAnd($sighashType, 31), SigHash::NONE) === 0) {
         // Set outputs to empty vector, and set sequence number of inputs to 0.
         $outputs->null();
         // Let the others update at will. Set sequence of inputs we're not signing to 0.
         foreach ($inputs as $i => $input) {
             if ($i !== $inputToSign) {
                 $input->sequence(0);
             }
         }
     } elseif ($math->cmp($math->bitwiseAnd($sighashType, 31), SigHash::SINGLE) === 0) {
         // Resize output array to $inputToSign + 1, set remaining scripts to null,
         // and set sequence's to zero.
         $nOutput = $inputToSign;
         if ($nOutput >= $this->nOutputs) {
             return Buffer::hex('0100000000000000000000000000000000000000000000000000000000000000', 32, $math);
         }
         // Resize, set to null
         $outputs->slice(0, $nOutput + 1);
         for ($i = 0; $i < $nOutput; $i++) {
             $outputs[$i]->null();
         }
         // Let the others update at will. Set sequence of inputs we're not signing to 0
         foreach ($inputs as $i => $input) {
             if ($i !== $inputToSign) {
                 $input->sequence(0);
             }
         }
     }
     // This can happen regardless of whether it's ALL, NONE, or SINGLE
     if ($math->cmp($math->bitwiseAnd($sighashType, SigHash::ANYONECANPAY), 0) > 0) {
         $input = $inputs[$inputToSign]->done();
         $inputs->null()->add($input);
     }
     return Hash::sha256d(Buffertools::concat($tx->done()->getBuffer(), Buffertools::flipBytes(Buffer::int($sighashType, 4, $math))));
 }
开发者ID:nmarley,项目名称:bitcoin-php,代码行数:58,代码来源:Hasher.php

示例11: tweakMul

 /**
  * @param int $tweak
  * @return PrivateKey
  */
 public function tweakMul($tweak)
 {
     $adapter = $this->ecAdapter;
     $math = $adapter->getMath();
     $context = $adapter->getContext();
     $privateKey = $this->getBinary();
     // mod by reference
     $tweak = Buffer::int($tweak, 32, $math)->getBinary();
     $ret = \secp256k1_ec_privkey_tweak_mul($context, $privateKey, $tweak);
     if ($ret !== 1) {
         throw new \RuntimeException('Secp256k1 privkey tweak mul: failed');
     }
     $secret = $math->hexDec(bin2hex($privateKey));
     return $adapter->getPrivateKey($secret, $this->compressed);
 }
开发者ID:sbwdlihao,项目名称:bitcoin-php,代码行数:19,代码来源:PrivateKey.php

示例12: bytes

 /**
  * @param int $bytes
  * @return Buffer
  */
 public function bytes($bytes)
 {
     $integer = $this->hmac->generate($this->ecAdapter->getGenerator()->getOrder());
     return Buffer::int($integer, $bytes, $this->ecAdapter->getMath());
 }
开发者ID:sbwdlihao,项目名称:bitcoin-php,代码行数:9,代码来源:Rfc6979.php

示例13: getTargetHash

 /**
  * @param Buffer $bits
  * @return Buffer
  */
 public function getTargetHash(Buffer $bits)
 {
     return Buffer::int($this->getTarget($bits), 32, $this->math);
 }
开发者ID:sbwdlihao,项目名称:bitcoin-php,代码行数:8,代码来源:ProofOfWork.php

示例14: deriveChild

 /**
  * Derive a child key
  *
  * @param $sequence
  * @return HierarchicalKey
  * @throws \Exception
  */
 public function deriveChild($sequence)
 {
     $chain = Buffer::int($this->getChainCode(), 32, $this->ecAdapter->getMath());
     $hash = Hash::hmac('sha512', $this->getHmacSeed($sequence), $chain);
     $offset = $hash->slice(0, 32);
     $chain = $hash->slice(32);
     $key = $this->isPrivate() ? $this->getPrivateKey() : $this->getPublicKey();
     if (false === $this->ecAdapter->validatePrivateKey($offset)) {
         return $this->deriveChild($sequence + 1);
     }
     return new HierarchicalKey($this->ecAdapter, $this->getDepth() + 1, $this->getChildFingerprint(), $sequence, $chain->getInt(), $key->tweakAdd($offset->getInt()));
 }
开发者ID:sbwdlihao,项目名称:bitcoin-php,代码行数:19,代码来源:HierarchicalKey.php

示例15: serialize

 /**
  * @param PrivateKeyInterface $privateKey
  * @return BufferInterface
  */
 public function serialize(PrivateKeyInterface $privateKey)
 {
     return Buffer::int($privateKey->getSecretMultiplier(), 32, $this->ecAdapter->getMath());
 }
开发者ID:nmarley,项目名称:bitcoin-php,代码行数:8,代码来源:PrivateKeySerializer.php


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