1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ZenCash\Rpc\Command\RawTransactions; |
4
|
|
|
|
5
|
|
|
use ZenCash\Rpc\Command; |
6
|
|
|
use ZenCash\Rpc\Command\RawTransactions\SignRawTransaction\SigHashType; |
7
|
|
|
|
8
|
|
|
final class SignRawTransaction implements Command |
9
|
|
|
{ |
10
|
|
|
private const METHOD = 'signrawtransaction'; |
11
|
|
|
private $hex; |
12
|
|
|
private $prevtxs; |
13
|
|
|
private $privateKeys; |
14
|
|
|
private $sigHashType; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @param string $hex |
18
|
|
|
* @param RawTransaction[] $prevtxs |
19
|
|
|
* @param string[] $privateKeys |
20
|
|
|
* @param null|SigHashType $sigHashType |
21
|
|
|
*/ |
22
|
|
|
public function __construct(string $hex, array $prevtxs, array $privateKeys, ?SigHashType $sigHashType) |
23
|
|
|
{ |
24
|
|
|
call_user_func_array(function (RawTransaction ...$t) {}, $prevtxs); |
|
|
|
|
25
|
|
|
call_user_func_array(function (string ...$keys) {}, $privateKeys); |
|
|
|
|
26
|
|
|
|
27
|
4 |
|
$this->hex = $hex; |
28
|
4 |
|
$this->prevtxs = $prevtxs; |
29
|
4 |
|
$this->privateKeys = $privateKeys; |
30
|
4 |
|
$this->sigHashType = $sigHashType ?: SigHashType::ALL(); |
31
|
4 |
|
} |
32
|
|
|
|
33
|
4 |
|
public function jsonSerialize(): object |
34
|
|
|
{ |
35
|
4 |
|
foreach ($this->prevtxs as $t) { |
36
|
3 |
|
if (!property_exists($t, 'scriptPubKey') || !property_exists($t, 'redeemScript')) { |
37
|
3 |
|
throw new \InvalidArgumentException("RawTransaction missing required data."); |
38
|
|
|
} |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
return (object) [ |
42
|
4 |
|
'jsonrpc' => Command::JSON_RPC_VERSION, |
43
|
|
|
'id' => Command::ID, |
44
|
4 |
|
'method' => self::METHOD, |
45
|
4 |
|
'params' => array_merge( |
46
|
4 |
|
[ $this->hex ], |
47
|
4 |
|
!empty($this->prevtxs) ? [ $this->prevtxs ] : [ ], |
48
|
4 |
|
!empty($this->prevtxs) && !empty($this->privateKeys) ? [ $this->privateKeys ] : [ ], |
49
|
4 |
|
(!empty($this->prevtxs) && !empty($this->privateKeys)) ? [ $this->sigHashType ] : [ ] |
50
|
|
|
) |
51
|
|
|
]; |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.