命中块密码 api laravel 时出错



这是我的代码:

public static function test(){
    try{
        $apiContext = ApiContext::create(
            'test', 'bcy', 'v1',
            new SimpleTokenCredential('my_token'),
            array(       'mode' => 'sandbox','log.LogEnabled' => false, 'log.FileName' => 'BlockCypher.log',   'log.LogLevel' => 'DEBUG') );
        $input = new BlockCypherApiTXInput();
        $input->addAddress("input_address");
        $output = new BlockCypherApiTXOutput();
        $output->addAddress("output_address ");
        $output->setValue(1000); // Satoshis
        /// Tx
        $tx = new BlockCypherApiTX();
        $tx->addInput($input);
        $tx->addOutput($output);
        $request = clone $tx;
        $txClient = new TXClient($apiContext);
        try {
            $output = $txClient->create($tx);
        } catch (Exception $ex) {
            dd("Created TX", "TXSkeleton", null, $request, $ex);
            exit(1);
        }
        dd("Created TX", "TXSkeleton", $output->getTx()->getHash(), $request, $output);
        return $output;
    }
    catch (BlockCypherExceptionBlockCypherConnectionException $ex) {
        echo $ex->getData();
        die;
    }
}

这是我用来创建创建交易 api 的,但是当我将模式从 bcy 更改为 btc 时,它会出错以检查 url get/post

代码源 :: 点击这里

在这里,我

得到的响应也来了,所以这是一个错误,我为生成地址创建了 api 并从那里创建输入地址,并在 block.io 上创建帐户,并从那里创建一个地址,以便在这些 api 中使用,除了这些我在 blockcypher 上的帐户免费,里面没有任何东西购买

{
  "errors":[
    {
      "error":"Unable to find a transaction to spend for address CCrB7dvBT1bqNfWxupKPH9v8yN7xukmqUF."
    },
    {
      "error":"Error building transaction: Address 33cjwDAyNeAPVUMWqh9hdRxdmwdTE4kyTx is of unknown size.."
    },
    {
      "error":"Not enough funds after fees in 0 inputs to pay for 0 outputs, missing -22200."
    },
    {
      "error":"Error validating generated transaction: Transaction missing input or output."
    }
  ],
  "tx":{
    "block_height":-1,
    "block_index":-1,
    "hash":"d21633ba23f70118185227be58a63527675641ad37967e2aa461559f577aec43",
    "addresses":[
    ],
    "total":0,
    "fees":0,
    "size":10,
    "preference":"low",
    "relayed_by":"116.193.163.150",
    "received":"2017-11-14T10:20:43.757719705Z",
    "ver":1,
    "double_spend":false,
    "vin_sz":0,
    "vout_sz":0,
    "confirmations":0,
    "inputs":[
    ],
    "outputs":[
    ]
  }
}

我正在测试目的,所以使用测试主要我已经从 github 安装了它

我在这里找到一种做这件事的方法是我的代码

<?php
try
    {
    $apiContext = ApiContext::create(env('BlockCypher_net') , env('BlockCypher_cn') , env('BlockCypher_v') , new SimpleTokenCredential(env('BlockCypher_key')) , array(
        'log.LogEnabled' => true,
        'log.FileName' => 'BlockCypher.log',
        'mode' => 'sandbox',
        'log.LogLevel' => 'DEBUG'
    ));
    $input = new BlockCypherApiTXInput();
    $input->addAddress($user['address']);
    $output = new BlockCypherApiTXOutput();
    $output->addAddress($data['address12']);
    $value_btc = 100000000 * ($data['btc12'] + 1 * ($data['btc12'] / 100));
    // dd($value_btc);
    $output->setValue($value_btc);
    $tx = new BlockCypherApiTX();
    $tx->addInput($input);
    $tx->addOutput($output);
    $request = clone $tx;
    $params = array(
        'includeToSignTx' => 1,
        'script_type' => 'mutlisig-n-of-m',
    );
    $txClient = new TXClient($apiContext);
    try
        {
        $txSkeleton = $txClient->create($tx, $params);
        $privateKeys = array(
            $user['private']
        );
        $txSkeleton = $txClient->sign($txSkeleton, $privateKeys);
        $txSkeleton = $txClient->send($txSkeleton);
        return array(
            'success' => 0
        );
        // dd($txSkeleton->getTx()->getHash());
        }
    catch(BlockCypherExceptionBlockCypherConnectionException $ex)
        {
        return array(
            'success' => 0,
            'msg' => $ex->getData()
        );
        }
    return $txSkeleton->getTx()->getHash();
    }
catch(BlockCypherExceptionBlockCypherConnectionException $ex)
    {
    return array(
        'success' => 0,
        'msg' => $ex->getData()
    );
    }

这对我来说是工作,希望它可以帮助您在收到任何错误时删除评论。

相关内容

  • 没有找到相关文章

最新更新