|
10 | 10 | use BitWasp\TrezorProto\ButtonRequest; |
11 | 11 | use BitWasp\TrezorProto\ButtonRequestType; |
12 | 12 | use BitWasp\TrezorProto\DebugLinkDecision; |
13 | | -use BitWasp\TrezorProto\DebugLinkGetState; |
14 | | -use BitWasp\TrezorProto\DebugLinkStop; |
15 | | -use BitWasp\TrezorProto\Success; |
16 | 13 |
|
17 | 14 | class DebugButtonAck extends ButtonAck |
18 | 15 | { |
| 16 | + /** |
| 17 | + * @var Session |
| 18 | + */ |
19 | 19 | private $debug; |
20 | 20 |
|
21 | | - public function __construct(Session $debugSession) |
22 | | - { |
| 21 | + /** |
| 22 | + * @var bool |
| 23 | + */ |
| 24 | + private $button; |
| 25 | + |
| 26 | + public function __construct( |
| 27 | + Session $debugSession, |
| 28 | + bool $button |
| 29 | + ) { |
23 | 30 | $this->debug = $debugSession; |
| 31 | + $this->button = $button; |
24 | 32 | } |
25 | 33 |
|
26 | | - public function acknowledge(Session $session, ButtonRequest $request, ButtonRequestType $expectedType) |
27 | | - { |
| 34 | + public function acknowledge( |
| 35 | + Session $session, |
| 36 | + ButtonRequest $request, |
| 37 | + ButtonRequestType $expectedType |
| 38 | + ): \Protobuf\Message { |
28 | 39 | $theirType = $request->getCode(); |
29 | 40 | if ($theirType->value() !== $expectedType->value()) { |
30 | 41 | throw new \RuntimeException("Unexpected button request (expected: {$expectedType->name()}, got {$theirType->name()})"); |
31 | 42 | } |
32 | 43 |
|
33 | | - fwrite(STDERR, microtime() . " - debugButtonAck.sending button ack (async)\n"); |
34 | | - $t1 = microtime(true); |
35 | 44 | $ack = new \BitWasp\TrezorProto\ButtonAck(); |
36 | 45 |
|
37 | 46 | $decision = new DebugLinkDecision(); |
38 | | - $decision->setYesNo(true); |
39 | | - |
40 | | - fwrite(STDERR, microtime() . " - debugButtonAck.sending DECISION (async)\n"); |
41 | | - $t1 = microtime(true); |
| 47 | + $decision->setYesNo($this->button); |
42 | 48 |
|
43 | 49 | $success = $session->sendMessageAsync(Message::buttonAck($ack)); |
44 | | - $debug = $this->debug->sendMessageAsync(DebugMessage::decision($decision), [ |
45 | | - 'Connection' => 'close', |
46 | | - ]); |
47 | | - |
48 | | - fwrite(STDERR, microtime() . " - debugButtonAck.DECISION async took ".(microtime(true)-$t1).PHP_EOL); |
49 | | - |
50 | | - fwrite(STDERR, "create promise"); |
51 | | - $val = null; |
52 | | - $success->then(function (Success $success) use (&$val) { |
53 | | - fwrite(STDERR, "success resolved"); |
54 | | - $val = $success; |
55 | | - }); |
56 | | - fwrite(STDERR, "wait for success"); |
57 | | - $success->wait(true); |
58 | | - fwrite(STDERR, "DONE waiting"); |
59 | | - |
60 | | - return $val; |
| 50 | + $this->debug->postMessage(DebugMessage::decision($decision)); |
| 51 | + return $success->wait(true); |
61 | 52 | } |
62 | 53 | } |
0 commit comments