1 | <?php |
||
2 | |||
3 | namespace AraneaDev\Electrum\App\Console; |
||
4 | |||
5 | use AraneaDev\Electrum\Electrum; |
||
6 | use Illuminate\Console\Command; |
||
7 | |||
8 | /** |
||
9 | * Class ElectrumCommand. |
||
10 | */ |
||
11 | class ElectrumCommand extends Command |
||
12 | { |
||
13 | /** @var Electrum */ |
||
14 | protected $electrum; |
||
15 | |||
16 | /** |
||
17 | * The name and signature of the console command. |
||
18 | * |
||
19 | * @var string |
||
20 | */ |
||
21 | protected $signature = 'electrum {method} {--address=} {--txid=} {--key=}'; |
||
22 | |||
23 | /** |
||
24 | * The console command description. |
||
25 | * |
||
26 | * @var string |
||
27 | */ |
||
28 | protected $description = 'Wrapper for Electrum'; |
||
29 | |||
30 | /** |
||
31 | * ElectrumCommand constructor. |
||
32 | * |
||
33 | * @param Electrum $electrum |
||
34 | */ |
||
35 | public function __construct(Electrum $electrum) |
||
36 | { |
||
37 | $this->electrum = $electrum; |
||
38 | |||
39 | parent::__construct(); |
||
40 | } |
||
41 | |||
42 | /** |
||
43 | * Execute the console command. |
||
44 | * |
||
45 | * @return mixed |
||
46 | */ |
||
47 | public function handle() |
||
48 | { |
||
49 | $method = $this->argument('method'); |
||
50 | |||
51 | if (! method_exists($this, $method)) { |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
52 | $this->info(json_encode($this->electrum->sendRequest($method, $this->get_params()))); |
||
53 | } else { |
||
54 | $this->$method(); |
||
55 | } |
||
56 | } |
||
57 | |||
58 | /** |
||
59 | * Returns package author. |
||
60 | * |
||
61 | * @return void |
||
62 | */ |
||
63 | public function author() |
||
64 | { |
||
65 | $this->info('Electrum for Laravel was written by Tim Schipper <[email protected]>'); |
||
66 | } |
||
67 | |||
68 | /** |
||
69 | * @return array |
||
70 | */ |
||
71 | public function get_params() |
||
72 | { |
||
73 | $params = []; |
||
74 | |||
75 | if ($this->option('address')) { |
||
76 | $params['address'] = $this->option('address'); |
||
77 | } |
||
78 | |||
79 | if ($this->option('txid')) { |
||
80 | $params['txid'] = $this->option('txid'); |
||
81 | } |
||
82 | |||
83 | if ($this->option('key')) { |
||
84 | $params['key'] = $this->option('key'); |
||
85 | } |
||
86 | |||
87 | return $params; |
||
88 | } |
||
89 | } |
||
90 |