melis-fork-claimer
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -6,3 +6,3 @@ { | ||
"license": "ISC", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"main": "src/index.js", | ||
@@ -9,0 +9,0 @@ "scripts": { |
@@ -808,7 +808,8 @@ // | ||
unspents.forEach(u => { | ||
tx.addInput(Buffer.from(u.hash, 'hex').reverse(), u.n, Bitcoin.Transaction.DEFAULT_SEQUENCE) | ||
inputAmount += u.amount | ||
}) | ||
tx.addInput(Buffer.from(u.hash, 'hex').reverse(), u.n, Bitcoin.Transaction.DEFAULT_SEQUENCE) | ||
inputAmount += u.amount | ||
}) | ||
/console.log("[prepareSignaturesForClaim] recipients:", recipients) | ||
/ | ||
console.log("[prepareSignaturesForClaim] recipients:", recipients) | ||
let outputAmount = 0 | ||
@@ -957,79 +958,75 @@ recipients.forEach(recipient => { | ||
async bsvScan(melis, accounts, doDebug) { | ||
try { | ||
const bchDriver = melis.getCoinDriver('BCH') | ||
const res = {} | ||
const bchDriver = melis.getCoinDriver('BCH') | ||
const res = {} | ||
for (let i = 0; i < accounts.length; i++) { | ||
const account = accounts[i] | ||
if (account.type !== '2' && account.type !== 'H') { | ||
console.log("Skipping account " + account.pubId + " of unsupported type " + account.type) | ||
continue | ||
for (let i = 0; i < accounts.length; i++) { | ||
const account = accounts[i] | ||
if (account.coin !== 'BCH') { | ||
console.log("Skipping account " + account.pubId + " " + account.coin) | ||
continue | ||
} | ||
if (account.type !== '2' && account.type !== 'H') { | ||
console.log("Skipping account " + account.pubId + " of unsupported type " + account.type) | ||
continue | ||
} | ||
console.log("scanning account " + account.pubId + " type: " + account.type + " meta: " + JSON.stringify(account.meta)) | ||
const slice = await melis.addressesGet(account) | ||
//console.log("slice result: " + slice) | ||
if (!slice.list) { | ||
console.log("No addresses on melis for account " + account.pubId) | ||
continue | ||
} | ||
const addrs = slice.list.map(aa => bchDriver.toLegacyAddress(aa.address)) | ||
if (doDebug) | ||
console.log("#Addresses: " + addrs.length + "\n", addrs) | ||
const utxos = await this.queryUtxos(addrs, { | ||
doDebug | ||
}) | ||
if (doDebug) | ||
console.log("utxos:", utxos) | ||
if (utxos.length) | ||
res[account.pubId] = { | ||
utxos, | ||
account | ||
} | ||
console.log("scanning account " + account.pubId + " type: " + account.type + " meta: " + JSON.stringify(account.meta)) | ||
const slice = await melis.addressesGet(account) | ||
//console.log("slice result: " + slice) | ||
if (!slice.list) { | ||
console.log("No addresses on melis for account " + account.pubId) | ||
continue | ||
} | ||
const addrs = slice.list.map(aa => bchDriver.toLegacyAddress(aa.address)) | ||
if (doDebug) | ||
console.log("#Addresses: " + addrs.length + "\n", addrs) | ||
const utxos = await this.queryUtxos(addrs, { | ||
doDebug | ||
}) | ||
if (doDebug) | ||
console.log("utxos:", utxos) | ||
if (utxos.length) | ||
res[account.pubId] = { | ||
utxos, | ||
account | ||
} | ||
} | ||
return res | ||
} catch (err) { | ||
console.log("bsvScan Ex:", err) | ||
} | ||
return res | ||
} | ||
async bsvRedeem(melis, params) { | ||
try { | ||
const account = params.account | ||
const utxos = params.utxos | ||
let targetAddress = params.targetAddress | ||
const account = params.account | ||
const utxos = params.utxos | ||
let targetAddress = params.targetAddress | ||
if (params && params.doDebug) | ||
console.log("[BSV CLAIM] utxos: ", utxos) | ||
if (!account) | ||
throw ("Missing account in parameters") | ||
if (!utxos || !utxos.length) | ||
throw ("Missing utxos in parameters") | ||
if (!targetAddress) { | ||
const pubId = await this.findExistingBSVAccount(melis) | ||
const aa = await melis.getPaymentAddressViaRest(pubId, { | ||
info: 'BSV Redeemed coins' | ||
}) | ||
if (params && params.doDebug) | ||
console.log("[BSV CLAIM] utxos: ", utxos) | ||
if (!account) | ||
throw ("Missing account in parameters") | ||
if (!utxos || !utxos.length) | ||
throw ("Missing utxos in parameters") | ||
console.log("Created new aa: ", aa) | ||
targetAddress = aa.address | ||
} | ||
if (!targetAddress) { | ||
const pubId = await this.findExistingBSVAccount(melis) | ||
const aa = await melis.getPaymentAddressViaRest(pubId, { | ||
info: 'BSV Redeemed coins' | ||
}) | ||
if (params && params.doDebug) | ||
console.log("Created new aa: ", aa) | ||
targetAddress = aa.address | ||
} | ||
console.log("Target BSV address: ", targetAddress) | ||
const unspents = utxos.map(u => ({ | ||
hash: u.txid, | ||
n: u.vout, | ||
address: u.address | ||
})) | ||
console.log("Target BSV address: ", targetAddress) | ||
const unspents = utxos.map(u => ({ | ||
hash: u.txid, | ||
n: u.vout, | ||
address: u.address | ||
})) | ||
const res = await this.redeem(melis, { | ||
account, | ||
targetCoin: 'BSV', | ||
targetAddress, | ||
unspents | ||
}) | ||
const res = await this.redeem(melis, { | ||
account, | ||
targetCoin: 'BSV', | ||
targetAddress, | ||
unspents | ||
}) | ||
return res | ||
} catch (err) { | ||
console.log("bsvRedeem Ex:", err) | ||
} | ||
return res | ||
} | ||
@@ -1036,0 +1033,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31400
939