ethereum-emissions-calculator
Advanced tools
Comparing version 2.0.0 to 2.1.0
@@ -20,5 +20,5 @@ "use strict"; | ||
* Based on 2021 methodology, see github and carbon.fyi for details. | ||
* Last updated: Mar. 7, 2021 | ||
* Last updated: June 24, 2021 | ||
*/ | ||
const KG_CO2_PER_GAS = 0.0002873993139; | ||
const KG_CO2_PER_GAS = 0.0001809589427; | ||
/** | ||
@@ -25,0 +25,0 @@ * Calculate emissions of an address. Emissions are allocated for SENT (outgoing) transactions only. |
@@ -9,8 +9,13 @@ "use strict"; | ||
const filterValidOutgoingTransactions = (transactions, address) => { | ||
return transactions.filter((txn) => { | ||
const isOutgoing = txn.from.toLowerCase() === address.toLowerCase(); | ||
const succeeded = txn.isError !== "1"; | ||
return isOutgoing && succeeded; | ||
}); | ||
return transactions.reduce((prev, txn) => { | ||
var _a; | ||
// since response is sorted, we only need to compare hash of preceeding valid txn | ||
if (txn.from.toLowerCase() === address.toLowerCase() && | ||
txn.isError !== "1" && | ||
((_a = prev[prev.length - 1]) === null || _a === void 0 ? void 0 : _a.hash) !== txn.hash) { | ||
return prev.concat([txn]); | ||
} | ||
return prev; | ||
}, []); | ||
}; | ||
exports.filterValidOutgoingTransactions = filterValidOutgoingTransactions; |
@@ -9,7 +9,11 @@ "use strict"; | ||
const filterValidTransactions = (transactions) => { | ||
return transactions.filter((txn) => { | ||
const succeeded = txn.isError !== "1"; | ||
return succeeded; | ||
}); | ||
return transactions.reduce((prev, txn) => { | ||
var _a; | ||
// since response is sorted, we only need to compare hash of preceeding valid txn | ||
if (txn.isError !== "1" && ((_a = prev[prev.length - 1]) === null || _a === void 0 ? void 0 : _a.hash) !== txn.hash) { | ||
return prev.concat([txn]); | ||
} | ||
return prev; | ||
}, []); | ||
}; | ||
exports.filterValidTransactions = filterValidTransactions; |
@@ -28,5 +28,7 @@ "use strict"; | ||
done: false, | ||
transactions: transactions.filter((txn) => txn.blockNumber > lowestBlockNumber), | ||
transactions: transactions.filter( | ||
// filter out the lowest block number because we don't know if we captured all of that blocks txns. | ||
(txn) => txn.blockNumber > lowestBlockNumber), | ||
}; | ||
}); | ||
exports.getAddressTransactions = getAddressTransactions; |
{ | ||
"name": "ethereum-emissions-calculator", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "TypeScript utils to calculate the CO2 emissions of an Ethereum wallet. Powered by the Etherscan.io API.", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
22724
25
348