本文整理汇总了PHP中BitWasp\Bitcoin\Bitcoin类的典型用法代码示例。如果您正苦于以下问题:PHP Bitcoin类的具体用法?PHP Bitcoin怎么用?PHP Bitcoin使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Bitcoin类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getNativeConsensus
/**
* @param int|null $flags
* @param EcAdapterInterface|null $ecAdapter
* @return NativeConsensus
*/
public static function getNativeConsensus($flags = null, EcAdapterInterface $ecAdapter = null)
{
if ($flags === null) {
$flags = self::defaultFlags();
}
return new NativeConsensus($ecAdapter ?: Bitcoin::getEcAdapter(), $flags);
}
示例2: fromHex
/**
* @param \BitWasp\Buffertools\Buffer|string $string
* @param EcAdapterInterface $ecAdapter
* @return SignatureInterface
*/
public static function fromHex($string, EcAdapterInterface $ecAdapter = null)
{
$ecAdapter = $ecAdapter ?: Bitcoin::getEcAdapter();
$serializer = EcSerializer::getSerializer($ecAdapter, 'BitWasp\\Bitcoin\\Crypto\\EcAdapter\\Serializer\\Signature\\DerSignatureSerializerInterface');
/** @var DerSignatureSerializerInterface $serializer */
return $serializer->parse($string);
}
示例3: 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);
}
示例4: testNetworkSerializer
public function testNetworkSerializer()
{
$mem = new MemPool();
$serializer = new NetworkMessageSerializer(Bitcoin::getDefaultNetwork());
$parsed = $serializer->parse($mem->getNetworkMessage()->getBuffer())->getPayload();
$this->assertEquals($mem, $parsed);
}
示例5: __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);
});
}
示例6: fromHex
/**
* @param $string
* @param Math $math
* @return TransactionSignatureInterface
*/
public static function fromHex($string, Math $math = null)
{
$math = $math ?: Bitcoin::getMath();
$serializer = new TransactionSignatureSerializer(new DerSignatureSerializer($math));
$signature = $serializer->parse($string);
return $signature;
}
示例7: execute
/**
* @param InputInterface $input
* @param OutputInterface $output
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$config = (new ConfigLoader())->load();
// Create the child process
// All the code after pcntl_fork () will be performed by two processes: parent and child
if ($config->getItem('config', 'daemon', false)) {
$child_pid = pcntl_fork();
if ($child_pid) {
// Exit from the parent process that is bound to the console
exit;
}
// Make the child as the main process.
posix_setsid();
}
$math = Bitcoin::getMath();
$params = new Params($math);
$loop = \React\EventLoop\Factory::create();
$db = new DebugDb(Db::create($config));
$node = new BitcoinNode($config, $params, $db);
$container = new Container();
$container['debug'] = function (Container $c) use($node) {
$context = $c['zmq'];
return new ZmqDebug($node, $context);
};
$this->setupServices($container, $node, $loop, $config, $db);
$loop->run();
return 0;
}
示例8: 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);
}
示例9: 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);
}
示例10: testNetworkSerializer
public function testNetworkSerializer()
{
$network = Bitcoin::getDefaultNetwork();
$parser = new NetworkMessageSerializer(Bitcoin::getDefaultNetwork());
$factory = new Factory($network, new Random());
$version = '1';
$relayUntil = '9999999';
$expiration = '9898989';
$id = '123';
$cancel = '0';
$minVer = '0';
$maxVer = '0';
$priority = '50';
$comment = new Buffer('comment');
$statusBar = new Buffer('statusBar');
$setCancel = [1, 2];
$setSubVer = [50, 99];
$detail = new AlertDetail($version, $relayUntil, $expiration, $id, $cancel, $minVer, $maxVer, $priority, $comment, $statusBar, $setCancel, $setSubVer);
$adapter = EcAdapterFactory::getPhpEcc(new Math(), EccFactory::getSecgCurves()->generator256k1());
$sig = new Signature($adapter, '1', '1');
$alert = $factory->alert($detail, $sig);
$serialized = $alert->getNetworkMessage()->getBuffer();
$parsed = $parser->parse($serialized)->getPayload();
/** @var \BitWasp\Bitcoin\Networking\Messages\Alert $parsed */
$this->assertEquals($alert->getDetail(), $parsed->getDetail());
$this->assertEquals($alert->getSignature()->getR(), $parsed->getSignature()->getR());
$this->assertEquals($alert->getSignature()->getS(), $parsed->getSignature()->getS());
}
示例11: __construct
public function __construct(NodeInterface $node, Container $container)
{
$this->db = $container['db'];
$this->retargetDb = new RetargetDb($this->db->getPdo());
$this->math = Bitcoin::getMath();
$this->consensus = new Consensus(Bitcoin::getMath(), new Params(Bitcoin::getMath()));
$node->chains()->on('retarget', [$this, 'onRetarget']);
}
示例12: testNetworkSerializable
public function testNetworkSerializable()
{
$factory = new Factory(Bitcoin::getDefaultNetwork(), new Random());
$filterclear = $factory->filterclear();
$serialized = $filterclear->getNetworkMessage()->getBuffer();
$parsed = $factory->parse(new Parser($serialized))->getPayload();
$this->assertEquals($parsed, $filterclear);
}
示例13: testNetworkSerializer
public function testNetworkSerializer()
{
$parser = new NetworkMessageSerializer(Bitcoin::getDefaultNetwork());
$getaddr = new GetAddr();
$serialized = $getaddr->getNetworkMessage()->getBuffer();
$parsed = $parser->parse($serialized)->getPayload();
$this->assertEquals($getaddr, $parsed);
}
示例14: 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);
}
示例15: fromParser
/**
* @param Parser $parser
* @return Alert
*/
public function fromParser(Parser $parser)
{
$detail = $this->detail->fromParser($parser);
list($sigBuffer) = $this->getSigBuf()->parse($parser);
$adapter = Bitcoin::getEcAdapter();
$serializer = EcSerializer::getSerializer('BitWasp\\Bitcoin\\Crypto\\EcAdapter\\Serializer\\Signature\\DerSignatureSerializerInterface', true, $adapter);
$sig = $serializer->parse($sigBuffer);
return new Alert($detail, $sig);
}