Skip to content

Commit

Permalink
Add local configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
TorstenStueber committed Oct 8, 2024
1 parent b1e0921 commit 18133a2
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 5 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ debug-project
debug-contracts
target-debug
solang-mac-arm

.yarn
.yarn
nabla/excluded
localConfig.json
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ The `deploy` command takes two required arguments:
- `mockTestnet`: described [on Notion](https://www.notion.so/satoshipay/24-09-30-Nabla-Foucoco-Paseo-Deployment-1118b1b29b2f804eababf94383a56f7b)
- `slippageTest`: used for validating slippage calulcations, see [this page on Notion](https://www.notion.so/satoshipay/24-09-30-Public-Deployment-1118b1b29b2f807283dbd10e0a6ae8b9?pvs=4#1158b1b29b2f80bc8be8efb7bc5197b4)

# Required
# Setup

```
brew install binaryen
Expand All @@ -31,6 +31,17 @@ brew install binaryen

You can find the installation instructions for solang [here](https://solang.readthedocs.io/en/v0.3.3/installing.html).

## Setup local configuration

Create a file `localConfig.json` in the root folder of this repository and add the following content:

```
{
"solangPath": "path/to/your/solang/binary"
}
```

### Build from source

If you want to test a specific version, you can build solang from source.
Expand Down
2 changes: 1 addition & 1 deletion nabla/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"init": "npm"
},
"pendulumWrappers": {
"git": "https://github.com/pendulum-chain/pendulum-ink-wrapper",
"git": "https://github.com/pendulum-chain/pendulum-solidity-wrapper",
"branch": "master"
}
},
Expand Down
5 changes: 4 additions & 1 deletion src/actions/compileContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { runCommand } from "../utils/childProcess";
import { ContractSourcecodeId } from "../types";
import { ContractDeploymentState } from "../processScripts";
import { Project } from "../project";
import { getLocalConfiguration } from "../utils/localConfiguration";

export async function compileContract(
contractId: ContractSourcecodeId,
Expand Down Expand Up @@ -72,9 +73,11 @@ async function actuallyCompileContract(
return metadataFileName;
}

const { solangPath } = await getLocalConfiguration();

updateContractStatus("compiling");
const solangResult = await runCommand([
"../clones/solang/target/release/solang",
solangPath,
"compile",
"--no-strength-reduce", // temporary fix for https://github.com/hyperledger/solang/issues/1507
"--target",
Expand Down
30 changes: 30 additions & 0 deletions src/utils/localConfiguration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { readFile } from "fs/promises";
import { join } from "path";

export interface LocalConfiguration {
solangPath: string;
}

const DEFAULT_LOCAL_CONFIGURATION: LocalConfiguration = {
solangPath: "solang",
};

let localConfiguration: LocalConfiguration | undefined = undefined;

export async function getLocalConfiguration(): Promise<LocalConfiguration> {
if (localConfiguration !== undefined) {
return localConfiguration;
}

const localConfigurationFile = join(import.meta.dirname, "../../localConfig.json");

try {
const localConfigurationContent = await readFile(localConfigurationFile, { encoding: "utf-8" });
const parsedLocalConfiguration = JSON.parse(localConfigurationContent) as LocalConfiguration;
localConfiguration = { ...DEFAULT_LOCAL_CONFIGURATION, ...parsedLocalConfiguration };
return localConfiguration;
} catch {
localConfiguration = DEFAULT_LOCAL_CONFIGURATION;
return localConfiguration;
}
}

0 comments on commit 18133a2

Please sign in to comment.