generated from thepiwo/aeproject-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
6,529 additions
and
544 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.