This repository has been archived by the owner on Jul 3, 2024. It is now read-only.
-
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.
feat(solidity/extension): interact backend POC
- Loading branch information
1 parent
c1ed290
commit a9007ac
Showing
8 changed files
with
519 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,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" | ||
} | ||
] | ||
} |
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,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) | ||
|
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
54 changes: 54 additions & 0 deletions
54
toolchains/solidity/extension/src/actions/ContractRepository.ts
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,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(); | ||
} | ||
} |
Oops, something went wrong.