New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

btcrelay-watchtower

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

btcrelay-watchtower - npm Package Compare versions

Comparing version 5.0.6 to 5.0.7

29

dist/watchtower/Watchtower.d.ts

@@ -6,13 +6,20 @@ /// <reference types="node" />

export declare class Watchtower<T extends SwapData, B extends BtcStoredHeader<any>, TX> {
hashMap: Map<string, SavedSwap<T>>;
escrowMap: Map<string, SavedSwap<T>>;
btcRelay: BtcRelay<B, TX, any>;
btcRelaySynchronizer: RelaySynchronizer<B, TX, BtcBlock>;
swapContract: SwapContract<T, TX, any, any>;
solEvents: ChainEvents<T>;
bitcoinRpc: BitcoinRpc<any>;
prunedTxoMap: PrunedTxoMap;
readonly dirName: any;
readonly rootDir: any;
constructor(directory: string, btcRelay: BtcRelay<B, TX, any>, btcRelaySynchronizer: RelaySynchronizer<B, TX, BtcBlock>, solEvents: ChainEvents<T>, swapContract: SwapContract<T, TX, any, any>, bitcoinRpc: BitcoinRpc<any>, pruningFactor?: number);
readonly hashMap: Map<string, SavedSwap<T>>;
readonly escrowMap: Map<string, SavedSwap<T>>;
readonly btcRelay: BtcRelay<B, TX, any>;
readonly btcRelaySynchronizer: RelaySynchronizer<B, TX, BtcBlock>;
readonly swapContract: SwapContract<T, TX, any, any>;
readonly solEvents: ChainEvents<T>;
readonly bitcoinRpc: BitcoinRpc<any>;
readonly prunedTxoMap: PrunedTxoMap;
readonly dirName: string;
readonly rootDir: string;
readonly shouldClaimCbk: (swap: SavedSwap<T>) => Promise<{
initAta: boolean;
feeRate: any;
}>;
constructor(directory: string, btcRelay: BtcRelay<B, TX, any>, btcRelaySynchronizer: RelaySynchronizer<B, TX, BtcBlock>, solEvents: ChainEvents<T>, swapContract: SwapContract<T, TX, any, any>, bitcoinRpc: BitcoinRpc<any>, pruningFactor?: number, shouldClaimCbk?: (swap: SavedSwap<T>) => Promise<{
initAta: boolean;
feeRate: any;
}>);
private load;

@@ -19,0 +26,0 @@ private save;

@@ -18,3 +18,3 @@ "use strict";

class Watchtower {
constructor(directory, btcRelay, btcRelaySynchronizer, solEvents, swapContract, bitcoinRpc, pruningFactor) {
constructor(directory, btcRelay, btcRelaySynchronizer, solEvents, swapContract, bitcoinRpc, pruningFactor, shouldClaimCbk) {
this.hashMap = new Map();

@@ -30,2 +30,3 @@ this.escrowMap = new Map();

this.prunedTxoMap = new PrunedTxoMap_1.PrunedTxoMap(directory + "/wt-height.txt", bitcoinRpc, pruningFactor);
this.shouldClaimCbk = shouldClaimCbk;
}

@@ -104,3 +105,3 @@ load() {

}
createClaimTxs(txoHash, swap, txId, voutN, blockheight, computedCommitedHeaders) {
createClaimTxs(txoHash, swap, txId, voutN, blockheight, computedCommitedHeaders, initAta, feeRate) {
return __awaiter(this, void 0, void 0, function* () {

@@ -111,18 +112,2 @@ const isCommited = yield this.swapContract.isCommited(swap.swapData);

const tx = yield this.bitcoinRpc.getTransaction(txId);
// const tx = await new Promise<BitcoindTransaction>((resolve, reject) => {
// BtcRPC.getRawTransaction(txId, 1, (err, info) => {
// if(err) {
// reject(err);
// return;
// }
// resolve(info.result);
// });
// });
//
// //Strip witness data
// const btcTx = bitcoin.Transaction.fromHex(tx.hex);
// for(let txIn of btcTx.ins) {
// txIn.witness = [];
// }
// tx.hex = btcTx.toHex();
//Re-check txoHash

@@ -141,7 +126,9 @@ const vout = tx.outs[voutN];

try {
txs = yield this.swapContract.txsClaimWithTxData(swap.swapData, blockheight, tx, voutN, storedHeader, null, false);
txs = yield this.swapContract.txsClaimWithTxData(swap.swapData, blockheight, tx, voutN, storedHeader, null, initAta == null ? false : initAta, feeRate);
}
catch (e) {
if (e instanceof crosslightning_base_1.SwapDataVerificationError)
if (e instanceof crosslightning_base_1.SwapDataVerificationError) {
console.error(e);
return null;
}
throw e;

@@ -279,3 +266,13 @@ }

continue;
const claimTxs = yield this.createClaimTxs(Buffer.from(txoHash, "hex"), savedSwap, data.txId, data.vout, data.height, computedHeaderMap);
//Check claimer's bounty and create ATA if the claimer bounty covers the costs of it!
let claimTxs;
if (this.shouldClaimCbk != null) {
const feeData = yield this.shouldClaimCbk(savedSwap);
if (feeData == null)
continue;
claimTxs = yield this.createClaimTxs(Buffer.from(txoHash, "hex"), savedSwap, data.txId, data.vout, data.height, computedHeaderMap, feeData.initAta, feeData.feeRate);
}
else {
claimTxs = yield this.createClaimTxs(Buffer.from(txoHash, "hex"), savedSwap, data.txId, data.vout, data.height, computedHeaderMap);
}
if (claimTxs == null) {

@@ -312,3 +309,13 @@ yield this.remove(savedSwap.txoHash);

continue;
const claimTxs = yield this.createClaimTxs(Buffer.from(txoHash, "hex"), savedSwap, data.txId, data.vout, data.height, computedHeaderMap);
//Check claimer's bounty and create ATA if the claimer bounty covers the costs of it!
let claimTxs;
if (this.shouldClaimCbk != null) {
const feeData = yield this.shouldClaimCbk(savedSwap);
if (feeData == null)
continue;
claimTxs = yield this.createClaimTxs(Buffer.from(txoHash, "hex"), savedSwap, data.txId, data.vout, data.height, computedHeaderMap, feeData.initAta, feeData.feeRate);
}
else {
claimTxs = yield this.createClaimTxs(Buffer.from(txoHash, "hex"), savedSwap, data.txId, data.vout, data.height, computedHeaderMap);
}
if (claimTxs == null) {

@@ -315,0 +322,0 @@ yield this.remove(savedSwap.txoHash);

{
"name": "btcrelay-watchtower",
"version": "5.0.6",
"version": "5.0.7",
"description": "Watchtower chain agnostic implementation",

@@ -5,0 +5,0 @@ "main": "./dist/index.js",

@@ -10,17 +10,19 @@ import {PrunedTxoMap} from "./PrunedTxoMap";

hashMap: Map<string, SavedSwap<T>> = new Map<string, SavedSwap<T>>();
escrowMap: Map<string, SavedSwap<T>> = new Map<string, SavedSwap<T>>();
readonly hashMap: Map<string, SavedSwap<T>> = new Map<string, SavedSwap<T>>();
readonly escrowMap: Map<string, SavedSwap<T>> = new Map<string, SavedSwap<T>>();
btcRelay: BtcRelay<B, TX, any>;
btcRelaySynchronizer: RelaySynchronizer<B, TX, BtcBlock>;
readonly btcRelay: BtcRelay<B, TX, any>;
readonly btcRelaySynchronizer: RelaySynchronizer<B, TX, BtcBlock>;
swapContract: SwapContract<T, TX, any, any>;
solEvents: ChainEvents<T>;
bitcoinRpc: BitcoinRpc<any>;
readonly swapContract: SwapContract<T, TX, any, any>;
readonly solEvents: ChainEvents<T>;
readonly bitcoinRpc: BitcoinRpc<any>;
prunedTxoMap: PrunedTxoMap;
readonly prunedTxoMap: PrunedTxoMap;
readonly dirName;
readonly rootDir;
readonly dirName: string;
readonly rootDir: string;
readonly shouldClaimCbk: (swap: SavedSwap<T>) => Promise<{initAta: boolean, feeRate: any}>;
constructor(

@@ -33,3 +35,4 @@ directory: string,

bitcoinRpc: BitcoinRpc<any>,
pruningFactor?: number
pruningFactor?: number,
shouldClaimCbk?: (swap: SavedSwap<T>) => Promise<{initAta: boolean, feeRate: any}>
) {

@@ -44,2 +47,3 @@ this.rootDir = directory;

this.prunedTxoMap = new PrunedTxoMap(directory+"/wt-height.txt", bitcoinRpc, pruningFactor);
this.shouldClaimCbk = shouldClaimCbk;
}

@@ -129,3 +133,5 @@

[height: number]: B
}
},
initAta?: boolean,
feeRate?: any
): Promise<TX[] | null> {

@@ -137,18 +143,2 @@ const isCommited = await this.swapContract.isCommited(swap.swapData);

const tx = await this.bitcoinRpc.getTransaction(txId);
// const tx = await new Promise<BitcoindTransaction>((resolve, reject) => {
// BtcRPC.getRawTransaction(txId, 1, (err, info) => {
// if(err) {
// reject(err);
// return;
// }
// resolve(info.result);
// });
// });
//
// //Strip witness data
// const btcTx = bitcoin.Transaction.fromHex(tx.hex);
// for(let txIn of btcTx.ins) {
// txIn.witness = [];
// }
// tx.hex = btcTx.toHex();

@@ -170,5 +160,8 @@ //Re-check txoHash

try {
txs = await this.swapContract.txsClaimWithTxData(swap.swapData, blockheight, tx, voutN, storedHeader, null, false);
txs = await this.swapContract.txsClaimWithTxData(swap.swapData, blockheight, tx, voutN, storedHeader, null, initAta==null ? false : initAta, feeRate);
} catch (e) {
if(e instanceof SwapDataVerificationError) return null;
if(e instanceof SwapDataVerificationError) {
console.error(e);
return null;
}
throw e;

@@ -352,3 +345,13 @@ }

const claimTxs = await this.createClaimTxs(Buffer.from(txoHash, "hex"), savedSwap, data.txId, data.vout, data.height, computedHeaderMap);
//Check claimer's bounty and create ATA if the claimer bounty covers the costs of it!
let claimTxs: TX[];
if(this.shouldClaimCbk!=null) {
const feeData = await this.shouldClaimCbk(savedSwap);
if(feeData==null) continue;
claimTxs = await this.createClaimTxs(Buffer.from(txoHash, "hex"), savedSwap, data.txId, data.vout, data.height, computedHeaderMap, feeData.initAta, feeData.feeRate);
} else {
claimTxs = await this.createClaimTxs(Buffer.from(txoHash, "hex"), savedSwap, data.txId, data.vout, data.height, computedHeaderMap);
}
if(claimTxs==null) {

@@ -384,3 +387,13 @@ await this.remove(savedSwap.txoHash);

const claimTxs = await this.createClaimTxs(Buffer.from(txoHash, "hex"), savedSwap, data.txId, data.vout, data.height, computedHeaderMap);
//Check claimer's bounty and create ATA if the claimer bounty covers the costs of it!
let claimTxs: TX[];
if(this.shouldClaimCbk!=null) {
const feeData = await this.shouldClaimCbk(savedSwap);
if(feeData==null) continue;
claimTxs = await this.createClaimTxs(Buffer.from(txoHash, "hex"), savedSwap, data.txId, data.vout, data.height, computedHeaderMap, feeData.initAta, feeData.feeRate);
} else {
claimTxs = await this.createClaimTxs(Buffer.from(txoHash, "hex"), savedSwap, data.txId, data.vout, data.height, computedHeaderMap);
}
if(claimTxs==null) {

@@ -387,0 +400,0 @@ await this.remove(savedSwap.txoHash);

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc