Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function getPastEvents() {
if (processing) {
await isDone()
}
processing = true
if (!triedIpfs && config.ipfsEventCache) {
debug('Try IPFS cache...')
let ipfsData
try {
ipfsData = await get(config.ipfsGateway, config.ipfsEventCache)
if (ipfsData.compressed) {
const decompressed = LZString.decompress(ipfsData.compressed)
ipfsData = JSON.parse(decompressed)
}
} catch (e) {
/* Ignore */
}
if (ipfsData && ipfsData.events) {
debug('Got IPFS cache')
// console.log(ipfsData)
events = ipfsData.events
lastLookup = ipfsData.lastLookup
fromBlock = ipfsData.lastLookup
// ({ events, lastLookup } = ipfsData)
} else {
debug('Error getting IPFS cache')
}
triedIpfs = true
function getBlockNumber() {
return toBlock
}
if (!contract.options.address) {
return { updateBlock }
}
const cacheStr = `eventCache${contract.options.address.slice(2, 8)}`
try {
if (window.localStorage[cacheStr]) {
let str = window.localStorage[cacheStr]
if (str[0] !== '{') {
str = LZString.decompress(str)
}
const parsed = JSON.parse(str)
events = parsed.events
lastLookup = fromBlock = parsed.lastLookup
triedIpfs = true
}
} catch (e) {
/* Ignore */
}
const isDone = () => new Promise(resolve => queue.push(resolve))
async function getPastEvents() {
if (processing) {
await isDone()
}
async function getPastEvents() {
if (processing) {
await isDone()
}
processing = true
if (!triedIpfs && config.ipfsEventCache) {
debug('Try IPFS cache...')
let ipfsData
try {
ipfsData = await get(config.ipfsGateway, ipfsEventCache)
if (ipfsData.compressed) {
const decompressed = LZString.decompress(ipfsData.compressed)
ipfsData = JSON.parse(decompressed)
}
} catch (e) {
/* Ignore */
}
if (ipfsData && ipfsData.events) {
debug('Got IPFS cache')
events = ipfsData.events
lastLookup = ipfsData.lastLookup
fromBlock = ipfsData.lastLookup
} else {
debug('Error getting IPFS cache')
}
triedIpfs = true
}
if (!toBlock) {
decompress() {
this.id = LZString.decompress(this.id);
this.lat = LZString.decompress(this.lat);
this.lon = LZString.decompress(this.lon);
this.speed = LZString.decompress(this.speed);
}
}
if (!database) return
const openingDatabase = message.dbNameHash && message.dbKey
if (openingDatabase) {
const dbKeyString = await crypto.aesGcm.decryptString(this.keys.encryptionKey, message.dbKey)
database.dbKeyString = dbKeyString
database.dbKey = await crypto.aesGcm.getKeyFromKeyString(dbKeyString)
}
if (!database.dbKey) return
if (message.bundle) {
const bundleSeqNo = message.bundleSeqNo
const base64Bundle = message.bundle
const compressedString = await crypto.aesGcm.decryptString(database.dbKey, base64Bundle)
const plaintextString = LZString.decompress(compressedString)
const bundle = JSON.parse(plaintextString)
database.applyBundle(bundle, bundleSeqNo)
}
const newTransactions = message.transactionLog
await database.applyTransactions(newTransactions)
database.onChange(database.getItems())
if (!database.init) {
this.state.dbIdToHash[dbId] = dbNameHash
database.dbId = dbId
database.init = true
}
break
unpack(raw) {
const uncompressed = LZString.decompress(raw);
return uncompressed ? jsonpack.unpack(uncompressed) : {};
}
}
get(key) {
let item = localStorage.getItem(key);
let val;
if (!_.isUndefined(item)) {
item = LZString.decompress(item);
}
try {
val = JSON.parse(item);
} catch (ex) {
val = item;
}
return val;
},
/**
get() {
const value = localStorage.getItem(STORAGE_KEY);
const uncompressed = LZString.decompress(value);
return uncompressed ? jsonpack.unpack(uncompressed) : {};
},
parse(payload) {
try {
const stateJSON = lzString.decompress(payload);
return JSON.parse(stateJSON);
} catch (e) {
return null;
}
},