-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsweepSlp.js
86 lines (74 loc) · 2.32 KB
/
sweepSlp.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
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
/*
sweepSlp.js
A script to sweep all of a user-specified slp token ID from multiple addresses and return to 1 receiving address
Script implements an SLP from many to one transaction
Inputs
1)See 'User Input' below
Outputs
1)A broadcast tx returning all of specified SLP token id to single address
*/
//Import slp-sdk
let SLPSDK = require("slp-sdk");
let SLP = new SLPSDK();
//Import keys
const keys = require("./keys");
const slpWallet = keys.slpWallet;
// User Input
const sweepableWallets = keys.sweepableWallets;
const tokenReceiverAddress = slpWallet.addr;
const tokenId = keys.slpTokens.train4;
const bchChangeReceiverAddress = slpWallet.bchChangeReceiverAddr;
// build array of fundingAddresses
// build array of fundingWifs
const fundingAddresses = [];
const fundingWifs = [];
for (let i = 0; i < sweepableWallets.length; i++) {
fundingAddress = SLP.Address.toSLPAddress(sweepableWallets[i].addr);
fundingWif = sweepableWallets[i].wif;
fundingAddresses.push(fundingAddress);
fundingWifs.push(fundingWif);
}
//console.log(fundingAddresses);
//console.log(fundingWifs);
// Check balance for token type across all input addresses
SLP.Utils.balancesForAddress(fundingAddresses).then(
result => {
//console.log(`balancesForAddress:`);
//console.log(`All token balances for addresses:`);
//console.log(JSON.stringify(result, null, 2));
// Parse for tokenId
let checkedBalance = 0;
for (let i = 0; i < result.length; i++) {
for (let j = 0; j < result[i].length; j++) {
if (result[i][j].tokenId === keys.slpTokens.train4) {
checkedBalance += result[i][j].balance;
}
}
}
console.log(`Total balance for TRAIN4: ${checkedBalance}`);
return sweepAllSlp(checkedBalance);
},
err => {
console.log(`Error in SLP.Utils.balancesForAddress:`);
console.log(err);
}
);
function sweepAllSlp(checkedBalance) {
SLP.TokenType1.send({
fundingAddress: fundingAddresses,
fundingWif: fundingWifs,
tokenReceiverAddress: tokenReceiverAddress,
bchChangeReceiverAddress: bchChangeReceiverAddress,
tokenId: tokenId,
amount: checkedBalance
}).then(
result => {
console.log(`SLP transaction successfully sent!`);
console.log(`txid: ${result}`);
},
err => {
console.log(`Error in SLP.TokenType1.send:`);
console.log(err);
}
);
}