Skip to content

Instantly share code, notes, and snippets.

Avatar

Yukishige Nakajo nakajo2011

View GitHub Profile
@nakajo2011
nakajo2011 / faucet_with_provider.js
Created Apr 9, 2020
with provider for mock web3.js
View faucet_with_provider.js
const Web3 = require('web3')
const Faucet = require('./faucet')
const BLOCK_NUMBER_PER_DAY = 24 * 60 * 4
const contractJson = require('../../build/contracts/MyToken')
class FaucetWithProvider extends Faucet {
constructor(provider, address, fromAddress) {
super(address, fromAddress)
this.provider = new Web3(provider)
this.myToken = new this.provider.eth.Contract(contractJson.abi, address, {from: fromAddress})
@nakajo2011
nakajo2011 / faucet.spec.js
Created Apr 8, 2020
web3.js mocking sample unit test
View faucet.spec.js
const Faucet = require('../src/model/faucet')
const CONTRACT_ADDRESS = '0xadDf5bC8b45571D94e2FD46Bfb81f8dD6D6f9FA0'
const FROM_ADDRESS = '0x259de638f0d6d79dfa084a810c1356d4d575b62e'
describe('Faucet', function () {
describe('init', function () {
it('should be return instance', async () => {
const ins = new Faucet(CONTRACT_ADDRESS, FROM_ADDRESS)
expect(ins).toBeDefined()
@nakajo2011
nakajo2011 / faucet.js
Last active Apr 8, 2020
web3.js mock sample
View faucet.js
const Web3 = require('web3')
const BLOCK_NUMBER_PER_DAY = 24 * 60 * 4
const contractJson = require('../../build/contracts/MyToken')
class Faucet {
constructor(address, fromAddress) {
this.provider = new Web3(new Web3.providers.HttpProvider("http://localhost:7545"))
this.myToken = new this.provider.eth.Contract(contractJson.abi, address, {from: fromAddress})
}
@nakajo2011
nakajo2011 / patricia_sampl_dump.js
Last active Nov 20, 2019
Simple Patricia Trie what showed in "Patricia Trie" in Ethereum wiki.
View patricia_sampl_dump.js
const BaseTrie = require('merkle-patricia-tree/baseTrie')
const TrieNode = require('merkle-patricia-tree/trieNode')
const toNibbleArray = (bytes) => {
let nibbles = []
bytes.forEach((b) => {
nibbles.push(parseInt(b / 16))
nibbles.push(b % 16)
})
return Buffer.from(nibbles)
@nakajo2011
nakajo2011 / daveauction.vy
Created Oct 9, 2019
Devcon5 Day2 hands-on
View daveauction.vy
# Devcon 5 Auction
# Masked Reveal Auction
#*******************************
#Every user has a bid amount, hash (bidamount,pass), sent masked amount
struct Data:
bidval: wei_value
hashval: bytes32
sentval: wei_value
View keybase.md

Keybase proof

I hereby claim:

  • I am nakajo2011 on github.
  • I am y_nakajo (https://keybase.io/y_nakajo) on keybase.
  • I have a public key ASDVHdcqYNHUJmuB-C_nfytsir7fRHTPyn5zrtAJkjKwIgo

To claim this, I am signing this object:

View sample.js
const Web3 = require('web3')
const {Solo, BigNumber} = require('./dist/js/src/index.js')
const {AmountReference, AmountDenomination, ConfirmationType} = require('./dist/js/src/types.js')
process.on('unhandledRejection', console.dir)
const WETH_Market_ID = new BigNumber('0')
const DAI_Market_ID = new BigNumber('1')
const USDC_Market_ID = new BigNumber('2')
/**
@nakajo2011
nakajo2011 / AddRemote_in_tx_pool.go
Last active Feb 5, 2019
20190206 blog parts2 reference from rev:27ce4eb78bdf5d9b742ed05babe9b86a434733a1
View AddRemote_in_tx_pool.go
L798-L803
// AddRemote enqueues a single transaction into the pool if it is valid. If the
// sender is not among the locally tracked ones, full pricing constraints will
// apply.
func (pool *TxPool) AddRemote(tx *types.Transaction) error {
return pool.addTx(tx, false)
}
...
L631-L641
@nakajo2011
nakajo2011 / broadcast_lines_in_tx_pool.go
Last active Feb 5, 2019
20190206_blog_parts_rev_27ce4eb78bdf5d9b742ed05babe9b86a434733a1_tx_pool
View broadcast_lines_in_tx_pool.go
if list := pool.pending[from]; list != nil && list.Overlaps(tx) {
// Nonce already pending, check if required price bump is met
inserted, old := list.Add(tx, pool.config.PriceBump)
if !inserted {
pendingDiscardCounter.Inc(1)
return false, ErrReplaceUnderpriced
}
// New transaction is better, replace old one
if old != nil {
pool.all.Remove(old.Hash())
View rev_ 27ce4eb78bdf5d9b742ed05babe9b86a434733a1_tx_pool.go
// Copyright 2014 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of