Skip to content

Commit

Permalink
line length 100
Browse files Browse the repository at this point in the history
  • Loading branch information
mrbonezy committed Jun 8, 2022
1 parent e1f3ff9 commit 3ed14f0
Show file tree
Hide file tree
Showing 23 changed files with 448 additions and 126 deletions.
23 changes: 11 additions & 12 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ name: Node.js CI

on:
push:
branches: [ "main" ]
branches: ["main"]
pull_request:
branches: [ "main" ]
branches: ["main"]

jobs:
build:

runs-on: ubuntu-latest

strategy:
Expand All @@ -20,12 +19,12 @@ jobs:
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
# - run: npm run build --if-present
- run: npm test
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: "npm"
- run: npm ci
# - run: npm run build --if-present
- run: npm test
4 changes: 1 addition & 3 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
{

}
{}
36 changes: 29 additions & 7 deletions build/_build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ async function main() {
let funcVersion = "";
try {
funcVersion = child_process.execSync("func -V").toString();
} catch (e) {/*ignore*/}
} catch (e) {
/*ignore*/
}
if (!funcVersion.includes("Func build information")) {
console.log("\nFATAL ERROR: 'func' executable is not found, is it installed and in path?");
process.exit(1);
Expand Down Expand Up @@ -87,15 +89,26 @@ async function main() {
const crc = crc32(tlbOpMessage);
const asQuery = `0x${(crc & 0x7fffffff).toString(16)}`;
const asResponse = `0x${((crc | 0x80000000) >>> 0).toString(16)}`;
console.log(` op '${tlbOpMessage.split(" ")[0]}': '${asQuery}' as query (&0x7fffffff), '${asResponse}' as response (|0x80000000)`);
console.log(
` op '${
tlbOpMessage.split(" ")[0]
}': '${asQuery}' as query (&0x7fffffff), '${asResponse}' as response (|0x80000000)`
);
}
} else {
console.log(` - Warning: TL-B file for contract '${tlbFile}' not found, are your op consts according to standard?`);
console.log(
` - Warning: TL-B file for contract '${tlbFile}' not found, are your op consts according to standard?`
);
}

