Skip to content

Commit

Permalink
chore: upgrade sdk, expose aci (wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
thepiwo committed Apr 29, 2024
1 parent be3b251 commit 6d54dfe
Show file tree
Hide file tree
Showing 26 changed files with 4,013 additions and 400 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,10 +1,9 @@
node_modules
.aeproject-store
.DS_Store
package-lock.json
*.iml
.idea
.data
data

*.aes.js
generated/*.aes.js
90 changes: 90 additions & 0 deletions .scripts/generate-bytecode-aci-hashes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
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 = [
"OracleGetter.aes",
"OracleService.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();
6 changes: 3 additions & 3 deletions .scripts/postinstall.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const fs = require('fs');

const oracleServiceInterface = fs.readFileSync(__dirname + '/../contracts/OracleServiceInterface.aes', 'utf-8');
fs.writeFileSync(__dirname + '/../OracleServiceInterface.aes.js', `module.exports = \`\n${oracleServiceInterface}\`;\n`, 'utf-8');
const oracleService = fs.readFileSync(__dirname + '/../contracts/OracleService.aes', 'utf-8');
fs.writeFileSync(__dirname + '/../generated/OracleService.aes.js', `module.exports = \`\n${oracleService}\`;\n`, 'utf-8');

const oracleGetter = fs.readFileSync(__dirname + '/../contracts/OracleGetter.aes', 'utf-8');
fs.writeFileSync(__dirname + '/../OracleGetter.aes.js', `module.exports = \`\n${oracleGetter}\`;\n`, 'utf-8');
fs.writeFileSync(__dirname + '/../generated/OracleGetter.aes.js', `module.exports = \`\n${oracleGetter}\`;\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.

4 changes: 2 additions & 2 deletions contracts/OracleGetter.aes
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ contract interface OracleService =
type oracle_query_tuples = list(oracle_type * oracle_query(string, string))

record success_claim = { success : bool, account : address, percentage : int }
record state = { trusted_oracles : map(int, oracle_type), trusted_oracle_seq : int, oracle_queries : map(string, oracle_query_tuples), minimum_amount_of_oracles : int, success_claimed_urls : map(string, success_claim), owner : address }
record state_workaround = { trusted_oracles : map(int, oracle_type), trusted_oracle_seq : int, oracle_queries : map(string, oracle_query_tuples), minimum_amount_of_oracles : int, success_claimed_urls : map(string, success_claim), owner : address }

entrypoint get_state : () => state
entrypoint get_state : () => state_workaround

main contract OracleGetter =

Expand Down
25 changes: 0 additions & 25 deletions contracts/OracleServiceInterface.aes

This file was deleted.

54 changes: 0 additions & 54 deletions deployment/deploy.js

This file was deleted.

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

This file was deleted.

7 changes: 0 additions & 7 deletions docker-compose.compiler.yml

This file was deleted.

Loading

0 comments on commit 6d54dfe

Please sign in to comment.