• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Buffertools\Buffer类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: __construct

 /**
  * @param int $type
  * @param Buffer $hash
  */
 public function __construct($type, Buffer $hash)
 {
     if (false === $this->checkType($type)) {
         throw new \InvalidArgumentException('Invalid type in InventoryVector');
     }
     if (false === (32 === $hash->getSize())) {
         throw new \InvalidArgumentException('Hash size must be 32 bytes');
     }
     $this->type = $type;
     $this->hash = $hash;
 }
开发者ID:tokenly,项目名称:bitcoin-p2p-php,代码行数:15,代码来源:Inventory.php


示例2: __construct

 /**
  * @param int|string $version
  * @param Buffer $prevBlock
  * @param Buffer $merkleRoot
  * @param int|string $timestamp
  * @param Buffer $bits
  * @param int|string $nonce
  */
 public function __construct($version, Buffer $prevBlock, Buffer $merkleRoot, $timestamp, Buffer $bits, $nonce)
 {
     if (!is_numeric($version)) {
         throw new \InvalidArgumentException('Block header version must be numeric');
     }
     if ($prevBlock->getSize() !== 32) {
         throw new \InvalidArgumentException('Block header prevBlock must be a 32-byte Buffer');
     }
     if ($merkleRoot->getSize() !== 32) {
         throw new \InvalidArgumentException('Block header prevBlock must be a 32-byte Buffer');
     }
     if (!is_numeric($timestamp)) {
         throw new \InvalidArgumentException('Block header timestamp must be numeric');
     }
     if (!is_numeric($nonce)) {
         throw new \InvalidArgumentException('Block header nonce must be numeric');
     }
     $this->version = $version;
     $this->prevBlock = $prevBlock;
     $this->merkleRoot = $merkleRoot;
     $this->timestamp = $timestamp;
     $this->bits = $bits;
     $this->nonce = $nonce;
     $this->initFunctionAlias('version', 'getVersion')->initFunctionAlias('prevBlock', 'getPrevBlock')->initFunctionAlias('merkleRoot', 'getMerkleRoot')->initFunctionAlias('timestamp', 'getTimestamp')->initFunctionAlias('bits', 'getBits')->initFunctionAlias('nonce', 'getNonce');
 }
开发者ID:sbwdlihao,项目名称:bitcoin-php,代码行数:33,代码来源:BlockHeader.php


示例3: parseIpBuffer

 /**
  * @param Buffer $ip
  * @return string
  * @throws \Exception
  */
 private function parseIpBuffer(Buffer $ip)
 {
     $end = $ip->slice(12, 4);
     return implode(".", array_map(function ($int) {
         return unpack("C", $int)[1];
     }, str_split($end->getBinary(), 1)));
 }
开发者ID:tokenly,项目名称:bitcoin-p2p-php,代码行数:12,代码来源:NetworkAddressTimestampSerializer.php


示例4: unpackCompact

 /**
  * @param Buffer $bits
  * @return array
  */
 public function unpackCompact(Buffer $bits)
 {
     $bitStr = $bits->getBinary();
     // Unpack and decode
     $sci = array_map(function ($value) {
         return $this->hexDec($value);
     }, unpack('H2exp/H6mul', $bitStr));
     return $sci;
 }
开发者ID:rubensayshi,项目名称:bitcoin-php,代码行数:13,代码来源:Math.php


示例5: __construct

 /**
  * OutPoint constructor.
  * @param Buffer $hashPrevOutput
  * @param int $nPrevOutput
  */
 public function __construct(Buffer $hashPrevOutput, $nPrevOutput)
 {
     if ($hashPrevOutput->getSize() !== 32) {
         throw new \InvalidArgumentException('OutPoint: hashPrevOut must be a 32-byte Buffer');
     }
     if (!is_numeric($nPrevOutput)) {
         throw new \InvalidArgumentException('OutPoint: nPrevOut must be numeric');
     }
     $this->hashPrevOutput = $hashPrevOutput;
     $this->nPrevOutput = $nPrevOutput;
     $this->initFunctionAlias('txid', 'getTxId')->initFunctionAlias('vout', 'getVout');
 }
