Skip to content

Instantly share code, notes, and snippets.

@cwhinfrey
Last active October 19, 2019 00:14
Show Gist options
  • Save cwhinfrey/8087cc4565054cdcd7eef82498cc8b37 to your computer and use it in GitHub Desktop.
Save cwhinfrey/8087cc4565054cdcd7eef82498cc8b37 to your computer and use it in GitHub Desktop.
UpgradabilityPatterns.sol
pragma solidity ^0.5.10;
// V1
contract AccountV1Storage {
uint lastInitializedVersion;
uint a;
}
contract AccountV1 is AccountV1Storage {
function initialize(uint _a) external {
require(lastInitializedVersion == 0);
lastInitializedVersion = 1;
a = _a;
}
/**
* Some functions
*/
}
// V2
contract AccountV2 is AccountV1 {
/**
* Some functions
*/
}
// V3
contract AccountV3Storage {
uint b;
}
contract AccountV3 is AccountV1, AccountV3Storage {
function initialize_v3 (uint _b) external {
require(lastInitializedVersion == 1);
lastInitializedVersion = 3;
b = _b;
}
/**
* Some functions
*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment