Example #1
0
func NewReceiptRes(rec *types.Receipt) *ReceiptRes {
	if rec == nil {
		return nil
	}

	var v = new(ReceiptRes)
	v.TransactionHash = newHexData(rec.TxHash)
	if rec.GasUsed != nil {
		v.GasUsed = newHexNum(rec.GasUsed.Bytes())
	}
	v.CumulativeGasUsed = newHexNum(rec.CumulativeGasUsed)

	// If the ContractAddress is 20 0x0 bytes, assume it is not a contract creation
	if bytes.Compare(rec.ContractAddress.Bytes(), bytes.Repeat([]byte{0}, 20)) != 0 {
		v.ContractAddress = newHexData(rec.ContractAddress)
	}

	logs := make([]interface{}, len(rec.Logs()))
	for i, log := range rec.Logs() {
		logs[i] = NewLogRes(log)
	}
	v.Logs = &logs

	return v
}
Example #2
0
func TestPutReceipt(t *testing.T) {
	db, _ := ethdb.NewMemDatabase()

	var addr common.Address
	addr[0] = 1
	var hash common.Hash
	hash[0] = 2

	receipt := new(types.Receipt)
	receipt.SetLogs(state.Logs{&state.Log{
		Address:   addr,
		Topics:    []common.Hash{hash},
		Data:      []byte("hi"),
		Number:    42,
		TxHash:    hash,
		TxIndex:   0,
		BlockHash: hash,
		Index:     0,
	}})

	PutReceipts(db, types.Receipts{receipt})
	receipt = GetReceipt(db, common.Hash{})
	if receipt == nil {
		t.Error("expected to get 1 receipt, got none.")
	}
}