开发者ID:sbwdlihao,项目名称:bitcoin-php,代码行数:17,代码来源:OutPoint.php


示例6: 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


示例7: 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


示例8: entropyToWords

 /**
  * @param Buffer $entropy
  * @return array
  */
 public function entropyToWords(Buffer $entropy)
 {
     $math = $this->ecAdapter->getMath();
     $ENT = $entropy->getSize() * 8;
     $CS = $ENT / 32;
     $entBits = $math->baseConvert($entropy->getHex(), 16, 2);
     $csBits = $this->calculateChecksum($entropy, $CS);
     $bits = str_pad($entBits . $csBits, $ENT + $CS, '0', STR_PAD_LEFT);
     $result = [];
     foreach (str_split($bits, 11) as $bit) {
         $idx = $math->baseConvert($bit, 2, 10);
         $result[] = $this->wordList->getWord($idx);
     }
     return $result;
 }
开发者ID:rubensayshi,项目名称:bitcoin-php,代码行数:19,代码来源:Bip39Mnemonic.php


示例9: fromHex

 /**
  * @param string $hex
  * @param bool $compressed
  * @param EcAdapterInterface|null $ecAdapter
  * @return PrivateKey
  */
 public static function fromHex($hex, $compressed = false, EcAdapterInterface $ecAdapter = null)
 {
     $hex = Buffer::hex($hex);
     $ecAdapter = $ecAdapter ?: Bitcoin::getEcAdapter();
     $hexSerializer = new HexPrivateKeySerializer($ecAdapter);
     return $hexSerializer->parse($hex)->setCompressed($compressed);
 }
开发者ID:rubensayshi,项目名称:bitcoin-php,代码行数:13,代码来源:PrivateKeyFactory.php


示例10: testPeer

 public function testPeer()
 {
     $localhost = '127.0.0.1';
     $localport = '8333';
     $remotehost = '127.0.0.1';
     $remoteport = '9999';
     $loop = new StreamSelectLoop();
     $dnsResolverFactory = new \React\Dns\Resolver\Factory();
     $dns = $dnsResolverFactory->createCached('8.8.8.8', $loop);
     $reactServer = new Server($loop);
     $network = Bitcoin::getDefaultNetwork();
     $client = new NetworkAddress(Buffer::hex('0000000000000001'), $localhost, $localport);
     $server = new NetworkAddress(Buffer::hex('0000000000000001'), $remotehost, $remoteport);
     $msgs = new Factory($network, new Random());
     $serverReceivedConnection = false;
     $serverListener = new Listener($server, $msgs, $reactServer, $loop);
     $serverListener->on('connection', function (Peer $peer) use(&$serverReceivedConnection, &$serverListener) {
         $peer->close();
         $serverReceivedConnection = true;
     });
     $serverListener->listen($server->getPort());
     $connector = new Connector($loop, $dns);
     $clientConnection = new Peer($client, $msgs, $loop);
     $clientConnection->connect($connector, $server)->then(function (Peer $peer) use($serverListener, &$loop) {
         $peer->close();
         $serverListener->close();
     });
     $loop->run();
     $this->assertTrue($serverReceivedConnection);
 }
开发者ID:tokenly,项目名称:bitcoin-p2p-php,代码行数:30,代码来源:PeerTest.php


