github.com/prysmaticlabs/prysm@v1.4.4/contracts/deposit-contract/ETH1logs.go (about)

     1  package depositcontract
     2  
     3  import (
     4  	"bytes"
     5  
     6  	"github.com/ethereum/go-ethereum/accounts/abi"
     7  	"github.com/pkg/errors"
     8  )
     9  
    10  // UnpackDepositLogData unpacks the data from a deposit log using the ABI decoder.
    11  func UnpackDepositLogData(data []byte) (pubkey, withdrawalCredentials, amount, signature, index []byte, err error) {
    12  	reader := bytes.NewReader([]byte(DepositContractABI))
    13  	contractAbi, err := abi.JSON(reader)
    14  	if err != nil {
    15  		return nil, nil, nil, nil, nil, errors.Wrap(err, "unable to generate contract abi")
    16  	}
    17  
    18  	unpackedLogs, err := contractAbi.Unpack("DepositEvent", data)
    19  	if err != nil {
    20  		return nil, nil, nil, nil, nil, errors.Wrap(err, "unable to unpack logs")
    21  	}
    22  
    23  	return unpackedLogs[0].([]byte), unpackedLogs[1].([]byte), unpackedLogs[2].([]byte), unpackedLogs[3].([]byte), unpackedLogs[4].([]byte), nil
    24  }