2019-01-28 08:45:28 +00:00
|
|
|
package depositcontract
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/accounts/abi"
|
2019-08-02 02:27:38 +00:00
|
|
|
"github.com/pkg/errors"
|
2019-01-28 08:45:28 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// UnpackDepositLogData unpacks the data from a deposit log using the ABI decoder.
|
2020-10-12 15:43:19 +00:00
|
|
|
func UnpackDepositLogData(data []byte) (pubkey, withdrawalCredentials, amount, signature, index []byte, err error) {
|
2019-01-28 08:45:28 +00:00
|
|
|
reader := bytes.NewReader([]byte(DepositContractABI))
|
|
|
|
contractAbi, err := abi.JSON(reader)
|
|
|
|
if err != nil {
|
2019-08-02 02:27:38 +00:00
|
|
|
return nil, nil, nil, nil, nil, errors.Wrap(err, "unable to generate contract abi")
|
2019-01-28 08:45:28 +00:00
|
|
|
}
|
|
|
|
|
2020-10-20 04:05:48 +00:00
|
|
|
unpackedLogs, err := contractAbi.Unpack("DepositEvent", data)
|
|
|
|
if err != nil {
|
2019-08-02 02:27:38 +00:00
|
|
|
return nil, nil, nil, nil, nil, errors.Wrap(err, "unable to unpack logs")
|
2019-01-28 08:45:28 +00:00
|
|
|
}
|
|
|
|
|
2020-10-20 04:05:48 +00:00
|
|
|
return unpackedLogs[0].([]byte), unpackedLogs[1].([]byte), unpackedLogs[2].([]byte), unpackedLogs[3].([]byte), unpackedLogs[4].([]byte), nil
|
2019-01-28 08:45:28 +00:00
|
|
|
}
|