Instantly share code, notes, and snippets.

Embed
What would you like to do?
Relay contract that contains only one state variable 'user_amounts' - Link first to Donation contract, then update to DonationNew to add the cancelDonation function.
// First, deploying Relay, then deploying Donation and retrieve Donation contract address in 'donation_contract_address'
// Then, linking Relay to my first version of my contract Donation
Relay.deployed().then(function(contractInstance) {
contractInstance.changeContract(donation_contract_address);
})
// Then, I want to call sendDonation from the Donation contract
// !!!!! I DON'T KNOW WHAT IS THE CORRECT WAY TO CALL THIS !!!!!!
Relay.deployed().then(function(contractInstance) {
contractInstance.sendDonation(5) ;
})
// OR
Relay.deployed().then(function(contractInstance) {
contractInstance.currentVersion.delegateCall(sendDonation(5)) ;
})
// Now I want to update the Donation contract to add the cancelDonation function
// First I deploy the new contract DonationNew and retrieve it's address in 'donation_new_contract_address'
Relay.deployed().then(function(contractInstance) {
contractInstance.changeContract(donation_new_contract_address);
})
// are the state variables still available from the old contract to the new one?
// Then if I want to call the new function :
Relay.deployed().then(function(contractInstance) {
contractInstance.cancelDonation() ;
})
contract Donation {
mapping (address => uint) user_amounts;
/* DOES THIS METHODS MODIFY user_amounts of the Relay contract ??? */
function sendDonation(uint n) {
user_amounts[msg.sender] = user_amounts[msg.sender] + n
}
}
contract DonationNew {
mapping (address => uint) user_amounts;
function sendDonation(uint n) {
user_amounts[msg.sender] = user_amounts[msg.sender] + n
}
function cancelDonation() {
user_amounts[msg.sender] = 0
}
}
contract Relay {
address public currentVersion;
address public owner;
mapping (address => uint) user_amounts;
modifier onlyOwner() {
if (msg.sender != owner) {
throw;
}
_
}
function Relay(address initAddr) {
currentVersion = initAddr;
owner = msg.sender; // this owner may be another contract with multisig, not a single contract owner
}
function changeContract(address newVersion) public
onlyOwner()
{
currentVersion = newVersion;
}
function() {
if(!currentVersion.delegatecall(msg.data)) throw;
}
}
@srameshr

This comment has been minimized.

Show comment
Hide comment
@srameshr

srameshr Feb 6, 2018

** Which is the right way to do it **

// Then, I want to call sendDonation from the Donation contract
// !!!!! I DON'T KNOW WHAT IS THE CORRECT WAY TO CALL THIS !!!!!!
Relay.deployed().then(function(contractInstance) {
   contractInstance.sendDonation(5) ;
})
// OR 
Relay.deployed().then(function(contractInstance) {
   contractInstance.currentVersion.delegateCall(sendDonation(5)) ;
})

srameshr commented Feb 6, 2018

** Which is the right way to do it **

// Then, I want to call sendDonation from the Donation contract
// !!!!! I DON'T KNOW WHAT IS THE CORRECT WAY TO CALL THIS !!!!!!
Relay.deployed().then(function(contractInstance) {
   contractInstance.sendDonation(5) ;
})
// OR 
Relay.deployed().then(function(contractInstance) {
   contractInstance.currentVersion.delegateCall(sendDonation(5)) ;
})
@srameshr

This comment has been minimized.

Show comment
Hide comment
@srameshr

srameshr Feb 6, 2018

And also, are the state variables preserved?

srameshr commented Feb 6, 2018

And also, are the state variables preserved?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment