Skip to content

Commit

Permalink
encapsulate abis to deployedAbis in deploys file
Browse files Browse the repository at this point in the history
  • Loading branch information
szerintedmi committed Apr 25, 2018
1 parent 8acf18a commit 0256f76
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 33 deletions.
46 changes: 24 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,29 +78,31 @@ Each file contains the contract's Abi in [Solidity ABI JSON format](https://soli
{
"contractName": "<contract name>",
"latestAbiHash": "7fde219f…",
"7fde219f…": {
"latestDeployedAddress": "7fde219f…",
"deployments": {
"7fde219f…": {
"generatedAt": "<ISO86901 timestamp>",
"truffleContractFileUpdatedAt": "<ISO86901 timestamp when source truffle contracts json was generated>",
"deployTransactionHash": "0x12…",
"compiler": {
"name": "solc",
"version": "0.4.23"
},
"sourceHash": "7fde219f…",
"bytecodeHash": "a454e8ba…",
"deployedBytecodeHash": "55abcee…",
"source": "<source code from truffle contract json"
},
"0xab444b...": {}
"deployedAbis": {
"7fde219f…": {
"latestDeployedAddress": "7fde219f…",
"deployments": {
"7fde219f…": {
"generatedAt": "<ISO86901 timestamp>",
"truffleContractFileUpdatedAt": "<ISO86901 timestamp when source truffle contracts json was generated>",
"deployTransactionHash": "0x12…",
"compiler": {
"name": "solc",
"version": "0.4.23"
},
"sourceHash": "7fde219f…",
"bytecodeHash": "a454e8ba…",
"deployedBytecodeHash": "55abcee…",
"source": "<source code from truffle contract json>"
}
"0xab444b...": {…}
}
},
"a454e8ba… ": {
"latestDeployedAddress": "a9de219f…",
"deployments": {…}
}
},
"a454e8ba… ": {
"latestDeployedAddress": "a9de219f…",
"deployments": {}
}
}
```
Expand Down
28 changes: 17 additions & 11 deletions lib/deploymentsExtractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,16 @@ module.exports = {
}

const deploymentAddressExists =
deploys[abiHash] && deploys[abiHash].deployments && deploys[abiHash].deployments[entry.address]
? true
: false;
deploys.deployedAbis &&
deploys.deployedAbis[abiHash] &&
deploys.deployedAbis[abiHash].deployments &&
deploys.deployedAbis[abiHash].deployments[entry.address];

// handle special case for ganache or private network deploys where the same address possible with different code
// in this case we will update the deployment info even if regenerate is not set
let infoChangedForDeployedAddress = false;
if (deploymentAddressExists) {
const existingEntry = deploys[abiHash].deployments[entry.address];
const existingEntry = deploys.deployedAbis[abiHash].deployments[entry.address];

infoChangedForDeployedAddress =
existingEntry.bytecodeHash !== bytecodeHash ||
Expand All @@ -68,14 +69,19 @@ module.exports = {
* UPDATE deployments file
**************************************/
deploys.latestAbiHash = abiHash;
if (!deploys[abiHash]) {
deploys[abiHash] = { latestDeployedAddress: entry.address, deployments: {} };

if (!deploys.deployedAbis) {
deploys.deployedAbis = {};
}

if (!deploys.deployedAbis[abiHash]) {
deploys.deployedAbis[abiHash] = { latestDeployedAddress: entry.address, deployments: {} };
} else {
deploys[abiHash].latestDeployedAddress = entry.address;
deploys.deployedAbis[abiHash].latestDeployedAddress = entry.address;
}

if (!deploys[abiHash].deployments[entry.address]) {
deploys[abiHash].deployments[entry.address] = {};
if (!deploys.deployedAbis[abiHash].deployments[entry.address]) {
deploys.deployedAbis[abiHash].deployments[entry.address] = {};
}

const newEntry = {
Expand All @@ -88,15 +94,15 @@ module.exports = {
sourceHash,
source: truffleContractFileContent.source
};
deploys[abiHash].deployments[entry.address] = newEntry;
deploys.deployedAbis[abiHash].deployments[entry.address] = newEntry;

const deploysFileNewContent = JSON.stringify(deploys, null, ' ');
filesLib
.writeFile(deploysFile, deploysFileNewContent)
.then(() => {
console.log(
`${
deploymentAddressExists ? 'Updated' : 'Created'
deploymentAddressExists ? 'Updated' : 'Added'
} deployment info for abi hash ${abiHash} with network id ${network} in: ${deploysFile}`
);
})
Expand Down

0 comments on commit 0256f76

Please sign in to comment.