From 69104d9db30cf1aefd7000d10b979b66b3ea6068 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 19 Feb 2025 21:47:30 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=BF=D0=B8=D1=81=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/.npmrc | 3 + backend/package.json | 8 +- backend/yarn.lock | 43 +++-------- .../src/components/ContractInteraction.vue | 77 +++++++++++++++++-- 4 files changed, 90 insertions(+), 41 deletions(-) create mode 100644 backend/.npmrc diff --git a/backend/.npmrc b/backend/.npmrc new file mode 100644 index 0000000..b4b6289 --- /dev/null +++ b/backend/.npmrc @@ -0,0 +1,3 @@ +# Принудительно обновить все зависимости с уязвимостями +public-hoist-pattern[]=elliptic +public-hoist-pattern[]=secp256k1 \ No newline at end of file diff --git a/backend/package.json b/backend/package.json index fdf0365..a138f23 100644 --- a/backend/package.json +++ b/backend/package.json @@ -20,9 +20,15 @@ "hardhat": "^2.21.0", "@nomicfoundation/hardhat-ethers": "^3.0.5", "@nomicfoundation/hardhat-chai-matchers": "^2.0.0", - "@openzeppelin/contracts": "4.9.3", + "@openzeppelin/contracts": "^4.9.6", "chai": "4.3.7", "dotenv": "^16.4.7", + "elliptic": "^6.6.1", "ethers": "^6.11.1" + }, + "resolutions": { + "elliptic": "^6.6.1", + "secp256k1": "^5.0.0", + "cookie": "^0.7.0" } } diff --git a/backend/yarn.lock b/backend/yarn.lock index e59c129..08a17d4 100644 --- a/backend/yarn.lock +++ b/backend/yarn.lock @@ -371,10 +371,10 @@ "@nomicfoundation/solidity-analyzer-linux-x64-musl" "0.1.2" "@nomicfoundation/solidity-analyzer-win32-x64-msvc" "0.1.2" -"@openzeppelin/contracts@4.9.3": - version "4.9.3" - resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-4.9.3.tgz#00d7a8cf35a475b160b3f0293a6403c511099364" - integrity sha512-He3LieZ1pP2TNt5JbkPA4PNT9WC3gOTOlDcFGJW4Le4QKqwmiNJCRt44APfxMxvq7OugU/cqYuPcSBzOw38DAg== +"@openzeppelin/contracts@^4.9.6": + version "4.9.6" + resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-4.9.6.tgz#2a880a24eb19b4f8b25adc2a5095f2aa27f39677" + integrity sha512-xSmezSupL+y9VkHZJGDoCBpmnB2ogM13ccaYDWqJTfS3dbuHkgjuwDFUmaFauBCboQMGB/S5UqUl2y54X99BmA== "@scure/base@~1.1.0": version "1.1.9" @@ -955,21 +955,11 @@ cookie-signature@1.0.7: resolved "https://registry.yarnpkg.com/cookie-signature/-/cookie-signature-1.0.7.tgz#ab5dd7ab757c54e60f37ef6550f481c426d10454" integrity sha512-NXdYc3dLr47pBkpUCHtKSwIOQXLVn8dZEuywboCOJY/osA0wFSLlSawr3KN8qXJEyX66FcONTH8EIlVuK0yyFA== -cookie@0.7.1: - version "0.7.1" - resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.7.1.tgz#2f73c42142d5d5cf71310a74fc4ae61670e5dbc9" - integrity sha512-6DnInpx7SJ2AK3+CTUE/ZM0vWTUboZCegxhC2xiIydHR9jNuTAASBrfEpHhiGOZw/nX51bHt6YQl8jsGo4y/0w== - -cookie@0.7.2: +cookie@0.7.1, cookie@0.7.2, cookie@^0.4.1, cookie@^0.7.0: version "0.7.2" resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.7.2.tgz#556369c472a2ba910f2979891b526b3436237ed7" integrity sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w== -cookie@^0.4.1: - version "0.4.2" - resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.4.2.tgz#0e41f24de5ecf317947c82fc789e06a884824432" - integrity sha512-aSWTXFzaKWkvHO1Ny/s+ePFpvKsPnjc551iI41v3ny/ow6tBG5Vd+FuqGNhh1LxOmVzOlGUriIlOaokOvhaStA== - cors@^2.8.5: version "2.8.5" resolved "https://registry.yarnpkg.com/cors/-/cors-2.8.5.tgz#eac11da51592dd86b9f06f6e7ac293b3df875d29" @@ -1061,20 +1051,7 @@ ee-first@1.1.1: resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d" integrity sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow== -elliptic@6.5.4: - version "6.5.4" - resolved "https://registry.yarnpkg.com/elliptic/-/elliptic-6.5.4.tgz#da37cebd31e79a1367e941b592ed1fbebd58abbb" - integrity sha512-iLhC6ULemrljPZb+QutR5TQGB+pdW6KGD5RSegS+8sorOZT+rdQFbsQFJgvN3eRqNALqJer4oQ16YvJHlU8hzQ== - dependencies: - bn.js "^4.11.9" - brorand "^1.1.0" - hash.js "^1.0.0" - hmac-drbg "^1.0.1" - inherits "^2.0.4" - minimalistic-assert "^1.0.1" - minimalistic-crypto-utils "^1.0.1" - -elliptic@^6.5.2, elliptic@^6.5.7: +elliptic@6.5.4, elliptic@^6.5.2, elliptic@^6.5.7, elliptic@^6.6.1: version "6.6.1" resolved "https://registry.yarnpkg.com/elliptic/-/elliptic-6.6.1.tgz#3b8ffb02670bf69e382c7f65bf524c97c5405c06" integrity sha512-RaddvvMatK2LJHqFJ+YA4WysVN5Ita9E35botqIYspQ4TkRAlCicdzKOjlyv/1Za5RyTNn7di//eEV0uTAfe3g== @@ -2101,10 +2078,10 @@ scrypt-js@^3.0.0: resolved "https://registry.yarnpkg.com/scrypt-js/-/scrypt-js-3.0.1.tgz#d314a57c2aef69d1ad98a138a21fe9eafa9ee312" integrity sha512-cdwTTnqPu0Hyvf5in5asVdZocVDTNRmR7XEcJuIzMjJeSHybHl7vpB66AzwTaIg6CLSbtjcxc8fqcySfnTkccA== -secp256k1@^4.0.1: - version "4.0.4" - resolved "https://registry.yarnpkg.com/secp256k1/-/secp256k1-4.0.4.tgz#58f0bfe1830fe777d9ca1ffc7574962a8189f8ab" - integrity sha512-6JfvwvjUOn8F/jUoBY2Q1v5WY5XS+rj8qSe0v8Y4ezH4InLgTEeOOPQsRll9OV429Pvo6BCHGavIyJfr3TAhsw== +secp256k1@^4.0.1, secp256k1@^5.0.0: + version "5.0.1" + resolved "https://registry.yarnpkg.com/secp256k1/-/secp256k1-5.0.1.tgz#dc2c86187d48ff2da756f0f7e96417ee03c414b1" + integrity sha512-lDFs9AAIaWP9UCdtWrotXWWF9t8PWgQDcxqgAnpM9rMqxb3Oaq2J0thzPVSxBwdJgyQtkU/sYtFtbM1RSt/iYA== dependencies: elliptic "^6.5.7" node-addon-api "^5.0.0" diff --git a/frontend/src/components/ContractInteraction.vue b/frontend/src/components/ContractInteraction.vue index 00206bf..8635d87 100644 --- a/frontend/src/components/ContractInteraction.vue +++ b/frontend/src/components/ContractInteraction.vue @@ -107,12 +107,50 @@ const SEPOLIA_CHAIN_ID = 11155111 const provider = new JsonRpcProvider(import.meta.env.VITE_APP_ETHEREUM_NETWORK_URL) const contractAddress = '0xFF7602583E82C097Ae548Fc8B894F0a73089985E' const contractABI = [ - 'function purchase(uint256 amount) payable', - 'function price() view returns (uint256)', - 'function owner() view returns (address)', - 'function setPrice(uint256 newPrice) public', - 'function withdraw() public', - 'event Purchase(address buyer, uint256 amount)' + { + "inputs": [{"internalType": "uint256", "name": "amount", "type": "uint256"}], + "name": "purchase", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [], + "name": "price", + "outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "owner", + "outputs": [{"internalType": "address", "name": "", "type": "address"}], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{"internalType": "uint256", "name": "newPrice", "type": "uint256"}], + "name": "setPrice", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "withdraw", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "anonymous": false, + "inputs": [ + {"indexed": false, "internalType": "address", "name": "buyer", "type": "address"}, + {"indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256"} + ], + "name": "Purchase", + "type": "event" + } ] // Вычисляемые свойства @@ -323,11 +361,27 @@ async function handlePurchase() { const contract = new Contract(contractAddress, contractABI, signer) const totalCost = calculateTotalCost() + + // Проверяем баланс + const balance = await ethersProvider.getBalance(await signer.getAddress()) + console.log('Баланс кошелька:', formatEther(balance), 'ETH') + + if (balance < totalCost) { + throw new Error(`Недостаточно средств. Нужно ${formatEther(totalCost)} ETH`) + } + console.log('Общая стоимость:', formatEther(totalCost), 'ETH') + console.log('Параметры транзакции:', { + amount: amount.value, + totalCost: formatEther(totalCost), + from: await signer.getAddress() + }) const tx = await contract.purchase(amount.value, { - value: totalCost + value: totalCost, + gasLimit: 100000 // Явно указываем лимит газа }) + console.log('Транзакция отправлена:', tx.hash) await tx.wait() console.log('Транзакция подтверждена') @@ -337,8 +391,17 @@ async function handlePurchase() { await fetchPrice() } catch (err) { console.error('Ошибка при покупке:', err) + console.error('Детали ошибки:', { + code: err.code, + message: err.message, + data: err.data, + reason: err.reason + }) + if (err.message.includes('user rejected')) { error.value = 'Транзакция отменена пользователем' + } else if (err.message.includes('Недостаточно средств')) { + error.value = err.message } else { error.value = 'Произошла ошибка при совершении покупки: ' + err.message }