mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-03 16:37:39 +00:00
f89fce9bd7
* 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
47 lines
1.4 KiB
Go
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
|
|
}
|