Skip to content

Instantly share code, notes, and snippets.

View qianbin's full-sized avatar

Qian Bin qianbin

View GitHub Profile
package main
import (
"fmt"
"log"
"math/rand"
"os"
"path"
"time"
@qianbin
qianbin / mpt-node-compress.go
Last active August 6, 2022 17:51
full nodes compression ratio
func main() {
var node [16][]byte
for i := 0; i < len(node); i++ {
b := make([]byte, 32)
rand.Read(b)
node[i] = b
}
buf := bytes.NewBuffer(nil)
@qianbin
qianbin / web3-styled-contract-binding.ts
Created April 12, 2021 06:10
connex2: demonstrate how to create an contract object like web3
function contract(thor: Connex.Thor, address: string, abis: Array<any>) {
const obj: Record<string, Connex.Thor.Account.Method> = {}
abis.filter(i => i.type === 'function' && i.name)
.forEach(i => {
obj[i.name] = thor.account(address).method(i)
})
return obj
}
@qianbin
qianbin / connex-playground.js
Last active January 21, 2021 02:45
Connex playground in browser
// copy and run following lines into your browser dev console,
// you'll get connex ready
const connex = await (() => {
const script = document.createElement('script')
script.src = 'https://unpkg.com/@vechain/connex@2'
document.body.appendChild(script)
return new Promise((resolve, reject) => {
script.onload = () => {
resolve(new Connex({
node: 'https://testnet.veblocks.net',
@qianbin
qianbin / surprise.sol
Created August 5, 2019 15:30
contract lost
pragma solidity ^0.4.23;
contract Surprise {
address public owner;
function whatWillHappen() public {
// defaults to 'storage' type, and points to `owner`.
uint8[20] x;
// will mamuplate value of `owner`
@qianbin
qianbin / encode.js
Created July 29, 2019 06:42
encode contract call data
// VIP-180 balanceOf method
const balanceOf = new abi.Function({
"constant": true,
"inputs": [
{
"name": "_owner",
"type": "address"
}
],
"name": "balanceOf",
@qianbin
qianbin / which-block.js
Last active July 9, 2019 08:20
calculate block number according to given time
// require connex-repl env
// calculate block number according to given time
async function whichBlock(targetTime) {
if(typeof targetTime === 'string') {
targetTime = new Date(targetTime).getTime()
}
return (await connex.thor.block().get()).number + Math.round((targetTime - Date.now()) / 1000 / 10)
}
const acc = connex.thor.account('0x0000000000000000000000000000456E65726779')
const ev = acc.event({
"anonymous": false,
"inputs": [
{
"indexed": true,
"name": "from",
"type": "address"
},
{
for {
t := time.Now().UnixNano()
for i := 0; i < 1000; i++ {
var key [2]byte
rand.Read(key[:])
it := mainDB.NewIterator(*kv.NewRangeWithBytesPrefix(key[:]))
if it.Next() {
it.Value()
}
it.Release()
package demo
import (
"bytes"
"github.com/ethereum/go-ethereum/crypto"
"github.com/vechain/thor/thor"
"github.com/vechain/thor/tx"
)