prysm-pulse/beacon-chain/utils/POWlogs.go
Nishant Das 08a06458d9 Add in ChainStart Listener (#1327)
* changing handling of logs

* gazelle

* removing outdated vars

* fixing tests

* adding vrc bindings to service

* updating vrc sol and bindings

* more changes

* adding trie

* remove functions

* addressing preston's review

* tests

* gazelle

* fixed tests

* note

* Lint

* doc

* exploration test

* adding new methods and tests

* adding log type checker

* lint

* Adding processChainstartLog

* gazelle

* addressing comments

* addressing comments and adding tests

* review comments

* comment

* comment

* abi naming
2019-01-17 23:14:32 +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{
&[]byte{},
&[]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{
&[]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
}