-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathSpamBat_inc.php
More file actions
100 lines (88 loc) · 2.84 KB
/
Copy pathSpamBat_inc.php
File metadata and controls
100 lines (88 loc) · 2.84 KB
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
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
#!/usr/bin/php
<?php
// SpamBat common file
// License: BSD
// Author: Oleg Khovayko (olegarch)
// Created: Oct, 30, 2022
//------------------------------------------------------------------------------
// EMC account in the work wallet
$AccountName = "SpamBat"; // Default account
// Label for sendmany for W0 output TX
$Label = "Pay to SpamBat";
// Number of addresses for addr-ppol
$AddrPoolSize = 20;
// Address pool file
$AddrPoolFname = "./addr_pool.txt";
// Stamp price n EMC; this value will burn
// $StampPrice = 1.00;
$StampPrice = 0.123;
// Number of available stamps (stamp-pool size)
$NumStamps = 5;
// This file contains ready-to-use stamps
$StampsFname = "./stamps.txt";
//------------------------------------------------------------------------------
// Export here connect variable, like:
// URL for connect to Emercoin wallet
#$emcCONNECT = "http://user:secret_pass@localhost:6662";
include("config-lite.php");
//------------------------------------------------------------------------------
// Performs NVS-request to EMC wallet
// Returns JSON of response result. Exit with err print, if error
// Example:
// $ret = EMC_req('name_show', array('val:emercoin'), "Unable to run name_show");
function EMC_req($cmd, $params, $errtxt) {
global $emcCONNECT;
// Prepares the request
$request = json_encode(array(
'method' => $cmd,
'params' => $params,
'id' => '1'
));
// Prepare and performs the HTTP POST
$opts = array ('http' => array (
'method' => 'POST',
'header' => 'Content-type: application/json',
'content' => $request
));
do {
$fp = @fopen($emcCONNECT, 'rb', false, stream_context_create($opts));
if(!$fp)
break;
$rc = json_decode(stream_get_contents($fp), true);
$er = $rc['error'];
if(!is_null($er)) {
printf("ERROR: %s\n", $er);
break;
}
return $rc['result'];
} while(false);
if(empty($errtxt))
return "";
printf("%s\nFail request details: cmd=[%s] and params:\n", $errtxt, $cmd);
print_r($params);
exit(1);
} // EMC_req
function CheckOpenWallet() {
$getinfo = EMC_req('getinfo', array(), "Unable connect wallet");
$err = $getinfo["errors"];
if(!empty($err)) {
echo("ERROR: Wallet must be open, error=[$err]\n");
exit(1);
}
}
function ValidStamp(&$rawtx) {
$rc = EMC_req('signrawtransactionwithkey', array($rawtx, array()), "Unable to validate raw transaction");
if(!boolval($rc['complete']))
return false;
// Check within mempool
$mempool = EMC_req('getrawmempool', array(), "Unable to fetch raw mempool");
if(count($mempool) == 0)
return true;
$tx = EMC_req('decoderawtransaction', array($rawtx), "Unable to decode stamp transaction");
$txid = $tx['txid'];
foreach($mempool as $mptx)
if($txid == $mptx)
return false; // Transaction exists within mempool
return true;
}
?>