From 0236886d3ef90c12431b1ffe8f413cc1c569b967 Mon Sep 17 00:00:00 2001 From: yann300 Date: Wed, 8 Jul 2015 13:14:21 +0200 Subject: [PATCH 1/2] bug fix. issue while getting the created contract address. --- mix/ClientModel.cpp | 8 ++++---- mix/ClientModel.h | 2 +- mix/MixClient.cpp | 6 ++++++ mix/MixClient.h | 3 +++ 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/mix/ClientModel.cpp b/mix/ClientModel.cpp index eae3f8834..e7e8811a3 100644 --- a/mix/ClientModel.cpp +++ b/mix/ClientModel.cpp @@ -390,7 +390,8 @@ void ClientModel::executeSequence(vector const& _sequence) { bytes param = encoder.encodedData(); contractCode.insert(contractCode.end(), param.begin(), param.end()); - Address newAddress = deployContract(contractCode, transaction); + deployContract(contractCode, transaction); + Address newAddress = m_client->lastCreatedContractAddr(); std::pair contractToken = retrieveToken(transaction.contractId); m_contractAddresses[contractToken] = newAddress; m_contractNames[newAddress] = contractToken.first; @@ -672,10 +673,9 @@ void ClientModel::debugRecord(unsigned _index) showDebuggerForTransaction(e); } -Address ClientModel::deployContract(bytes const& _code, TransactionSettings const& _ctrTransaction) +void ClientModel::deployContract(bytes const& _code, TransactionSettings const& _ctrTransaction) { - Address newAddress = m_client->submitTransaction(_ctrTransaction.sender, _ctrTransaction.value, _code, _ctrTransaction.gas, _ctrTransaction.gasPrice, _ctrTransaction.gasAuto); - return newAddress; + m_client->submitTransaction(_ctrTransaction.sender, _ctrTransaction.value, _code, _ctrTransaction.gas, _ctrTransaction.gasPrice, _ctrTransaction.gasAuto); } void ClientModel::callAddress(Address const& _contract, bytes const& _data, TransactionSettings const& _tr) diff --git a/mix/ClientModel.h b/mix/ClientModel.h index 92f06b48b..66a14ad5b 100644 --- a/mix/ClientModel.h +++ b/mix/ClientModel.h @@ -252,7 +252,7 @@ private: QVariantMap contractAddresses() const; QVariantList gasCosts() const; void executeSequence(std::vector const& _sequence); - dev::Address deployContract(bytes const& _code, TransactionSettings const& _tr = TransactionSettings()); + void deployContract(bytes const& _code, TransactionSettings const& _tr = TransactionSettings()); void callAddress(Address const& _contract, bytes const& _data, TransactionSettings const& _tr); void onNewTransaction(); void onStateReset(); diff --git a/mix/MixClient.cpp b/mix/MixClient.cpp index 7978ff1ac..c41661046 100644 --- a/mix/MixClient.cpp +++ b/mix/MixClient.cpp @@ -313,6 +313,12 @@ h256 MixClient::submitTransaction(eth::TransactionSkeleton const& _ts, Secret co return t.sha3(); } +Address MixClient::lastCreatedContractAddr() const +{ + Transaction tr = m_state.pending().back(); + return tr.isCreation() ? right160(sha3(rlpList(tr.sender(), tr.nonce()))) : Address(); +} + dev::eth::ExecutionResult MixClient::call(Address const& _from, u256 _value, Address _dest, bytes const& _data, u256 _gas, u256 _gasPrice, BlockNumber _blockNumber, bool _gasAuto, FudgeFactor _ff) { (void)_blockNumber; diff --git a/mix/MixClient.h b/mix/MixClient.h index e4ad9c133..5b1b155a1 100644 --- a/mix/MixClient.h +++ b/mix/MixClient.h @@ -76,6 +76,9 @@ public: using Interface::blockInfo; // to remove warning about hiding virtual function eth::BlockInfo blockInfo() const; + /// return the new address generated by the last tr (if creation). returns empty address if other cases. + Address lastCreatedContractAddr() const; + protected: /// ClientBase methods using ClientBase::asOf; From 9f164af459ff5c299c70d6965b2f5ab682817784 Mon Sep 17 00:00:00 2001 From: yann300 Date: Wed, 8 Jul 2015 14:12:35 +0200 Subject: [PATCH 2/2] small changes --- mix/ClientModel.cpp | 6 +++--- mix/ClientModel.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/mix/ClientModel.cpp b/mix/ClientModel.cpp index e7e8811a3..23f68996c 100644 --- a/mix/ClientModel.cpp +++ b/mix/ClientModel.cpp @@ -390,8 +390,7 @@ void ClientModel::executeSequence(vector const& _sequence) { bytes param = encoder.encodedData(); contractCode.insert(contractCode.end(), param.begin(), param.end()); - deployContract(contractCode, transaction); - Address newAddress = m_client->lastCreatedContractAddr(); + Address newAddress = deployContract(contractCode, transaction); std::pair contractToken = retrieveToken(transaction.contractId); m_contractAddresses[contractToken] = newAddress; m_contractNames[newAddress] = contractToken.first; @@ -673,9 +672,10 @@ void ClientModel::debugRecord(unsigned _index) showDebuggerForTransaction(e); } -void ClientModel::deployContract(bytes const& _code, TransactionSettings const& _ctrTransaction) +Address ClientModel::deployContract(bytes const& _code, TransactionSettings const& _ctrTransaction) { m_client->submitTransaction(_ctrTransaction.sender, _ctrTransaction.value, _code, _ctrTransaction.gas, _ctrTransaction.gasPrice, _ctrTransaction.gasAuto); + return m_client->lastCreatedContractAddr(); } void ClientModel::callAddress(Address const& _contract, bytes const& _data, TransactionSettings const& _tr) diff --git a/mix/ClientModel.h b/mix/ClientModel.h index 66a14ad5b..ca8c36b79 100644 --- a/mix/ClientModel.h +++ b/mix/ClientModel.h @@ -252,7 +252,7 @@ private: QVariantMap contractAddresses() const; QVariantList gasCosts() const; void executeSequence(std::vector const& _sequence); - void deployContract(bytes const& _code, TransactionSettings const& _tr = TransactionSettings()); + Address deployContract(bytes const& _code, TransactionSettings const& _tr = TransactionSettings()); void callAddress(Address const& _contract, bytes const& _data, TransactionSettings const& _tr); void onNewTransaction(); void onStateReset();