我正在使用BlockCypher php-client,主要是示例代码:
$input = new \BlockCypher\Api\TXInput();
$input->addAddress($address);
$output = new \BlockCypher\Api\TXOutput();
$output->addAddress($receivingWallet);
$output->setValue(intval($SatoshiAmount));
$tx = new \BlockCypher\Api\TX();
$tx->addInput($input);
$tx->addOutput($output);
$txClient = new \BlockCypher\Client\TXClient($apiContexts['BTC.main']);
$txSkeleton;
$request = clone $tx;
try {
$txSkeleton = $txClient->create($tx);
} catch (Exception $ex) {
ResultPrinter::printError("Created TX", "TXSkeleton", null, $request, $ex);
exit(1);
}
$txSkeleton = $txSkeleton->toJSON(128);
$txSkeleton = json_decode(json_encode(json_decode($txSkeleton)), True); // Object -> Stdclass -> Array
$signed = array();
$pubkeys = array();
for($x = 0; $x < count($txSkeleton['tosign']); $x++){
$toSign = $txSkeleton['tosign'][$x];
$tmp = \BlockCypher\Crypto\Signer::sign($toSign, $privkey);
array_push($signed, $tmp);
array_push($pubkeys, $pubkey);
}
$txSkeleton["signatures"] = $signed;
$txSkeleton["pubkeys"] = $pubkeys;
$txClient = new \BlockCypher\Client\TXClient($apiContexts['BTC.main']);
$txSkel = new \BlockCypher\Api\TXSkeleton();
$txSkel->fromJson(json_encode($txSkeleton));
$request = clone $txSkel;
try {
$txSkel = $txClient->send($txSkel);
} catch (Exception $ex) {
ResultPrinter::printError("Send TX", "TXSkeleton", null, $request, $ex);
continue 2;
}
除了签字,这是不同的。由于私钥是错误的格式,原始代码会抛出错误。
这有时会起作用。它可能适用于10到20个请求。然后它会为每个后续请求抛出以下错误:
"errors": [
{
"error": "Unable to find a transaction to spend for address 1Ag7YScJCtqoZ9ZcnuTto4B4yFs9qvkq6."
},
{
"error": "Not enough funds in 0 inputs to pay for 1 outputs, missing -233616."
},
{
"error": "Not enough funds after fees in 0 inputs to pay for 1 outputs, missing -293816."
},
{
"error": "Error validating generated transaction: insufficient priority and fee for relay"
}
],
优先级默认为高。所有交易(特别是收货)都已确认。输入在请求中,但在错误响应中将被删除。钱包有足够的平衡。
这里发生了什么?它不应该工作吗?难道我做错了什么?我不能设置比高更高的优先级。
请在此处查看完整错误: