Browse Source

Merge pull request #106 from stakwork/fix-thread-amt

fix splitting amount if TLV is split between multiple keysends
dependabot/npm_and_yarn/ini-1.3.7
Evan Feenstra 4 years ago
committed by GitHub
parent
commit
bad02e731a
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      dist/src/utils/lightning.js
  2. 2
      dist/src/utils/lightning.js.map
  3. 7
      src/utils/lightning.ts

6
dist/src/utils/lightning.js

@ -16,6 +16,7 @@ const helpers_1 = require("../helpers");
const sha = require("js-sha256");
const crypto = require("crypto");
const path = require("path");
const constants_1 = require("../constants");
// var protoLoader = require('@grpc/proto-loader')
const env = process.env.NODE_ENV || 'development';
const config = require(path.join(__dirname, '../../config/app.json'))[env];
@ -135,7 +136,7 @@ const keysend = (opts) => {
const randoStr = crypto.randomBytes(32).toString('hex');
const preimage = ByteBuffer.fromHex(randoStr);
const options = {
amt: Math.max(opts.amt, 3),
amt: Math.max(opts.amt, constants_1.default.min_sat_amount || 3),
final_cltv_delta: 10,
dest: ByteBuffer.fromHex(opts.dest),
dest_custom_records: {
@ -191,8 +192,9 @@ function keysendMessage(opts) {
yield asyncForEach(Array.from(Array(n)), (u, i) => __awaiter(this, void 0, void 0, function* () {
const spliti = Math.ceil(opts.data.length / n);
const m = opts.data.substr(i * spliti, spliti);
const amt = Math.round(opts.amt / n);
try {
res = yield keysend(Object.assign(Object.assign({}, opts), { data: `${ts}_${i}_${n}_${m}` }));
res = yield keysend(Object.assign(Object.assign({}, opts), { amt, data: `${ts}_${i}_${n}_${m}` }));
success = true;
yield helpers_1.sleep(432);
}

2
dist/src/utils/lightning.js.map

File diff suppressed because one or more lines are too long

7
src/utils/lightning.ts

@ -5,6 +5,7 @@ import { sleep } from '../helpers';
import * as sha from 'js-sha256'
import * as crypto from 'crypto'
import * as path from 'path'
import constants from '../constants'
// var protoLoader = require('@grpc/proto-loader')
const env = process.env.NODE_ENV || 'development';
@ -125,7 +126,7 @@ const keysend = (opts) => {
const randoStr = crypto.randomBytes(32).toString('hex');
const preimage = ByteBuffer.fromHex(randoStr)
const options = {
amt: Math.max(opts.amt, 3),
amt: Math.max(opts.amt, constants.min_sat_amount||3),
final_cltv_delta: 10,
dest: ByteBuffer.fromHex(opts.dest),
dest_custom_records: {
@ -177,8 +178,10 @@ async function keysendMessage(opts) {
await asyncForEach(Array.from(Array(n)), async(u,i)=> {
const spliti = Math.ceil(opts.data.length/n)
const m = opts.data.substr(i*spliti, spliti)
const amt = Math.round(opts.amt/n)
try {
res = await keysend({...opts,
res = await keysend({
...opts, amt, // split the amt too
data: `${ts}_${i}_${n}_${m}`
})
success = true

Loading…
Cancel
Save