forked from MPOS/php-mpos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathliquid_payout.php
executable file
·72 lines (62 loc) · 2.21 KB
/
liquid_payout.php
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
64
65
66
67
68
69
70
71
72
#!/usr/bin/php
<?php
// Change to working directory
chdir(dirname(__FILE__));
// Include all settings and classes
require_once('shared.inc.php');
// Simple configuration check
if (!is_array($config['coldwallet'])) {
$log->logFatal('Missing config option: coldwallet');
$monitoring->endCronjob($cron_name, 'E0075', 1, true);
}
// Check RPC connection
if ($bitcoin->can_connect() !== true) {
$log->logFatal('Unable to connect to RPC server, exiting');
$monitoring->endCronjob($cron_name, 'E0006', 1, true);
} else {
// Check Wallet Balance
$dBalance = $bitcoin->getbalance();
$log->logDebug('The wallet balance is: ' .$dBalance);
// Do we have anything available at all?
if (! ($dBalance > 0)) {
$log->logInfo('No coins available in wallet');
$monitoring->endCronjob($cron_name, 'E0076', 0, true, false);
}
// Check for POS Mint
$dGetInfo = $bitcoin->getinfo();
if (is_array($dGetInfo) && array_key_exists('newmint', $dGetInfo)) {
$dNewmint = $dGetInfo['newmint'];
$log->logDebug('Current Mint is: ' . $dNewmint);
} else {
$dNewmint = -1;
}
}
// Fetch locked balance from transactions
$dLockedBalance = $transaction->getLockedBalance();
$log->logDebug('The locked wallet balance for users is: ' . $dLockedBalance);
// Fetch Final Wallet Balance after Transfer
$dFloat = $dLockedBalance + $config['coldwallet']['reserve'];
$dThreshold = $config['coldwallet']['threshold'];
$log->logDebug('The locked wallet balance + reserves amounts to: ' . $dFloat);
// Send Liquid Balance
$sendAddress = $config['coldwallet']['address'];
$send = $dBalance - $dFloat ;
$log->logDebug('Final Sending Amount is : ' . $send);
if($send > $dThreshold) {
if (!empty($sendAddress)) {
try {
$bitcoin->sendtoaddress($sendAddress, $send);
} catch (Exception $e) {
$log->logFatal('Failed to send coins to address, skipping liquid assets payout:' . $e->getMessage());
$monitoring->endCronjob($cron_name, 'E0077', 1, true);
}
$log->logInfo('Sent out ' . $send . ' liquid assets');
} else {
$log->logDebug('No wallet address set');
}
} else {
$log->logDebug('Final sending amount not exceeding threshold: ' . $send);
}
// Cron cleanup and monitoring
require_once('cron_end.inc.php');
?>