Skip to content

Instantly share code, notes, and snippets.

@alex-miller-0
alex-miller-0 / eth-utxo.md
Last active February 3, 2024 15:20
UTXO tokens on Ethereum

Suppose we wish to model a UTXO system on the EVM. We need to represent UTXO tokens such that all value is preserved when tokens are spent. Note: For this example, we are not concerned about the security of the system and are satisfied with giving authorities the power to create tokens (e.g. as in a plasma system).

Consider the following object:

{
  owner: <address>,
  value: <uint>,
@xavierlepretre
xavierlepretre / promisifyWeb3.js
Created January 8, 2017 17:36
Convert `web3` asynchronous calls into Promises.
module.exports = {
promisify: function (web3) {
// Pipes values from a Web3 callback.
var callbackToResolve = function (resolve, reject) {
return function (error, value) {
if (error) {
reject(error);
} else {
resolve(value);
}
@xavierlepretre
xavierlepretre / rxifyWeb3.js
Last active September 12, 2019 22:29
Convert `web3.eth` asynchronous calls into Rx observables.
const Rx = require('rx');
module.exports = {
rxify: function (web3) {
// List synchronous functions masquerading as values.
var syncGetters = {
db: [],
eth: [ "accounts", "blockNumber", "coinbase", "gasPrice", "hashrate",
"mining", "protocolVersion", "syncing" ],
net: [ "listening", "peerCount" ],
@jimschubert
jimschubert / Markdown-JavaScript.markdown.js
Last active September 24, 2023 13:31
DataGrip (IntelliJ) output SQL results to Markdown
if (!String.prototype.repeat) {
// polyfill from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat
String.prototype.repeat = function(count) {
'use strict';
if (this == null) {
throw new TypeError('can\'t convert ' + this + ' to object');
}
var str = '' + this;
count = +count;
if (count != count) {
web3.eth.filter("pending").watch(function() {
if (eth.mining) return;
console.log(new Date() + "-- Transactions detected, so starting mining.");
miner.start(1);
});
web3.eth.filter('latest', function(error, result) {
console.log(new Date() + "-- Got latest, so stopping mining");
miner.stop();
if (txpool.status.pending > 0) {
@yoavniran
yoavniran / ultimate-ut-cheat-sheet.md
Last active April 13, 2024 16:19
The Ultimate Unit Testing Cheat-sheet For Mocha, Chai, Sinon, and Jest
@brigand
brigand / utils-from-map.js
Created January 29, 2015 11:09
bend a map function to do other things
// where map(x, function(y, i, z){ z === x; return y }) === x
// and i is the index/key, and z is the first argument to map
// e.g. utilsFromMap(function(array, fn){ array.map(fn) });
// e.g. utilsFromMap(React.Children.map);
function utilsFromMap(map){
var utils = {};
// herein fn is a function,
// X is the thing to be passed to map as the first argument
// and there other parameters are specific to the function