Skip to content

Commit

Permalink
chore: update sdk, expose aci
Browse files Browse the repository at this point in the history
  • Loading branch information
thepiwo committed Apr 30, 2024
1 parent c0a6ac5 commit acf9950
Show file tree
Hide file tree
Showing 27 changed files with 6,529 additions and 544 deletions.
13 changes: 8 additions & 5 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@master
- name: Use Node.js 14.x
uses: actions/setup-node@v1
uses: actions/checkout@v4
- name: Use Node.js 20.x
uses: actions/setup-node@v4
with:
node-version: 14.x
node-version: 20.x
- run: npm install -g @aeternity/aeproject
- run: npm install
- run: aeproject env
- run: npm test
- run: aeproject test
- run: |
npm run generate-bytecode-aci-hashes
git diff --exit-code
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
node_modules
.aeproject-store
.DS_Store
package-lock.json
*.iml
.idea

*.aes.js
generated/*.aes.js
92 changes: 92 additions & 0 deletions .scripts/generate-bytecode-aci-hashes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
const { utils, networks } = require("@aeternity/aeproject");
const fs = require("fs");
const crypto = require("crypto");
const path = require("path");
const { CompilerHttp, hash, getFileSystem} = require("@aeternity/aepp-sdk");

// add contract paths from base
const CONTRACTS = [
"TokenSale.aes",
"TokenVoting.aes",
"WordRegistry.aes",
"FungibleTokenCustom.aes",
];

function generateSourceHashes() {
const hashes = CONTRACTS.reduce((acc, contract) => {
const source = fs.readFileSync("./contracts/" + contract, "utf-8");
acc[contract] = Buffer.from(hash(source)).toString("base64");
return acc;
}, {});

fs.writeFileSync(
"./generated/source_hashes.json",
JSON.stringify(hashes, null, 2),
);
}

function writeAci(aci, contract) {
fs.writeFileSync(
`${__dirname}/../generated/${path.basename(contract, ".aes")}.aci.json`,
JSON.stringify(aci, null, 2),
"utf-8",
);
}

async function generateBytecodeAci() {
const aeSdk = await utils.getSdk();

const bytecode_hashes = await CONTRACTS.reduce(
async (promiseAcc, contract) => {
const acc = await promiseAcc;
const fileSystem = await getFileSystem(
"./contracts/" + contract,
);
let sourceCode = utils.getContractContent("./contracts/" + contract);

try {
const compiled = await aeSdk.compilerApi.compileBySourceCode(
sourceCode,
fileSystem,
);

const compilerVersion = await aeSdk.compilerApi.version();
if (!acc[compilerVersion]) acc[compilerVersion] = {};

acc[compilerVersion][contract] = {
hash: crypto
.createHash("sha256")
.update(compiled.bytecode)
.digest("hex"),
bytecode: compiled.bytecode,
};

writeAci(compiled.aci, contract);
} catch (e) {
console.log(
"falling back to just aci generation without compilation for",
contract,
e.message,
);

const compilerHttp = new CompilerHttp(networks.devmode.compilerUrl);
await compilerHttp
.generateAciBySourceCode(sourceCode, fileSystem)
.then((aci) => writeAci(aci, contract))
.catch(console.error);
}

return acc;
},
Promise.resolve({}),
);

fs.writeFileSync(
"./generated/bytecode_hashes.json",
JSON.stringify(bytecode_hashes, null, 2),
"utf-8",
);
}

generateSourceHashes();
void generateBytecodeAci();
19 changes: 3 additions & 16 deletions .scripts/postinstall.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,10 @@
const fs = require('fs');

const FungibleTokenCustom = fs.readFileSync(__dirname + '/../contracts/FungibleTokenCustom.aes', 'utf-8');
fs.writeFileSync(__dirname + '/../FungibleTokenCustom.aes.js', `module.exports = \`\n${FungibleTokenCustom.replace(/`/g, "\\`")}\`;\n`, 'utf-8');

const TokenSale = fs.readFileSync(__dirname + '/../contracts/TokenSale.aes', 'utf-8');
fs.writeFileSync(__dirname + '/../TokenSale.aes.js', `module.exports = \`\n${TokenSale.replace(/`/g, "\\`")}\`;\n`, 'utf-8');
fs.writeFileSync(__dirname + '/../generated/TokenSale.aes.js', `module.exports = \`\n${TokenSale.replace(/`/g, "\\`")}\`;\n`, 'utf-8');

const WordRegistry = fs.readFileSync(__dirname + '/../contracts/WordRegistry.aes', 'utf-8');
fs.writeFileSync(__dirname + '/../WordRegistry.aes.js', `module.exports = \`\n${WordRegistry.replace(/`/g, "\\`")}\`;\n`, 'utf-8');
fs.writeFileSync(__dirname + '/../generated/WordRegistry.aes.js', `module.exports = \`\n${WordRegistry.replace(/`/g, "\\`")}\`;\n`, 'utf-8');

const TokenVoting = fs.readFileSync(__dirname + '/../contracts/TokenVoting.aes', 'utf-8');
fs.writeFileSync(__dirname + '/../TokenVoting.aes.js', `module.exports = \`\n${TokenVoting.replace(/`/g, "\\`")}\`;\n`, 'utf-8');


const TokenSaleInterface = fs.readFileSync(__dirname + '/../contracts/interfaces/TokenSaleInterface.aes', 'utf-8');
fs.writeFileSync(__dirname + '/../TokenSaleInterface.aes.js', `module.exports = \`\n${TokenSaleInterface.replace(/`/g, "\\`")}\`;\n`, 'utf-8');

const TokenVotingInterface = fs.readFileSync(__dirname + '/../contracts/interfaces/TokenVotingInterface.aes', 'utf-8');
fs.writeFileSync(__dirname + '/../TokenVotingInterface.aes.js', `module.exports = \`\n${TokenVotingInterface.replace(/`/g, "\\`")}\`;\n`, 'utf-8');

const WordRegistryInterface = fs.readFileSync(__dirname + '/../contracts/interfaces/WordRegistryInterface.aes', 'utf-8');
fs.writeFileSync(__dirname + '/../WordRegistryInterface.aes.js', `module.exports = \`\n${WordRegistryInterface.replace(/`/g, "\\`")}\`;\n`, 'utf-8');
fs.writeFileSync(__dirname + '/../generated/TokenVoting.aes.js', `module.exports = \`\n${TokenVoting.replace(/`/g, "\\`")}\`;\n`, 'utf-8');
17 changes: 0 additions & 17 deletions config/network.json

This file was deleted.

44 changes: 0 additions & 44 deletions config/wallets.json

This file was deleted.

37 changes: 0 additions & 37 deletions contracts/interfaces/TokenSaleInterface.aes

This file was deleted.

48 changes: 0 additions & 48 deletions contracts/interfaces/TokenVotingInterface.aes

This file was deleted.

13 changes: 0 additions & 13 deletions contracts/interfaces/WordRegistryInterface.aes

This file was deleted.

31 changes: 0 additions & 31 deletions deployment/deploy-testnet.js

This file was deleted.

Loading

0 comments on commit acf9950

Please sign in to comment.