mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 01:43:47 +00:00
Succesfully get ALL TX from the db
This commit is contained in:
parent
309c57d39e
commit
abd663a6b7
3 changed files with 31 additions and 20 deletions
|
|
@ -94,8 +94,6 @@ func newTransaction(nonce uint64, to *common.Address, amount *big.Int, gasLimit
|
||||||
if len(data) > 0 {
|
if len(data) > 0 {
|
||||||
data = common.CopyBytes(data)
|
data = common.CopyBytes(data)
|
||||||
}
|
}
|
||||||
fmt.Println("DASas")
|
|
||||||
fmt.Println(to)
|
|
||||||
d := txdata{
|
d := txdata{
|
||||||
AccountNonce: nonce,
|
AccountNonce: nonce,
|
||||||
Recipient: to,
|
Recipient: to,
|
||||||
|
|
|
||||||
|
|
@ -4,20 +4,11 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/syndtr/goleveldb/leveldb"
|
"github.com/syndtr/goleveldb/leveldb"
|
||||||
|
"github.com/syndtr/goleveldb/leveldb/util"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetBlock(db *leveldb.DB, block *types.Block) {
|
|
||||||
hash := block.Header().Hash().Bytes()
|
|
||||||
bar, err := db.Get(hash, nil)
|
|
||||||
fmt.Println("Our error is ")
|
|
||||||
fmt.Println(err)
|
|
||||||
fmt.Println("Our result is ")
|
|
||||||
fmt.Println(bar)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func WriteBlock(db *leveldb.DB, block *types.Block) error {
|
func WriteBlock(db *leveldb.DB, block *types.Block) error {
|
||||||
hash := block.Header().Hash().Bytes()
|
hash := block.Header().Hash().Bytes()
|
||||||
fmt.Println(hash)
|
fmt.Println(hash)
|
||||||
|
|
@ -33,22 +24,44 @@ func WriteBlock(db *leveldb.DB, block *types.Block) error {
|
||||||
|
|
||||||
func WriteTransactions(db *leveldb.DB, transactions []*types.Transaction, blockHash []byte) error {
|
func WriteTransactions(db *leveldb.DB, transactions []*types.Transaction, blockHash []byte) error {
|
||||||
for _, tx := range transactions {
|
for _, tx := range transactions {
|
||||||
txHash := tx.Hash().Bytes()
|
key := append([]byte("tx-")[:], tx.Hash().Bytes()[:]...)
|
||||||
if err := db.Put(txHash, []byte("Hello hello"), nil); err != nil {
|
if err := db.Put(key, []byte("Hello hello"), nil); err != nil {
|
||||||
log.Crit("Failed to store TX", "err", err)
|
log.Crit("Failed to store TX", "err", err)
|
||||||
}
|
}
|
||||||
GetTransaction(db, tx)
|
GetTransaction(db, tx)
|
||||||
}
|
}
|
||||||
|
GetAllTransactions(db)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetTransaction(db *leveldb.DB, tx *types.Transaction) {
|
// Meant for internal tests
|
||||||
data, err := db.Get(tx.Hash().Bytes(), nil)
|
|
||||||
|
func GetBlock(db *leveldb.DB, block *types.Block) {
|
||||||
|
hash := block.Header().Hash().Bytes()
|
||||||
|
bar, err := db.Get(hash, nil)
|
||||||
|
fmt.Println("Our error is ")
|
||||||
|
fmt.Println(err)
|
||||||
|
fmt.Println("Our result is ")
|
||||||
|
fmt.Println(bar)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetAllTransactions(db *leveldb.DB) {
|
||||||
|
//iter := db.NewIterator(util.BytesPrefix([]byte("tx-")), nil)
|
||||||
|
iter := db.NewIterator(util.BytesPrefix([]byte("tx-")), nil)
|
||||||
|
for iter.Next() {
|
||||||
|
fmt.Println(iter.Key())
|
||||||
|
fmt.Println(iter.Value())
|
||||||
|
}
|
||||||
|
iter.Release()
|
||||||
|
}
|
||||||
|
func GetTransaction (db *leveldb.DB, tx *types.Transaction) {
|
||||||
|
key := append([]byte("tx-")[:], tx.Hash().Bytes()[:]...)
|
||||||
|
value, err := db.Get(key, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Crit("Could not retrieve data")
|
log.Crit("Could not retrieve data")
|
||||||
}
|
}
|
||||||
if len(data) > 0 {
|
if len(value) > 0 {
|
||||||
fmt.Println("\n\t\t\t DATA \n")
|
fmt.Println(value)
|
||||||
fmt.Println(data)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2,7 +2,7 @@ var firstAccount = web3.eth.accounts[0]
|
||||||
var secondAccount = web3.eth.accounts[1]
|
var secondAccount = web3.eth.accounts[1]
|
||||||
var thirdAccount = web3.eth.accounts[2]
|
var thirdAccount = web3.eth.accounts[2]
|
||||||
|
|
||||||
for (var i = 0; i < 3; i++) {
|
for (var i = 0; i < 1; i++) {
|
||||||
console.log('\t\t' + (i + 1) + ' - Transactions')
|
console.log('\t\t' + (i + 1) + ' - Transactions')
|
||||||
web3.eth.sendTransaction({
|
web3.eth.sendTransaction({
|
||||||
from: web3.eth.accounts[0],
|
from: web3.eth.accounts[0],
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue