-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathsplit_bytes.js
43 lines (37 loc) · 1.23 KB
/
split_bytes.js
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
/*jslint node: true */
"use strict";
var conf = require('ocore/conf.js');
var db = require('ocore/db.js');
var eventBus = require('ocore/event_bus.js');
var headlessWallet = require('headless-obyte');
headlessWallet.setupChatEventHandlers();
function work(){
function onError(err){
throw err;
}
var network = require('ocore/network.js');
var walletGeneral = require('ocore/wallet_general.js');
var composer = require('ocore/composer.js');
db.query(
"SELECT amount, address FROM my_addresses JOIN outputs USING(address) WHERE asset IS NULL AND is_spent=0 ORDER BY amount DESC LIMIT 1",
function(rows){
if (rows.length !== 1)
throw Error("not 1 output");
var amount = rows[0].amount;
var address = rows[0].address;
var chunk_amount = Math.round(amount/100);
var arrOutputs = [{amount: 0, address: address}];
for (var i=1; i<100; i++) // 99 iterations
arrOutputs.push({amount: chunk_amount, address: address});
console.log(arrOutputs);
composer.composeAndSavePaymentJoint([address], arrOutputs, headlessWallet.signer, {
ifNotEnoughFunds: onError,
ifError: onError,
ifOk: function(objJoint){
network.broadcastJoint(objJoint);
}
});
}
);
}
eventBus.on('headless_wallet_ready', work);