Commit 8f3a0989 authored by George Hotz's avatar George Hotz

fix transaction order

parent 1495f490
......@@ -20,6 +20,12 @@ import (
"github.com/ethereum/go-ethereum/trie"
)
func check(err error) {
if err != nil {
log.Fatal(err)
}
}
func main() {
// init secp256k1BytePoints
crypto.S256()
......@@ -38,10 +44,7 @@ func main() {
// read start block header
var parent types.Header
rlperr := rlp.DecodeBytes(oracle.Preimage(oracle.Input(0)), &parent)
if rlperr != nil {
log.Fatal(rlperr)
}
check(rlp.DecodeBytes(oracle.Preimage(oracle.Input(0)), &parent))
// read header
var newheader types.Header
......@@ -74,14 +77,17 @@ func main() {
tt, _ := trie.New(newheader.TxHash, &triedb)
tni := tt.NodeIterator([]byte{})
for tni.Next(true) {
fmt.Println(tni.Hash(), tni.Leaf(), tni.Path(), tni.Error())
//fmt.Println(tni.Hash(), tni.Leaf(), tni.Path(), tni.Error())
if tni.Leaf() {
tx := types.Transaction{}
lerr := tx.UnmarshalBinary(tni.LeafBlob())
if lerr != nil {
log.Fatal(lerr)
var rlpKey uint64
check(rlp.DecodeBytes(tni.LeafKey(), &rlpKey))
check(tx.UnmarshalBinary(tni.LeafBlob()))
// TODO: resize an array in go?
for uint64(len(txs)) <= rlpKey {
txs = append(txs, nil)
}
txs = append(txs, &tx)
txs[rlpKey] = &tx
}
}
fmt.Println("read", len(txs), "transactions")
......
......@@ -247,7 +247,7 @@ func PrefetchBlock(blockNumber *big.Int, startBlock bool, hasher types.TrieHashe
txs := make([]*types.Transaction, len(jr.Result.Transactions))
for i := 0; i < len(jr.Result.Transactions); i++ {
txs[i] = jr.Result.Transactions[i].ToTransaction()
fmt.Println("tx", i, "hash", txs[i].Hash())
//fmt.Println("tx", i, "hash", txs[i].Hash())
}
testTxHash := types.DeriveSha(types.Transactions(txs), hasher)
if testTxHash != blockHeader.TxHash {
......
......@@ -41,9 +41,7 @@ func (kw PreimageKeyValueWriter) Put(key []byte, value []byte) error {
if hash != common.BytesToHash(key) {
panic("bad preimage value write")
}
nval := make([]byte, len(value))
copy(nval, value)
preimages[hash] = nval
preimages[hash] = common.CopyBytes(value)
//fmt.Println("tx preimage", hash, common.Bytes2Hex(value))
return nil
}
......
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