53 lines
1.3 KiB
JavaScript
53 lines
1.3 KiB
JavaScript
|
|
const objects = require('bitmessage').objects,
|
|
Address = require('bitmessage').Address;
|
|
|
|
const { spawn } = require('child_process');
|
|
const { setTimeout } = require('timers');
|
|
const xmlrpc = require('xmlrpc');
|
|
|
|
|
|
(async () => {
|
|
spawn('pybitmessage', ['-t'], {timeout: 31000}).on('close', (code) => {
|
|
spawn('pybitmessage', ['-d'], {timeout: 300000})
|
|
});
|
|
|
|
const sender = Address.fromRandom(),
|
|
recipient = Address.fromPassphrase('test');
|
|
console.log('sender:', sender.encode());
|
|
console.log('recipient:', recipient.encode());
|
|
|
|
var msg = await objects.msg.encodePayloadAsync({
|
|
ttl: 1800,
|
|
from: sender,
|
|
to: recipient,
|
|
message: 'The quick brown fox jumps over the lazy dog.',
|
|
subject: 'hello',
|
|
encoding: 2,
|
|
skipPow: true
|
|
});
|
|
|
|
msg = msg.slice(8).toString('hex');
|
|
console.log('msg:', msg);
|
|
|
|
const client = xmlrpc.createClient({
|
|
host: '127.0.0.1', port: '8442', path: '/',
|
|
basic_auth: {user: 'username', pass: 'password'}
|
|
});
|
|
|
|
setTimeout(
|
|
function () {
|
|
console.log('Sending the msg');
|
|
|
|
client.methodCall(
|
|
'disseminatePreEncryptedMsg', [msg, 1000, 1000],
|
|
function (error, value) {
|
|
if (error) {
|
|
console.error('An error has occurred:', error);
|
|
} else {
|
|
console.log('the response was', value);
|
|
}
|
|
});
|
|
}, 30000);
|
|
})();
|