示例11: composeSend

 /**
  * Composes a send transaction
  * @param  string $asset                     A counterparty asset name or BTC
  * @param  mixed  $quantity                  Quantity of asset to send.  Accepts a float or a Tokenly\CounterpartyTransactionComposer\Quantity or Tokenly\CryptoQuantity\CryptoQuantity object.  Use a Quantity object for indivisible assets.
  * @param  mixed  $destination               A single destination bitcoin address.  For BTC sends an array of [[address, amount], [address, amount]] is also allowed.  Amounts should be float values.
  * @param  string $private_key_wif           The private key in ASCII WIF format.  This can be null to compose an unsigned transaction.
  * @param  array  $utxos                     An array of UTXOs.  Each UTXO should be ['txid' => txid, 'n' => n, 'amount' => amount (in satoshis), 'script' => script hexadecimal string]
  * @param  mixed  $change_address_collection a single address string to receive all change. Or an array of [[address, amount], [address, amount], [address]].  Amounts should be float values.  An address with no amount for the last entry will send the remaining change to that address.
  * @param  float  $fee                       A fee
  * @param  float  $btc_dust                  Amount of BTC dust to send with the Counterparty transaction.
  * @return Array returns a ComposedTransaction object
  */
 public function composeSend($asset, $quantity, $destination, $private_key_wif, $utxos, $change_address_collection = null, $fee = null, $btc_dust = null)
 {
     if ($asset == 'BTC') {
         return $this->composeBTCSend($quantity, $destination, $private_key_wif, $utxos, $change_address_collection, $fee);
     }
     $fee_satoshis = $fee === null ? self::DEFAULT_FEE : intval(round($fee * self::SATOSHI));
     $btc_dust_satoshis = $btc_dust === null ? self::DEFAULT_BTC_DUST : intval(round($btc_dust * self::SATOSHI));
     // get total and change amount
     $change_amounts = $this->calculateAndValidateChange($utxos, $btc_dust_satoshis, $fee_satoshis, $change_address_collection);
     $tx_builder = TransactionFactory::build();
     // add the UTXO inputs
     $transaction_outputs = $this->addInputsAndReturnPreviousOutputs($utxos, $tx_builder);
     // pay the btc_dust to the destination
     if (is_array($destination)) {
         throw new Exception("Multiple destinations are not supported for counterparty sends", 1);
     }
     $tx_builder->payToAddress($btc_dust_satoshis, AddressFactory::fromString($destination));
     // build the OP_RETURN script
     $op_return_builder = new OpReturnBuilder();
     $op_return = $op_return_builder->buildOpReturn($quantity, $asset, $utxos[0]['txid']);
     $script = ScriptFactory::create()->op('OP_RETURN')->push(Buffer::hex($op_return, 28))->getScript();
     $tx_builder->output(0, $script);
     // pay the change to self
     $this->payChange($change_amounts, $tx_builder);
     // sign
     if ($private_key_wif !== null) {
         $signed_transaction = $this->signTx($private_key_wif, $tx_builder, $transaction_outputs);
         return $this->buildReturnValuesFromTransactionAndInputs($signed_transaction, $utxos, true);
     }
     return $this->buildReturnValuesFromTransactionAndInputs($tx_builder->get(), $utxos, false);
 }
开发者ID:tokenly,项目名称:counterparty-transaction-composer,代码行数:43,代码来源:Composer.php


示例12: __construct

 public function __construct()
 {
     parent::__construct(function () {
         $consensus = new ConsensusFactory(Bitcoin::getEcAdapter());
         $loop = LoopFactory::create();
         $context = new ZmqContext($loop);
         $control = $context->getSocket(\ZMQ::SOCKET_SUB);
         $control->connect('tcp://127.0.0.1:5594');
         $control->subscribe('control');
         $control->on('messages', function ($msg) use($loop) {
             if ($msg[1] == 'shutdown') {
                 $loop->stop();
             }
         });
         $results = $context->getSocket(\ZMQ::SOCKET_PUSH);
         $results->connect("tcp://127.0.0.1:5593");
         $workers = $context->getSocket(\ZMQ::SOCKET_PULL);
         $workers->connect('tcp://127.0.0.1:5592');
         $workers->on('message', function ($message) use($consensus, $results) {
             $details = json_decode($message, true);
             $txid = $details['txid'];
             $flags = $details['flags'];
             $vin = $details['vin'];
             $scriptPubKey = new Script(Buffer::hex($details['scriptPubKey']));
             $tx = TransactionFactory::fromHex($details['tx']);
             $results->send(json_encode(['txid' => $txid, 'vin' => $vin, 'result' => $consensus->getConsensus(new Flags($flags))->verify($tx, $scriptPubKey, $vin)]));
         });
         $loop->run();
         exit(0);
     });
 }
开发者ID:sbwdlihao,项目名称:node-php,代码行数:31,代码来源:ScriptWorkerThread.php


