예제 #1
0
 /**
  * @param array $pubkeys
  * @param string $scriptType
  * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
  * @param BlockCypherRestCall $restCall is the Rest Call Service that is used to make rest calls
  * @return AddressKeyChain
  */
 public function generateMultisigAddress($pubkeys, $scriptType, $apiContext = null, $restCall = null)
 {
     ArgumentArrayValidator::validate($pubkeys, 'pubkeys');
     $addressKeyChain = new AddressKeyChain();
     $addressKeyChain->setPubkeys($pubkeys);
     // script type format: 'multisig-n-of-m', where n and m are integers. For example: 'multisig-2-of-3'
     $addressKeyChain->setScriptType($scriptType);
     return $this->create($addressKeyChain, $apiContext, $restCall);
 }
예제 #2
0
 /**
  * Create a new address.
  *
  * @deprecated since version 1.2. Use AddressClient.
  * @param AddressKeyChain $addressKeyChain
  * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
  * @param BlockCypherRestCall $restCall is the Rest Call Service that is used to make rest calls
  * @return AddressKeyChain
  */
 public static function create($addressKeyChain = null, $apiContext = null, $restCall = null)
 {
     if ($addressKeyChain === null) {
         $payLoad = "";
     } else {
         // multisig address
         $payLoad = $addressKeyChain->toJSON();
     }
     $chainUrlPrefix = self::getChainUrlPrefix($apiContext);
     $json = self::executeCall("{$chainUrlPrefix}/addrs", "POST", $payLoad, null, $apiContext, $restCall);
     $ret = new AddressKeyChain();
     $ret->fromJson($json);
     return $ret;
 }
예제 #3
0
 /**
  * @depends testSerializationDeserialization
  * @param AddressKeyChain $obj
  */
 public function testGetters($obj)
 {
     $this->assertEquals($obj->getPrivate(), "bf442658d87e2fa590aca663b9f2bbff4fd19cac690941e6225b4eee3c6318d1");
     $this->assertEquals($obj->getPublic(), "028043b74cddd7e25c8ad27794927f245cf7f8a9c2d08ffb9fb5e5776c03febaa1");
     $this->assertEquals($obj->getAddress(), "2NBbY8fbHRLjWXHqRvs8P996N82eTYic1yX");
     $this->assertEquals($obj->getWif(), "L3dWP9XFYznfeoDRabcUGDddcJrvauuMqx5bpSpoH7QgKiGe1PLq");
     $this->assertEquals($obj->getPubkeys(), array("033e88a5503dc09243e58d9e7a53831c2b77cac014415ad8c29cabab5d933894c1", "02087f346641256d4ba19cc0473afaa8d3d1b903761b9220a915e1af65a12e613c", "03051fa1586ff8d509125d3e25308b4c66fcf656b377bf60bfdb296a4898d42efd"));
     $this->assertEquals($obj->getScriptType(), "multisig-2-of-3");
 }
<?php

// Run on console:
// php -f .\sample\address-api\GenerateMultisigAddressEndpoint.php
require __DIR__ . '/../bootstrap.php';
use BlockCypher\Api\AddressKeyChain;
use BlockCypher\Auth\SimpleTokenCredential;
use BlockCypher\Client\AddressClient;
use BlockCypher\Rest\ApiContext;
$apiContext = ApiContext::create('main', 'btc', 'v1', new SimpleTokenCredential('c0afcccdde5081d6429de37d16166ead'), array('mode' => 'sandbox', 'log.LogEnabled' => true, 'log.FileName' => 'BlockCypher.log', 'log.LogLevel' => 'DEBUG'));
$addressClient = new AddressClient($apiContext);
$pubkeys = array("02c716d071a76cbf0d29c29cacfec76e0ef8116b37389fb7a3e76d6d32cf59f4d3", "033ef4d5165637d99b673bcdbb7ead359cee6afd7aaf78d3da9d2392ee4102c8ea", "022b8934cc41e76cb4286b9f3ed57e2d27798395b04dd23711981a77dc216df8ca");
$addressKeyChain = $addressClient->generateMultisigAddress($pubkeys, 'multisig-2-of-3');
// For Sample Purposes Only.
$request = new AddressKeyChain();
$request->setPubkeys($pubkeys);
$request->setScriptType('multisig-2-of-3');
ResultPrinter::printResult("Create Multisig Address", "AddressKeyChain", $addressKeyChain->getAddress(), $request, $addressKeyChain);