1 | <?php |
||
16 | class ScriptCreator |
||
17 | { |
||
18 | /** |
||
19 | * @var string |
||
20 | */ |
||
21 | private $script = ''; |
||
22 | |||
23 | /** |
||
24 | * @var Opcodes |
||
25 | */ |
||
26 | private $opcodes; |
||
27 | |||
28 | /** |
||
29 | * @var Math |
||
30 | */ |
||
31 | private $math; |
||
32 | |||
33 | /** |
||
34 | * @param Math $math |
||
35 | * @param Opcodes $opcodes |
||
36 | * @param BufferInterface|null $buffer |
||
37 | */ |
||
38 | 1170 | public function __construct(Math $math, Opcodes $opcodes, BufferInterface $buffer = null) |
|
47 | |||
48 | /** |
||
49 | * @param int[]|\BitWasp\Bitcoin\Script\Interpreter\Number[]|BufferInterface[] $sequence |
||
50 | * @return $this |
||
51 | */ |
||
52 | 300 | public function sequence(array $sequence) |
|
74 | |||
75 | /** |
||
76 | * Add an opcode to the script |
||
77 | * |
||
78 | * @param string $name |
||
79 | * @return $this |
||
80 | */ |
||
81 | 174 | public function op($name) |
|
87 | |||
88 | /** |
||
89 | * Push data into the stack. |
||
90 | * |
||
91 | * @param $data |
||
92 | * @return $this |
||
93 | * @throws \Exception |
||
94 | */ |
||
95 | 390 | public function push(BufferInterface $data) |
|
125 | |||
126 | /** |
||
127 | * @param int $n |
||
128 | * @return $this |
||
129 | */ |
||
130 | 78 | public function int($n) |
|
131 | { |
||
132 | 78 | if ($n === 0) { |
|
133 | $this->script .= chr(Opcodes::OP_0); |
||
134 | 78 | } else if ($n === -1 || ($n >= 1 && $n <= 16)) { |
|
135 | 78 | $this->script .= chr(\BitWasp\Bitcoin\Script\encodeOpN($n)); |
|
136 | 78 | } else { |
|
137 | $this->script .= Number::int($n)->getBinary(); |
||
138 | } |
||
139 | |||
140 | 78 | return $this; |
|
141 | } |
||
142 | |||
143 | /** |
||
144 | * @param Serializable $object |
||
145 | * @return $this |
||
146 | */ |
||
147 | public function pushSerializable(Serializable $object) |
||
152 | |||
153 | /** |
||
154 | * @param Serializable[] $serializable |
||
155 | * @return $this |
||
156 | */ |
||
157 | public function pushSerializableArray(array $serializable) |
||
165 | |||
166 | /** |
||
167 | * @param ScriptInterface $script |
||
168 | * @return $this |
||
169 | */ |
||
170 | 300 | public function concat(ScriptInterface $script) |
|
175 | |||
176 | /** |
||
177 | * @return ScriptInterface |
||
178 | */ |
||
179 | 1164 | public function getScript() |
|
183 | } |
||
184 |