示例13: queryDnsSeeds

 /**
  * Connect to $numSeeds DNS seeds
  *
  * @param int $numSeeds
  * @return \React\Promise\Promise|\React\Promise\PromiseInterface
  */
 public function queryDnsSeeds($numSeeds = 1)
 {
     $peerList = new Deferred();
     // Take $numSeeds
     $seedHosts = self::dnsSeedHosts();
     $seeds = array_slice($seedHosts, 0, min($numSeeds, count($seedHosts)));
     // Connect to $numSeeds peers
     /** @var Peer[] $vNetAddr */
     $vNetAddr = [];
     foreach ($seeds as $seed) {
         echo " [ query DNS seed: " . $seed . " ] \n";
         $this->dns->resolve($seed)->then(function ($ipList) use(&$vNetAddr, $peerList, &$numSeeds) {
             $vNetAddr[] = $ipList;
             if (count($vNetAddr) == $numSeeds) {
                 $peerList->resolve($vNetAddr);
             }
         });
     }
     // Compile the list of lists of peers into $this->knownAddresses
     return $peerList->promise()->then(function (array $vPeerVAddrs) {
         shuffle($vPeerVAddrs);
         /** @var NetworkAddressInterface[] $addresses */
         $addresses = [];
         array_map(function (array $value) use(&$addresses) {
             foreach ($value as $ip) {
                 $addresses[] = new NetworkAddress(Buffer::hex('01', 8), $ip, 8333);
             }
         }, $vPeerVAddrs);
         $this->knownAddresses = array_merge($this->knownAddresses, $addresses);
         return $this;
     });
 }
开发者ID:tokenly,项目名称:bitcoin-p2p-php,代码行数:38,代码来源:Locator.php


示例14: testMethods

 public function testMethods()
 {
     $loop = new \React\EventLoop\StreamSelectLoop();
     $dns = (new \BitWasp\Bitcoin\Networking\Dns\Factory())->create('8.8.8.8', $loop);
     $network = Bitcoin::getDefaultNetwork();
     $random = new Random();
     $messages = new \BitWasp\Bitcoin\Networking\Messages\Factory($network, $random);
     $factory = new Factory($dns, $messages, $loop);
     $this->assertInstanceOf($this->peerType, $factory->getPeer());
     $services = Buffer::hex('00', 8);
     $address = $factory->getAddress('127.0.0.1', 8332, $services);
     $this->assertInstanceOf($this->addrType, $address);
     $connector = $factory->getConnector();
     $this->assertInstanceOf($this->connType, $connector);
     $server = $factory->getServer();
     $this->assertInstanceOf($this->serverType, $server);
     $locator = $factory->getLocator();
     $this->assertInstanceOf($this->locatorType, $locator);
     $listener = $factory->getListener($server);
     $this->assertInstanceOf($this->listenerType, $listener);
     $handler = $factory->getPacketHandler();
     $this->assertInstanceOf($this->handlerType, $handler);
     $manager = $factory->getManager();
     $this->assertInstanceOf($this->managerType, $manager);
 }
开发者ID:tokenly,项目名称:bitcoin-p2p-php,代码行数:25,代码来源:FactoryTest.php


