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

221 - EVM interact core POC #227

Draft
wants to merge 2 commits into
base: dev
Choose a base branch
from
Draft
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
176 changes: 175 additions & 1 deletion .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions remove-me-12390190201f4f6388f2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
12390190201f4f6388f2
26 changes: 26 additions & 0 deletions toolchains/solidity/extension/.osmium/contracts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"contracts": [
{
"name": "Contract 1",
"address": "0xabcabcabcabcabcabca",
"abi": [
{
"constant": true,
"inputs": [],
"name": "name",
"outputs": [
{
"name": "",
"type": "string"
}
],
"payable": false,
"type": "function"
}
],
"chain": "ETH", // viem chain
"rpc": "https://mainnet.infura.io/v3/1234567890", // viem public rpc url
"usedWallet": "0xabcabcabcabcabcabca"
}
]
}
23 changes: 23 additions & 0 deletions toolchains/solidity/extension/.osmium/wallets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"wallets": [
{
"name": "wallet1",
"address": "0x1234567890",
"privateKey": "0x1234567890",
"rpc": "http://localhost:8545"
},
]
}

/*

WalletRepository: interaction avec wallets.json
CotnractsRepository: interaction avec contracts.json
Interact:
- async createContract(name, abi, address, rpc)
- async getContractsInfo -> liste des contrats(name, liste fonctions, adresse)
- async getWalletsInfos -> liste des wallets(name, adresse, balance)
- async createWallet(name, pKey or mnemonic, rpc)
- async readContract(addresse contrat, nom fonction, parametres)
- async writeContract(addresse contrat, nom fonction, parametres, adresse wallet, gas limit, value)

1 change: 1 addition & 0 deletions toolchains/solidity/extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"extension:publish": "yarn run package && vsce publish --no-dependencies"
},
"dependencies": {
"viem": "^2.0.6",
"vscode-languageclient": "^8.1.0",
"vscode-languageserver": "^8.1.0",
"vscode-languageserver-textdocument": "^1.0.8"
Expand Down
54 changes: 54 additions & 0 deletions toolchains/solidity/extension/src/actions/ContractRepository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import * as path from 'path';
import * as fs from 'fs';
import { Chain, Abi } from 'viem';

export interface Contract {
name: string;
address: `0x${string}`;
abi: Abi;
chain: Chain;
rpc: `ws://${string}` | `wss://${string}` | `http://${string}` | `https://${string}`;
usedWallet: `0x${string}`;
}

export type Contracts = Contract[];

export class ContractRepository
{
private _contracts: Contracts = [];
private _contractsPath: string;

constructor(workspacePath: string) {
this._contractsPath = path.join(workspacePath, '.osmium', 'contracts.json');
this._load();
}

private _load(): void {
if (!fs.existsSync(this._contractsPath)) {
this._contracts = [];
fs.writeFileSync(this._contractsPath, JSON.stringify({ contracts: this._contracts }));
} else {
const raw = fs.readFileSync(this._contractsPath);
const json = JSON.parse(raw.toString());
this._contracts = json.contracts;
}
}

private _save(): void {
const json = JSON.stringify({ contracts: this._contracts });
fs.writeFileSync(this._contractsPath, json, { encoding: 'utf-8' });
}

getContracts(): Contracts {
return this._contracts;
}

getContract(name: Contract['address']): Contract | undefined {
return this._contracts.find(c => c.address === name);
}

createContract(contract: Contract): void {
this._contracts.push(contract);
this._save();
}
}
Loading
Loading