2019-01-28 08:45:28 +00:00
|
|
|
package depositcontract
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/accounts/abi"
|
|
|
|
)
|
|
|
|
|
|
|
|
// UnpackDepositLogData unpacks the data from a deposit log using the ABI decoder.
|
2019-02-08 17:01:15 +00:00
|
|
|
func UnpackDepositLogData(data []byte) (depositRoot [32]byte, depositData []byte, merkleTreeIndex []byte, merkleBranch [32][32]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-02-08 17:01:15 +00:00
|
|
|
return [32]byte{}, nil, nil, [32][32]byte{}, fmt.Errorf("unable to generate contract abi: %v", err)
|
2019-01-28 08:45:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unpackedLogs := []interface{}{
|
|
|
|
&depositRoot,
|
|
|
|
&depositData,
|
|
|
|
&merkleTreeIndex,
|
2019-02-08 17:01:15 +00:00
|
|
|
&merkleBranch,
|
2019-01-28 08:45:28 +00:00
|
|
|
}
|
|
|
|
if err := contractAbi.Unpack(&unpackedLogs, "Deposit", data); err != nil {
|
2019-02-08 17:01:15 +00:00
|
|
|
return [32]byte{}, nil, nil, [32][32]byte{}, fmt.Errorf("unable to unpack logs: %v", err)
|
2019-01-28 08:45:28 +00:00
|
|
|
}
|
|
|
|
|
2019-02-08 17:01:15 +00:00
|
|
|
return depositRoot, depositData, merkleTreeIndex, merkleBranch, nil
|
2019-01-28 08:45:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|