// create a merged fc file with source code from all dependencies
let sourceToCompile = "";
const importFiles = glob.sync(["contracts/imports/*.fc", "contracts/imports/*.func", `contracts/imports/${contractName}/*.fc`, `contracts/imports/${contractName}/*.func`]);
const importFiles = glob.sync([
"contracts/imports/*.fc",
"contracts/imports/*.func",
`contracts/imports/${contractName}/*.fc`,
`contracts/imports/${contractName}/*.func`,
]);
for (const importFile of importFiles) {
console.log(` - Adding import '${importFile}'`);
sourceToCompile += `${fs.readFileSync(importFile).toString()}\n`;
Expand All @@ -107,7 +120,11 @@ async function main() {

// run the func compiler to create a fif file
console.log(` - Trying to compile '${mergedFuncArtifact}' with 'func' compiler..`);
const buildErrors = child_process.execSync(`func -APS -o build/${contractName}.fif ${mergedFuncArtifact} 2>&1 1>node_modules/.tmpfunc`).toString();
const buildErrors = child_process
.execSync(
`func -APS -o build/${contractName}.fif ${mergedFuncArtifact} 2>&1 1>node_modules/.tmpfunc`
)
.toString();
if (buildErrors.length > 0) {
console.log(" - OH NO! Compilation Errors! The compiler output was:");
console.log(`\n${buildErrors}`);
Expand All @@ -125,7 +142,7 @@ async function main() {
}

// create a temp cell.fif that will generate the cell
let fiftCellSource = "\"Asm.fif\" include\n";
let fiftCellSource = '"Asm.fif" include\n';
fiftCellSource += `${fs.readFileSync(fiftArtifact).toString()}\n`;
fiftCellSource += `boc>B "${cellArtifact}" B>file`;
fs.writeFileSync(fiftCellArtifact, fiftCellSource);
Expand All @@ -147,7 +164,12 @@ async function main() {
fs.unlinkSync(fiftCellArtifact);
}

fs.writeFileSync(hexArtifact, JSON.stringify({hex: Cell.fromBoc(fs.readFileSync(cellArtifact))[0].toBoc().toString("hex")}));
fs.writeFileSync(
hexArtifact,
JSON.stringify({
hex: Cell.fromBoc(fs.readFileSync(cellArtifact))[0].toBoc().toString("hex"),
})
);

// make sure hex artifact was created
if (!fs.existsSync(hexArtifact)) {
Expand Down
97 changes: 80 additions & 17 deletions build/_deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,17 @@ dotenv.config();
import fs from "fs";
import path from "path";
import glob from "fast-glob";
import { Address, Cell, CellMessage, CommonMessageInfo, fromNano, InternalMessage, StateInit, toNano, WalletV3R1Source } from "ton";
import {
Address,
Cell,
CellMessage,
CommonMessageInfo,
fromNano,
InternalMessage,
StateInit,
toNano,
WalletV3R1Source,
} from "ton";
import { TonClient, WalletContract, WalletV3R2Source, contractAddress, SendMode } from "ton";
import { mnemonicNew, mnemonicToWalletKey } from "ton-crypto";

Expand All @@ -24,13 +34,17 @@ async function main() {

// check input arguments (given through environment variables)
if (process.env.TESTNET || process.env.npm_lifecycle_event == "deploy:testnet") {
console.log(`\n* We are working with 'testnet' (https://t.me/testgiver_ton_bot will give you test TON)`);
console.log(
`\n* We are working with 'testnet' (https://t.me/testgiver_ton_bot will give you test TON)`
);
} else {
console.log(`\n* We are working with 'mainnet'`);
}

// initialize globals
const client = new TonClient({ endpoint: `https://${process.env.TESTNET ? "testnet." : ""}toncenter.com/api/v2/jsonRPC` });
const client = new TonClient({
endpoint: `https://${process.env.TESTNET ? "testnet." : ""}toncenter.com/api/v2/jsonRPC`,
});
const deployerWalletType = "org.ton.wallets.v3.r1"; // also see WalletV3R2Source class used below
const newContractFunding = toNano(0.02); // this will be (almost in full) the balance of a new deployed contract and allow it to pay rent
const workchain = 0; // normally 0, only special contracts should be deployed to masterchain (-1)
Expand All @@ -39,7 +53,9 @@ async function main() {
const deployConfigEnv = ".env";
let deployerMnemonic;
if (!fs.existsSync(deployConfigEnv) || !process.env.DEPLOYER_MNEMONIC) {
console.log(`\n* Config file '${deployConfigEnv}' not found, creating a new wallet for deploy..`);
console.log(
`\n* Config file '${deployConfigEnv}' not found, creating a new wallet for deploy..`
);
deployerMnemonic = (await mnemonicNew(24)).join(" ");
const deployWalletEnvContent = `DEPLOYER_WALLET=${deployerWalletType}\nDEPLOYER_MNEMONIC="${deployerMnemonic}"\n`;
fs.writeFileSync(deployConfigEnv, deployWalletEnvContent);
Expand All @@ -52,11 +68,18 @@ async function main() {
// open the wallet and make sure it has enough TON
const walletKey = await mnemonicToWalletKey(deployerMnemonic.split(" "));
// TODO specify wallet type?
const walletContract = WalletContract.create(client, WalletV3R1Source.create({ publicKey: walletKey.publicKey, workchain }));
const walletContract = WalletContract.create(
client,
WalletV3R1Source.create({ publicKey: walletKey.publicKey, workchain })
);
console.log(` - Wallet address used to deploy from is: ${walletContract.address.toFriendly()}`);
const walletBalance = await client.getBalance(walletContract.address);
if (walletBalance.lt(toNano(0.2))) {
console.log(` - ERROR: Wallet has less than 0.2 TON for gas (${fromNano(walletBalance)} TON), please send some TON for gas first`);
console.log(
` - ERROR: Wallet has less than 0.2 TON for gas (${fromNano(
walletBalance
)} TON), please send some TON for gas first`
);
process.exit(1);
} else {
console.log(` - Wallet balance is ${fromNano(walletBalance)} TON, which will be used for gas`);
Expand Down Expand Up @@ -93,11 +116,25 @@ async function main() {
const initCodeCell = Cell.fromBoc(fs.readFileSync(cellArtifact))[0];

// make sure the contract was not already deployed
const newContractAddress = contractAddress({ workchain, initialData: initDataCell, initialCode: initCodeCell });
console.log(` - Based on your init code+data, your new contract address is: ${newContractAddress.toFriendly()}`);
const newContractAddress = contractAddress({
workchain,
initialData: initDataCell,
initialCode: initCodeCell,
});
console.log(
` - Based on your init code+data, your new contract address is: ${newContractAddress.toFriendly()}`
);
if (await client.isContractDeployed(newContractAddress)) {
console.log(` - Looks like the contract is already deployed in this address, skipping deployment`);
await performPostDeploymentTest(rootContract, deployInitScript, walletContract, walletKey.secretKey, newContractAddress);
console.log(
` - Looks like the contract is already deployed in this address, skipping deployment`
);
await performPostDeploymentTest(
rootContract,
deployInitScript,
walletContract,
walletKey.secretKey,
newContractAddress
);
continue;
}

Expand All @@ -122,20 +159,38 @@ async function main() {
console.log(` - Deploy transaction sent successfully`);

// make sure that the contract was deployed
console.log(` - Block explorer link: https://${process.env.TESTNET ? "test." : ""}tonwhales.com/explorer/address/${newContractAddress.toFriendly()}`);
console.log(
` - Block explorer link: https://${
process.env.TESTNET ? "test." : ""
}tonwhales.com/explorer/address/${newContractAddress.toFriendly()}`
);
console.log(` - Waiting up to 20 seconds to check if the contract was actually deployed..`);
for (let attempt = 0; attempt < 10; attempt++) {
await sleep(2000);
const seqnoAfter = await walletContract.getSeqNo();
if (seqnoAfter > seqno) break;
}
if (await client.isContractDeployed(newContractAddress)) {
console.log(` - SUCCESS! Contract deployed successfully to address: ${newContractAddress.toFriendly()}`);
console.log(
` - SUCCESS! Contract deployed successfully to address: ${newContractAddress.toFriendly()}`
);
const contractBalance = await client.getBalance(newContractAddress);
console.log(` - New contract balance is now ${fromNano(contractBalance)} TON, make sure it has enough to pay rent`);
await performPostDeploymentTest(rootContract, deployInitScript, walletContract, walletKey.secretKey, newContractAddress);
console.log(
` - New contract balance is now ${fromNano(
contractBalance
)} TON, make sure it has enough to pay rent`
);
await performPostDeploymentTest(
rootContract,
deployInitScript,
walletContract,
walletKey.secretKey,
newContractAddress
);
} else {
console.log(` - FAILURE! Contract address still looks uninitialized: ${newContractAddress.toFriendly()}`);
console.log(
` - FAILURE! Contract address still looks uninitialized: ${newContractAddress.toFriendly()}`
);
}
}

Expand All @@ -150,9 +205,17 @@ function sleep(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms));
}

async function performPostDeploymentTest(rootContract: string, deployInitScript: any, walletContract: WalletContract, secretKey: Buffer, newContractAddress: Address) {
async function performPostDeploymentTest(
rootContract: string,
deployInitScript: any,
walletContract: WalletContract,
secretKey: Buffer,
newContractAddress: Address
) {
if (typeof deployInitScript.postDeployTest !== "function") {
console.log(` - Not running a post deployment test, '${rootContract}' does not have 'postDeployTest()' function`);
console.log(
` - Not running a post deployment test, '${rootContract}' does not have 'postDeployTest()' function`
);
return;
}
console.log(` - Running a post deployment test:`);
Expand Down
12 changes: 9 additions & 3 deletions build/_setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,17 @@ if (fs.existsSync("/app/.glitchdotcom.json")) {
// make sure we're installed once
if (!fs.existsSync("/app/bin")) {
child_process.execSync(`mkdir bin`);
child_process.execSync(`wget https://github.com/ton-defi-org/ton-binaries/releases/download/ubuntu-16/fift -P ./bin`);
child_process.execSync(
`wget https://github.com/ton-defi-org/ton-binaries/releases/download/ubuntu-16/fift -P ./bin`
);
child_process.execSync(`chmod +x ./bin/fift`);
child_process.execSync(`wget https://github.com/ton-defi-org/ton-binaries/releases/download/ubuntu-16/func -P ./bin`);
child_process.execSync(
`wget https://github.com/ton-defi-org/ton-binaries/releases/download/ubuntu-16/func -P ./bin`
);
child_process.execSync(`chmod +x ./bin/func`);
child_process.execSync(`wget https://github.com/ton-defi-org/ton-binaries/releases/download/fiftlib/fiftlib.zip -P ./bin`);
child_process.execSync(
`wget https://github.com/ton-defi-org/ton-binaries/releases/download/fiftlib/fiftlib.zip -P ./bin`
);
child_process.execSync(`unzip ./bin/fiftlib.zip -d ./bin/fiftlib`);
}
}
4 changes: 3 additions & 1 deletion build/jetton-minter-hex.json
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
{"hex":"b5ee9c72c1020b010001ed000000000d00120018002a006b007000bc01390152016c0114ff00f4a413f4bcf2c80b01020162050202037a600403001faf16f6a2687d007d206a6a183faa9040007dadbcf6a2687d007d206a6a183618fc1400b82a1009aa0a01e428027d012c678b00e78b666491646580897a007a00658064fc80383a6465816503e5ffe4e8400202cc07060093b3f0508806e0a84026a8280790a009f404b19e2c039e2d99924591960225e801e80196019241f200e0e9919605940f97ff93a0ef003191960ab19e2ca009f4042796d625999992e3f60103efd9910e38048adf068698180b8d848adf07d201800e98fe99ff6a2687d007d206a6a18400aa9385d47181a9aa8aae382f9702480fd207d006a18106840306b90fd001812881a28217804d02a906428027d012c678b666664f6aa7041083deecbef29385d71811a92e001f1811802600271812f82c207f97840a0908002e5143c705f2e049d43001c85004fa0258cf16ccccc9ed5400303515c705f2e049fa403059c85004fa0258cf16ccccc9ed5400fe3603fa00fa40f82854120870542013541403c85004fa0258cf1601cf16ccc922c8cb0112f400f400cb00c9f9007074c8cb02ca07cbffc9d05008c705f2e04a12a1035024c85004fa0258cf16ccccc9ed5401fa403020d70b01c3008e1f8210d53276db708010c8cb055003cf1622fa0212cb6acb1fcb3fc98042fb00915be2cc665c46"}
{
"hex": "b5ee9c72c1020b010001ed000000000d00120018002a006b007000bc01390152016c0114ff00f4a413f4bcf2c80b01020162050202037a600403001faf16f6a2687d007d206a6a183faa9040007dadbcf6a2687d007d206a6a183618fc1400b82a1009aa0a01e428027d012c678b00e78b666491646580897a007a00658064fc80383a6465816503e5ffe4e8400202cc07060093b3f0508806e0a84026a8280790a009f404b19e2c039e2d99924591960225e801e80196019241f200e0e9919605940f97ff93a0ef003191960ab19e2ca009f4042796d625999992e3f60103efd9910e38048adf068698180b8d848adf07d201800e98fe99ff6a2687d007d206a6a18400aa9385d47181a9aa8aae382f9702480fd207d006a18106840306b90fd001812881a28217804d02a906428027d012c678b666664f6aa7041083deecbef29385d71811a92e001f1811802600271812f82c207f97840a0908002e5143c705f2e049d43001c85004fa0258cf16ccccc9ed5400303515c705f2e049fa403059c85004fa0258cf16ccccc9ed5400fe3603fa00fa40f82854120870542013541403c85004fa0258cf1601cf16ccc922c8cb0112f400f400cb00c9f9007074c8cb02ca07cbffc9d05008c705f2e04a12a1035024c85004fa0258cf16ccccc9ed5401fa403020d70b01c3008e1f8210d53276db708010c8cb055003cf1622fa0212cb6acb1fcb3fc98042fb00915be2cc665c46"
}
4 changes: 3 additions & 1 deletion build/jetton-wallet-hex.json
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
{"hex":"b5ee9c72c1021201000328000000000d001200220027002c00700075007a00ea016b01a801b101eb026902b802bd02c80114ff00f4a413f4bcf2c80b010201620302001ba0f605da89a1f401f481f481a8610202cc0f0402012006050083d40106b90f6a2687d007d207d206a1802698fc1080bc6a28ca9105d41083deecbef09dd0958f97162e99f98fd001809d02811e428027d012c678b00e78b6664f6aa40201200d07020120090800db3b51343e803e903e90350c01f4cffe803e900c145468549271c17cb8b049f0bffcb8b0a0822625a02a8005a805af3cb8b0e0841ef765f7b232c7c572cfd400fe8088b3c58073c5b25c60063232c14933c59c3e80b2dab33260103ec01004f214013e809633c58073c5b3327b552003f73b51343e803e903e90350c0234cffe80145468017e903e9014d6f1c1551cdb5c150804d50500f214013e809633c58073c5b33248b232c044bd003d0032c0327e401c1d3232c0b281f2fff274140371c1472c7cb8b0c2be80146a2860822625a020822625a004ad822860822625a028062849f8c3c975c2c070c008e00c0b0a0076c200b08e218210d53276db708010c8cb055008cf165004fa0216cb6a12cb1f12cb3fc972fb0093356c21e203c85004fa0258cf1601cf16ccc9ed54000e10491038375f0400705279a018a182107362d09cc8cb1f5230cb3f58fa025007cf165007cf16c9718018c8cb0524cf165006fa0215cb6a14ccc971fb001024102301f5503d33ffa00fa4021f001ed44d0fa00fa40fa40d4305136a1522ac705f2e2c128c2fff2e2c254344270542013541403c85004fa0258cf1601cf16ccc922c8cb0112f400f400cb00c920f9007074c8cb02ca07cbffc9d004fa40f40431fa00778018c8cb055008cf1670fa0217cb6b13cc8210178d4519c8cb1f1980e009acb3f5007fa0222cf165006cf1625fa025003cf16c95005cc2391729171e25008a813a08208989680aa008208989680a0a014bcf2e2c504c98040fb001023c85004fa0258cf1601cf16ccc9ed540201d4111000113e910c1c2ebcb8536000bb0831c02497c138007434c0c05c6c2544d7c0fc03383e903e900c7e800c5c75c87e800c7e800c00b4c7e08403e29fa954882ea54c4d167c0278208405e3514654882ea58c511100fc02b80d60841657c1ef2ea4d67c02f817c12103fcbc20c2d0bee8"}
{
"hex": "b5ee9c72c1021201000328000000000d001200220027002c00700075007a00ea016b01a801b101eb026902b802bd02c80114ff00f4a413f4bcf2c80b010201620302001ba0f605da89a1f401f481f481a8610202cc0f0402012006050083d40106b90f6a2687d007d207d206a1802698fc1080bc6a28ca9105d41083deecbef09dd0958f97162e99f98fd001809d02811e428027d012c678b00e78b6664f6aa40201200d07020120090800db3b51343e803e903e90350c01f4cffe803e900c145468549271c17cb8b049f0bffcb8b0a0822625a02a8005a805af3cb8b0e0841ef765f7b232c7c572cfd400fe8088b3c58073c5b25c60063232c14933c59c3e80b2dab33260103ec01004f214013e809633c58073c5b3327b552003f73b51343e803e903e90350c0234cffe80145468017e903e9014d6f1c1551cdb5c150804d50500f214013e809633c58073c5b33248b232c044bd003d0032c0327e401c1d3232c0b281f2fff274140371c1472c7cb8b0c2be80146a2860822625a020822625a004ad822860822625a028062849f8c3c975c2c070c008e00c0b0a0076c200b08e218210d53276db708010c8cb055008cf165004fa0216cb6a12cb1f12cb3fc972fb0093356c21e203c85004fa0258cf1601cf16ccc9ed54000e10491038375f0400705279a018a182107362d09cc8cb1f5230cb3f58fa025007cf165007cf16c9718018c8cb0524cf165006fa0215cb6a14ccc971fb001024102301f5503d33ffa00fa4021f001ed44d0fa00fa40fa40d4305136a1522ac705f2e2c128c2fff2e2c254344270542013541403c85004fa0258cf1601cf16ccc922c8cb0112f400f400cb00c920f9007074c8cb02ca07cbffc9d004fa40f40431fa00778018c8cb055008cf1670fa0217cb6b13cc8210178d4519c8cb1f1980e009acb3f5007fa0222cf165006cf1625fa025003cf16c95005cc2391729171e25008a813a08208989680aa008208989680a0a014bcf2e2c504c98040fb001023c85004fa0258cf1601cf16ccc9ed540201d4111000113e910c1c2ebcb8536000bb0831c02497c138007434c0c05c6c2544d7c0fc03383e903e900c7e800c5c75c87e800c7e800c00b4c7e08403e29fa954882ea54c4d167c0278208405e3514654882ea58c511100fc02b80d60841657c1ef2ea4d67c02f817c12103fcbc20c2d0bee8"
}
Loading

0 comments on commit 3ed14f0

Please sign in to comment.