Skip to content

Commit

Permalink
Merge pull request #207 from m-Peter/fix-to-address-inconsistency
Browse files Browse the repository at this point in the history
Return `null` `to` address for contract creation
  • Loading branch information
m-Peter authored Apr 18, 2024
2 parents 9a9b198 + 5fe50d7 commit 0b977af
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
11 changes: 6 additions & 5 deletions api/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ type StorageResult struct {
type Transaction struct {
BlockHash *common.Hash `json:"blockHash"`
BlockNumber *hexutil.Big `json:"blockNumber"`
From *common.MixedcaseAddress `json:"from"`
From common.MixedcaseAddress `json:"from"`
Gas hexutil.Uint64 `json:"gas"`
GasPrice *hexutil.Big `json:"gasPrice"`
GasFeeCap *hexutil.Big `json:"maxFeePerGas,omitempty"`
Expand Down Expand Up @@ -116,9 +116,10 @@ func NewTransaction(tx models.Transaction, receipt types.Receipt) (*Transaction,
}
from := common.NewMixedcaseAddress(f)

var to common.MixedcaseAddress
var to *common.MixedcaseAddress
if t := tx.To(); t != nil {
to = common.NewMixedcaseAddress(*t)
mixedCaseAddress := common.NewMixedcaseAddress(*t)
to = &mixedCaseAddress
}

v, r, s := tx.RawSignatureValues()
Expand All @@ -128,8 +129,8 @@ func NewTransaction(tx models.Transaction, receipt types.Receipt) (*Transaction,
Hash: txHash,
BlockHash: &receipt.BlockHash,
BlockNumber: (*hexutil.Big)(receipt.BlockNumber),
From: &from,
To: &to,
From: from,
To: to,
Gas: hexutil.Uint64(receipt.GasUsed),
GasPrice: (*hexutil.Big)(receipt.EffectiveGasPrice),
Input: tx.Data(),
Expand Down
3 changes: 3 additions & 0 deletions tests/web3js/eth_deploy_contract_and_interact_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@ it('deploy contract and interact', async() => {
assert.isString(deployed.receipt.transactionHash)
assert.isString(contractAddress)
assert.equal(deployed.receipt.from, conf.eoa.address)
assert.isUndefined(deployed.receipt.to)

let rcp = await web3.eth.getTransactionReceipt(deployed.receipt.transactionHash)
assert.equal(rcp.contractAddress, contractAddress)
assert.equal(rcp.status, conf.successStatus)
assert.isUndefined(rcp.to)

// check if latest block contains the deploy results
let latestHeight = await web3.eth.getBlockNumber()
let deployTx = await web3.eth.getTransactionFromBlock(latestHeight, 0)
assert.equal(deployTx.hash, deployed.receipt.transactionHash)
assert.isUndefined(deployTx.to)

let code = await web3.eth.getCode(contractAddress)
// deploy data has more than just the contract
Expand Down

0 comments on commit 0b977af

Please sign in to comment.