Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove contractAddress from receipt if not contract deployment #546

2 changes: 1 addition & 1 deletion blockchain/storage/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ func testReceipts(t *testing.T, m MockStorage) {
TxHash: txn.Hash,
LogsBloom: types.Bloom{0x1},
GasUsed: 10,
ContractAddress: types.Address{0x1},
ContractAddress: &types.Address{0x1},
Logs: []*types.Log{
{
Address: addr2,
Expand Down
2 changes: 1 addition & 1 deletion jsonrpc/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ type receipt struct {
BlockHash types.Hash `json:"blockHash"`
BlockNumber argUint64 `json:"blockNumber"`
GasUsed argUint64 `json:"gasUsed"`
ContractAddress types.Address `json:"contractAddress"`
ContractAddress *types.Address `json:"contractAddress"`
FromAddr types.Address `json:"from"`
ToAddr *types.Address `json:"to"`
}
Expand Down
4 changes: 2 additions & 2 deletions state/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func (t *Transition) WriteFailedReceipt(txn *types.Transaction) error {
t.receipts = append(t.receipts, receipt)

if txn.To == nil {
receipt.ContractAddress = crypto.CreateAddress(txn.From, txn.Nonce)
receipt.ContractAddress = crypto.CreateAddress(txn.From, txn.Nonce).Ptr()
}

return nil
Expand Down Expand Up @@ -286,7 +286,7 @@ func (t *Transition) Write(txn *types.Transaction) error {

// if the transaction created a contract, store the creation address in the receipt.
if msg.To == nil {
receipt.ContractAddress = crypto.CreateAddress(msg.From, txn.Nonce)
receipt.ContractAddress = crypto.CreateAddress(msg.From, txn.Nonce).Ptr()
}

// Set the receipt logs and create a bloom for filtering
Expand Down
6 changes: 5 additions & 1 deletion types/receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,18 @@ type Receipt struct {

// context fields
GasUsed uint64
ContractAddress Address
ContractAddress *Address
TxHash Hash
}

func (r *Receipt) SetStatus(s ReceiptStatus) {
r.Status = &s
}

func (r *Receipt) SetContractAddress(contractAddress Address) {
r.ContractAddress = &contractAddress
}

type Log struct {
Address Address
Topics []Hash
Expand Down
2 changes: 1 addition & 1 deletion types/rlp_marshal_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (r *Receipt) MarshalStoreRLPWith(a *fastrlp.Arena) *fastrlp.Value {
vv := a.NewArray()
vv.Set(r.MarshalRLPWith(a))

if r.ContractAddress == ZeroAddress {
if r.ContractAddress == nil {
vv.Set(a.NewNull())
} else {
vv.Set(a.NewBytes(r.ContractAddress.Bytes()))
Expand Down
2 changes: 1 addition & 1 deletion types/rlp_unmarshal_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (r *Receipt) UnmarshalStoreRLPFrom(p *fastrlp.Parser, v *fastrlp.Value) err
}
if len(vv) == 20 {
// address
r.ContractAddress = BytesToAddress(vv)
r.SetContractAddress(BytesToAddress(vv))
}
}

Expand Down
4 changes: 4 additions & 0 deletions types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ func (a Address) checksumEncode() string {
return "0x" + string(result)
}

func (a Address) Ptr() *Address {
return &a
}

func (a Address) String() string {
return a.checksumEncode()
}
Expand Down