Commit ca0d6c8f authored by George Hotz's avatar George Hotz

typescript to get block

parent a5710aab
node_modules
\ No newline at end of file
import { ethers } from 'ethers'
import assert from 'assert'
import fs from 'fs'
const keccak256 = ethers.utils.keccak256
const rlp = require('rlp')
// local geth
const provider = new ethers.providers.JsonRpcProvider('http://192.168.1.213:8545')
function getBlockRlp(block : any) {
let dat = [
block['parentHash'],
block['sha3Uncles'],
block['miner'],
block['stateRoot'],
block['transactionsRoot'],
block['receiptsRoot'],
block['logsBloom'],
block['difficulty'],
block['number'],
block['gasLimit'],
block['gasUsed'],
block['timestamp'],
block['extraData'],
block['mixHash'],
block['nonce'],
block['baseFeePerGas']
];
// special case for 0
dat = dat.map((x) => (x == "0x0") ? "0x" : x)
return rlp.encode(dat);
}
async function main() {
const blockNumber = 13247502;
let blockData = await provider.send("eth_getBlockByNumber", ["0x"+(blockNumber).toString(16), true])
const blockHeaderRlp = getBlockRlp(blockData)
assert(keccak256(blockHeaderRlp) == blockData['hash'])
fs.writeFileSync(`data/block_${blockNumber}`, blockHeaderRlp)
}
main().then(() => process.exit(0))
...@@ -4,12 +4,15 @@ import ( ...@@ -4,12 +4,15 @@ import (
"fmt" "fmt"
"github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
) )
func main() { func main() {
bc := &core.BlockChain{} bc := &core.BlockChain{}
//engine := ethash.NewFullFaker() //engine := ethash.NewFullFaker()
core.NewStateProcessor(params.MainnetChainConfig, bc, nil) statedb := &state.StateDB{}
processor := core.NewStateProcessor(params.MainnetChainConfig, bc, nil)
fmt.Println("made state processor") fmt.Println("made state processor")
processor.Process()
} }
{
"dependencies": {
"@types/node": "^16.9.2",
"ethers": "^5.4.7",
"rlp": "^2.2.6",
"typescript": "^4.4.3"
}
}
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment