1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Appino\Blockchain\Classes; |
4
|
|
|
|
5
|
|
|
use Appino\Blockchain\Classes\Create; |
6
|
|
|
use Appino\Blockchain\Classes\Receive; |
7
|
|
|
use Appino\Blockchain\Classes\Wallet; |
8
|
|
|
use GuzzleHttp\Client; |
9
|
|
|
use GuzzleHttp\Exception\GuzzleException; |
10
|
|
|
use Illuminate\Contracts\Container\Container; |
11
|
|
|
|
12
|
|
|
class Blockchain{ |
13
|
|
|
|
14
|
|
|
protected $client; |
15
|
|
|
protected $params; |
16
|
|
|
public $HD = false; |
17
|
|
|
const GET = 'GET'; |
18
|
|
|
const POST = 'POST'; |
19
|
|
|
|
20
|
|
|
public function __construct($config){ |
21
|
|
|
$this->client = new Client(['base_uri'=>data_get($config,'base_uri')]); |
22
|
|
|
$this->params['api_code'] = data_get($config,'api_code'); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Set the IoC Container. |
27
|
|
|
* |
28
|
|
|
* @param $container Container instance |
29
|
|
|
* |
30
|
|
|
* @return Blockchain |
31
|
|
|
*/ |
32
|
|
|
public function setContainer(Container $container): self{ |
33
|
|
|
$this->container = $container; |
|
|
|
|
34
|
|
|
return $this; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @return Create |
39
|
|
|
*/ |
40
|
|
|
public function Create(){ |
41
|
|
|
return new Create($this); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @return Wallet |
46
|
|
|
*/ |
47
|
|
|
public function Wallet(){ |
48
|
|
|
return new Wallet($this); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @return Receive |
53
|
|
|
*/ |
54
|
|
|
public function Receive(){ |
55
|
|
|
return new Receive($this); |
|
|
|
|
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @param $base_uri string Default : http://localhost:3000 |
60
|
|
|
*/ |
61
|
|
|
|
62
|
|
|
public function newBaseUri($base_uri){ |
63
|
|
|
$this->client = new Client(['base_uri'=>$base_uri]); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param $method |
68
|
|
|
* @param $url |
69
|
|
|
* @param $params |
70
|
|
|
* @return array |
71
|
|
|
*/ |
72
|
|
|
|
73
|
|
|
public function Request($method, $url, $params){ |
74
|
|
|
$params = array_merge($params, $this->params); |
75
|
|
|
$options = array( |
76
|
|
|
'form_params'=>$params, |
77
|
|
|
'headers'=>[ |
78
|
|
|
'Content-Type'=>'application/x-www-form-urlencoded', |
79
|
|
|
] |
80
|
|
|
); |
81
|
|
|
try { |
82
|
|
|
$response = $this->client->request($method, $url, $options); |
83
|
|
|
return json_decode($response->getBody()->getContents(),true); |
84
|
|
|
} catch (GuzzleException $e) { |
85
|
|
|
echo $e->getMessage(); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
} |
90
|
|
|
|