Skip to content
This repository has been archived by the owner on Aug 6, 2021. It is now read-only.

Commit

Permalink
Remove deployments.json and move ap-chain address into ap-chain snaps…
Browse files Browse the repository at this point in the history
…hot [AP-681]
  • Loading branch information
jo-es committed Oct 6, 2020
1 parent 5979031 commit aaba6ba
Show file tree
Hide file tree
Showing 18 changed files with 58 additions and 144 deletions.
Binary file removed packages/ap-contracts/ap-chain-snapshot.tar.gz
Binary file not shown.
21 changes: 21 additions & 0 deletions packages/ap-contracts/ap-chain/addresses.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"ANNEngine": "0x0c662f6Cf73d547EdBF6f19be14665a050062Cc4",
"CECEngine": "0xdC73265D46b7a36263499ef042880AC2e804BD7b",
"CEGEngine": "0xCA386B0fD4f446aA61957f87d0A1630042255b37",
"CERTFEngine": "0x1725b9c802415a25202B3Da4A33E0631f44BBbf2",
"PAMEngine": "0xAC68a00bB798C3923210909244Eb900E76D4726A",
"ANNRegistry": "0x54aF1553Ea0D564E1B45FFe3EB1Bca85F0703331",
"CECRegistry": "0x1B3B145d4234Cd48EA33ABdD333F6E62767960A2",
"CEGRegistry": "0xE82F1D585DBC1D3B2068487206d39CdAe3590e4A",
"CERTFRegistry": "0xA240Ee48f8dD44CdEeAC513C6fd6739F0C6bE46c",
"PAMRegistry": "0x89E5C5d824F63add4Bb7E17cA7B9BA462CD51A70",
"DataRegistry": "0x77A94244ED2F9137ee2BB6A71D79C3188f86c3Cd",
"ANNActor": "0xCD4359f9AB7070d825fe0311d86Abc689c09A6fC",
"CECActor": "0x456458C2Ae55a573E54B120Ff2BFe04655a20C78",
"CEGActor": "0xf8a1BfCC2d1d5FaD14B04BE317bf84C272560a62",
"CERTFActor": "0x0B84EcC3cb862E82e6F6A687BBeEdC8866B8DebD",
"PAMActor": "0x5f1bC4808153b95aed8537C0ba57bc1034a97196",
"Custodian": "0x5DB04e348C343027993618A15Ae7Ba285dda1708",
"FDTFactory": "0x48AB3b2Fc6D667BC89Ab7f078C99CC707059023E",
"DvPSettlement": "0x309F3F86051E1589f7d662A2F9D49d92dF1F4B16"
}
Binary file added packages/ap-contracts/ap-chain/snapshot.tar.gz
Binary file not shown.
4 changes: 2 additions & 2 deletions packages/ap-contracts/build/contracts/ANNActor.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions packages/ap-contracts/build/contracts/ANNEngine.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions packages/ap-contracts/build/contracts/ANNSTF.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions packages/ap-contracts/build/contracts/CEGActor.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions packages/ap-contracts/build/contracts/CERTFActor.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions packages/ap-contracts/build/contracts/Dependencies.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"contractName": "Dependencies",
"abi": [],
"bytecode": "0x6080604052348015600f57600080fd5b50603f80601d6000396000f3fe6080604052600080fdfea26469706673582212202ff482f12a39a86dbf793de8c7b99afae427f34f14ee5278ebb2472a269ceb2564736f6c634300060b0033",
"deployedBytecode": "0x6080604052600080fdfea26469706673582212202ff482f12a39a86dbf793de8c7b99afae427f34f14ee5278ebb2472a269ceb2564736f6c634300060b0033",
"bytecode": "0x6080604052348015600f57600080fd5b50603f80601d6000396000f3fe6080604052600080fdfea26469706673582212204550622570ea3f7ddb891a5a0f9ba7d2c99a1fd03c0eae26c6cfdfd146be4dd264736f6c634300060b0033",
"deployedBytecode": "0x6080604052600080fdfea26469706673582212204550622570ea3f7ddb891a5a0f9ba7d2c99a1fd03c0eae26c6cfdfd146be4dd264736f6c634300060b0033",
"linkReferences": {},
"deployedLinkReferences": {}
}
4 changes: 2 additions & 2 deletions packages/ap-contracts/build/contracts/PAMActor.json

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion packages/ap-contracts/deploy/0-include-tags-to-migrate.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ module.exports.dependencies = [
"_balance", // assert deployer balance
"_deployment", // deploy contracts
"_init", // init contracts
"_export", // update '../deployments.js'
"_verification", // do contract verification
];
Original file line number Diff line number Diff line change
@@ -1,37 +1,34 @@
const fs = require("fs");
const path = require('path');

