github.com/0xsequence/ethkit@v1.25.0/ethreceipts/receipt.go (about)

     1  package ethreceipts
     2  
     3  import (
     4  	"math/big"
     5  
     6  	"github.com/0xsequence/ethkit"
     7  	"github.com/0xsequence/ethkit/go-ethereum/common"
     8  	"github.com/0xsequence/ethkit/go-ethereum/core/types"
     9  )
    10  
    11  type Receipt struct {
    12  	Filter  Filterer // reference to filter which triggered this event
    13  	Final   bool     // flags that this receipt is finalized
    14  	Reorged bool     // chain reorged / removed the txn
    15  
    16  	transaction *types.Transaction
    17  	message     *types.Message // TOOD: this intermediate type is lame.. with new ethrpc we can remove
    18  	receipt     *types.Receipt
    19  	logs        []*types.Log
    20  }
    21  
    22  func (r *Receipt) Receipt() *types.Receipt {
    23  	return r.receipt
    24  }
    25  
    26  func (r *Receipt) FilterID() uint64 {
    27  	if r.Filter != nil && r.Filter.Options().ID > 0 {
    28  		return r.Filter.FilterID()
    29  	} else {
    30  		return 0
    31  	}
    32  }
    33  
    34  func (r *Receipt) TransactionHash() ethkit.Hash {
    35  	if r.transaction != nil {
    36  		return r.transaction.Hash()
    37  	} else if r.receipt != nil {
    38  		return r.receipt.TxHash
    39  	} else {
    40  		return ethkit.Hash{}
    41  	}
    42  }
    43  
    44  func (r *Receipt) Status() uint64 {
    45  	if r.receipt != nil {
    46  		return r.receipt.Status
    47  	} else {
    48  		return 0
    49  	}
    50  }
    51  
    52  func (r *Receipt) BlockNumber() *big.Int {
    53  	if r.receipt != nil {
    54  		return r.receipt.BlockNumber
    55  	} else {
    56  		return nil
    57  	}
    58  }
    59  
    60  func (r *Receipt) BlockHash() ethkit.Hash {
    61  	if r.receipt != nil {
    62  		return r.receipt.BlockHash
    63  	} else {
    64  		return ethkit.Hash{}
    65  	}
    66  }
    67  
    68  func (r *Receipt) Type() uint8 {
    69  	if r.receipt != nil {
    70  		return r.receipt.Type
    71  	} else {
    72  		return 0
    73  	}
    74  }
    75  
    76  func (r *Receipt) Root() []byte {
    77  	if r.receipt != nil {
    78  		return r.receipt.PostState
    79  	} else {
    80  		return nil
    81  	}
    82  }
    83  
    84  func (r *Receipt) Bloom() types.Bloom {
    85  	if r.receipt != nil {
    86  		return r.receipt.Bloom
    87  	} else {
    88  		return types.Bloom{}
    89  	}
    90  }
    91  
    92  func (r *Receipt) TransactionIndex() uint {
    93  	if r.receipt != nil {
    94  		return r.receipt.TransactionIndex
    95  	} else {
    96  		return 0
    97  	}
    98  }
    99  
   100  // DeployedContractAddress returns the address if this receipt is related to
   101  // a contract deployment.
   102  func (r *Receipt) DeployedContractAddress() common.Address {
   103  	if r.receipt != nil {
   104  		return r.receipt.ContractAddress
   105  	} else {
   106  		return common.Address{}
   107  	}
   108  }
   109  
   110  func (r *Receipt) CumulativeGasUsed() uint64 {
   111  	if r.receipt != nil {
   112  		return r.receipt.CumulativeGasUsed
   113  	} else {
   114  		return 0
   115  	}
   116  }
   117  
   118  func (r *Receipt) EffectiveGasPrice() *big.Int {
   119  	if r.receipt != nil {
   120  		return r.receipt.EffectiveGasPrice
   121  	} else {
   122  		return nil
   123  	}
   124  }
   125  
   126  func (r *Receipt) GasUsed() uint64 {
   127  	if r.receipt != nil {
   128  		return r.receipt.GasUsed
   129  	} else {
   130  		return 0
   131  	}
   132  }
   133  
   134  func (r *Receipt) Logs() []*types.Log {
   135  	if r.receipt != nil && len(r.receipt.Logs) > 0 {
   136  		return r.receipt.Logs
   137  	} else {
   138  		return r.logs
   139  	}
   140  }
   141  
   142  func (r *Receipt) From() common.Address {
   143  	if r.receipt != nil {
   144  		return r.receipt.From
   145  	} else if r.message != nil {
   146  		return r.message.From()
   147  	} else {
   148  		return common.Address{}
   149  	}
   150  }
   151  
   152  func (r *Receipt) To() common.Address {
   153  	if r.receipt != nil {
   154  		return r.receipt.To
   155  	} else if r.message != nil {
   156  		to := r.message.To()
   157  		if to == nil {
   158  			return common.Address{}
   159  		} else {
   160  			return *to
   161  		}
   162  	} else {
   163  		return common.Address{}
   164  	}
   165  }