示例15: isDERSignature

 /**
  * @param \BitWasp\Buffertools\Buffer $sig
  * @return bool
  * @throws SignatureNotCanonical
  */
 public static function isDERSignature(Buffer $sig)
 {
     $checkVal = function ($fieldName, $start, $length, $binaryString) {
         if ($length == 0) {
             throw new SignatureNotCanonical('Signature ' . $fieldName . ' length is zero');
         }
         $typePrefix = ord(substr($binaryString, $start - 2, 1));
         if ($typePrefix !== 0x2) {
             throw new SignatureNotCanonical('Signature ' . $fieldName . ' value type mismatch');
         }
         $val = substr($binaryString, $start, $length);
         $vAnd = $val[0] & pack("H*", '80');
         if (ord($vAnd) === 128) {
             throw new SignatureNotCanonical('Signature ' . $fieldName . ' value is negative');
         }
         if ($length > 1 && ord($val[0]) == 0x0 && !ord($val[1] & pack('H*', '80'))) {
             throw new SignatureNotCanonical('Signature ' . $fieldName . ' value excessively padded');
         }
     };
     $bin = $sig->getBinary();
     $size = $sig->getSize();
     if ($size < 9) {
         throw new SignatureNotCanonical('Signature too short');
     }
     if ($size > 73) {
         throw new SignatureNotCanonical('Signature too long');
     }
     if (ord($bin[0]) !== 0x30) {
         throw new SignatureNotCanonical('Signature has wrong type');
     }
     if (ord($bin[1]) !== $size - 3) {
         throw new SignatureNotCanonical('Signature has wrong length marker');
     }
     $lenR = ord($bin[3]);
     $startR = 4;
     if (5 + $lenR >= $size) {
         throw new SignatureNotCanonical('Signature S length misplaced');
     }
     $lenS = ord($bin[5 + $lenR]);
     $startS = 4 + $lenR + 2;
     if ($lenR + $lenS + 7 !== $size) {
         throw new SignatureNotCanonical('Signature R+S length mismatch');
     }
     $checkVal('R', $startR, $lenR, $bin);
     $checkVal('S', $startS, $lenS, $bin);
     return true;
 }
开发者ID:rubensayshi,项目名称:bitcoin-php,代码行数:52,代码来源:TransactionSignature.php


示例16: read

 /**
  * @param Parser $parser
  * @return Buffer
  * @throws \BitWasp\Buffertools\Exceptions\ParserOutOfRange
  */
 public function read(Parser &$parser)
 {
     $bits = $this->readBits($parser->readBytes($this->length));
     if (!$this->isBigEndian()) {
         $bits = $this->flipBits($bits);
     }
     return Buffer::hex(str_pad($this->getMath()->baseConvert($bits, 2, 16), $this->length * 2, '0', STR_PAD_LEFT), $this->length, $this->getMath());
 }
开发者ID:sbwdlihao,项目名称:buffertools-php,代码行数:13,代码来源:ByteString.php


示例17: parse

 /**
  * @param $hex
  * @return PublicKey
  * @throws \Exception
  */
 public function parse($hex)
 {
     $hex = Buffer::hex($hex);
     if (!in_array($hex->getSize(), [PublicKey::LENGTH_COMPRESSED, PublicKey::LENGTH_UNCOMPRESSED])) {
         throw new \Exception('Invalid hex string, must match size of compressed or uncompressed public key');
     }
     return $this->ecAdapter->publicKeyFromBuffer($hex);
 }
开发者ID:rubensayshi,项目名称:bitcoin-php,代码行数:13,代码来源:HexPublicKeySerializer.php


示例18: execute

 /**
  * @param NodeInterface $node
  * @param array $params
  * @return array
  */
 public function execute(NodeInterface $node, array $params)
 {
     if (strlen($params[self::PARAM_HASH]) !== 64) {
         throw new \RuntimeException('Invalid hash');
     }
     $index = $node->chain()->fetchIndex(Buffer::hex($params[self::PARAM_HASH]));
     return ['header' => $this->convertIndexToArray($index)];
 }
开发者ID:Bit-Wasp,项目名称:node-php,代码行数:13,代码来源:GetHeaderCommand.php


示例19: 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


示例20: getAddress

 /**
  * @param NetworkInterface|null $network
  * @return string
  */
 public function getAddress(NetworkInterface $network = null)
 {
     $network = $network ?: Bitcoin::getNetwork();
     $witnessByte = dechex($this->witnessVersion);
     $witnessByte = strlen($witnessByte) % 2 == 0 ? $witnessByte : '0' . $witnessByte;
     $payload = Buffer::hex($this->getPrefixByte($network) . $witnessByte . "00" . $this->getHash());
     return Base58::encodeCheck($payload);
 }
开发者ID:nmarley,项目名称:bitcoin-php,代码行数:12,代码来源:WitnessScriptHash.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP models\User类代码示例发布时间:2022-05-23
下一篇:
PHP Bitcoin\Bitcoin类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap