Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
namespace Monero;
use App\Project;
use Carbon\Carbon;
use Illuminate\Support\Collection;
class WalletOld
{
/**
* WalletOld constructor.
*
* @param null $client
*/
public function __construct($client = null)
{
$this->client = $client ?: new jsonRPCClient(env('RPC_URL'));
}
/**
* Gets a Payment address for receiving payments
*
* @return array
*
* @internal param \WalletOld $wallet
*/
public function getPaymentAddress()
{
$integratedAddress = $this->createIntegratedAddress();
if (!$integratedAddress) {
return ['address' => 'not valid'];
}
return ['address' => $integratedAddress['integrated_address'], 'paymentId' => $integratedAddress['payment_id']];
}
/**
* Returns the actual available and useable balance (unlocked balance)
*
* @return float|int|mixed
*/
public function balance()
{
return $this->client->balance();
}
public function mempoolTransfers()
{
return $this->client->incomingTransfers();
}
public function bulkPayments($paymentIds)
{
$blockBuffer = 10;
return $this->client->payments($paymentIds, intval($this->wallet->last_scanned_block_height) - $blockBuffer);
}
/**
* Scans the monero blockchain for transactions for the payment ids
*
* @param int $blockheight
* @param Collection $paymentIDs
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
*
* @return array|Transaction
*/
public function scanBlocks($blockheight, $paymentIDs)
{
$response = $this->bulkPayments($paymentIDs);
$address = $this->getAddress();
$transactions = [];
if ($response && isset($response['payments'])) {
foreach ($response['payments'] as $payment) {
$transaction = new Transaction(
$payment['tx_hash'],
$payment['amount'],
$address,
$blockheight - $payment['block_height'],
0,
Carbon::now(),
$payment['payment_id'],
$payment['block_height']
);
$transactions[] = $transaction;
}
}
return collect($transactions);
}
/**
* @param $blockheight
*
* @return \Illuminate\Support\Collection
*/
public function scanMempool($blockheight)
{
$address = $this->getAddress();
$transactions = [];
$response = $this->mempoolTransfers();
if ($response && isset($response['pool'])) {
foreach ($response['pool'] as $payment) {
$transaction = new Transaction(
$payment['txid'],
$payment['amount'],
$address,
0,
0,
Carbon::now(),
$payment['payment_id'],
$blockheight
);
$transactions[] = $transaction;
}
}
return collect($transactions);
}
/**
* Gets the current blockheight of xmr
*
* @return int
*/
public function blockHeight()
{
return $this->client->blockHeight();
}
/**
* Returns monero wallet address
*
* @return string
*/
public function getAddress()
{
return $this->client->address();
}
/**
* Returns XMR integrated address
*
* @return mixed
*/
public function createIntegratedAddress()
{
return $this->client->createIntegratedAddress();
}
/**
* @param $amount
* @param $address
* @param $paymentId
*
* @return string
*/
public function createQrCodeString($address, $amount = null, $paymentId = null): string
{
return $this->client->createUri($address, $amount, $paymentId);
}
/**
* gets all the payment_ids outstanding from the address_pool, we use these to check against the latest mined blocks
*
* @return Collection
*/
public function getPaymentIds()
{
return Project::pluck('payment_id'); //stop scanning for payment_ids after 24h
}
}