Skip to content

Instantly share code, notes, and snippets.

View qianbin's full-sized avatar

Qian Bin qianbin

View GitHub Profile
import Deferred from '@/base/deferred'
class PromiseTracker {
private readonly deferred = new Deferred()
constructor() {
this.deferred.catch()
}
public track<T extends object>(obj: T): T {
return this._track(obj)
@qianbin
qianbin / demo.ts
Created March 6, 2019 06:13
deployment data for contract with constructor arguments
import { abi } from 'thor-devkit'
// assume we have a demo contract
// contract DemoContract {
// constructor(int arg) public {
// }
// }
const byteCode = '0x....'
const constructorABI = {
@qianbin
qianbin / demo.ts
Last active March 6, 2019 06:27
deployment data for contract with constructor arguments
import { abi } from 'thor-devkit'
// assume we have a demo contract
// contract DemoContract {
// constructor(int arg) public {
// }
// }
const byteCode = '0x....'
const constructorABI = {
const ticker = connex.thor.ticker()
let receipt = null
do {
await ticker.next()
// need to catch exception
receipt = await transaction.getReceipt()
} while(!receipt)
package demo
import (
"bytes"
"github.com/ethereum/go-ethereum/crypto"
"github.com/vechain/thor/thor"
"github.com/vechain/thor/tx"
)
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()
const acc = connex.thor.account('0x0000000000000000000000000000456E65726779')
const ev = acc.event({
"anonymous": false,
"inputs": [
{
"indexed": true,
"name": "from",
"type": "address"
},
{
@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)
}
@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 / 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`