module.exports = updateDeploymentsJson;
module.exports = updateAddressesJson;
module.exports.tags = ["_export"];
module.exports.dependencies = ["_env", "_deployment"];

/** @param {import('./1-extend-buidler-env').ExtendedBRE} buidlerRuntime */
async function updateDeploymentsJson(buidlerRuntime) {
async function updateAddressesJson(buidlerRuntime) {

const { deployments: { log }, usrNs: { chainId, package: { contracts }}} = buidlerRuntime;

if (!chainId || !contracts) {
throw new Error("unexpected Buidler Runtime Environment");
throw new Error('Unexpected Buidler Runtime Environment');
}

// store addresses for ap-chain in ap-chain-snapshot
const deploymentsFile = (chainId !== '1994')
? path.resolve(__dirname, '../', 'deployments.json')
: path.resolve(__dirname, '../ap-chain-snapshot', 'deployments.json');
const addressesFile = path.resolve(__dirname, '../ap-chain', 'addresses.json');

if (!fs.existsSync(deploymentsFile)) {
fs.writeFileSync(deploymentsFile, JSON.stringify({}, null, 2), { encoding: 'utf-8', flag: 'w'});
if (!fs.existsSync(addressesFile)) {
fs.writeFileSync(addressesFile, JSON.stringify({}, null, 2), { encoding: 'utf-8', flag: 'w'});
}

const deployments = JSON.parse(fs.readFileSync(deploymentsFile, 'utf8'));
let addresses = JSON.parse(fs.readFileSync(addressesFile, 'utf8'));

/** @type {import('./3-deploy-contracts').ContractsListDeployedItem[]} deployed */
const deployed = contracts;
deployments[chainId] = deployed.reduce(
addresses = deployed.reduce(
(acc, { name, deployable = true, exportable = true, deployment }) => {
if (deployable && exportable) {
acc[name] = deployment.address;
if (!acc[name]) throw new Error('unexpected address');
if (!acc[name]) throw new Error('Undefined address');
}
return acc;
},
Expand All @@ -40,12 +37,12 @@ async function updateDeploymentsJson(buidlerRuntime) {

await new Promise(
(res, rej) => fs.writeFile(
deploymentsFile,
JSON.stringify(deployments, null, 2),
addressesFile,
JSON.stringify(addresses, null, 2),
{ encoding: 'utf8', flag: 'w' },
(err) => {
if (err) return rej(err);
log(`deployments.json saved`);
log(`addresses.json saved`);
res();
}
)
Expand Down
86 changes: 0 additions & 86 deletions packages/ap-contracts/deployments.json

This file was deleted.

6 changes: 3 additions & 3 deletions packages/ap-contracts/scripts/setup-ap-chain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ npx --quiet ganache-cli \
--gasLimit "8000000" \
--defaultBalanceEther "5000000000" \
--deterministic --mnemonic "helmet copy pause hood gun soon fork drum educate curious despair embrace" \
`if [[ $* == *--take-snapshot* ]]; then echo --db "./ap-chain-snapshot/db"; fi` \
`if [[ $* == *--take-snapshot* ]]; then echo --db "./ap-chain/snapshot"; fi` \
1>/dev/null &

ganache_pid=$!
Expand All @@ -32,8 +32,8 @@ fi

if [[ $* == *--take-snapshot* ]]; then
sleep 3
tar -zcf ap-chain-snapshot.tar.gz ap-chain-snapshot
rm -r ap-chain-snapshot
tar -zcf ap-chain/snapshot.tar.gz ap-chain/snapshot
rm -r ap-chain/snapshot
echo "✓ created snapshot"
exit 0
fi
Expand Down
4 changes: 2 additions & 2 deletions packages/ap.js/__tests__/apis/Contracts.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Web3 from 'web3';

// @ts-ignore
import Deployments from '@atpar/ap-contracts/deployments.json';
import ADDRESS_BOOK from '@atpar/ap-contracts/ap-chain/addresses.json';

import { Contracts } from '../../src/apis';
import { AddressBook } from '../../src/types';
Expand All @@ -18,7 +18,7 @@ describe('Contracts', (): void => {
web3 = new Web3(new Web3.providers.WebsocketProvider('ws://localhost:8545'));

// @ts-ignore
addressBook = Deployments[await web3.eth.net.getId()];
addressBook = ADDRESS_BOOK;
});

it('should instantiate ContractsAPI', async (): Promise<void> => {
Expand Down
4 changes: 2 additions & 2 deletions packages/ap.js/__tests__/apis/Utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Web3 from 'web3';

// @ts-ignore
import Deployments from '@atpar/ap-contracts/deployments.json';
import ADDRESS_BOOK from '@atpar/ap-contracts/ap-chain/addresses.json';

import { Utils, Contracts } from '../../src/apis';
import { Terms, isPAMTerms, isANNTerms, isCERTFTerms, isCECTerms, isCEGTerms } from '../../src/types';
Expand All @@ -19,7 +19,7 @@ describe('Utils', (): void => {
web3 = new Web3(new Web3.providers.WebsocketProvider('ws://localhost:8545'));

// @ts-ignore
const addressBook = Deployments[await web3.eth.net.getId()];
const addressBook = ADDRESS_BOOK;
contracts = new Contracts(web3, addressBook);
});

Expand Down
10 changes: 2 additions & 8 deletions packages/ap.js/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Web3 from 'web3';
import { AP } from '../src';

// @ts-ignore
import Deployments from '@atpar/ap-contracts/deployments.json';
import ADDRESS_BOOK from '@atpar/ap-contracts/ap-chain/addresses.json';


describe('APClass', (): void => {
Expand All @@ -15,15 +15,9 @@ describe('APClass', (): void => {
web3 = new Web3(new Web3.providers.WebsocketProvider('ws://localhost:8545'));
});

it('should initialize ap.js', async (): Promise<void> => {
const ap = await AP.init(web3);

expect(ap instanceof AP).toBe(true);
});

it('should initialize ap.js with a custom addressbook', async (): Promise<void> => {
// @ts-ignore
const addressbook = Deployments[await web3.eth.net.getId()];
const addressbook = ADDRESS_BOOK;

const ap = await AP.init(web3, addressbook);

Expand Down
15 changes: 2 additions & 13 deletions packages/ap.js/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Web3 from 'web3';
import Deployments from '@atpar/ap-contracts/deployments.json';

import * as APTypes from './types';

Expand All @@ -26,27 +25,17 @@ export class AP {
/**
* Returns a new AP instance.
* @param {Web3} web3 Web3 instance
* @param {AddressBook?} addressBook object containing custom addresses for ap-contracts (overwrites default addresses)
* @param {AddressBook} addressBook object containing addresses for ap-contracts
* @returns {Promise<AP>}
*/
public static async init (
web3: Web3,
addressBook?: APTypes.AddressBook
addressBook: APTypes.AddressBook
): Promise<AP> {
if (!(await web3.eth.net.isListening())) {
throw(new Error('Could not establish connection to Ethereum node.'));
}

if (addressBook == undefined) {
const netId = await web3.eth.net.getId();
// @ts-ignore
if (Deployments[netId] == undefined) {
throw new Error('Contracts are not deployed on current network.');
}
// @ts-ignore
addressBook = Deployments[netId] as AddressBook;
}

const contracts = new Contracts(web3, addressBook);

return new AP(web3, contracts);
Expand Down

0 comments on commit aaba6ba

Please sign in to comment.