· 6 years ago · Oct 10, 2019, 07:34 PM
1var Twitter = require('twitter');
2const datapay = require('datapay');
3//let hc = require('handcash');
4const bitcore = require('bsv');
5const fetch = require('node-fetch');
6const https = require("https");
7
8var bchaddr = require('bchaddrjs');
9var toLegacyAddress = bchaddr.toLegacyAddress;
10var toBitpayAddress = bchaddr.toBitpayAddress;
11var toCashAddress = bchaddr.toCashAddress;
12var isLegacyAddress = bchaddr.isLegacyAddress;
13var isBitpayAddress = bchaddr.isBitpayAddress;
14var isCashAddress = bchaddr.isCashAddress;
15var detectAddressFormat = bchaddr.detectAddressFormat;
16
17//let handcash = new hc({network: "mainnet"});
18
19var client = new Twitter({
20 consumer_key: '---',
21 consumer_secret: '---',
22 access_token_key: '----',
23 access_token_secret: '-----'
24});
25
26var key_cycle = 1;
27var key_array_size = 100;
28var key_array = new Array();
29var seed = "random mnemonic seed here or random text";
30for(var counter = 0; counter < key_array_size; counter++) {
31 var value = new Buffer(seed + counter.toString());
32 var hash = bitcore.crypto.Hash.sha256(value);
33 var bn = bitcore.crypto.BN.fromBuffer(hash);
34 var private_key = new bitcore.PrivateKey(bn);
35 var address = private_key.toAddress();
36 key_array.push([address, private_key]);
37}
38
39// RPC
40//var rpc_server = "http://127.0.0.1:8332";
41
42// API KEY
43//const privateKey = "-----";
44
45//var twitter_account_id = "-----";
46var twitter_account_id = "-------";
47
48//var stream = client.stream('statuses/filter', {follow: twitter_account_id });
49var stream = client.stream('statuses/filter', {track: "amrita" });
50
51//const regex_exp = \$[a-zA-Z0-9._-]{4,30}\;
52
53function isAlphaNumeric(str) {
54 var code, i, len;
55
56 for (i = 0, len = str.length; i < len; i++) {
57 code = str.charCodeAt(i);
58 if (!(code > 47 && code < 58) && // numeric (0-9)
59 !(code > 64 && code < 91) && // upper alpha (A-Z)
60 !(code > 96 && code < 123)) { // lower alpha (a-z)
61 return false;
62 }
63 }
64 return true;
65};
66
67stream.on('data', function(event) {
68
69 if(typeof event !== 'undefined' && event) {
70 if(typeof event.text !== 'undefined' && event.text) {
71
72 //var bitcoin_address = event.text.substring( event.text.indexOf("@") + 1 );
73 var bitcoin_address = event.text;
74
75 if(bitcoin_address.indexOf("$") != -1) {
76 bitcoin_address = bitcoin_address.substring(bitcoin_address.indexOf("$"));
77 if(bitcoin_address.indexOf(" ") != -1)
78 bitcoin_address = bitcoin_address.substring(0, bitcoin_address.indexOf(" "));
79 bitcoin_address = bitcoin_address.replace("$", "");
80 bitcoin_address = bitcoin_address.trim();
81 }
82 else
83 return;
84 if(bitcoin_address.length < 4 || parseInt(bitcoin_address) || !isAlphaNumeric(bitcoin_address))
85 return;
86
87 if(bitcoin_address.indexOf("Find") == 0 || bitcoin_address.indexOf("Valor") == 0 || bitcoin_address.indexOf("Current") == 0 || bitcoin_address.indexOf("Waouh") == 0 ||
88 bitcoin_address.indexOf("Banco") == 0 || bitcoin_address.indexOf("Download") == 0 || bitcoin_address.indexOf("When") == 0 || bitcoin_address.indexOf("Handle") == 0 || bitcoin_address.indexOf("handle") == 0 ||
89 bitcoin_address.indexOf("Handcash") == 0 || bitcoin_address.indexOf("handcash") == 0 || bitcoin_address.indexOf("Hcash") == 0 || bitcoin_address.indexOf("hcash") == 0 || bitcoin_address.indexOf("TURKEY") == 0 )
90 return;
91
92 console.log("RAW: " + bitcoin_address);
93
94
95 var found = true;
96 // handcash.io
97 if(found /*bitcoin_address.indexOf("$") !== -1*/) {
98
99 var hc_api_call = 'https://api.handcash.io/api/receivingAddress/' + bitcoin_address;
100
101 console.log("Requesting from: " + hc_api_call);
102
103 if(true)
104 https.get(hc_api_call, res => {
105
106 let body = "";
107
108 res.on("data", data => {
109 body += data;
110 });
111
112 res.on("end", () => {
113 if(body)
114 body = JSON.parse(body);
115 else
116 return;
117
118 if(!body.receivingAddress)
119 return;
120
121 console.log("Got address from handcash: " + body.receivingAddress);
122 bitcoin_address = body.receivingAddress;
123
124
125 // handcash
126 console.log("Sending to: " + toLegacyAddress(bitcoin_address));
127
128 var user_message = "";//Thanks to $TheWildCard $CryptoStorm $JoelDalais $CashMeIfYouCan $JerryFrench $tackmyBCHup $leondavibe $marquee $derose $Kevin_J_Modzelewski $splifftail710 $orgonite $MrEternal and more!";// $donald $vegardwikeby $Georgetoshi $shikari $satoshidoodles $electon $jordan $Georgetown $agsupun $eyeone $atoshivision $VilliersHunter $ehanik $Varaha";
129
130 var send_satoshi_amount = 10000;
131 var fee_satbytes = 20;
132 var fee_amount = (user_message.length * fee_satbytes) + (20 * fee_satbytes);
133 if(fee_amount < (fee_satbytes * 1000))
134 fee_amount = (fee_satbytes * 1000);
135
136
137 var tx;
138
139 // NOT SURE WHAT I WAS DOING HERE LOL? BUT PROBABLY COULD CLEAN IT UP SIMPLER
140 tx = {"address":"--------------","txid":"-------------","vout":1,"scriptPubKey":"-------------","amount":0.01578291,"satoshis":1578291,"height":567860,"confirmations":287};
141
142 console.log("Sending from key: " + key_cycle);
143
144 datapay.send(tx, function(err, result) {
145 if(typeof result !== 'undefined' && result) {
146 key_cycle++;
147 if(key_cycle == key_array_size || key_cycle > key_array_size)
148 key_cycle = 0;
149 console.log("SUCCESS|" + result);
150 //res.end();
151 }
152 else {
153 key_cycle++;
154 if(key_cycle == key_array_size || key_cycle > key_array_size)
155 key_cycle = 0;
156 console.log("RPC_ERROR|" + err);
157 }
158 });
159 });
160 });
161 }
162 }
163 }
164});
165
166stream.on('error', function(error) {
167 throw error;
168});