mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 12:57:18 +00:00
1e862511aa
* adding deposit contract * Adding bindings * remove unused info * shifting deploy function over * new changes * fixing tests and moving log utils to contract package * new changes,helpers, fixing tests * fix failing test * readme * contract change * changes to contract * new changes,helpers, fixing tests * missing files * adding constructor to contract * lint * updating with spec * finally got it fixed * add in deposit arguments * new changes * all tests pass * addresing raul's and terence's comments * remove vrc
47 lines
1.4 KiB
Go
47 lines
1.4 KiB
Go
package depositcontract
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
|
|
"github.com/ethereum/go-ethereum/accounts/abi"
|
|
)
|
|
|
|
// UnpackDepositLogData unpacks the data from a deposit log using the ABI decoder.
|
|
func UnpackDepositLogData(data []byte) (depositRoot [32]byte, depositData []byte, merkleTreeIndex []byte, err error) {
|
|
reader := bytes.NewReader([]byte(DepositContractABI))
|
|
contractAbi, err := abi.JSON(reader)
|
|
if err != nil {
|
|
return [32]byte{}, nil, nil, fmt.Errorf("unable to generate contract abi: %v", err)
|
|
}
|
|
|
|
unpackedLogs := []interface{}{
|
|
&depositRoot,
|
|
&depositData,
|
|
&merkleTreeIndex,
|
|
}
|
|
if err := contractAbi.Unpack(&unpackedLogs, "Deposit", data); err != nil {
|
|
return [32]byte{}, nil, nil, fmt.Errorf("unable to unpack logs: %v", err)
|
|
}
|
|
|
|
return depositRoot, depositData, merkleTreeIndex, nil
|
|
}
|
|
|
|
// UnpackChainStartLogData unpacks the data from a chain start log using the ABI decoder.
|
|
func UnpackChainStartLogData(data []byte) (depositRoot [32]byte, timestamp []byte, err error) {
|
|
reader := bytes.NewReader([]byte(DepositContractABI))
|
|
contractAbi, err := abi.JSON(reader)
|
|
if err != nil {
|
|
return [32]byte{}, nil, fmt.Errorf("unable to generate contract abi: %v", err)
|
|
}
|
|
unpackedLogs := []interface{}{
|
|
&depositRoot,
|
|
×tamp,
|
|
}
|
|
if err := contractAbi.Unpack(&unpackedLogs, "ChainStart", data); err != nil {
|
|
return [32]byte{}, nil, fmt.Errorf("unable to unpack logs: %v", err)
|
|
}
|
|
|
|
return depositRoot, timestamp, nil
|
|
}
|