Browse Source

little endian byte encoding

master^2
Evan Feenstra 4 years ago
parent
commit
dfd1d83534
  1. 14
      dist/src/controllers/queries.js
  2. 2
      dist/src/controllers/queries.js.map
  3. 12
      src/controllers/queries.ts

14
dist/src/controllers/queries.js

@ -101,9 +101,11 @@ function genChannelAndConfirmAccounting(acc) {
sat_per_byte sat_per_byte
}); });
console.log("[WATCH]=> CHANNEL OPENED!", r); console.log("[WATCH]=> CHANNEL OPENED!", r);
const fundingTxidRev = Buffer.from(r.funding_txid_bytes).toString('hex');
const fundingTxid = fundingTxidRev.match(/.{2}/g).reverse().join("");
yield models_1.models.Accounting.update({ yield models_1.models.Accounting.update({
status: constants_1.default.statuses.received, status: constants_1.default.statuses.received,
fundingTxid: r.funding_txid_str, fundingTxid: fundingTxid,
amount: acc.amount amount: acc.amount
}, { }, {
where: { id: acc.id } where: { id: acc.id }
@ -139,8 +141,6 @@ function checkForConfirmedChannels() {
const received = yield getReceivedAccountings(); const received = yield getReceivedAccountings();
console.log('[WATCH] received accountings:', received); console.log('[WATCH] received accountings:', received);
yield asyncForEach(received, (rec) => __awaiter(this, void 0, void 0, function* () { yield asyncForEach(received, (rec) => __awaiter(this, void 0, void 0, function* () {
if (rec.confirmations <= 0)
return; // needs confs
if (rec.amount <= 0) if (rec.amount <= 0)
return; // needs amount return; // needs amount
if (!rec.pubkey) if (!rec.pubkey)
@ -154,12 +154,14 @@ function checkForConfirmedChannels() {
function checkChannelsAndKeysend(rec) { function checkChannelsAndKeysend(rec) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
const owner = yield models_1.models.Contact.findOne({ where: { isOwner: true } }); const owner = yield models_1.models.Contact.findOne({ where: { isOwner: true } });
const channels = yield lightning.listChannels({ const chans = yield lightning.listChannels({
active_only: true, active_only: true,
peer: rec.pubkey peer: rec.pubkey
}); });
console.log('[WATCH] found active channel for pubkey:', rec.pubkey, channels); console.log('[WATCH] found active channel for pubkey:', rec.pubkey, chans);
channels.forEach(chan => { if (!(chans && chans.channels))
return;
chans.channels.forEach(chan => {
if (chan.channel_point.includes(rec.fundingTxid)) { if (chan.channel_point.includes(rec.fundingTxid)) {
console.log('[WATCH] found channel to keysend:', chan); console.log('[WATCH] found channel to keysend:', chan);
const msg = { const msg = {

2
dist/src/controllers/queries.js.map

File diff suppressed because one or more lines are too long

12
src/controllers/queries.ts

@ -105,9 +105,11 @@ async function genChannelAndConfirmAccounting(acc: Accounting) {
sat_per_byte sat_per_byte
}) })
console.log("[WATCH]=> CHANNEL OPENED!", r) console.log("[WATCH]=> CHANNEL OPENED!", r)
const fundingTxidRev = Buffer.from(r.funding_txid_bytes).toString('hex')
const fundingTxid = (fundingTxidRev.match(/.{2}/g) as any).reverse().join("")
await models.Accounting.update({ await models.Accounting.update({
status: constants.statuses.received, status: constants.statuses.received,
fundingTxid: r.funding_txid_str, fundingTxid: fundingTxid,
amount: acc.amount amount: acc.amount
}, { }, {
where: { id: acc.id } where: { id: acc.id }
@ -137,7 +139,6 @@ async function checkForConfirmedChannels(){
const received = await getReceivedAccountings() const received = await getReceivedAccountings()
console.log('[WATCH] received accountings:', received) console.log('[WATCH] received accountings:', received)
await asyncForEach(received, async (rec: Accounting) => { await asyncForEach(received, async (rec: Accounting) => {
if (rec.confirmations <= 0) return // needs confs
if (rec.amount <= 0) return // needs amount if (rec.amount <= 0) return // needs amount
if (!rec.pubkey) return // this shouldnt happen if (!rec.pubkey) return // this shouldnt happen
if (!rec.fundingTxid) return if (!rec.fundingTxid) return
@ -147,12 +148,13 @@ async function checkForConfirmedChannels(){
async function checkChannelsAndKeysend(rec: Accounting){ async function checkChannelsAndKeysend(rec: Accounting){
const owner = await models.Contact.findOne({ where: { isOwner: true } }) const owner = await models.Contact.findOne({ where: { isOwner: true } })
const channels = await lightning.listChannels({ const chans = await lightning.listChannels({
active_only:true, active_only:true,
peer: rec.pubkey peer: rec.pubkey
}) })
console.log('[WATCH] found active channel for pubkey:', rec.pubkey, channels) console.log('[WATCH] found active channel for pubkey:', rec.pubkey, chans)
channels.forEach(chan=>{ // find by txid if(!(chans && chans.channels)) return
chans.channels.forEach(chan=>{ // find by txid
if(chan.channel_point.includes(rec.fundingTxid)) { if(chan.channel_point.includes(rec.fundingTxid)) {
console.log('[WATCH] found channel to keysend:', chan) console.log('[WATCH] found channel to keysend:', chan)
const msg: { [k: string]: any } = { const msg: { [k: string]: any } = {

Loading…
Cancel
Save