This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"log" | |
"math/rand" | |
"os" | |
"path" | |
"time" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// VIP-180 balanceOf method | |
const balanceOf = new abi.Function({ | |
"constant": true, | |
"inputs": [ | |
{ | |
"name": "_owner", | |
"type": "address" | |
} | |
], | |
"name": "balanceOf", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const acc = connex.thor.account('0x0000000000000000000000000000456E65726779') | |
const ev = acc.event({ | |
"anonymous": false, | |
"inputs": [ | |
{ | |
"indexed": true, | |
"name": "from", | |
"type": "address" | |
}, | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package demo | |
import ( | |
"bytes" | |
"github.com/ethereum/go-ethereum/crypto" | |
"github.com/vechain/thor/thor" | |
"github.com/vechain/thor/tx" | |
) |
NewerOlder