mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 09:53:48 +00:00
Merge branch 'shyft/greg' of github.com:ShyftNetwork/shyft_go-ethereum into tx-struct
This commit is contained in:
commit
75e452e2d9
1 changed files with 23 additions and 7 deletions
|
|
@ -29,20 +29,34 @@ func WriteBlock(db *leveldb.DB, block *types.Block) error {
|
||||||
leng := block.Transactions().Len()
|
leng := block.Transactions().Len()
|
||||||
var tx_strs = make([]string, leng)
|
var tx_strs = make([]string, leng)
|
||||||
//var tx_bytes = make([]byte, leng)
|
//var tx_bytes = make([]byte, leng)
|
||||||
|
|
||||||
|
hash := block.Header().Hash().Bytes()
|
||||||
|
if block.Transactions().Len() > 0 {
|
||||||
|
// this is inefficient, there are 2 loops over
|
||||||
|
// block.Transactions
|
||||||
|
// TODO: Fix this so there is only one loop
|
||||||
|
WriteTransactions(db, block.Transactions(), hash)
|
||||||
|
for i, tx := range block.Transactions() {
|
||||||
|
fmt.Println(tx.Hash())
|
||||||
|
fmt.Println("TX HASH")
|
||||||
|
fmt.Println(tx.To().Hex())
|
||||||
|
tx_strs[i] = tx.Hash().String()
|
||||||
|
//tx_bytes[i] = tx.Hash().Bytes()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fmt.Println("The tx_strs is")
|
fmt.Println("The tx_strs is")
|
||||||
fmt.Println(tx_strs)
|
fmt.Println(tx_strs)
|
||||||
//strs := []string{"foo", "bar"}
|
//strs := []string{"foo", "bar"}
|
||||||
buf := &bytes.Buffer{}
|
buf := &bytes.Buffer{}
|
||||||
gob.NewEncoder(buf).Encode(tx_strs)
|
gob.NewEncoder(buf).Encode(tx_strs)
|
||||||
bs := buf.Bytes()
|
bs := buf.Bytes()
|
||||||
hash := block.Header().Hash().Bytes()
|
|
||||||
if err := db.Put(hash, bs, nil); err != nil {
|
key := append([]byte("bk-")[:], hash[:]...)
|
||||||
|
if err := db.Put(key, bs, nil); err != nil {
|
||||||
log.Crit("Failed to store block", "err", err)
|
log.Crit("Failed to store block", "err", err)
|
||||||
return nil // Do we want to force an exit here?
|
return nil // Do we want to force an exit here?
|
||||||
}
|
}
|
||||||
if block.Transactions().Len() > 0 {
|
|
||||||
WriteTransactions(db, block.Transactions(), hash)
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -85,13 +99,15 @@ func GenerateFromAddr(tx *types.Transaction) *common.Address {
|
||||||
|
|
||||||
// Meant for internal tests
|
// Meant for internal tests
|
||||||
|
|
||||||
func GetBlock(db *leveldb.DB, block *types.Block) {
|
func GetBlock(db *leveldb.DB, block *types.Block) []byte {
|
||||||
hash := block.Header().Hash().Bytes()
|
hash := block.Header().Hash().Bytes()
|
||||||
data, err := db.Get(hash, nil)
|
key := append([]byte("bk-")[:], hash[:]...)
|
||||||
|
data, err := db.Get(key, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Crit("Could not retrieve block", "err", err)
|
log.Crit("Could not retrieve block", "err", err)
|
||||||
}
|
}
|
||||||
fmt.Println("\nBLOCK Value: " + string(data))
|
fmt.Println("\nBLOCK Value: " + string(data))
|
||||||
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetAllTransactions(db *leveldb.DB) {
|
func GetAllTransactions(db *leveldb.DB) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue