Skip to content
This repository was archived by the owner on Jul 3, 2024. It is now read-only.

Commit 9f05ff5

Browse files
feat(solidity/extension): interact backend POC
1 parent 86284de commit 9f05ff5

File tree

8 files changed

+519
-1
lines changed

8 files changed

+519
-1
lines changed

.pnp.cjs

+175-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"contracts": [
3+
{
4+
"name": "Contract 1",
5+
"address": "0xabcabcabcabcabcabca",
6+
"abi": [
7+
{
8+
"constant": true,
9+
"inputs": [],
10+
"name": "name",
11+
"outputs": [
12+
{
13+
"name": "",
14+
"type": "string"
15+
}
16+
],
17+
"payable": false,
18+
"type": "function"
19+
}
20+
],
21+
"chain": "ETH", // viem chain
22+
"rpc": "https://mainnet.infura.io/v3/1234567890", // viem public rpc url
23+
"usedWallet": "0xabcabcabcabcabcabca"
24+
}
25+
]
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"wallets": [
3+
{
4+
"name": "wallet1",
5+
"address": "0x1234567890",
6+
"privateKey": "0x1234567890",
7+
"rpc": "http://localhost:8545"
8+
},
9+
]
10+
}
11+
12+
/*
13+
14+
WalletRepository: interaction avec wallets.json
15+
CotnractsRepository: interaction avec contracts.json
16+
Interact:
17+
- async createContract(name, abi, address, rpc)
18+
- async getContractsInfo -> liste des contrats(name, liste fonctions, adresse)
19+
- async getWalletsInfos -> liste des wallets(name, adresse, balance)
20+
- async createWallet(name, pKey or mnemonic, rpc)
21+
- async readContract(addresse contrat, nom fonction, parametres)
22+
- async writeContract(addresse contrat, nom fonction, parametres, adresse wallet, gas limit, value)
23+

toolchains/solidity/extension/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
"extension:publish": "yarn run package && vsce publish --no-dependencies"
7171
},
7272
"dependencies": {
73+
"viem": "^2.0.6",
7374
"vscode-languageclient": "^8.1.0",
7475
"vscode-languageserver": "^8.1.0",
7576
"vscode-languageserver-textdocument": "^1.0.8"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import * as path from 'path';
2+
import * as fs from 'fs';
3+
import { Chain, Abi } from 'viem';
4+
5+
export interface Contract {
6+
name: string;
7+
address: `0x${string}`;
8+
abi: Abi;
9+
chain: Chain;
10+
rpc: `ws://${string}` | `wss://${string}` | `http://${string}` | `https://${string}`;
11+
usedWallet: `0x${string}`;
12+
}
13+
14+
export type Contracts = Contract[];
15+
16+
export class ContractRepository
17+
{
18+
private _contracts: Contracts = [];
19+
private _contractsPath: string;
20+
21+
constructor(workspacePath: string) {
22+
this._contractsPath = path.join(workspacePath, '.osmium', 'contracts.json');
23+
this._load();
24+
}
25+
26+
private _load(): void {
27+
if (!fs.existsSync(this._contractsPath)) {
28+
this._contracts = [];
29+
fs.writeFileSync(this._contractsPath, JSON.stringify({ contracts: this._contracts }));
30+
} else {
31+
const raw = fs.readFileSync(this._contractsPath);
32+
const json = JSON.parse(raw.toString());
33+
this._contracts = json.contracts;
34+
}
35+
}
36+
37+
private _save(): void {
38+
const json = JSON.stringify({ contracts: this._contracts });
39+
fs.writeFileSync(this._contractsPath, json, { encoding: 'utf-8' });
40+
}
41+
42+
getContracts(): Contracts {
43+
return this._contracts;
44+
}
45+
46+
getContract(name: Contract['address']): Contract | undefined {
47+
return this._contracts.find(c => c.address === name);
48+
}
49+
50+
createContract(contract: Contract): void {
51+
this._contracts.push(contract);
52+
this._save();
53+
}
54+
}

0 commit comments

Comments
 (0)