1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* User: delboy1978uk |
4
|
|
|
* Date: 18/08/15 |
5
|
|
|
* Time: 19:57 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace Del\Bitcoin\Api; |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
class RawTransaction extends AbstractApi |
12
|
|
|
{ |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* The createrawtransaction RPC creates an unsigned serialized |
16
|
|
|
* transaction that spends a previous output to a new output with |
17
|
|
|
* a P2PKH or P2SH address. The transaction is not stored in the |
18
|
|
|
* wallet or transmitted to the network. |
19
|
|
|
* |
20
|
|
|
* @param string $refs json object |
21
|
|
|
* Outpoints array Required(exactly 1) |
22
|
|
|
* An array of objects,each one being an unspent outpoint |
23
|
|
|
* Outpoint object Required(1 or more) |
24
|
|
|
* An object describing a particular unspent outpoint |
25
|
|
|
* txid string (hex) Required(exactly 1) |
26
|
|
|
* The TXID of the outpoint encoded as hex in RPC byte order |
27
|
|
|
* vout int Require(exactly 1) |
28
|
|
|
* The output index number (vout) of the outpoint; |
29
|
|
|
* the first output in a transaction is index 0 |
30
|
|
|
* @param string $addresses json objects |
31
|
|
|
* Outputs object Required(exactly 1) |
32
|
|
|
* The addresses and amounts to pay |
33
|
|
|
* Address/Amount string : number (bitcoins) Required(1 or more) |
34
|
|
|
* A key/value pair with the address to pay as a string |
35
|
|
|
* (key) and the amount to pay that address (value) in |
36
|
|
|
* bitcoins |
37
|
|
|
* @return mixed |
38
|
|
|
*/ |
39
|
|
|
public function createRawTransaction($refs,$addresses) |
40
|
|
|
{ |
41
|
|
|
return $this->send('createrawtransaction',[$refs,$addresses]); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* The decoderawtransaction RPC decodes a serialized transaction hex |
46
|
|
|
* string into a JSON object describing the transaction.\ |
47
|
|
|
* |
48
|
|
|
* @param string $transaction (hex) The transaction to decode in |
49
|
|
|
* serialized transaction format |
50
|
|
|
* @return mixed |
51
|
|
|
*/ |
52
|
|
|
public function decodeRawTransaction($transaction) |
53
|
|
|
{ |
54
|
|
|
return $this->send('decoderawtransaction',[$transaction]); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* The decodescript RPC decodes a hex-encoded P2SH redeem script. |
59
|
|
|
* |
60
|
|
|
* @param string $script The redeem script to decode as a |
61
|
|
|
* hex-encoded serialized script |
62
|
|
|
* @return mixed |
63
|
|
|
*/ |
64
|
|
|
public function decodeScript($script) |
65
|
|
|
{ |
66
|
|
|
return $this->send('decodescript',[$script]); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* The getrawtransaction RPC gets a hex-encoded serialized transaction |
71
|
|
|
* or a JSON object describing the transaction. By default, Bitcoin Core |
72
|
|
|
* only stores complete transaction data for UTXOs and your own |
73
|
|
|
* transactions, so the RPC may fail on historic transactions unless you |
74
|
|
|
* use the non-default txindex=1 in your Bitcoin Core startup settings. |
75
|
|
|
* |
76
|
|
|
* Note: if you begin using txindex=1 after downloading the block chain, |
77
|
|
|
* you must rebuild your indexes by starting Bitcoin Core with the |
78
|
|
|
* option -reindex. This may take several hours to complete, during |
79
|
|
|
* which time your node will not process new blocks or transactions. This |
80
|
|
|
* reindex only needs to be done once. |
81
|
|
|
* |
82
|
|
|
* @param $txid |
83
|
|
|
* @param bool $verbose |
84
|
|
|
* @return mixed |
85
|
|
|
*/ |
86
|
|
|
public function getRawTransaction($txid,$verbose = false) |
87
|
|
|
{ |
88
|
|
|
return $this->send('getrawtransaction',[$txid,$verbose]); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* The sendrawtransaction RPC validates a transaction and broadcasts it to |
93
|
|
|
* the peer-to-peer network. |
94
|
|
|
* |
95
|
|
|
* @param string $transaction The serialized transaction to broadcast |
96
|
|
|
* encoded as hex |
97
|
|
|
* @param bool $allow_high_fees Set to true to allow the transaction to pay |
98
|
|
|
* a high transaction fee. Set to false (the default) to prevent Bitcoin |
99
|
|
|
* Core from broadcasting the transaction if it includes a high fee. |
100
|
|
|
* Transaction fees are the sum of the inputs minus the sum of the outputs, |
101
|
|
|
* so this high fees check helps ensures user including a change address to |
102
|
|
|
* return most of the difference back to themselves |
103
|
|
|
* @return mixed |
104
|
|
|
*/ |
105
|
|
|
public function sendRawTransaction($transaction,$allow_high_fees = false) |
106
|
|
|
{ |
107
|
|
|
return $this->send('sendrawtransaction',[$transaction,$allow_high_fees]); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* The signrawtransaction RPC signs a transaction in the serialized |
112
|
|
|
* transaction format using private keys stored in the wallet or provided in |
113
|
|
|
* the call. |
114
|
|
|
* |
115
|
|
|
* @param string $transaction The transaction to sign as a serialized |
116
|
|
|
* transaction |
117
|
|
|
* @param string $unspent json object |
118
|
|
|
* Dependencies array Optional(0 or 1) |
119
|
|
|
* The previous outputs being spent by this transaction |
120
|
|
|
* Output object Optional(0 or more) |
121
|
|
|
* An output being spent |
122
|
|
|
* txid string (hex) Required(exactly 1) |
123
|
|
|
* The TXID of the transaction the output appeared in. The |
124
|
|
|
* TXID must be encoded in hex in RPC byte order |
125
|
|
|
* @return mixed |
126
|
|
|
*/ |
127
|
|
|
public function signRawTransaction($transaction,$unspent) |
128
|
|
|
{ |
129
|
|
|
return $this->send('signrawtransaction',[$transaction,$unspent]); |
130
|
|
|
} |
131
|
|
|
} |