prysm-pulse/beacon-chain/utils/POWlogs.go
Raul Jordan f89fce9bd7
Implement Basic LMD Ghost Fork Choice Skeleton + Helper Funcs (#1310)
* add fork choice helpers

* LMD GHOST basic implementation

* add todos

* add in the initial test and finalize rest of functions

* added tests

* more simulation, adding trivial case with only one option for a head

* panics

* begin helper function tests

* more helper tests

* higher vote wins

* LMD Ghost full test

* comment

* add types

* optimize

* prepared

* deposits for chain

* lint

* use the hash beacon block util

* rem unnecessary db methods

* comments

* setup works
2019-01-19 10:57:51 +08:00

47 lines
1.4 KiB
Go

package utils
import (
"bytes"
"fmt"
"github.com/ethereum/go-ethereum/accounts/abi"
contracts "github.com/prysmaticlabs/prysm/contracts/validator-registration-contract"
)
// UnpackDepositLogData unpacks the data from a deposit log using the ABI decoder.
func UnpackDepositLogData(data []byte) (depositData []byte, merkleTreeIndex []byte, err error) {
reader := bytes.NewReader([]byte(contracts.ValidatorRegistrationABI))
contractAbi, err := abi.JSON(reader)
if err != nil {
return nil, nil, fmt.Errorf("unable to generate contract abi: %v", err)
}
unpackedLogs := []*[]byte{
{},
{},
}
if err := contractAbi.Unpack(&unpackedLogs, "Deposit", data); err != nil {
return nil, nil, fmt.Errorf("unable to unpack logs: %v", err)
}
depositData = *unpackedLogs[0]
merkleTreeIndex = *unpackedLogs[1]
return depositData, merkleTreeIndex, nil
}
// UnpackChainStartLogData unpacks the data from a chain start log using the ABI decoder.
func UnpackChainStartLogData(data []byte) ([]byte, error) {
reader := bytes.NewReader([]byte(contracts.ValidatorRegistrationABI))
contractAbi, err := abi.JSON(reader)
if err != nil {
return nil, fmt.Errorf("unable to generate contract abi: %v", err)
}
unpackedLogs := []*[]byte{
{},
}
if err := contractAbi.Unpack(&unpackedLogs, "ChainStart", data); err != nil {
return nil, fmt.Errorf("unable to unpack logs: %v", err)
}
timestamp := *unpackedLogs[0]
return timestamp, nil
}