Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: upgrade sdk, expose aci #35

Merged
merged 1 commit into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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